MCPcopy Create free account
hub / github.com/ARM-software/armnn / TransposeLoop

Class TransposeLoop

src/armnnUtils/Transpose.cpp:17–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15{
16
17class TransposeLoop
18{
19public:
20 using size_type = unsigned int;
21
22 TransposeLoop(const armnn::TensorShape& srcShape, const armnn::PermutationVector& mappings)
23 : m_SrcShape(srcShape)
24 {
25 if (srcShape.GetNumDimensions() != mappings.GetSize())
26 {
27 std::stringstream msg;
28 msg << "Transpose: Number of shape dimensions (" << srcShape.GetNumDimensions() <<
29 ") does not match the size of the mappings (" << mappings.GetSize() << ")";
30 throw armnn::InvalidArgumentException(msg.str());
31 }
32
33 const size_type numDims = srcShape.GetNumDimensions();
34
35 size_type srcStride = 1U;
36 size_type dstStride = 1U;
37
38 for (size_type i = numDims - 1U, k = 0U; k < numDims; ++k, --i)
39 {
40 m_SrcStrides[i] = srcStride;
41 m_DstStrides[mappings[i]] = dstStride;
42
43 srcStride *= srcShape[i];
44 dstStride *= srcShape[mappings[i]];
45 }
46 }
47
48 void Unroll(const void* srcData, void* dstData, size_t dataTypeSize)
49 {
50 if (srcData == nullptr)
51 {
52 throw armnn::Exception("Transpose: Source Data pointer is null");
53 }
54 if (dstData == nullptr)
55 {
56 throw armnn::Exception("Transpose: Destination Data pointer is null");
57 }
58 if (dataTypeSize == 0)
59 {
60 throw armnn::Exception("Transpose: dataTypeSize is zero");
61 }
62
63 const unsigned char* srcDataPtr = reinterpret_cast<const unsigned char*>(srcData);
64 unsigned char* dstDataPtr = reinterpret_cast<unsigned char*>(dstData);
65
66 const unsigned char* const srcEndPtr = srcDataPtr + m_SrcShape.GetNumElements() * dataTypeSize;
67 unsigned char* const dstEndPtr = dstDataPtr + m_SrcShape.GetNumElements() * dataTypeSize;
68
69 Unroll(0, srcDataPtr, dstDataPtr, srcEndPtr, dstEndPtr, dataTypeSize);
70 }
71
72private:
73 void Unroll(size_type dimension,
74 const unsigned char* srcData, unsigned char* dstData,

Callers 1

TransposeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected