From f674aa0fd2809126debdaaeb8067067790d86907 Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Thu, 1 Aug 2019 15:56:25 +0100 Subject: IVGCVSW-3277 Mem export/import suppor for Tensors * Rename MemoryStrategy to EdgeStrategy * Add MemImportLayer * Import memory rather than copy when possible Change-Id: I1d3a9414f2cbe517dc2aae9bbd4fdd92712b38ef Signed-off-by: Derek Lamberti --- src/backends/reference/RefLayerSupport.cpp | 150 +---------------------------- 1 file changed, 1 insertion(+), 149 deletions(-) (limited to 'src/backends/reference/RefLayerSupport.cpp') diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index d42404d25b..187cc01c77 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -65,155 +66,6 @@ std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected, } // anonymous namespace -namespace -{ -template -bool CheckSupportRule(F rule, Optional reasonIfUnsupported, const char* reason) -{ - bool supported = rule(); - if (!supported && reason) - { - reasonIfUnsupported.value() += std::string(reason) + "\n"; // Append the reason on a new line - } - return supported; -} - -struct Rule -{ - bool operator()() const - { - return m_Res; - } - - bool m_Res = true; -}; - -template -bool AllTypesAreEqualImpl(T t) -{ - return true; -} - -template -bool AllTypesAreEqualImpl(T t1, T t2, Rest... rest) -{ - static_assert(std::is_same::value, "Type T must be a TensorInfo"); - - return (t1.GetDataType() == t2.GetDataType()) && AllTypesAreEqualImpl(t2, rest...); -} - -struct TypesAreEqual : public Rule -{ - template - TypesAreEqual(const Ts&... ts) - { - m_Res = AllTypesAreEqualImpl(ts...); - } -}; - -struct QuantizationParametersAreEqual : public Rule -{ - QuantizationParametersAreEqual(const TensorInfo& info0, const TensorInfo& info1) - { - m_Res = info0.GetQuantizationScale() == info1.GetQuantizationScale() && - info0.GetQuantizationOffset() == info1.GetQuantizationOffset(); - } -}; - -struct TypeAnyOf : public Rule -{ - template - TypeAnyOf(const TensorInfo& info, const Container& c) - { - m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) - { - return dt == info.GetDataType(); - }); - } -}; - -struct TypeIs : public Rule -{ - TypeIs(const TensorInfo& info, DataType dt) - { - m_Res = dt == info.GetDataType(); - } -}; - -struct BiasAndWeightsTypesMatch : public Rule -{ - BiasAndWeightsTypesMatch(const TensorInfo& biases, const TensorInfo& weights) - { - m_Res = biases.GetDataType() == GetBiasTypeFromWeightsType(weights.GetDataType()).value(); - } -}; - -struct BiasAndWeightsTypesCompatible : public Rule -{ - template - BiasAndWeightsTypesCompatible(const TensorInfo& info, const Container& c) - { - m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) - { - return dt == GetBiasTypeFromWeightsType(info.GetDataType()).value(); - }); - } -}; - -struct ShapesAreSameRank : public Rule -{ - ShapesAreSameRank(const TensorInfo& info0, const TensorInfo& info1) - { - m_Res = info0.GetShape().GetNumDimensions() == info1.GetShape().GetNumDimensions(); - } -}; - -struct ShapesAreSameTotalSize : public Rule -{ - ShapesAreSameTotalSize(const TensorInfo& info0, const TensorInfo& info1) - { - m_Res = info0.GetNumElements() == info1.GetNumElements(); - } -}; - -struct ShapesAreBroadcastCompatible : public Rule -{ - unsigned int CalcInputSize(const TensorShape& in, const TensorShape& out, unsigned int idx) - { - unsigned int offset = out.GetNumDimensions() - in.GetNumDimensions(); - unsigned int sizeIn = (idx < offset) ? 1 : in[idx-offset]; - return sizeIn; - } - - ShapesAreBroadcastCompatible(const TensorInfo& in0, const TensorInfo& in1, const TensorInfo& out) - { - const TensorShape& shape0 = in0.GetShape(); - const TensorShape& shape1 = in1.GetShape(); - const TensorShape& outShape = out.GetShape(); - - for (unsigned int i=0; i < outShape.GetNumDimensions() && m_Res; i++) - { - unsigned int sizeOut = outShape[i]; - unsigned int sizeIn0 = CalcInputSize(shape0, outShape, i); - unsigned int sizeIn1 = CalcInputSize(shape1, outShape, i); - - m_Res &= ((sizeIn0 == sizeOut) || (sizeIn0 == 1)) && - ((sizeIn1 == sizeOut) || (sizeIn1 == 1)); - } - } -}; - -struct TensorNumDimensionsAreCorrect : public Rule -{ - TensorNumDimensionsAreCorrect(const TensorInfo& info, unsigned int expectedNumDimensions) - { - m_Res = info.GetNumDimensions() == expectedNumDimensions; - } -}; - -} // namespace - - bool RefLayerSupport::IsActivationSupported(const TensorInfo& input, const TensorInfo& output, const ActivationDescriptor& descriptor, -- cgit v1.2.1