23 template <
typename ArrayType,
typename Arg>
24 void AssignValues(
unsigned int num,
unsigned int& idx,
const ArrayType& array, Arg& arg)
31 arg = array[(num - 1) - idx];
35 template <
typename T,
typename ArrayType,
typename... Args>
36 void AssignValues(
unsigned int num,
unsigned int idx,
const ArrayType& array, T& assignee, Args&... args)
38 AssignValues(num, idx, array, assignee);
40 AssignValues(num, idx, array, args...);
45 template <
typename CopyFunc>
54 const auto srcSize = srcTensor->
GetStrides()[0] * srcShape[0];
57 const auto dstSize = dstTensor->
GetStrides()[0] * dstShape[0];
60 size_t srcBatches = 1;
63 size_t srcChannels = 1;
73 size_t srcDepthStride = 0;
74 size_t srcBatchStride = 0;
75 size_t srcHeightStride = 0;
76 size_t srcWidthStride = 0;
77 size_t srcChannelStride = 0;
88 size_t dstBatches = 1;
91 size_t dstChannels = 1;
101 size_t dstDepthStride = 0;
102 size_t dstBatchStride = 0;
103 size_t dstHeightStride = 0;
104 size_t dstWidthStride = 0;
105 size_t dstChannelStride = 0;
115 const unsigned char* srcDataStart;
116 unsigned char* dstDataStart;
119 srcDataStart =
static_cast<const uint8_t*
>(srcTensor->
Map());
120 dstDataStart =
static_cast<uint8_t*
>(dstTensor->
Map());
122 if (srcDataStart ==
nullptr)
126 if (dstDataStart ==
nullptr)
131 size_t copyLength = std::min(srcChannels * srcChannelStride, dstChannels * dstChannelStride);
132 size_t copyWidth = std::min(srcWidth, dstWidth);
133 size_t copyHeight = std::min(srcHeight, dstHeight);
134 size_t copyBatches = std::min(srcBatches, dstBatches);
135 size_t copyDepth = std::min(srcDepth, dstDepth);
140 if (copyLength == srcWidthStride &&
141 copyLength == dstWidthStride)
145 copyLength *= copyWidth;
148 if (copyLength == srcHeightStride &&
149 copyLength == dstHeightStride)
153 copyLength *= copyHeight;
158 const unsigned char* srcData = srcDataStart;
159 unsigned char* dstData = dstDataStart;
160 for (
unsigned int d = 0; d < copyDepth; ++d)
162 auto srcPtrDepth = srcData;
163 auto dstPtrDepth = dstData;
164 for (
unsigned int b = 0; b < copyBatches; ++b)
166 auto srcPtrBatch = srcData;
167 auto dstPtrBatch = dstData;
168 for (
unsigned int h = 0; h < copyHeight; ++h)
170 auto srcPtrChannel = srcData;
171 auto dstPtrChannel = dstData;
172 for (
unsigned int w = 0; w < copyWidth; ++w)
175 if (copyLength > srcSize)
178 "The source tensor size does not match the size of the allocated tensor.");
180 if (copyLength > dstSize)
183 "The destination tensor size will overrun the destination tensor.");
185 copy(dstData, srcData, copyLength);
186 dstData += dstWidthStride;
187 srcData += srcWidthStride;
189 dstData += (
static_cast<long>(dstHeightStride) - (dstData - dstPtrChannel));
190 srcData += (
static_cast<long>(srcHeightStride) - (srcData - srcPtrChannel));
192 dstData += (
static_cast<long>(dstBatchStride) - (dstData - dstPtrBatch));
193 srcData += (
static_cast<long>(srcBatchStride) - (srcData - srcPtrBatch));
195 dstData += (
static_cast<long>(dstDepthStride) - (dstData - dstPtrDepth));
196 srcData += (
static_cast<long>(srcDepthStride) - (srcData - srcPtrDepth));
203 template <
typename SrcTensorHandleType,
typename DstTensorHandleType,
typename DescriptorType>
205 std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs)
207 const unsigned int numInputs =
static_cast<unsigned int>(descriptor.m_Inputs.size());
208 tensorHandlePairs.reserve(numInputs);
210 for (
unsigned int i = 0; i < numInputs; ++i)
212 SrcTensorHandleType*
const srcTensorHandle =
213 PolymorphicDowncast<SrcTensorHandleType*>(descriptor.m_Inputs[i]);
214 DstTensorHandleType*
const dstTensorHandle =
215 PolymorphicDowncast<DstTensorHandleType*>(descriptor.m_Outputs[i]);
217 tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle);
224 const PermutationVector& permutationVector,
225 void* permuteBuffer);
236 const TensorInfo& inputInfo,
241 void* permuteBuffer);
253 const TensorInfo& inputInfo,
255 void* permuteBuffer);
264 std::tuple<ConstTensor, unsigned int>
Convert1HWOtoMIHW(
const ConstTensorHandle* weightTensor,
265 const TensorInfo& inputInfo,
267 void* permuteBuffer);