MCPcopy Create free account
hub / github.com/alibaba/MNN / convert

Method convert

source/backend/cpu/CPUTensorConvert.cpp:53–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51typedef void(*PackProc)(void* dst, const void* src, size_t area, size_t depth, int* areaOffset);
52
53ErrorCode CPUTensorConverter::convert(const void* inputRaw, void* outputRaw, MNN_DATA_FORMAT source, MNN_DATA_FORMAT dest, int batch, int area, int channel, int bitLength, const CoreFunctions* core, int tId, int numberThread) {
54 // the case when source and dest data layout are the same
55 // This case occurs in BackendTest of BF16 data.
56 if(source == dest) {
57 if (tId == 0) {
58 ::memcpy(outputRaw, inputRaw, batch * area * channel * bitLength);
59 }
60 return NO_ERROR;
61 }
62 if (MNN_DATA_FORMAT_NHWC == source && MNN_DATA_FORMAT_NCHW == dest) {
63 if (tId == 0) {
64 switch (bitLength) {
65 case 1:
66 NHWC2NCHW((int8_t*)inputRaw, (int8_t*)outputRaw, batch, channel, area);
67 break;
68 case 2:
69 NHWC2NCHW((int16_t*)inputRaw, (int16_t*)outputRaw, batch, channel, area);
70 break;
71 case 4:
72 NHWC2NCHW((float*)inputRaw, (float*)outputRaw, batch, channel, area);
73 break;
74 default:
75 break;
76 }
77 }
78 return NO_ERROR;
79 }
80 if (MNN_DATA_FORMAT_NCHW == source && MNN_DATA_FORMAT_NHWC == dest) {
81 if (tId == 0) {
82 switch (bitLength) {
83 case 1:
84 NCHW2NHWC((int8_t*)inputRaw, (int8_t*)outputRaw, batch, channel, area);
85 break;
86 case 2:
87 NCHW2NHWC((int16_t*)inputRaw, (int16_t*)outputRaw, batch, channel, area);
88 break;
89 case 4:
90 NCHW2NHWC((float*)inputRaw, (float*)outputRaw, batch, channel, area);
91 break;
92 default:
93 break;
94 }
95 }
96 return NO_ERROR;
97 }
98 // Need Pack
99 PackProc proc = nullptr;
100 int inside = area;
101 int outside = batch;
102 if (MNN_DATA_FORMAT_NHWC == source || MNN_DATA_FORMAT_NHWC == dest) {
103 inside = 1;
104 outside = batch * area;
105 }
106 //MNN_PRINT("bytes = %d, from %d -> %d, %d - %d - %d\n", bitLength, source, dest, inside, outside, channel);
107 if (MNN_DATA_FORMAT_NC4HW4 == source) {
108 if (1 == inside) {
109 int offset[2] = {
110 outside,

Callers

nothing calls this directly

Calls 10

MNNGetCoreFunctionsFunction · 0.85
_getBytesFunction · 0.85
EnumNameMNN_DATA_FORMATFunction · 0.85
NHWC2NCHWFunction · 0.70
NCHW2NHWCFunction · 0.70
minFunction · 0.70
convertFunction · 0.50
bufferMethod · 0.45
dimensionsMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected