24.02
|
Go to the documentation of this file.
15 namespace optimizations
29 ReplaceConstDequantisationLayer(graph,
30 PolymorphicDowncast<ConstantLayer*>(&base),
31 PolymorphicDowncast<DequantizeLayer*>(&child));
39 static void ReplaceConstDequantisationLayer(
Graph&,
43 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl::ReplaceConstDequantisationLayer()";
53 bool requiresPermute =
false;
66 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: Connected to "
68 auto conv2dLayer = PolymorphicDowncast<Convolution2dLayer*>(&connection->GetOwningLayer());
71 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: Connected to "
72 "Convolution layer and requires permute on weights. ";
73 requiresPermute =
true;
85 std::vector<float> newValues(outputDequantizeInfo.
GetNumElements());
90 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: Converting FP16 -> FP32";
101 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: Converting INT8 -> FP32";
109 TensorInfo newInfo = outputDequantizeInfo;
113 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: Permuting the constant data.";
114 const PermutationVector OHWIToOIHW = {0, 2, 3, 1};
115 std::vector<float> permutedValues(outputDequantizeInfo.
GetNumElements());
117 newValues.data(), permutedValues.data(),
119 ConstTensor newInput(newInfo, permutedValues);
120 constantLayer->
m_LayerOutput.reset(
new ScopedTensorHandle(newInput));
124 ConstTensor newInput(newInfo, newValues);
125 constantLayer->
m_LayerOutput.reset(
new ScopedTensorHandle(newInput));
137 for (
unsigned int i = numConnections; i < constantLayer->
GetOutputSlot(0).GetNumConnections(); ++i)
148 static void ConvertInt8To32(
const void* srcInt8Buffer,
151 const int32_t offset,
152 float* dstFloat32Buffer)
157 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: scale: " << scale;
158 ARMNN_LOG(info) <<
"ConvertConstDequantisationLayersToConstLayersImpl:: offset: " << offset;
160 const auto* pInt8 =
static_cast<const int8_t*
>(srcInt8Buffer);
162 for (
size_t i = 0; i < numElements; ++i)
164 dstFloat32Buffer[i] =
static_cast<float>(pInt8[i] - offset) * scale;
171 = OptimizeForConnection<ConstantLayer,
#define ARMNN_ASSERT(COND)
unsigned int GetNumElements() const
const TensorInfo & GetTensorInfo() const override
ConvertConstDequantisationLayersToConstLayersImpl()=default
void SetTensorInfo(const TensorInfo &tensorInfo) override
float GetQuantizationScale() const
constexpr const char * GetDataTypeName(DataType dataType)
OptimizeForConnection< ConstantLayer, DequantizeLayer, ConvertConstDequantisationLayersToConstLayersImpl > ConvertConstDequantisationLayersToConstLayers
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
#define ARMNN_LOG(severity)
Layer & GetOwningLayer() const
unsigned int GetNumConnections() const override
static void ConvertFloat16To32(const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
~ConvertConstDequantisationLayersToConstLayersImpl()=default
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
This layer dequantizes the input tensor.
constexpr unsigned int GetDataTypeSize(DataType dataType)
DataType GetDataType() const
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
const TensorShape & GetShape() const
std::shared_ptr< ConstTensorHandle > m_LayerOutput
void Run(Graph &graph, InputSlot &connection) const
A layer that the constant data can be bound to.
Copyright (c) 2021 ARM Limited and Contributors.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
int32_t GetQuantizationOffset() const
const InputSlot * GetConnection(unsigned int index) const override