From fce86cd9581e7ba746d1ec75bbd67dd35d35d11c Mon Sep 17 00:00:00 2001 From: Zhou Wang Date: Thu, 20 Oct 2016 16:46:14 +0200 Subject: [PATCH] Move primitiveOpNames out from PrimitiveOpTypeName(), as local static variables are not thread-safe under VS2013. --- Source/CNTKv2LibraryDll/Function.h | 102 +++++++++++++++-------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/Source/CNTKv2LibraryDll/Function.h b/Source/CNTKv2LibraryDll/Function.h index e811a4987..967d3949c 100644 --- a/Source/CNTKv2LibraryDll/Function.h +++ b/Source/CNTKv2LibraryDll/Function.h @@ -28,58 +28,60 @@ namespace std namespace CNTK { + // Move primitiveOpNames out from PrimitiveOpTypeName(), as local static variables are not thread-safe under VS2013. + // Todo: Move it into PrimitiveOpTypeName() as local static after upgraded to VS2015. + static const std::unordered_map primitiveOpNames = { + {PrimitiveOpType::Negate, L"Negate"}, + {PrimitiveOpType::Sigmoid, L"Sigmoid"}, + {PrimitiveOpType::Tanh, L"Tanh"}, + {PrimitiveOpType::ReLU, L"ReLU"}, + {PrimitiveOpType::Exp, L"Exp"}, + {PrimitiveOpType::Log, L"Log"}, + {PrimitiveOpType::Sqrt, L"Sqrt"}, + {PrimitiveOpType::Floor, L"Floor"}, + {PrimitiveOpType::Abs, L"Abs"}, + {PrimitiveOpType::Reciprocal, L"Reciprocal"}, + {PrimitiveOpType::Softmax, L"Softmax"}, + {PrimitiveOpType::Hardmax, L"Hardmax"}, + {PrimitiveOpType::TransposeAxes, L"TransposeAxes"}, + {PrimitiveOpType::Where, L"Where"}, + {PrimitiveOpType::Slice, L"Slice"}, + {PrimitiveOpType::Dropout, L"Dropout"}, + {PrimitiveOpType::Reshape, L"Reshape"}, + {PrimitiveOpType::Pooling, L"Pooling"}, + {PrimitiveOpType::SumAll, L"SumAll"}, + {PrimitiveOpType::Plus, L"Plus"}, + {PrimitiveOpType::Minus, L"Minus"}, + {PrimitiveOpType::ElementTimes, L"ElementTimes"}, + {PrimitiveOpType::Equal, L"Equal"}, + {PrimitiveOpType::NotEqual, L"NotEqual"}, + {PrimitiveOpType::Less, L"Less"}, + {PrimitiveOpType::LessEqual, L"LessEqual"}, + {PrimitiveOpType::Greater, L"Greater"}, + {PrimitiveOpType::GreaterEqual, L"GreaterEqual"}, + {PrimitiveOpType::PackedIndex, L"PackedIndex"}, + {PrimitiveOpType::GatherPacked, L"GatherPacked"}, + {PrimitiveOpType::ScatterPacked, L"ScatterPacked"}, + {PrimitiveOpType::Times, L"Times"}, + {PrimitiveOpType::TransposeTimes, L"TransposeTimes"}, + {PrimitiveOpType::Convolution, L"Convolution"}, + {PrimitiveOpType::SquaredError, L"SquaredError"}, + {PrimitiveOpType::CrossEntropyWithSoftmax, L"CrossEntropyWithSoftmax"}, + {PrimitiveOpType::ClassificationError, L"ClassificationError"}, + {PrimitiveOpType::PastValue, L"PastValue"}, + {PrimitiveOpType::FutureValue, L"FutureValue"}, + {PrimitiveOpType::ReduceElements, L"ReduceElements"}, + {PrimitiveOpType::BatchNormalization, L"BatchNormalization"}, + {PrimitiveOpType::Clip, L"Clip"}, + {PrimitiveOpType::Select, L"Select"}, + {PrimitiveOpType::Splice, L"Splice"}, + {PrimitiveOpType::Combine, L"Combine"}, + {PrimitiveOpType::RandomSample, L"RandomSample"}, + {PrimitiveOpType::RandomSampleInclusionFrequency, L"RandomSampleInclusionFrequency"}, + }; + inline const std::wstring& PrimitiveOpTypeName(PrimitiveOpType opType) { - static const std::unordered_map primitiveOpNames = { - { PrimitiveOpType::Negate, L"Negate" }, - { PrimitiveOpType::Sigmoid, L"Sigmoid" }, - { PrimitiveOpType::Tanh, L"Tanh" }, - { PrimitiveOpType::ReLU, L"ReLU" }, - { PrimitiveOpType::Exp, L"Exp" }, - { PrimitiveOpType::Log, L"Log" }, - { PrimitiveOpType::Sqrt, L"Sqrt" }, - { PrimitiveOpType::Floor, L"Floor" }, - { PrimitiveOpType::Abs, L"Abs" }, - { PrimitiveOpType::Reciprocal, L"Reciprocal" }, - { PrimitiveOpType::Softmax, L"Softmax" }, - { PrimitiveOpType::Hardmax, L"Hardmax" }, - { PrimitiveOpType::TransposeAxes, L"TransposeAxes" }, - { PrimitiveOpType::Where, L"Where" }, - { PrimitiveOpType::Slice, L"Slice" }, - { PrimitiveOpType::Dropout, L"Dropout" }, - { PrimitiveOpType::Reshape, L"Reshape" }, - { PrimitiveOpType::Pooling, L"Pooling" }, - { PrimitiveOpType::SumAll, L"SumAll" }, - { PrimitiveOpType::Plus, L"Plus" }, - { PrimitiveOpType::Minus, L"Minus" }, - { PrimitiveOpType::ElementTimes, L"ElementTimes" }, - { PrimitiveOpType::Equal, L"Equal" }, - { PrimitiveOpType::NotEqual, L"NotEqual" }, - { PrimitiveOpType::Less, L"Less" }, - { PrimitiveOpType::LessEqual, L"LessEqual" }, - { PrimitiveOpType::Greater, L"Greater" }, - { PrimitiveOpType::GreaterEqual, L"GreaterEqual" }, - { PrimitiveOpType::PackedIndex, L"PackedIndex" }, - { PrimitiveOpType::GatherPacked, L"GatherPacked" }, - { PrimitiveOpType::ScatterPacked, L"ScatterPacked" }, - { PrimitiveOpType::Times, L"Times" }, - { PrimitiveOpType::TransposeTimes, L"TransposeTimes" }, - { PrimitiveOpType::Convolution, L"Convolution" }, - { PrimitiveOpType::SquaredError, L"SquaredError" }, - { PrimitiveOpType::CrossEntropyWithSoftmax, L"CrossEntropyWithSoftmax" }, - { PrimitiveOpType::ClassificationError, L"ClassificationError" }, - { PrimitiveOpType::PastValue, L"PastValue" }, - { PrimitiveOpType::FutureValue, L"FutureValue" }, - { PrimitiveOpType::ReduceElements, L"ReduceElements" }, - { PrimitiveOpType::BatchNormalization, L"BatchNormalization" }, - { PrimitiveOpType::Clip, L"Clip" }, - { PrimitiveOpType::Select, L"Select" }, - { PrimitiveOpType::Splice, L"Splice" }, - { PrimitiveOpType::Combine, L"Combine" }, - { PrimitiveOpType::RandomSample, L"RandomSample" }, - { PrimitiveOpType::RandomSampleInclusionFrequency, L"RandomSampleInclusionFrequency" }, - }; - if (primitiveOpNames.find(opType) == primitiveOpNames.end()) LogicError("Unknown PrimitiveOpType");