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 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);
138 if(copyLength != srcSize &&
139 srcSize != dstSize &&
140 srcWidthStride == copyLength &&
141 srcWidthStride == dstSize)
144 srcWidthStride = dstWidthStride;
150 if (copyLength == srcWidthStride &&
151 copyLength == dstWidthStride)
155 copyLength *= copyWidth;
158 if (copyLength == srcHeightStride &&
159 copyLength == dstHeightStride)
163 copyLength *= copyHeight;
168 const unsigned char* srcData = srcDataStart;
169 unsigned char* dstData = dstDataStart;
170 for (
unsigned int d = 0; d < copyDepth; ++d)
172 auto srcPtrDepth = srcData;
173 auto dstPtrDepth = dstData;
174 for (
unsigned int b = 0; b < copyBatches; ++b)
176 auto srcPtrBatch = srcData;
177 auto dstPtrBatch = dstData;
178 for (
unsigned int h = 0; h < copyHeight; ++h)
180 auto srcPtrChannel = srcData;
181 auto dstPtrChannel = dstData;
182 for (
unsigned int w = 0; w < copyWidth; ++w)
185 if (copyLength > srcSize)
188 "The source tensor size does not match the size of the allocated tensor.");
190 if (copyLength > dstSize)
193 "The destination tensor size will overrun the destination tensor.");
195 copy(dstData, srcData, copyLength);
196 dstData += dstWidthStride;
197 srcData += srcWidthStride;
199 dstData += (
static_cast<long>(dstHeightStride) - (dstData - dstPtrChannel));
200 srcData += (
static_cast<long>(srcHeightStride) - (srcData - srcPtrChannel));
202 dstData += (
static_cast<long>(dstBatchStride) - (dstData - dstPtrBatch));
203 srcData += (
static_cast<long>(srcBatchStride) - (srcData - srcPtrBatch));
205 dstData += (
static_cast<long>(dstDepthStride) - (dstData - dstPtrDepth));
206 srcData += (
static_cast<long>(srcDepthStride) - (srcData - srcPtrDepth));
213 template <
typename SrcTensorHandleType,
typename DstTensorHandleType,
typename DescriptorType>
215 std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs)
217 const unsigned int numInputs =
static_cast<unsigned int>(descriptor.m_Inputs.size());
218 tensorHandlePairs.reserve(numInputs);
220 for (
unsigned int i = 0; i < numInputs; ++i)
222 SrcTensorHandleType*
const srcTensorHandle =
223 PolymorphicDowncast<SrcTensorHandleType*>(descriptor.m_Inputs[i]);
224 DstTensorHandleType*
const dstTensorHandle =
225 PolymorphicDowncast<DstTensorHandleType*>(descriptor.m_Outputs[i]);
227 tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle);
234 const PermutationVector& permutationVector,
235 void* permuteBuffer);
246 const TensorInfo& inputInfo,
251 void* permuteBuffer);
263 const TensorInfo& inputInfo,
265 void* permuteBuffer);
274 std::tuple<ConstTensor, unsigned int>
Convert1HWOtoMIHW(
const ConstTensorHandle* weightTensor,
275 const TensorInfo& inputInfo,
277 void* permuteBuffer);