MNN/source/backend/cpu/compute/ConvInt8TiledExecutor.cpp

1123 lines
50 KiB
C++
Raw Normal View History

//
// ConvInt8TiledExecutor.cpp
// MNN
//
// Created by MNN on 2019/5/17.
// Copyright © 2018, Alibaba Group Holding Limited
//
2023-06-16 09:42:45 +08:00
#include "ConvInt8TiledExecutor.hpp"
#include "ConvolutionTiledExecutor.hpp"
#include "core/Macro.h"
2023-06-16 09:42:45 +08:00
#include "core/BufferAllocator.hpp"
#include <math.h>
#include "backend/cpu/CPUBackend.hpp"
#include "core/Concurrency.h"
#include "core/TensorUtils.hpp"
2024-07-22 19:51:53 +08:00
namespace MNN {
2024-08-24 15:46:21 +08:00
ConvInt8TiledExecutor::ConvInt8TiledExecutor(Backend* backend, const Op* op): CPUConvolution(op->main_as_Convolution2D()->common(), backend) {}
ConvInt8TiledExecutor::ConvInt8TiledExecutor(Backend* backend, const Op* op, std::shared_ptr<ResourceInt8> res): CPUConvolution(op->main_as_Convolution2D()->common(), backend), mResourceInt8(res) {
2024-09-12 12:57:57 +08:00
if (!res->mDynamicQuant) {
mMutableResource.reset(new MutableResourceInt8(res, backend));
mValid = mMutableResource->mValid;
}
2021-09-18 15:52:30 +08:00
}
ConvInt8TiledExecutor::~ConvInt8TiledExecutor() {
// Do nothing
}
bool ConvInt8TiledExecutor::onClone(Backend* bn, const Op* op, Execution** dst) {
return false;
}
ErrorCode ConvInt8TiledExecutor::onResize(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs) {
2024-09-12 12:57:57 +08:00
if (nullptr != mMutableResource) {
mMutableResource->updateInputOutputScale(TensorUtils::getQuantInfo(inputs[0]), TensorUtils::getQuantInfo(outputs[0]));
}
2021-09-18 15:52:30 +08:00
CPUConvolution::onResize(inputs, outputs);
2023-06-16 09:42:45 +08:00
ConvolutionTiledExecutor::setIm2ColParameter(mIm2ColParamter, mCommon, inputs[0], outputs[0], mPadX, mPadY, static_cast<CPUBackend*>(backend())->functions(), static_cast<CPUBackend*>(backend())->int8Functions());
2021-09-18 15:52:30 +08:00
return NO_ERROR;
}
2024-10-14 19:26:28 +08:00
void ConvInt8TiledExecutor::reorderWeight(Tensor* weight, const uint8_t* weightSrc, int SRC_UNIT, int UNIT, int ic, int oc, int kernelCount, int pack, int blockNum) {
2023-06-16 09:42:45 +08:00
auto weightDst = weight->host<uint8_t>();
memset(weightDst, 0, weight->size());
2024-10-14 19:26:28 +08:00
int kernelCountUnit = weight->shape()[1];
int blockL = kernelCountUnit / blockNum;
int strideOutside = ROUND_UP(oc, UNIT) * SRC_UNIT * blockL;
int strideInside = weight->stride(0) / blockNum;
if (SRC_UNIT > pack) { // shape = {blockNum, UP_DIV(oc, UNIT), UP_DIV(UP_DIV(ic, pack) * kernelCount, SRC_UNIT / pack) / blockNum, UNIT, SRC_UNIT};
auto icDivU = UP_DIV(ic, pack);
2023-06-16 09:42:45 +08:00
for (int k = 0; k < kernelCount; ++k) {
const auto srcK = weightSrc + k;
for (int y = 0; y < ic; ++y) {
const int yOutSide = y / pack;
const int yInSide = y % pack;
2023-06-16 09:42:45 +08:00
const int yIndex = yOutSide + k * icDivU;
const int ySubOutSide = yIndex / (SRC_UNIT / pack);
const int ySubInSide = yIndex % (SRC_UNIT / pack);
2023-06-16 09:42:45 +08:00
2024-10-14 19:26:28 +08:00
int blockId = ySubOutSide / blockL;
int blockInsideId = ySubOutSide % blockL;
auto dstY = weightDst + blockId * strideOutside + blockInsideId * weight->stride(1) + ySubInSide * pack + yInSide;
2023-06-16 09:42:45 +08:00
const auto srcY = srcK + y * kernelCount;
for (int x = 0; x < oc; ++x) {
const int xOutSide = x / UNIT;
const int xInSide = x % UNIT;
2024-10-14 19:26:28 +08:00
const int dstIndex = xOutSide * strideInside + xInSide * SRC_UNIT;
2023-06-16 09:42:45 +08:00
const int srcIndex = x * kernelCount * ic;
dstY[dstIndex] = srcY[srcIndex];
}
}
}
2024-10-14 19:26:28 +08:00
} else { // shape = {blockNum, UP_DIV(oc, UNIT), UP_DIV(ic, SRC_UNIT) * kernelCount / blockNum, UNIT, SRC_UNIT};
2023-06-16 09:42:45 +08:00
for (int k = 0; k < kernelCount; ++k) {
auto icDivU = UP_DIV(ic, SRC_UNIT);
const auto srcK = weightSrc + k;
for (int y = 0; y < ic; ++y) {
const int yOutSide = y / SRC_UNIT;
const int yInSide = y % SRC_UNIT;
2024-10-14 19:26:28 +08:00
int blockId = (yOutSide + k * icDivU) / blockL;
int blockInsideId = (yOutSide + k * icDivU) % blockL;
2023-06-16 09:42:45 +08:00
2024-10-14 19:26:28 +08:00
auto dstY = weightDst + blockId * strideOutside + blockInsideId * weight->stride(1) + yInSide;
2023-06-16 09:42:45 +08:00
const auto srcY = srcK + y * kernelCount;
for (int x = 0; x < oc; ++x) {
const int xOutSide = x / UNIT;
const int xInSide = x % UNIT;
2024-10-14 19:26:28 +08:00
const int dstIndex = xOutSide * strideInside + xInSide * SRC_UNIT;
2023-06-16 09:42:45 +08:00
const int srcIndex = x * kernelCount * ic;
dstY[dstIndex] = srcY[srcIndex];
}
}
}
}
}
static bool _reorderWeightInside(Backend* bn, const Convolution2DCommon* common,
2024-07-22 19:51:53 +08:00
const std::shared_ptr<Tensor>& weightOrigin,
2024-10-14 19:26:28 +08:00
std::shared_ptr<Tensor>& weight, int blockNum) {
MNN_ASSERT(blockNum > 0);
auto core = static_cast<CPUBackend*>(bn)->int8Functions();
2024-07-22 19:51:53 +08:00
auto gcore = static_cast<CPUBackend*>(bn)->functions();
int UNIT, SRC_UNIT, DST_XUNIT;
core->MNNGetGemmUnit(&UNIT, &SRC_UNIT, &DST_XUNIT);
// reorder weight, [oc, ic, k^2] => [oc/unit, ((ic/unit)*k^2)/(src_unit/unit), unit(oc), (src_unit/unit), unit(ic)]
int oc = common->outputCount(), ic = common->inputCount(), kernelCount = common->kernelX() * common->kernelY();
2023-06-16 09:42:45 +08:00
std::vector<int> shape;
int pack = gcore->pack;
if (SRC_UNIT > pack) {
2024-08-24 15:46:21 +08:00
MNN_ASSERT(SRC_UNIT % pack == 0);
shape = {UP_DIV(oc, UNIT), UP_DIV(UP_DIV(ic, pack) * kernelCount, SRC_UNIT / pack), UNIT, SRC_UNIT};
2023-06-16 09:42:45 +08:00
} else {
shape = {UP_DIV(oc, UNIT), UP_DIV(ic, SRC_UNIT) * kernelCount, UNIT, SRC_UNIT};
}
2021-09-18 15:52:30 +08:00
weight.reset(Tensor::createDevice<int8_t>(shape));
2021-09-18 15:52:30 +08:00
bool succ = bn->onAcquireBuffer(weight.get(), Backend::STATIC);
if (!succ) {
MNN_ERROR("Memory not enough");
return false;
}
2024-10-14 19:26:28 +08:00
ConvInt8TiledExecutor::reorderWeight(weight.get(), weightOrigin->host<uint8_t>(), SRC_UNIT, UNIT, ic, oc, kernelCount, pack, blockNum);
return true;
}
2024-10-14 19:26:28 +08:00
static void GetResourceInt8(std::shared_ptr<CPUConvolution::ResourceInt8> resource, std::shared_ptr<ConvolutionCommon::Int8Common> quantCommon, const Convolution2D* conv2d, Backend* backend, int32_t* blocknumPtr) {
2024-07-22 19:51:53 +08:00
// common parameters
int outputCount = conv2d->common()->outputCount();
2024-08-24 15:46:21 +08:00
auto core = static_cast<CPUBackend*>(backend)->functions();
2024-07-22 19:51:53 +08:00
int LSize = conv2d->common()->inputCount() * conv2d->common()->kernelX() * conv2d->common()->kernelY();
int ocUp4 = ROUND_UP(outputCount, core->pack);
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
int dequantCnt = quantCommon->alpha.size();
if (quantCommon->asymmetric) {
dequantCnt /= 2;
}
int blockNum = dequantCnt / outputCount;
2024-10-14 19:26:28 +08:00
blocknumPtr[0] = blockNum;
2024-07-22 19:51:53 +08:00
int scaleSize = blockNum * ocUp4; // pack size.
int blockSize = LSize / blockNum;
int originOffset = 0;
2024-08-24 15:46:21 +08:00
resource->mActBits = 8;
2024-07-22 19:51:53 +08:00
if (quantCommon->canUseInt4) {
originOffset = -8;
2024-08-24 15:46:21 +08:00
resource->mActBits = 4;
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
// Save bias
resource->mOriginBias.reset(Tensor::createDevice<int32_t>({ocUp4})); // float
auto success = backend->onAcquireBuffer(resource->mOriginBias.get(), Backend::STATIC);
if (!success) {
MNN_ERROR("Alloc bias memory error\n");
return;
}
::memset(resource->mOriginBias->host<float>(), 0, ocUp4 * sizeof(float));
if (conv2d->bias()) {
::memcpy(resource->mOriginBias->host<float>(), conv2d->bias()->data(), outputCount * sizeof(float));
} else {
::memset(resource->mOriginBias->host<float>(), 0, ocUp4 * sizeof(float));
}
// Save weight quant alpha and zero: wf=alpha*wi+zero
2024-07-22 19:51:53 +08:00
int bytes = 4;
2024-08-24 15:46:21 +08:00
resource->mOriginScale.reset(Tensor::createDevice<uint8_t>({2 * scaleSize * bytes}));
success = backend->onAcquireBuffer(resource->mOriginScale.get(), Backend::STATIC);
2024-07-22 19:51:53 +08:00
if (!success) {
2024-08-24 15:46:21 +08:00
MNN_ERROR("Alloc denquant alpha, zero memory error\n");
2024-07-22 19:51:53 +08:00
return;
}
2024-08-24 15:46:21 +08:00
auto alphaPtr = resource->mOriginScale->host<float>();
2024-07-22 19:51:53 +08:00
auto biasPtr = reinterpret_cast<float*>(reinterpret_cast<uint8_t*>(alphaPtr) + scaleSize * bytes);
2024-11-18 14:37:45 +08:00
if (outputCount % core->pack != 0) {
::memset(alphaPtr, 0, scaleSize * bytes);
::memset(biasPtr, 0, scaleSize * bytes);
}
2024-07-22 19:51:53 +08:00
auto quanInfoPtr = quantCommon->alpha.get();
int h = quantCommon->alpha.size();
if (quantCommon->asymmetric) {
for (int i = 0; i < blockNum; ++i) {
auto dstAlpha = alphaPtr + i * ocUp4;
auto dstBias = biasPtr + i * ocUp4;
for (int j = 0; j < outputCount; ++j) {
int scaleIndex = j * blockNum + i;
dstAlpha[j] = quanInfoPtr[2 * scaleIndex + 1];
dstBias[j] = quanInfoPtr[2 * scaleIndex] + (float)originOffset * dstAlpha[j];
}
}
} else {
for (int i = 0; i < blockNum; ++i) {
auto dstAlpha = alphaPtr + i * ocUp4;
auto dstBias = biasPtr + i * ocUp4;
for (int j = 0; j < outputCount; ++j) {
int scaleIndex = j * blockNum + i;
dstAlpha[j] = quanInfoPtr[scaleIndex];
dstBias[j] = (float)originOffset * dstAlpha[j];
}
}
}
// Save float weight kernel sum
resource->mWeightKernelSum.reset(Tensor::createDevice<uint8_t>({bytes * ocUp4}));
2024-08-24 15:46:21 +08:00
success = backend->onAcquireBuffer(resource->mWeightKernelSum.get(), Backend::STATIC);
2024-07-22 19:51:53 +08:00
if (!success) {
2024-08-24 15:46:21 +08:00
MNN_ERROR("Alloc denquant weight kernel sum memory error\n");
2024-07-22 19:51:53 +08:00
return;
}
auto weightKernelSum = resource->mWeightKernelSum->host<float>();
2024-08-24 15:46:21 +08:00
auto realWeightData = quantCommon->weight.get();
2024-07-22 19:51:53 +08:00
::memset(weightKernelSum, 0, resource->mWeightKernelSum->size());
for (int j = 0; j < outputCount; ++j) {
float sum = 0.f;
for (int k = 0; k < blockNum; ++k) {
int scaleIndex = k + j * blockNum;
float scale = 0;
float bias = 0;
if (quantCommon->asymmetric) {
scale = quanInfoPtr[2 * scaleIndex + 1];
bias = quanInfoPtr[2 * scaleIndex];
} else {
scale = quanInfoPtr[scaleIndex];
bias = 0;
}
int tmp = 0;
2024-08-24 15:46:21 +08:00
if (quantCommon->canUseInt4) {
for (int i = 0; i < blockSize; ++i) {
int l_index = k * blockSize + i;
int w_idx = (j * blockNum * blockSize + l_index);
int w_offset = w_idx / 2;
int w_mask = w_idx % 2;
uint8_t s = realWeightData[w_offset];
int val = w_idx % 2 ? s & 0x0f : s >> 4;
tmp += (val - 8);
}
} else {
for (int i = 0; i < blockSize; ++i) {
int l_index = k * blockSize + i;
tmp += (int)realWeightData[j * blockNum * blockSize + l_index];
}
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
sum += (tmp * scale + blockSize * bias);
}
weightKernelSum[j] = sum;
}
}
2024-09-12 12:57:57 +08:00
DenseConvInt8TiledExecutor::DenseConvInt8TiledExecutor(Backend* backend, const Op* op, std::shared_ptr<ConvolutionCommon::Int8Common> quanCommon) : ConvInt8TiledExecutor(backend, op) {
2024-08-24 15:46:21 +08:00
auto convOp = op->main_as_Convolution2D();
auto core = static_cast<CPUBackend*>(backend)->int8Functions();
2024-07-22 19:51:53 +08:00
auto gcore = static_cast<CPUBackend*>(backend)->functions();
2024-08-24 15:46:21 +08:00
mResourceInt8.reset(new CPUConvolution::ResourceInt8);
2024-09-12 12:57:57 +08:00
mResourceInt8->mDynamicQuant = true;
2024-10-14 19:26:28 +08:00
int blockNum = 1;
GetResourceInt8(mResourceInt8, quanCommon, convOp, backend, &blockNum);
mBlockNum = blockNum;
2024-07-22 19:51:53 +08:00
// dynamic quant
int UNIT, SRC_UNIT, DST_XUNIT;
core->MNNGetGemmUnit(&UNIT, &SRC_UNIT, &DST_XUNIT);
2024-08-24 15:46:21 +08:00
int pack = gcore->pack;
auto weightLength = quanCommon->weight.size();
int kernelCount = mCommon->kernelX() * mCommon->kernelY();
int oc = convOp->common()->outputCount();
int ic = convOp->common()->inputCount();
bool directReadInt4weight = (kernelCount == 1 && ROUND_UP(oc, UNIT) == oc && ROUND_UP(ic, SRC_UNIT) == ic);
2024-10-22 14:37:28 +08:00
#ifdef MNN_KLEIDIAI_ENABLED
bool half_act = gcore->bytes == 2;
int biasSize = mResourceInt8->mOriginBias->size();
int alphaSize = mResourceInt8->mOriginScale->size();
bool blockwise = (biasSize * 2) != alphaSize;
KleidiAI kai = KleidiAI::getInstance(quanCommon->asymmetric, half_act, blockwise);
2024-10-24 14:07:29 +08:00
if(quanCommon->canUseInt4 && kai.canAccelerate()) {
int n = oc;
int k = ic;
int packedWeightSize = kai.getRhsPackedSize(n, k);
2024-10-22 14:37:28 +08:00
2024-10-24 14:07:29 +08:00
//Alloc packed weight tensor.
mResourceInt8->mWeightInt8.reset(Tensor::createDevice<uint8_t>({packedWeightSize}));
bool success = backend->onAcquireBuffer(mResourceInt8->mWeightInt8.get(), Backend::STATIC);
2024-10-22 14:37:28 +08:00
2024-10-24 14:07:29 +08:00
if (!success) {
MNN_ERROR("Out of static memory!\n");
2024-10-22 14:37:28 +08:00
return;
}
2024-10-24 14:07:29 +08:00
//Run rhs pack.
kai.runRhsPack(n, k, (uint8_t*)quanCommon->weight.get(),
mResourceInt8->mOriginScale->host<float>(),
mResourceInt8->mOriginBias->host<float>(),
mResourceInt8->mWeightInt8->host<uint8_t>(),
directReadInt4weight);
return;
}
2024-10-22 14:37:28 +08:00
#endif
2024-08-24 15:46:21 +08:00
if (quanCommon->canUseInt4 && directReadInt4weight) {
// int4 weight reorder
2024-07-22 19:51:53 +08:00
mResourceInt8->mWeightAsymmetricQuant = true;
2024-08-24 15:46:21 +08:00
// shape = {UP_DIV(oc, UNIT), UP_DIV(ic, SRC_UNIT) * kernelCount, UNIT, SRC_UNIT};
int hU = UP_DIV(oc, UNIT);
int lU = UP_DIV(ic, SRC_UNIT);
int hP = UNIT;
int lP = SRC_UNIT;
2024-08-24 15:46:21 +08:00
// weight shape.
std::vector<int32_t> shape;
if (SRC_UNIT > pack) {
MNN_ASSERT(SRC_UNIT % pack == 0);
2024-09-12 12:57:57 +08:00
shape = {UP_DIV(oc, UNIT), UP_DIV(UP_DIV(ic, pack) * kernelCount, SRC_UNIT / pack), UNIT * SRC_UNIT / 2};
2024-08-24 15:46:21 +08:00
} else {
2024-09-12 12:57:57 +08:00
shape = {UP_DIV(oc, UNIT), UP_DIV(ic, SRC_UNIT) * kernelCount, UNIT * SRC_UNIT / 2};
2024-08-24 15:46:21 +08:00
}
mResourceInt8->mWeightInt8.reset(Tensor::createDevice<uint8_t>(shape));
auto res = backend->onAcquireBuffer(mResourceInt8->mWeightInt8.get(), Backend::STATIC);
2024-07-22 19:51:53 +08:00
if (!res) {
MNN_ERROR("int4 weight acquire buffer error\n");
return ;
}
2024-08-24 15:46:21 +08:00
auto srcPtr = (uint8_t*)quanCommon->weight.get();
auto dstPtr = mResourceInt8->mWeightInt8->host<uint8_t>();
::memset(dstPtr, 0, mResourceInt8->mWeightInt8->size());
2024-07-22 19:51:53 +08:00
// Pack two int4-weight to one int8-weight.
2024-09-12 12:57:57 +08:00
int cnt = lP * hP / 4;
int L = lU * lP;
2024-10-14 19:26:28 +08:00
int blockL = lU / blockNum;
int stride0 = (lP * hP) * hU * blockL;
int stride1 = (lP * hP) * blockL;
2024-09-12 12:57:57 +08:00
for (int i = 0; i < hU; ++i) {
for (int j = 0; j < lU; ++j) {
2024-10-14 19:26:28 +08:00
int blockId = j / blockL;
int blockkInsideId = j % blockL;
2024-09-12 12:57:57 +08:00
for (int k = 0; k < cnt; ++k) {
2024-10-14 19:26:28 +08:00
int dstIndx0 = (blockId * stride0 + i * stride1 + blockkInsideId * lP * hP) / 2 + (2 * k);
2024-09-12 12:57:57 +08:00
int hpId0 = (2 * k + 1) / lP;
int lpId0 = (2 * k) % lP;
int hpId1 = (2 * (k + cnt) + 1) / lP;
int lpId1 = (2 * (k + cnt)) % lP;
int srcIndx0 = ((i * hP + hpId0) * L + (j * lP + lpId0)) / 2;
int srcIndx1 = ((i * hP + hpId1) * L + (j * lP + lpId1)) / 2;
int s0 = (srcPtr[srcIndx0] >> 4);
int s1 = (srcPtr[srcIndx0] & 15);
int s2 = (srcPtr[srcIndx1] >> 4);
int s3 = (srcPtr[srcIndx1] & 15);
int d0 = s0 * 16 + s2;
int d1 = s1 * 16 + s3;
2024-09-12 12:57:57 +08:00
dstPtr[dstIndx0] = d0;
dstPtr[dstIndx0 + 1] = d1;
2024-08-24 15:46:21 +08:00
}
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
}
} else {
// std::shared_ptr<Tensor> srcWeight;
2024-08-24 15:46:21 +08:00
if (quanCommon->canUseInt4) {
mResourceInt8->mWeightAsymmetricQuant = true;
auto srcPtr = reinterpret_cast<uint8_t*>(quanCommon->weight.get());
std::vector<int8_t> tmpWeight(weightLength * 2, 0);
for (int i = 0; i < weightLength; ++i) {
int8_t s0 = (srcPtr[i] >> 4) - 8; // For int4 quant weight, +8 saved in quant buffer
int8_t s1 = (srcPtr[i] & 0x0f) - 8;
tmpWeight[2 * i + 0] = s0;
tmpWeight[2 * i + 1] = s1;
}
std::shared_ptr<Tensor> srcWeight(Tensor::create<uint8_t>({weightLength * 2}, (void*)tmpWeight.data()));
2024-10-14 19:26:28 +08:00
mValid = _reorderWeightInside(backend, convOp->common(), srcWeight, mResourceInt8->mWeightInt8, blockNum);
2024-08-24 15:46:21 +08:00
if(!mValid) {
return;
}
MNN_ASSERT(mResourceInt8->mWeightInt8->size() % 2 == 0);
int leng = mResourceInt8->mWeightInt8->size();
int halflen = leng / 2;
std::shared_ptr<Tensor> weightLow(Tensor::create<uint8_t>({halflen}));
auto dstint4Ptr = weightLow->host<uint8_t>();
auto srcint4Ptr = mResourceInt8->mWeightInt8->host<int8_t>();
2024-09-12 12:57:57 +08:00
int permuteUnit = UNIT * SRC_UNIT;
int halfPermuteStride = static_cast<int32_t>(permuteUnit / 2);
for (int i = 0; i < leng / permuteUnit; ++i) {
auto src0 = srcint4Ptr + i * permuteUnit;
auto dst0 = dstint4Ptr + i * halfPermuteStride;
for (int j = 0; j < halfPermuteStride; ++j) {
int s0 = src0[j];
int s1 = src0[j + halfPermuteStride];
2024-07-22 19:51:53 +08:00
int d = (s0 + 8) * 16 + (s1 + 8);
2024-09-12 12:57:57 +08:00
dst0[j] = d;
2024-08-24 15:46:21 +08:00
}
}
2024-08-24 15:46:21 +08:00
// Update int4 weight to mWeightInt8.
mResourceInt8->mWeightInt8 = weightLow;
} else {
std::shared_ptr<Tensor> srcWeight(Tensor::create<uint8_t>({weightLength}, (void*)quanCommon->weight.get()));
2024-10-14 19:26:28 +08:00
mValid = _reorderWeightInside(backend, convOp->common(), srcWeight, mResourceInt8->mWeightInt8, blockNum);
2024-08-24 15:46:21 +08:00
if(!mValid) {
return;
2024-07-22 19:51:53 +08:00
}
}
}
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
// Relu/Relu6 post parameters
auto postPtr = getPostParameters();
2024-08-24 15:46:21 +08:00
mResourceInt8->mReluThreshold.resize(2);
mResourceInt8->mReluThreshold[0] = postPtr[2];
mResourceInt8->mReluThreshold[1] = postPtr[3];
2024-07-22 19:51:53 +08:00
if (gcore->bytes == 2) {
2024-08-24 15:46:21 +08:00
gcore->MNNFp32ToLowp(mResourceInt8->mReluThreshold.data(), reinterpret_cast<int16_t*>(mResourceInt8->mReluThreshold.data()), 2);
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
}
2024-09-12 12:57:57 +08:00
static void _computeAlphaScale(Backend* backend, const Convolution2D* conv2d, std::shared_ptr<CPUConvolution::ResourceInt8> resourceInt8) {
/* Used to compute weight quant scale and bias and weightKernelSum of type float. */
bool quanBuffer = (conv2d->quanParameter() != nullptr && conv2d->quanParameter()->buffer() != nullptr);
MNN_ASSERT(quanBuffer || resourceInt8);
auto core = static_cast<CPUBackend*>(backend)->functions();
// common parameters
int outputCount = conv2d->common()->outputCount();
int LSize = conv2d->common()->inputCount() * conv2d->common()->kernelX() * conv2d->common()->kernelY();
int ocUp4 = ROUND_UP(outputCount, core->pack);
int8_t* weightOrigin;
2024-08-24 15:46:21 +08:00
2024-09-12 12:57:57 +08:00
// Save weight quant scale and bias: wf=scale*wi+bias
std::shared_ptr<Tensor> scaleBias(Tensor::createDevice<uint8_t>({2 * ocUp4 * core->bytes}));
auto success = backend->onAcquireBuffer(scaleBias.get(), Backend::STATIC);
if (!success) {
MNN_ERROR("Alloc dequant scaleBias memory error\n");
return;
}
auto alphaPtr = scaleBias->host<float>();
auto biasPtr = reinterpret_cast<float*>(reinterpret_cast<uint8_t*>(alphaPtr) + ocUp4 * core->bytes);
::memset(alphaPtr, 0, 2 * ocUp4 * core->bytes);
2024-09-12 12:57:57 +08:00
// Load quant scale and bias
weightOrigin = resourceInt8->mWeightInt8->host<int8_t>();
auto wZero = resourceInt8->mWeightQuantZero->host<int32_t>(); // has packed to outputUp4
auto wScale = resourceInt8->mOriginScale->host<float>();
int h = ocUp4;
2024-11-18 14:37:45 +08:00
MNN_ASSERT(4 == core->bytes);
for (int i=0; i< h; ++i) {
alphaPtr[i] = wScale[i];
biasPtr[i] = (-1.f) * wZero[i] * wScale[i];
2024-09-12 12:57:57 +08:00
}
resourceInt8->mOriginScale = scaleBias;
2024-09-12 12:57:57 +08:00
// Compute float weightKernelSum
resourceInt8->mWeightKernelSum.reset(Tensor::createDevice<uint8_t>({ocUp4 * 4}));
success = backend->onAcquireBuffer(resourceInt8->mWeightKernelSum.get(), Backend::STATIC);
if (!success) {
MNN_ERROR("Alloc dequant mWeightKernelSum memory error\n");
return;
}
auto weightKernelSum = resourceInt8->mWeightKernelSum->host<float>();
for (int i = 0; i < outputCount; ++i) {
int sum = 0;
for (int j = 0; j < LSize; ++j) {
sum = sum + static_cast<int>(weightOrigin[j + i * LSize]);
}
auto scale = alphaPtr[i];
auto bias = biasPtr[i];
weightKernelSum[i] = static_cast<float>(sum) * scale + LSize * bias;
}
}
DenseConvInt8TiledExecutor::DenseConvInt8TiledExecutor(Backend* backend, const Op* op, std::shared_ptr<ResourceInt8> res) : ConvInt8TiledExecutor(backend, op, res) {
2024-08-24 15:46:21 +08:00
std::shared_ptr<Tensor> weightOrigin = mResourceInt8->mWeightInt8;
auto convOp = op->main_as_Convolution2D();
2024-10-14 19:26:28 +08:00
mValid = _reorderWeightInside(backend, convOp->common(), weightOrigin, mResourceInt8->mWeightInt8, mBlockNum);
2024-08-24 15:46:21 +08:00
if(!mValid) {
return;
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
// offline quant: choose int8 gemm kernel
auto core = static_cast<CPUBackend*>(backend)->int8Functions();
mGemmKernel = core->Int8GemmKernel;
#ifdef MNN_USE_SSE
int actBits = convOp->symmetricQuan()->nbits();
if (actBits <= 7) {
mGemmKernel = core->Int8GemmKernelFast;
2024-07-22 19:51:53 +08:00
}
2024-08-24 15:46:21 +08:00
#else
if(convOp->symmetricQuan()->method() == QuantizeAlgo_OVERFLOW_AWARE){
mGemmKernel = core->Int8GemmKernelFast;
}
#endif
2024-09-12 12:57:57 +08:00
_computeAlphaScale(backend, convOp, mResourceInt8);
2024-07-22 19:51:53 +08:00
}
2021-09-18 15:52:30 +08:00
2024-08-24 15:46:21 +08:00
DenseConvInt8TiledExecutor::DenseConvInt8TiledExecutor(Backend* backend, const Op* op, const DenseConvInt8TiledExecutor& exe)
2024-09-12 12:57:57 +08:00
: ConvInt8TiledExecutor(backend, op, exe.mResourceInt8), mGemmKernel(exe.mGemmKernel) {
}
2021-09-18 15:52:30 +08:00
DenseConvInt8TiledExecutor::~DenseConvInt8TiledExecutor() {
// Do nothing
}
2021-09-18 15:52:30 +08:00
bool DenseConvInt8TiledExecutor::onClone(Backend* bn, const Op* op, Execution** dst) {
if (nullptr == dst) {
return true;
}
2024-08-24 15:46:21 +08:00
auto exe = new DenseConvInt8TiledExecutor(bn, op, *this);
if (!exe->valid()) {
return false;
}
*dst = exe;
return true;
}
2021-09-18 15:52:30 +08:00
void DenseConvInt8TiledExecutor::getPackParameter(int* Unit, int* srcUnit, int* DestUnit, const CoreInt8Functions* core) {
core->MNNGetGemmUnit(Unit, srcUnit, DestUnit);
}
2021-09-18 15:52:30 +08:00
ErrorCode DenseConvInt8TiledExecutor::onResize(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs) {
2024-07-22 19:51:53 +08:00
mUseBatchQuan = (static_cast<CPUBackend*>(backend())->getRuntime()->hint().dynamicQuantOption == 1);
mUseBatchQuan &= mCommon->kernelY() == 1 && mCommon->kernelX() == 1
&& outputs[0]->width() == inputs[0]->width() && outputs[0]->height() == inputs[0]->height()
&& mCommon->strideX() == 1 && mCommon->strideY() == 1 && mCommon->padX() == 0 && mCommon->padY() == 0
&& outputs[0]->height() == 1 && outputs[0]->width() == 1;
2024-09-12 12:57:57 +08:00
mUseBatchQuan &= mResourceInt8->mDynamicQuant;
2024-07-22 19:51:53 +08:00
mUseBatchQuan &= (inputs[0]->batch() > 1);
2021-09-18 15:52:30 +08:00
auto core = static_cast<CPUBackend*>(backend())->int8Functions();
2024-07-22 19:51:53 +08:00
auto gcore =static_cast<CPUBackend*>(backend())->functions();
2021-09-18 15:52:30 +08:00
int UNIT, SRC_UNIT, DST_XUNIT;
2024-07-22 19:51:53 +08:00
core->MNNGetGemmUnit(&UNIT, &SRC_UNIT, &DST_XUNIT);
2024-10-22 14:37:28 +08:00
#ifdef MNN_KLEIDIAI_ENABLED
KleidiAI& kai = KleidiAI::getInstance();
if(mResourceInt8->mDynamicQuant && mResourceInt8->mActBits == 4 && kai.canAccelerate()) {
int batch = inputs[0]->batch();
int channel = inputs[0]->channel();
int packedSize = kai.getLhsQuantedPackedSize(batch, channel);
mTempIm2ColBuffer.reset(Tensor::createDevice<int8_t>({packedSize}));
bool success = backend()->onAcquireBuffer(mTempIm2ColBuffer.get(), Backend::DYNAMIC);
if (!success) {
MNN_ERROR("Out of dynamic memory!\n");
return OUT_OF_MEMORY;
}
backend()->onReleaseBuffer(mTempIm2ColBuffer.get(), Backend::DYNAMIC);
return NO_ERROR;
}
#endif
2024-09-12 12:57:57 +08:00
if (mResourceInt8->mDynamicQuant == false) {
2024-08-24 15:46:21 +08:00
mMutableResource->updateInputOutputScale(TensorUtils::getQuantInfo(inputs[0]), TensorUtils::getQuantInfo(outputs[0]));
2024-07-22 19:51:53 +08:00
CPUConvolution::onResize(inputs, outputs);
ConvolutionTiledExecutor::setIm2ColParameter(mIm2ColParamter, mCommon, inputs[0], outputs[0], mPadX, mPadY, gcore, core);
mBlockNum = 1;
} else { // Dynamic Quant kernels
CPUConvolution::onResize(inputs, outputs);
// Gemm Kernel
mGemmKernel = core->Int8GemmKernel;
2024-08-24 15:46:21 +08:00
if (mResourceInt8->mActBits == 4) {
2024-07-22 19:51:53 +08:00
mGemmKernel = core->Int8GemmKernel_W4;
}
mQuantFunc = core->MNNFloat2Int8;
if (gcore->bytes == 2 && gcore->pack == 8) {
mGemmKernel = core->MNNGemmInt8AddBiasScale_Unit_FP16;
2024-08-24 15:46:21 +08:00
if (mResourceInt8->mActBits == 4) {
2024-07-22 19:51:53 +08:00
mGemmKernel = core->MNNGemmInt8AddBiasScale_w4_Unit_FP16;
}
mQuantFunc = core->DynamicQuanInput_ARM82;
mQuantAndReorderFunc = core->DynamicQuanInputAndReorder_ARM82;
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
}
// A axisSum kernel
mSumByAxisLFunc = gcore->MNNSumByAxisLForMatmul_A;
2024-11-18 14:37:45 +08:00
ConvolutionTiledExecutor::setIm2ColParameter(mIm2ColParamter, mCommon, inputs[0], outputs[0], mPadX, mPadY, gcore, core);
2024-07-22 19:51:53 +08:00
int ocUp4 = ROUND_UP(outputs[0]->channel(), gcore->pack);
2024-08-24 15:46:21 +08:00
int alphaSize = mResourceInt8->mOriginScale->size() / (sizeof(float) * 2);
2024-07-22 19:51:53 +08:00
mBlockNum = alphaSize / ocUp4;
}
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
// input scale buffer
int batch = inputs[0]->batch();
// mTempIm2ColBuffer.reset(Tensor::createDevice<int8_t>({mThreadNums, DST_XUNIT * mIm2ColCount * mResourceInt8->mWeightInt8->length(1) * SRC_UNIT}));
mInputDeqScales.reset(Tensor::createDevice<int8_t>({batch * 4}));
bool success = backend()->onAcquireBuffer(mInputDeqScales.get(), Backend::DYNAMIC);
// Im2col info
auto output = outputs[0];
const int threads = static_cast<CPUBackend*>(backend())->threadNumber();
2023-06-16 09:42:45 +08:00
auto planeSize = output->width() * output->height() * output->batch();
const int L2Size = 2048;
const int tileLimitByC = UP_DIV(L2Size, mIm2ColParamter.kernelCountUnit * SRC_UNIT);
2024-07-22 19:51:53 +08:00
int tileLimit = 0;
int outC = output->channel();
int outC4 = UP_DIV(outC, gcore->pack);
if (threads < planeSize) { // Thread split by output nhw.
tileLimit = ALIMIN(tileLimitByC, UP_DIV(planeSize, threads));
mSplitByOc = false;
} else {
tileLimit = ALIMIN(tileLimitByC, planeSize);
auto ocPerThread = UP_DIV(outC4, threads);
auto threadNeed = UP_DIV(outC4, ocPerThread);
2024-08-24 15:46:21 +08:00
int totalWork = outC4;
int part = 1;
2024-07-22 19:51:53 +08:00
if (UNIT > gcore->pack) { // AVX512:UNIT=64,pack=16
MNN_ASSERT(UNIT % gcore->pack == 0);
int ocDivUnit = UP_DIV(outC4 * gcore->pack, UNIT);
ocPerThread = UP_DIV(ocDivUnit, threads);
threadNeed = UP_DIV(ocDivUnit, ocPerThread);
2024-08-24 15:46:21 +08:00
totalWork = ocDivUnit;
part = UNIT / gcore->pack;
2024-07-22 19:51:53 +08:00
}
mThreadNums = ALIMIN(threads, threadNeed);
mSplitByOc = true;
mDivides.resize(threads+1);
mDivides[0] = 0;
2024-10-14 19:26:28 +08:00
static_cast<CPUBackend *>(backend())->computeDivideSizes(totalWork, mDivides.data() + 1);
2024-08-24 15:46:21 +08:00
for (int i = 0; i < mDivides.size(); ++i) {
mDivides[i] *= part;
}
2024-07-22 19:51:53 +08:00
}
2023-06-16 09:42:45 +08:00
mIm2ColCount = UP_DIV(tileLimit, DST_XUNIT);
auto DynamicDestUnit = DST_XUNIT * mIm2ColCount;
mTileCount = UP_DIV(planeSize, DynamicDestUnit);
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
if (threads < planeSize) {
mThreadNums = ALIMIN(threads, mTileCount);
mDivides.resize(threads+1);
mDivides[0] = 0;
2024-10-14 19:26:28 +08:00
static_cast<CPUBackend *>(backend())->computeDivideSizes(mTileCount, mDivides.data() + 1);
}
2024-07-22 19:51:53 +08:00
int ocUp4 = ROUND_UP(outC, gcore->pack);
2024-08-24 15:46:21 +08:00
// int alphaSize = mResource->mDequantize.mScaleBias->size() / (sizeof(float) * 2);
int alphaSize = mResourceInt8->mOriginScale->size() / (sizeof(float) * 2);
2024-07-22 19:51:53 +08:00
2023-06-16 09:42:45 +08:00
auto bufferAlloc = static_cast<CPUBackend*>(backend())->getBufferAllocator();
auto blitInfoSize = ConvolutionTiledExecutor::computeBlitInfoSize(DST_XUNIT * mIm2ColCount, mIm2ColParamter.ow, mIm2ColParamter.kernelX * mIm2ColParamter.kernelY, mThreadNums);
2024-07-22 19:51:53 +08:00
mBlitInfoStride = blitInfoSize.second;
2023-06-16 09:42:45 +08:00
mBlitInfo = bufferAlloc->alloc(blitInfoSize.first);
2024-08-24 15:46:21 +08:00
auto icDiv4KernelCount = mIm2ColParamter.kernelCountUnit;
mTempIm2ColBuffer.reset(Tensor::createDevice<int8_t>({threads, DST_XUNIT * mIm2ColCount * icDiv4KernelCount * SRC_UNIT}));
mTempSrcSum.resize(threads * mBlockNum * DST_XUNIT * mIm2ColCount * 4); // Use 4 bytes to save kernel sum.
2024-07-22 19:51:53 +08:00
success &= backend()->onAcquireBuffer(mTempIm2ColBuffer.get(), Backend::DYNAMIC);
if (!success || mBlitInfo.invalid()) {
2023-06-16 09:42:45 +08:00
return OUT_OF_MEMORY;
}
2024-09-12 12:57:57 +08:00
if (false == mResourceInt8->mDynamicQuant) {
2024-07-22 19:51:53 +08:00
bufferAlloc->free(mBlitInfo);
backend()->onReleaseBuffer(mInputDeqScales.get(), Backend::DYNAMIC);
backend()->onReleaseBuffer(mTempIm2ColBuffer.get(), Backend::DYNAMIC);
return NO_ERROR;
}
2023-06-16 09:42:45 +08:00
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
int inC = inputs[0]->channel();
// set im2col tensor info
mQuantInput.reset((Tensor::createDevice<int8_t>({batch, mIm2ColParamter.ih, mIm2ColParamter.iw, ROUND_UP(inC, gcore->pack)})));
// set dynamic quant buffer
mTempMaxMinValueBuffer.reset(Tensor::createDevice<uint8_t>({mThreadNums, 2 * gcore->bytes}));
// set compute buffer
mDynamicBias.reset(Tensor::createDevice<uint8_t>({ocUp4 * 4}));
mScaleFuse.reset(Tensor::createDevice<uint8_t>({alphaSize * 4}));
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
success &= backend()->onAcquireBuffer(mQuantInput.get(), Backend::DYNAMIC);
success &= backend()->onAcquireBuffer(mDynamicBias.get(), Backend::DYNAMIC);
success &= backend()->onAcquireBuffer(mTempMaxMinValueBuffer.get(), Backend::DYNAMIC);
success &= backend()->onAcquireBuffer(mScaleFuse.get(), Backend::DYNAMIC);
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
if (mUseBatchQuan) {
int infobytes = 4; // use float32 to save dequant scale and quant scale.
int size = mThreadNums * batch * gcore->bytes + 2 * batch * infobytes;
mBatchQuantInfo.reset(Tensor::createDevice<int8_t>({size}));
success &= backend()->onAcquireBuffer(mBatchQuantInfo.get(), Backend::DYNAMIC);
}
if (!success) {
return OUT_OF_MEMORY;
}
bufferAlloc->free(mBlitInfo);
backend()->onReleaseBuffer(mInputDeqScales.get(), Backend::DYNAMIC);
backend()->onReleaseBuffer(mTempIm2ColBuffer.get(), Backend::DYNAMIC);
2024-07-22 19:51:53 +08:00
backend()->onReleaseBuffer(mQuantInput.get(), Backend::DYNAMIC);
backend()->onReleaseBuffer(mDynamicBias.get(), Backend::DYNAMIC);
backend()->onReleaseBuffer(mTempMaxMinValueBuffer.get(), Backend::DYNAMIC);
backend()->onReleaseBuffer(mScaleFuse.get(), Backend::DYNAMIC);
if (mUseBatchQuan) {
backend()->onReleaseBuffer(mBatchQuantInfo.get(), Backend::DYNAMIC);
}
return NO_ERROR;
}
2021-09-18 15:52:30 +08:00
ErrorCode DenseConvInt8TiledExecutor::onExecute(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs) {
// Timer kernelTimer;
const auto input = inputs[0];
auto output = outputs[0];
auto core = static_cast<CPUBackend*>(backend())->int8Functions();
2024-07-22 19:51:53 +08:00
auto gcore = static_cast<CPUBackend*>(backend())->functions();
2021-09-18 15:52:30 +08:00
2024-10-21 14:32:47 +08:00
#ifdef MNN_KLEIDIAI_ENABLED
KleidiAI& kai = KleidiAI::getInstance();
2024-10-22 14:37:28 +08:00
if(mResourceInt8->mDynamicQuant && mResourceInt8->mActBits == 4 && kai.canAccelerate()) {
const size_t m = input->batch(); //lhs vector number.
const size_t n = output->channel(); //rhs vector number.
const size_t k = input->channel(); //vector size.
2024-10-22 14:37:28 +08:00
auto lhs = input->host<uint8_t>();
auto lhsPacked = mTempIm2ColBuffer->host<int8_t>();
auto rhsPacked = mResourceInt8->mWeightInt8->host<uint8_t>();
auto dst = output->host<uint8_t>();
2024-10-21 14:32:47 +08:00
2024-10-22 14:37:28 +08:00
int threadNum = static_cast<CPUBackend*>(backend())->threadNumber();
int threadNeed, vecPerThread;
#if !KAI_CONV_NCHW_IN_OUT
2024-10-22 14:37:28 +08:00
kai.packNC4HW4ToNCHW((float *)lhs, m, k);
#endif
2024-10-22 14:37:28 +08:00
//Dynamic quant pack lhs.
if(m == 1) {
kai.runLhsQuantPack(1, k, 1, lhs, lhsPacked);
} else {
vecPerThread = kai.getVecNumPerThread(m, threadNum, kai.getMr(m));
threadNeed = m % vecPerThread == 0 ? m / vecPerThread : (m / vecPerThread + 1);
size_t srcStride = vecPerThread * k * sizeof(float);
auto BatchDynamicQuant = [=, &kai](int tId) {
auto threadSrc = lhs + tId * srcStride;
auto threadDst = lhsPacked + kai.getLhsQuantedPackedOffset(m, tId * vecPerThread, k);
int vecNum = (tId == threadNeed - 1) ? (m - vecPerThread * tId) : vecPerThread; //Last threadN may less than vecPerThread.
kai.runLhsQuantPack(vecNum, k, kai.getMr(m), threadSrc, threadDst);
};
MNN_CONCURRENCY_BEGIN(tId, threadNeed) {
2024-10-22 14:37:28 +08:00
BatchDynamicQuant((int)tId);
}
MNN_CONCURRENCY_END();
2024-10-22 14:37:28 +08:00
}
//Run matmul.
vecPerThread = kai.getVecNumPerThread(n, threadNum, kai.getNStep());
threadNeed = n % vecPerThread == 0 ? n / vecPerThread : (n / vecPerThread + 1);
auto ThreadFunction = [=, &kai](int tId) {
auto threadRhsPacked = rhsPacked + kai.getRhsPackedOffset(tId * vecPerThread, k);
auto threadDst = dst + kai.getDstOffset(0, tId * vecPerThread, n);
int vecNum = (tId == threadNeed - 1) ? (n - vecPerThread * tId) : vecPerThread; //Last threadN may less than vecPerThread.
kai.runMatmul(m, vecNum, k, lhsPacked, threadRhsPacked, n * sizeof(float), threadDst);
};
MNN_CONCURRENCY_BEGIN(tId, threadNeed) {
ThreadFunction((int)tId);
}
MNN_CONCURRENCY_END();
#if !KAI_CONV_NCHW_IN_OUT
2024-10-22 14:37:28 +08:00
kai.packNCHWToNC4HW4((float *)dst, m, n);
#endif
2024-10-22 14:37:28 +08:00
return NO_ERROR;
}
#endif
2023-06-16 09:42:45 +08:00
int UNIT__, SRC_UNIT, DST_XUNIT;
core->MNNGetGemmUnit(&UNIT__, &SRC_UNIT, &DST_XUNIT);
auto blitProc = core->MNNPackC4Int8ForMatMul_A;
2024-07-22 19:51:53 +08:00
const int plane = output->batch() * mIm2ColParamter.oh * mIm2ColParamter.ow;
const int batch = input->batch();
const int PackUnit = gcore->pack;
const int dstZStep = plane * PackUnit;
const int ocDiv4 = UP_DIV(output->channel(), PackUnit);
const int ocUp4 = ROUND_UP(output->channel(), PackUnit);
const auto kernelCountUnitDouble = mIm2ColParamter.kernelCountUnit;
2024-07-22 19:51:53 +08:00
const auto col_buffer_unit_size = kernelCountUnitDouble * DST_XUNIT * SRC_UNIT * sizeof(int8_t);
const auto col_buffer_size = col_buffer_unit_size * mIm2ColCount;
const int dstBytes = static_cast<CPUBackend*>(backend())->getBytes(backend(), output);
2024-08-24 15:46:21 +08:00
// const int alphaSize = mResource->mDequantize.mScaleBias->size() / (4 * 2);
const int alphaSize = mResourceInt8->mOriginScale->size() / (sizeof(float) * 2);
2024-07-22 19:51:53 +08:00
const int blockL = kernelCountUnitDouble / mBlockNum; // source depthQuad for each block.
float weightBytes = 1.f;
int weight_step_Y = weightBytes * (UNIT__ * SRC_UNIT);
int src_step_Y = DST_XUNIT * SRC_UNIT;
auto inputDataPtr = input->host<int8_t>();
auto im2colPtr = mTempIm2ColBuffer->host<int8_t>();
2024-10-14 19:26:28 +08:00
if (SRC_UNIT > PackUnit) {
memset(im2colPtr, 0, mTempIm2ColBuffer->size());
}
2024-07-22 19:51:53 +08:00
const auto weightDataPtr = mResourceInt8->mWeightInt8->host<int8_t>();
auto srcKernelSumPtr = mTempSrcSum.data();
2024-08-24 15:46:21 +08:00
auto weightDequantBias = mResourceInt8->mOriginScale->host<uint8_t>() + alphaSize * 4;
2024-07-22 19:51:53 +08:00
auto outputDataPtr = output->host<int8_t>();
2024-09-12 12:57:57 +08:00
uint8_t* biasPtr = nullptr;
uint8_t* scalePtr = nullptr;
int32_t inputZeroPoint = 0;
2024-07-22 19:51:53 +08:00
auto inputScalePtr = mInputDeqScales->host<uint8_t>();
2024-09-12 12:57:57 +08:00
if (nullptr != mMutableResource.get()) {
biasPtr = mMutableResource->mBiasFloat->host<uint8_t>();
scalePtr = mMutableResource->mScaleFloat->host<uint8_t>();
inputZeroPoint = mMutableResource->mInputZeroPoint;
(reinterpret_cast<float*>(inputScalePtr))[0] = mMutableResource->mInputScale;
}
2024-07-22 19:51:53 +08:00
auto SingleDynamicQuant = [&] () {
const auto floatptr = input->host<float>();
auto int8ptr = mQuantInput->host<int8_t>();
auto inputsize = static_cast<CPUBackend*>(backend())->getTensorSize(inputs[0]);
float quantscale = 0.f;
float dequantscale = 0.f;
2024-09-12 12:57:57 +08:00
float zeropoint = 0;
2024-07-22 19:51:53 +08:00
/* Count max and min value to compute input scale and zeropoint */
auto maxMinValPtr = mTempMaxMinValueBuffer->host<uint8_t>();
int threadNeed = mThreadNums;
auto inputSizeCount = UP_DIV(inputsize, mThreadNums);
if (inputSizeCount < 9) {
threadNeed = 1;
inputSizeCount = inputsize;
} else {
threadNeed = ALIMIN(UP_DIV(inputsize, inputSizeCount), mThreadNums);
inputSizeCount = UP_DIV(inputsize, threadNeed);
}
auto findMaxMinValueFunction = [&](int tId) {
auto perThreadWorkCount = ALIMIN(inputSizeCount, inputsize - tId * inputSizeCount);
auto minValPtrTid = reinterpret_cast<float*>(maxMinValPtr + tId * mTempMaxMinValueBuffer->stride(0));
auto maxValPtrTid = reinterpret_cast<float*>(maxMinValPtr + tId * mTempMaxMinValueBuffer->stride(0) + gcore->bytes);
auto inputDataPtrTid = reinterpret_cast<float*>(reinterpret_cast<uint8_t*>(floatptr) + tId * inputSizeCount * gcore->bytes);
gcore->MNNCountMaxMinValue(inputDataPtrTid, minValPtrTid, maxValPtrTid, perThreadWorkCount);
};
MNN_CONCURRENCY_BEGIN(tId, threadNeed) {
findMaxMinValueFunction((int)tId);
}
MNN_CONCURRENCY_END();
if (threadNeed > 1) {
gcore->MNNCountMaxMinValue(reinterpret_cast<float*>(maxMinValPtr),reinterpret_cast<float*>(maxMinValPtr), reinterpret_cast<float*>(maxMinValPtr + gcore->bytes), 2 * mThreadNums);
}
float maxVal = 0;
float minVal = 0;
if (gcore->bytes == 4) {
maxVal = (reinterpret_cast<float*>(maxMinValPtr))[1];
minVal = (reinterpret_cast<float*>(maxMinValPtr))[0];
}
if (gcore->bytes == 2) {
std::vector<float> _mVal(2);
gcore->MNNLowpToFp32(reinterpret_cast<int16_t*>(maxMinValPtr), _mVal.data(), 2);
maxVal = _mVal[1];
minVal = _mVal[0];
}
2024-07-22 19:51:53 +08:00
/* Dynamic quant */
2024-11-18 14:37:45 +08:00
if (mCommon->padX() > 0 || mCommon->padY() > 0) { // Ensure "0.0f" included in range.
if (minVal > 0.f) {
minVal = 0.f;
} else if (maxVal < 0.f){
maxVal = 0.f;
} else {
//
}
}
2024-07-22 19:51:53 +08:00
float range = maxVal - minVal;
if (fabs(range) < 1e-7) {
zeropoint = maxVal;
quantscale = 1.0f;
dequantscale = 1.0f;
} else {
quantscale = 255.0f / range;
dequantscale = range / 255.0f;
zeropoint = roundf(-minVal * 255.f / range) - 128.0f;
}
2024-07-22 19:51:53 +08:00
auto sizeDiv = UP_DIV(inputsize, PackUnit);
2024-11-18 14:37:45 +08:00
threadNeed = mThreadNums;
inputSizeCount = UP_DIV(sizeDiv, mThreadNums);
if (inputSizeCount < 9) {
threadNeed = 1;
inputSizeCount = sizeDiv;
2024-07-22 19:51:53 +08:00
} else {
2024-11-18 14:37:45 +08:00
threadNeed = ALIMIN(UP_DIV(sizeDiv, inputSizeCount), mThreadNums);
inputSizeCount = UP_DIV(sizeDiv, threadNeed);
2024-07-22 19:51:53 +08:00
}
2024-11-18 14:37:45 +08:00
MNN_CONCURRENCY_BEGIN(tId, threadNeed) {
auto perThreadWorkCount = ALIMIN(inputSizeCount, sizeDiv - tId * inputSizeCount);
auto inptr_ = (float*)(((int8_t*)floatptr) + tId * inputSizeCount * PackUnit * gcore->bytes);
mQuantFunc(inptr_ , int8ptr + tId * inputSizeCount * PackUnit, perThreadWorkCount, &quantscale, -128, 127, &zeropoint, 0);
}
MNN_CONCURRENCY_END();
2021-09-18 15:52:30 +08:00
2024-07-22 19:51:53 +08:00
/* bias float */
2024-08-24 15:46:21 +08:00
#ifdef MNN_USE_SSE
2024-07-22 19:51:53 +08:00
int offset = 128;
#else
int offset = 0;
#endif
2024-09-12 12:57:57 +08:00
auto biasfp32 = mResourceInt8->mOriginBias->host<float>();
2024-08-24 15:46:21 +08:00
auto weightDequantScale = mResourceInt8->mOriginScale->host<float>();
2024-07-22 19:51:53 +08:00
float zerofp32 = (zeropoint + offset) * dequantscale;
2024-08-24 15:46:21 +08:00
gcore->MNNDynamicUpdateConvBiasScale(mDynamicBias->host<float>(), mScaleFuse->host<float>(), biasfp32, weightDequantScale, &dequantscale, mResourceInt8->mWeightKernelSum->host<float>(), &zerofp32, UP_DIV(output->channel(), 4), alphaSize);
2024-07-22 19:51:53 +08:00
// Move step for A and B for each block computing
inputZeroPoint = zeropoint;
(reinterpret_cast<float*>(inputScalePtr))[0] = dequantscale;
biasPtr = mDynamicBias->host<uint8_t>();
scalePtr = mScaleFuse->host<uint8_t>();
inputDataPtr = int8ptr;
};
auto BatchDynamicQuant = [&]() {
// Allocate input max/sum/dequant/quant buffer
auto infobytes = 4;
auto dequantPtr = mBatchQuantInfo->host<uint8_t>();
auto quantPtr = dequantPtr + batch * infobytes;
auto maxPtr = mBatchQuantInfo->host<uint8_t>() + 2 * batch * infobytes;
// compute sum and absmax
int icDiv4 = UP_DIV(input->channel(), PackUnit);
int threadwork = UP_DIV(icDiv4, mThreadNums);
int threadNeed = UP_DIV(icDiv4, threadwork);
int threadTmp = ALIMIN(mThreadNums, threadNeed);
threadwork = UP_DIV(icDiv4, threadTmp);
MNN_CONCURRENCY_BEGIN(tId, threadTmp) {
int workCount = threadwork;
if (tId == threadTmp - 1) {
workCount = icDiv4 - tId * threadwork;
}
int icIndex = tId * threadwork;
auto inputData = reinterpret_cast<const float*>(input->host<uint8_t>() + icIndex * batch * PackUnit * gcore->bytes);
auto batchMax = reinterpret_cast<float*>(maxPtr + tId * batch * gcore->bytes);
gcore->MNNAbsMax(inputData, batchMax, workCount, batch, PackUnit);
}
MNN_CONCURRENCY_END();
// Compute quant scale
gcore->MNNQuantScale((float*)maxPtr, (float*)quantPtr, (float*)dequantPtr, threadTmp, batch);
// quant
MNN_CONCURRENCY_BEGIN(tId, threadTmp) {
int workCount = threadwork;
if (tId == threadTmp - 1) {
workCount = icDiv4 - tId * threadwork;
}
auto icIndex = tId * threadwork;
auto inputData = reinterpret_cast<float*>(input->host<uint8_t>() + icIndex * batch * PackUnit * gcore->bytes);
auto int8ptr = mQuantInput->host<int8_t>() + icIndex * batch * PackUnit;
auto scale_ptr = reinterpret_cast<float*>(quantPtr);
gcore->MNNDynamicQuant(inputData, int8ptr, scale_ptr, workCount, batch, PackUnit);
}
MNN_CONCURRENCY_END();
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
inputZeroPoint = 0;
inputScalePtr = (uint8_t*)dequantPtr;
inputDataPtr = mQuantInput->host<int8_t>();
2024-09-12 12:57:57 +08:00
biasPtr = mResourceInt8->mOriginBias->host<uint8_t>();
2024-08-24 15:46:21 +08:00
scalePtr = mResourceInt8->mOriginScale->host<uint8_t>();
2024-07-22 19:51:53 +08:00
};
ssize_t oneScale = 1;
if (mUseBatchQuan) {
BatchDynamicQuant();
oneScale = 0;
2024-09-12 12:57:57 +08:00
} else if (mResourceInt8->mDynamicQuant) {
2024-07-22 19:51:53 +08:00
SingleDynamicQuant();
} else {
2024-07-22 19:51:53 +08:00
// offline quant.
}
2024-08-24 15:46:21 +08:00
if (mResourceInt8->mActBits == 4) {
2024-07-22 19:51:53 +08:00
weightBytes = 0.5;
weight_step_Y *= 0.5;
2023-12-27 17:26:44 +08:00
}
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
SumByAxisParams sumParams;
sumParams.oneScale = oneScale;
sumParams.SRC_UNIT = SRC_UNIT;
sumParams.blockNum = mBlockNum;
sumParams.DST_XUNIT = DST_XUNIT;
sumParams.col_buffer_unit_size = col_buffer_unit_size;
sumParams.kernelCountUnitDouble = kernelCountUnitDouble;
2024-08-24 15:46:21 +08:00
2024-07-22 19:51:53 +08:00
auto ThreadFunction = [&](int tId, int eStartIndex, int eEndIndex, int estep, int ocIndex) {
auto ocDivThread = ocDiv4;
if (mSplitByOc) { // Thread split by OC
ocDivThread = ALIMIN(mDivides[tId + 1] - mDivides[tId], ocDiv4 - mDivides[tId]);
}
2024-08-24 15:46:21 +08:00
float* reluPtr = mResourceInt8->mReluThreshold.data();
2024-07-22 19:51:53 +08:00
uint8_t* extraScale = nullptr; // input scale for batch dynamic quant.
QuanPostTreatParameters quanParam;
quanParam.blockNum = mBlockNum;
if (mUseBatchQuan) {
extraScale = inputScalePtr;
}
#ifdef MNN_USE_SSE
2024-08-24 15:46:21 +08:00
quanParam.extraBias = mResourceInt8->mWeightKernelSum->host<float>() + ocIndex;
2024-07-22 19:51:53 +08:00
#endif
if (dstBytes != 1) {
quanParam.useInt8 = 0;
quanParam.fp32minmax = reluPtr;
} else {
2024-08-24 15:46:21 +08:00
quanParam.maxValue = mMutableResource->mClampMax;
2024-07-22 19:51:53 +08:00
if (mResourceInt8->mRelu) {
2024-08-24 15:46:21 +08:00
quanParam.minValue = mMutableResource->mOutputZeroPoint;
2024-07-22 19:51:53 +08:00
} else {
2024-08-24 15:46:21 +08:00
quanParam.minValue = mMutableResource->mClampMin;
2024-07-22 19:51:53 +08:00
}
}
auto outputTid = outputDataPtr + ocIndex * plane * dstBytes;
const auto biasFloatTid = reinterpret_cast<float*>(biasPtr + ocIndex * 4);
const auto scaleFloatTid = reinterpret_cast<float*>(scalePtr + ocIndex * 4);
const auto weightDequanBiasTid = reinterpret_cast<float*>(weightDequantBias + ocIndex * 4);
2024-10-14 19:26:28 +08:00
const auto weightPtrTid = weightDataPtr + static_cast<int32_t>(ocIndex * blockL * SRC_UNIT * weightBytes);
2024-07-22 19:51:53 +08:00
if (mBlockNum == 1) {
quanParam.biasFloat = biasFloatTid;
quanParam.scale = scaleFloatTid;
quanParam.weightQuanBias = weightDequanBiasTid;
}
[MNN:Sync] Sync internal github Commits: 8148ae75c 弗人 bugfix 14cb8ec7f 弗人 [Converter:Bugfix] bugfix for onnx depthwise convtranspose 476fbcd90 雁行 [MNN:Feature] Open AVX cast and bugfix for contentCFG. 5e26b9fd3 雁行 [Test:Feature] Add android test. 37e147b25 雁行 [MNN:Bugfix] Bugfix for floordiv. 144c185f5 tianbu.xsw hangxing fix hiai b4fd429d6 tianbu.xsw updateCacheFile bugfix -- update cache size d4ba572a8 雁行 [MNN:Bugfix] Support int8 in AVX2 and some Bugfix. 43061f07e xiaying [MNN:Bugfix] Fix bug for module mode run part of model 398cc5ab6 tianhang.yth refactor demo 736380600 xiaying [Express:Bugfix] Fix memory leak for copy branch b8dab0a27 tianhang.yth MNNFloat2Int8 sizeQuad=0 crash fix 94b95bfed ghz [BugFix]1.Better method for fast pack valid check 6a921f85e xiaying [Converter:Bugfix] Fix bug for Fuseconsttosubgraph 5f77ae889 tianhang.yth numThread bugfix a807ef879 tianhang.yth add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix ad05409d3 xiaying [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode 9d81b8299 xiaying [MNN:Bugfix] Fix bug for Unique op for output size = 1 03b15e9af xiaying [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert c944a76ee tianhang.yth add auto backend and getSessionInfo @tianbu 91fa7267b ghz [BugFix]1.fix the error in eP check bf0041f77 ghz [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error 693871672 雁行 [CPU:Bugfix] rm adrp instruction for clang compiler bug. 1b8f6b3d8 ghz 1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process. feb7ecc4c 弗人 modify log of python offline quant 040c04811 ghz [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version 609f37db8 弗人 add log for python quant, python convert 5511dd30a ghz [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter. a93ff9280 tianhang.yth add tf.Unique op support 9729ff773 allen.lk [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead. 297c1ad14 雁行 [Expr:Bugfix] bugfix for tensor content used by shape compute. ef8c369e3 弗人 catch exception 07c2dd670 弗人 add dependence to setup, base64 encode url, add time log 177e590c1 弗人 [Python:Feature] add aliyun log for python quant tool 40a7928cf allen.lk [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution 3bdea84a1 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. c3c6fbdbd allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. bc590eee4 雁行 [Converter:Bugfix] bugfix for onnx instancenormalization convert. d8918593f tianhang.yth add auto backend and getSessionInfo @tianbu 83a198ed7 杭行 update d0dd3e09b 杭行 update 99540202e xiaying [Converter:Optimize] Opt the tensor convert insert 333d8db82 allen.lk [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64. db5994672 杭行 merge 6293de7b8 tianbu.xsw fix pymnn updateCacheFile 5c2e11cb1 tianbu.xsw do updateCache in createSession 6e7641ff4 tianbu.xsw do not limit cacheFile for a model 5287a65e4 tianbu.xsw bugfix 52ba53a91 tianbu.xsw revert pymnn api 60284d830 tianbu.xsw bugfix 6d8077490 tianbu.xsw rename updateCacheFile api params 3cb172710 tianhang.yth updateCacheFile API size default value is 0 c5b69aabf tianbu.xsw updateCacheFile python api fix 5d5da7aa5 tianbu.xsw reflector code 5707877a4 雁行 [MNN:Speed] Speedup for softmax in x86 and arm. 2a211825c tianbu.xsw reflector code for updateCacheFile 76db3a835 tianbu.xsw [Cache Feature]: Add updateCacheFile API for increment cache b06b0fd43 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. e68bfa495 雁行 [Converter:Feature] Add UUID when model convert. a9cb935dc xiaying [MNN:Speed] Support c4nhwc for more fastblit 019f40353 xiaying [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G -> 1G) d2a6d3d05 xiaying [MNN:Bugfix] Fix bug for identity output not find 604d0801b xiaying [Converter:Bugfix] Fix bug for FuseGeLu 4bada2367 xiaying [MNN:Refractor] SegmentMean rewrite as segment 82070e708 xiaying [MNN:Bugfix] Fix bug for GeometryBinary e8ea4266e xiaying Fix bug for ShapeTensorConvert compute for dim = 1 error 1f1cf1991 xiaying [Tools:Bugfix] Fix system compability for fastTestOnnx 6f422efe2 xiaying [Tools:Bugfix] Remove color for checkDir for easy to dump 968f7ec88 xiaying [MNN:Speed] Support turn broadcast binary to loop 3e7aaf46f xiaying [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr 1f65ab163 xiaying [MNN:Bugfix] Fix bug for mini mnn can't convert model d65953d47 xiaying [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82 8b68be45c xiaying [MNN:Feature] Add segment 8a8f264f5 xiaying [Vulkan:Bugfix] Remove unuseful print 025bb0fda xiaying [Converter:Bugfix] Fix bug for oneof don't support 43900251e tianbu.xsw enable setCacheFile python API ebfb05c74 tianbu.xsw [Metal Feature] support metallib obtain from walle transfer task 9665c0a79 弗人 add check for path in json file c66fef224 xiaying [Converter:Bugfix] Fix bug for oneof don't support 42f192852 xiaying [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs 1b95354ff 雁行 [Feature]: Support shape compute for SetDiff1D, and null input for Prod. 83966d043 xiaying [Test:Feature] Add test for static module 42d1be933 xiaying [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model 9067531c3 xiaying [Converter:Refractor] formatLicence 99558bed9 xiaying [Converter:Bugfix] Count the op for unuseful and controlflow 4f6da0fa7 allen.lk [Feature:GRUMultiOutput] fix multi output dimension type c6b219bce xiaying [Converter:Feature] Turn torch converter to object dd4e68a37 xiaying [Converter:Feature] Support dump supported ops 80b6a60a3 xiaying [Converter:Info] If has output name, print output name instead of computed 015278fc3 xiaying [MNN:Refractor] Revert IfModule's debug info 23ac967c4 xiaying Don't transform for multi-input convolution/deconvolution b02b0d4de xiaying Fix bug for multi-input for conv1d 254d8b1d4 xiaying Fix bug for Conv1dSqueezeMove for multi input convolution 1d d47d0b9ca xiaying Fix bug for CPURaster's fuse nc4hw4 357c5bd33 xiaying Fix ConvBiasAdd for conv's inputs op > 1 55b1f0c9c xiaying [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution 1902a30f5 xiaying [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d c23fe617b xiaying [MNN:Bugfix] Fix bug for multi-input for conv1d 8ff018426 xiaying [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4 d4e8cd602 xiaying [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1 846266b42 tianbu.xsw return when program and tune both nullptr fd67c76a9 xiaying [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite e77a242c4 xiaying [Converter:Feature] Support tflite's half pixel be054c377 tianbu.xsw [OpenCL Bugfix] do not rewrite cache when binary program is produced 51e65aa35 xiaying [Converter:Feature] Support tflite for fp16 and multi-input convolution 1ccdfdeb5 tianbu.xsw redefine svm macro name 31234d372 tianbu.xsw [OpenCL SVM] add macro for only use wrapper d739e35da xiaying [MNN:Bugfix] Fix compile bug for grid op 24ab13c79 Joker feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying) 7b142978e xiaying [AVX512:Speed] Optimize for e <= 8 5f6febe7b tianbu.xsw code refactor 998d91b57 xiaying [Express:Speed] Merge submodule for speed 22c89146f tianhang.yth fix alpha div by zero bug and arm server compile bug 8f829a170 tianbu.xsw [OpenCL Pad] unify conv/deconv pad computing 4a28f603e xiaying [Express:Speed] Shared Const for All Submodule c74cf28f3 xiaying [MNN:Refractor] Seperate Const init and schedule 2a1eebb7a xiaying [Tools:Bugfix] Fix bug for modelTest.py count size 72f04008c xiaying [MNN:Refractor] Delete unuseful const op 1e735d03c xiaying [Converter:Bugfix] Fix bug for static module gen 4dfadbc6e xiaying [MNN:Refractor] Rewrite const init mode 1fcf0417a xiaying [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch 41d429cfd xiaying [Train:Bugfix] Revert convert NCHW for mnistTrain f947a5f01 xiaying [Test:Feature] Add testTrain dad59b6f6 tianbu.xsw move realize code from Backend.hpp to Tensor.cpp cf4473ad1 xiaying [Train:Bugfix] Support pad for GeometryPoolGrad 91ab13734 xiaying [MNN:Bugfix] Fix compile bug for avx512 742e80f47 xiaying [MNN:Refractor] Opt the logic for checknan judge 12543b841 xiaying [ARM82:Bugfix] Fix compile bug for ios 3a2b0a49f xiaying [ARM82:Speed] Opt Pack / Unpack for armv8 c0f1995cd xiaying [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm e0fc77dcf xiaying [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it 584bec578 xiaying [MNN:Bugfix] Fix bug for format set error for onnx d5bd4148d xiaying [MNN:Bugfix] Fix bug for format set error for onnx b00265841 xiaying [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor bb09188ac xiaying [Test:Bugfix] Fix bug for run into sparse auto 426d1babd xiaying [MNN:Refractor] Small bugfix for Group convolution and pack 7d0ea1c46 tianbu.xsw [testModel Feature] support testModel.out input resize 4169c54ce xiaying [MNN:Bugfix] Fix bug for checkNAN for origin 412a82222 xiaying [Test:Bugfix] Fix bug for CheckNAN's error of matmul 319b1d425 xiaying [MNN:Bugfix] Fix bug for multi-batch for ConvInt8 050b728a6 xiaying [Test:Bugfix] Use NCHW for ConvInt8Test 7db3423a1 xiaying [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4 adcec6a7f xiaying [Vulkan:Bugfix] Fix bug for invalid tensor size limit d2a7cf4e9 xiaying [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4 557bebdd3 xiaying [MNN:Bugfix] Fix bug for BF16-ARM32 bbe186649 tianbu.xsw [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority 6deb23439 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size b137590e4 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size 7003558ea xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case b5f8cae5a xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case 29b09e125 xiaying [MNN:Bugfix] Fix bug for arm64-bf16 42ce00770 xiaying [MNN:Bugfix] Fix bug for ARM64 - float a2d89fc18 雁行 [Converter:Feature] Support Binary Unary for Torch. 7f1c0deb1 xiaying [MNN:Bugfix] Fix bug for Raster for Int8 8335a6f18 tianbu.xsw [OpenCL Shared Memory] modify data_format method b359e031b xiaying [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8 24bf3fc88 雁行 [Convert:Feature] Support LayerNormFuse without gamma beta. 3e629624b xiaying [MNN:Bugfix] Fix bug for float - armv7a 2b7908ec7 tianbu.xsw modify workItemSize 3cee0d413 xiaying [MNN:Bugfix] test wrong clear 9cbbfb998 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 2d7a44484 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 eb7d0cb53 xiaying [Test:Bugfix] Don't test for NC4HW4 directly 7b40ca8d1 xiaying [MNN:Bugfix] Fix bug for ConvolutionGroup 2694d8a91 xiaying [MNN:Bugfix] Fix bug for CPUGridSample f89af60f6 xiaying [MNN:Bugfix] Fix compile bug for arm a151abcdd xiaying [MNN:Bugfix] Fix bug for convert for int8 / int16 b254dbe61 雁行 [MNN:Bugfix] Bugfix for Conv onClone. d08150631 xiaying [MNN:Bugfix] Fix bug for fast rcnn e5568a0df xiaying [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit 128318933 雁行 [Raster:Bugfix] bugfix for Raster merge onResize. 03caacbea xiaying [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow e1e3c245c xiaying [MNN:Bugfix] Fix bug for ConvolutionWinograd 2524cbc6d xiaying [MNN:Bugfix] Fix bug for CPUSoftmax 44ec79b8f xiaying [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW 21ae956ce xiaying [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor 09a5069c7 xiaying [MNN:Speed] Add offset for src and dst 6776c6784 xiaying [MNN:Bugfix] Fix bug for trainable model cc83ae30b xiaying [MNN:Bugfix] Fix bug for trainable model
2021-07-29 11:46:59 +08:00
auto colAddr = im2colPtr + tId * mTempIm2ColBuffer->stride(0);
2023-09-04 10:42:11 +08:00
auto srcPtr = (int8_t const **)(mBlitInfo.ptr() + tId * mBlitInfoStride.first);
2023-06-16 09:42:45 +08:00
auto el = (int32_t *)(srcPtr + mBlitInfoStride.second);
2024-07-22 19:51:53 +08:00
auto xKernelSumPtrTid = reinterpret_cast<float*>(srcKernelSumPtr + tId * mBlockNum * DST_XUNIT * mIm2ColCount * 4);
2023-06-16 09:42:45 +08:00
2024-07-22 19:51:53 +08:00
int32_t info[6];
2023-06-16 09:42:45 +08:00
info[1] = mIm2ColParamter.iw * mIm2ColParamter.ih * batch;
2024-07-22 19:51:53 +08:00
info[2] = static_cast<int32_t>(col_buffer_unit_size);
2023-06-16 09:42:45 +08:00
info[3] = mIm2ColParamter.strideX;
2024-07-22 19:51:53 +08:00
info[5] = kernelCountUnitDouble;
for (int tIndex = eStartIndex; tIndex < eEndIndex; tIndex += estep) {
2023-06-16 09:42:45 +08:00
const int xIndexStart = tIndex * DST_XUNIT * mIm2ColCount;
int realDstCount = ALIMIN(plane - xIndexStart, DST_XUNIT * mIm2ColCount);
2024-07-22 19:51:53 +08:00
auto ptrExtraScale = extraScale != nullptr ? (extraScale + xIndexStart * 4) : nullptr;
auto ptrInputscale = mUseBatchQuan == true ? (inputScalePtr + xIndexStart * 4) : inputScalePtr;
2023-06-16 09:42:45 +08:00
// im2col
auto res = ConvolutionTiledExecutor::turnIm2ColToBlitInfo((const float**)srcPtr, el, xIndexStart, realDstCount, mIm2ColParamter, (const uint8_t*)inputDataPtr, 1);
int number = res.first;
bool needZero = res.second;
if (needZero) {
#ifdef MNN_USE_SSE
2024-07-22 19:51:53 +08:00
::memset(colAddr, inputZeroPoint + 128, col_buffer_size);
2021-09-18 15:52:30 +08:00
#else
2024-07-22 19:51:53 +08:00
::memset(colAddr, inputZeroPoint, col_buffer_size);
#endif
}
2023-06-16 09:42:45 +08:00
info[0] = number;
2024-07-22 19:51:53 +08:00
info[4] = realDstCount;
2023-06-16 09:42:45 +08:00
if (number > 0) {
blitProc(colAddr, srcPtr, info, el);
}
2024-07-22 19:51:53 +08:00
if (mResourceInt8->mWeightAsymmetricQuant) {
mSumByAxisLFunc(xKernelSumPtrTid, colAddr, (float*)ptrInputscale, realDstCount, sumParams);
}
auto outputInTilePtr = outputTid + xIndexStart * PackUnit * dstBytes;
2023-06-16 09:42:45 +08:00
auto colAddrTemp = colAddr;
2024-07-22 19:51:53 +08:00
auto ptrX = xKernelSumPtrTid;
if (mBlockNum == 1) {
do {
int step = ALIMIN(DST_XUNIT, realDstCount);
quanParam.srcKernelSum = ptrX;
quanParam.extraScale = extraScale != nullptr ? (float*)ptrExtraScale : nullptr;
2024-08-24 15:46:21 +08:00
// printf("step=%d, ocDivThread=%d\n", step, ocDivThread);
2024-07-22 19:51:53 +08:00
mGemmKernel(outputInTilePtr, colAddrTemp, weightPtrTid, kernelCountUnitDouble, dstZStep * dstBytes, ocDivThread, &quanParam, step);
ptrX += step;
realDstCount-=step;
outputInTilePtr += DST_XUNIT * PackUnit * dstBytes;
colAddrTemp += col_buffer_unit_size;
ptrExtraScale = extraScale != nullptr ? (ptrExtraScale + step * 4) : nullptr;
} while(realDstCount > 0);
} else { // Now offline quant do not run into.
do {
int step = ALIMIN(DST_XUNIT, realDstCount);
quanParam.extraScale = extraScale != nullptr ? (float*)ptrExtraScale : nullptr;
for (int k = 0; k < mBlockNum; ++k) {
quanParam.biasFloat = nullptr;
quanParam.fp32minmax = nullptr;
if (k == 0) {
quanParam.biasFloat = (float*)biasFloatTid;
}
if (k == mBlockNum - 1) {
quanParam.fp32minmax = reluPtr;
}
quanParam.srcKernelSum = ptrX + k * step;
quanParam.weightQuanBias = weightDequanBiasTid + k * ocUp4;
quanParam.scale = (float*)(scaleFloatTid + k * ocUp4);
2024-11-18 14:37:45 +08:00
mGemmKernel(outputInTilePtr, colAddrTemp + k * blockL * step * SRC_UNIT, weightPtrTid + k * blockL * weight_step_Y * UP_DIV(output->channel(), UNIT__), blockL, dstZStep * dstBytes, ocDivThread, &quanParam, step);
2024-07-22 19:51:53 +08:00
}
ptrX += (step * mBlockNum);
realDstCount-=step;
outputInTilePtr += DST_XUNIT * PackUnit * dstBytes;
colAddrTemp += col_buffer_unit_size;
ptrExtraScale = extraScale != nullptr ? (ptrExtraScale + step * 4) : nullptr;
} while(realDstCount > 0);
}
}
[MNN:Sync] Sync internal github Commits: 8148ae75c 弗人 bugfix 14cb8ec7f 弗人 [Converter:Bugfix] bugfix for onnx depthwise convtranspose 476fbcd90 雁行 [MNN:Feature] Open AVX cast and bugfix for contentCFG. 5e26b9fd3 雁行 [Test:Feature] Add android test. 37e147b25 雁行 [MNN:Bugfix] Bugfix for floordiv. 144c185f5 tianbu.xsw hangxing fix hiai b4fd429d6 tianbu.xsw updateCacheFile bugfix -- update cache size d4ba572a8 雁行 [MNN:Bugfix] Support int8 in AVX2 and some Bugfix. 43061f07e xiaying [MNN:Bugfix] Fix bug for module mode run part of model 398cc5ab6 tianhang.yth refactor demo 736380600 xiaying [Express:Bugfix] Fix memory leak for copy branch b8dab0a27 tianhang.yth MNNFloat2Int8 sizeQuad=0 crash fix 94b95bfed ghz [BugFix]1.Better method for fast pack valid check 6a921f85e xiaying [Converter:Bugfix] Fix bug for Fuseconsttosubgraph 5f77ae889 tianhang.yth numThread bugfix a807ef879 tianhang.yth add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix ad05409d3 xiaying [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode 9d81b8299 xiaying [MNN:Bugfix] Fix bug for Unique op for output size = 1 03b15e9af xiaying [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert c944a76ee tianhang.yth add auto backend and getSessionInfo @tianbu 91fa7267b ghz [BugFix]1.fix the error in eP check bf0041f77 ghz [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error 693871672 雁行 [CPU:Bugfix] rm adrp instruction for clang compiler bug. 1b8f6b3d8 ghz 1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process. feb7ecc4c 弗人 modify log of python offline quant 040c04811 ghz [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version 609f37db8 弗人 add log for python quant, python convert 5511dd30a ghz [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter. a93ff9280 tianhang.yth add tf.Unique op support 9729ff773 allen.lk [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead. 297c1ad14 雁行 [Expr:Bugfix] bugfix for tensor content used by shape compute. ef8c369e3 弗人 catch exception 07c2dd670 弗人 add dependence to setup, base64 encode url, add time log 177e590c1 弗人 [Python:Feature] add aliyun log for python quant tool 40a7928cf allen.lk [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution 3bdea84a1 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. c3c6fbdbd allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. bc590eee4 雁行 [Converter:Bugfix] bugfix for onnx instancenormalization convert. d8918593f tianhang.yth add auto backend and getSessionInfo @tianbu 83a198ed7 杭行 update d0dd3e09b 杭行 update 99540202e xiaying [Converter:Optimize] Opt the tensor convert insert 333d8db82 allen.lk [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64. db5994672 杭行 merge 6293de7b8 tianbu.xsw fix pymnn updateCacheFile 5c2e11cb1 tianbu.xsw do updateCache in createSession 6e7641ff4 tianbu.xsw do not limit cacheFile for a model 5287a65e4 tianbu.xsw bugfix 52ba53a91 tianbu.xsw revert pymnn api 60284d830 tianbu.xsw bugfix 6d8077490 tianbu.xsw rename updateCacheFile api params 3cb172710 tianhang.yth updateCacheFile API size default value is 0 c5b69aabf tianbu.xsw updateCacheFile python api fix 5d5da7aa5 tianbu.xsw reflector code 5707877a4 雁行 [MNN:Speed] Speedup for softmax in x86 and arm. 2a211825c tianbu.xsw reflector code for updateCacheFile 76db3a835 tianbu.xsw [Cache Feature]: Add updateCacheFile API for increment cache b06b0fd43 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. e68bfa495 雁行 [Converter:Feature] Add UUID when model convert. a9cb935dc xiaying [MNN:Speed] Support c4nhwc for more fastblit 019f40353 xiaying [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G -> 1G) d2a6d3d05 xiaying [MNN:Bugfix] Fix bug for identity output not find 604d0801b xiaying [Converter:Bugfix] Fix bug for FuseGeLu 4bada2367 xiaying [MNN:Refractor] SegmentMean rewrite as segment 82070e708 xiaying [MNN:Bugfix] Fix bug for GeometryBinary e8ea4266e xiaying Fix bug for ShapeTensorConvert compute for dim = 1 error 1f1cf1991 xiaying [Tools:Bugfix] Fix system compability for fastTestOnnx 6f422efe2 xiaying [Tools:Bugfix] Remove color for checkDir for easy to dump 968f7ec88 xiaying [MNN:Speed] Support turn broadcast binary to loop 3e7aaf46f xiaying [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr 1f65ab163 xiaying [MNN:Bugfix] Fix bug for mini mnn can't convert model d65953d47 xiaying [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82 8b68be45c xiaying [MNN:Feature] Add segment 8a8f264f5 xiaying [Vulkan:Bugfix] Remove unuseful print 025bb0fda xiaying [Converter:Bugfix] Fix bug for oneof don't support 43900251e tianbu.xsw enable setCacheFile python API ebfb05c74 tianbu.xsw [Metal Feature] support metallib obtain from walle transfer task 9665c0a79 弗人 add check for path in json file c66fef224 xiaying [Converter:Bugfix] Fix bug for oneof don't support 42f192852 xiaying [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs 1b95354ff 雁行 [Feature]: Support shape compute for SetDiff1D, and null input for Prod. 83966d043 xiaying [Test:Feature] Add test for static module 42d1be933 xiaying [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model 9067531c3 xiaying [Converter:Refractor] formatLicence 99558bed9 xiaying [Converter:Bugfix] Count the op for unuseful and controlflow 4f6da0fa7 allen.lk [Feature:GRUMultiOutput] fix multi output dimension type c6b219bce xiaying [Converter:Feature] Turn torch converter to object dd4e68a37 xiaying [Converter:Feature] Support dump supported ops 80b6a60a3 xiaying [Converter:Info] If has output name, print output name instead of computed 015278fc3 xiaying [MNN:Refractor] Revert IfModule's debug info 23ac967c4 xiaying Don't transform for multi-input convolution/deconvolution b02b0d4de xiaying Fix bug for multi-input for conv1d 254d8b1d4 xiaying Fix bug for Conv1dSqueezeMove for multi input convolution 1d d47d0b9ca xiaying Fix bug for CPURaster's fuse nc4hw4 357c5bd33 xiaying Fix ConvBiasAdd for conv's inputs op > 1 55b1f0c9c xiaying [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution 1902a30f5 xiaying [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d c23fe617b xiaying [MNN:Bugfix] Fix bug for multi-input for conv1d 8ff018426 xiaying [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4 d4e8cd602 xiaying [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1 846266b42 tianbu.xsw return when program and tune both nullptr fd67c76a9 xiaying [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite e77a242c4 xiaying [Converter:Feature] Support tflite's half pixel be054c377 tianbu.xsw [OpenCL Bugfix] do not rewrite cache when binary program is produced 51e65aa35 xiaying [Converter:Feature] Support tflite for fp16 and multi-input convolution 1ccdfdeb5 tianbu.xsw redefine svm macro name 31234d372 tianbu.xsw [OpenCL SVM] add macro for only use wrapper d739e35da xiaying [MNN:Bugfix] Fix compile bug for grid op 24ab13c79 Joker feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying) 7b142978e xiaying [AVX512:Speed] Optimize for e <= 8 5f6febe7b tianbu.xsw code refactor 998d91b57 xiaying [Express:Speed] Merge submodule for speed 22c89146f tianhang.yth fix alpha div by zero bug and arm server compile bug 8f829a170 tianbu.xsw [OpenCL Pad] unify conv/deconv pad computing 4a28f603e xiaying [Express:Speed] Shared Const for All Submodule c74cf28f3 xiaying [MNN:Refractor] Seperate Const init and schedule 2a1eebb7a xiaying [Tools:Bugfix] Fix bug for modelTest.py count size 72f04008c xiaying [MNN:Refractor] Delete unuseful const op 1e735d03c xiaying [Converter:Bugfix] Fix bug for static module gen 4dfadbc6e xiaying [MNN:Refractor] Rewrite const init mode 1fcf0417a xiaying [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch 41d429cfd xiaying [Train:Bugfix] Revert convert NCHW for mnistTrain f947a5f01 xiaying [Test:Feature] Add testTrain dad59b6f6 tianbu.xsw move realize code from Backend.hpp to Tensor.cpp cf4473ad1 xiaying [Train:Bugfix] Support pad for GeometryPoolGrad 91ab13734 xiaying [MNN:Bugfix] Fix compile bug for avx512 742e80f47 xiaying [MNN:Refractor] Opt the logic for checknan judge 12543b841 xiaying [ARM82:Bugfix] Fix compile bug for ios 3a2b0a49f xiaying [ARM82:Speed] Opt Pack / Unpack for armv8 c0f1995cd xiaying [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm e0fc77dcf xiaying [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it 584bec578 xiaying [MNN:Bugfix] Fix bug for format set error for onnx d5bd4148d xiaying [MNN:Bugfix] Fix bug for format set error for onnx b00265841 xiaying [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor bb09188ac xiaying [Test:Bugfix] Fix bug for run into sparse auto 426d1babd xiaying [MNN:Refractor] Small bugfix for Group convolution and pack 7d0ea1c46 tianbu.xsw [testModel Feature] support testModel.out input resize 4169c54ce xiaying [MNN:Bugfix] Fix bug for checkNAN for origin 412a82222 xiaying [Test:Bugfix] Fix bug for CheckNAN's error of matmul 319b1d425 xiaying [MNN:Bugfix] Fix bug for multi-batch for ConvInt8 050b728a6 xiaying [Test:Bugfix] Use NCHW for ConvInt8Test 7db3423a1 xiaying [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4 adcec6a7f xiaying [Vulkan:Bugfix] Fix bug for invalid tensor size limit d2a7cf4e9 xiaying [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4 557bebdd3 xiaying [MNN:Bugfix] Fix bug for BF16-ARM32 bbe186649 tianbu.xsw [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority 6deb23439 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size b137590e4 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size 7003558ea xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case b5f8cae5a xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case 29b09e125 xiaying [MNN:Bugfix] Fix bug for arm64-bf16 42ce00770 xiaying [MNN:Bugfix] Fix bug for ARM64 - float a2d89fc18 雁行 [Converter:Feature] Support Binary Unary for Torch. 7f1c0deb1 xiaying [MNN:Bugfix] Fix bug for Raster for Int8 8335a6f18 tianbu.xsw [OpenCL Shared Memory] modify data_format method b359e031b xiaying [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8 24bf3fc88 雁行 [Convert:Feature] Support LayerNormFuse without gamma beta. 3e629624b xiaying [MNN:Bugfix] Fix bug for float - armv7a 2b7908ec7 tianbu.xsw modify workItemSize 3cee0d413 xiaying [MNN:Bugfix] test wrong clear 9cbbfb998 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 2d7a44484 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 eb7d0cb53 xiaying [Test:Bugfix] Don't test for NC4HW4 directly 7b40ca8d1 xiaying [MNN:Bugfix] Fix bug for ConvolutionGroup 2694d8a91 xiaying [MNN:Bugfix] Fix bug for CPUGridSample f89af60f6 xiaying [MNN:Bugfix] Fix compile bug for arm a151abcdd xiaying [MNN:Bugfix] Fix bug for convert for int8 / int16 b254dbe61 雁行 [MNN:Bugfix] Bugfix for Conv onClone. d08150631 xiaying [MNN:Bugfix] Fix bug for fast rcnn e5568a0df xiaying [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit 128318933 雁行 [Raster:Bugfix] bugfix for Raster merge onResize. 03caacbea xiaying [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow e1e3c245c xiaying [MNN:Bugfix] Fix bug for ConvolutionWinograd 2524cbc6d xiaying [MNN:Bugfix] Fix bug for CPUSoftmax 44ec79b8f xiaying [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW 21ae956ce xiaying [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor 09a5069c7 xiaying [MNN:Speed] Add offset for src and dst 6776c6784 xiaying [MNN:Bugfix] Fix bug for trainable model cc83ae30b xiaying [MNN:Bugfix] Fix bug for trainable model
2021-07-29 11:46:59 +08:00
};
2024-08-24 15:46:21 +08:00
const int threads = static_cast<CPUBackend*>(backend())->threadNumber();
2024-07-22 19:51:53 +08:00
if (!mSplitByOc) {
2024-08-24 15:46:21 +08:00
MNN_CONCURRENCY_BEGIN(tId, threads) {
2024-11-18 14:37:45 +08:00
ThreadFunction((int)tId, mDivides[tId], mDivides[tId + 1], 1, 0);
2024-07-22 19:51:53 +08:00
}
MNN_CONCURRENCY_END();
} else {
2024-08-24 15:46:21 +08:00
MNN_CONCURRENCY_BEGIN(tId, threads) {
2024-07-22 19:51:53 +08:00
int ocIndex = PackUnit * mDivides[tId];
2024-10-22 15:11:21 +08:00
if (ocIndex < ocUp4) {
2024-08-24 15:46:21 +08:00
ThreadFunction((int)tId, 0, mTileCount,1, ocIndex);
}
2024-07-22 19:51:53 +08:00
}
MNN_CONCURRENCY_END();
}
return NO_ERROR;
}
2021-09-18 15:52:30 +08:00
} // namespace MNN