Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accelerate MNNPackTranspose #2079

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions source/backend/cpu/compute/CommonOptFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,40 @@ void MNNPackTransposeUint8(uint8_t* dst, const uint8_t* src, size_t area,size_t
}

void MNNPackTranspose(float* dst, const float* src, size_t area, size_t depth, int* areaOffset) {
#if defined(MNN_USE_NEON)
if (3 == depth) {
int areaC4 = (int)area / 4;
int remain = areaC4 * 4;
for (int i = 0; i < areaC4; ++i) {
auto srcCur = src + 16 * i;
auto dstCur = dst + 12 * i;
auto srcValue = vld4q_f32(srcCur);
float32x4x3_t dstValue;
dstValue.val[0] = srcValue.val[0];
dstValue.val[1] = srcValue.val[1];
dstValue.val[2] = srcValue.val[2];
vst3q_f32(dstCur, dstValue);
}
for (int i = remain; i < area; ++i) {
dst[3 * i + 0] = src[4 * i + 0];
dst[3 * i + 1] = src[4 * i + 1];
dst[3 * i + 2] = src[4 * i + 2];
}
return;
}
#elif defined(MNN_USE_SSE)
if (3 == depth) {
if (area < 1) return;
for (int i = 0; i < area - 1; ++i) {
auto srcValue = Vec4::load(src + 4 * i);
Vec4::save(dst + 3 * i, srcValue);
}
for (int i = 0; i < 3; ++i) {
dst[3 * (area - 1) + i] = src[4 * (area - 1) + i];
}
return;
}
#endif
int c = (int)depth;
int cDiv4 = c / 4;
int cAlign = cDiv4 * 4;
Expand Down