| 34 | |
| 35 | #ifdef MNN_KLEIDIAI_ENABLED |
| 36 | static Execution* _createKleidiAIUnit(const Tensor* input, const Tensor* output, Backend* backend, const Op* op, |
| 37 | const float* originWeight, size_t originWeightSize, const float* bias, |
| 38 | size_t biasSize, std::shared_ptr<ConvolutionCommon::Int8Common> weightQuantInfo, |
| 39 | bool supportSparse, bool lowMemory) { |
| 40 | auto cpuBackend = (CPUBackend*)backend; |
| 41 | auto conv2d = op->main_as_Convolution2D(); |
| 42 | auto common = conv2d->common(); |
| 43 | |
| 44 | bool fastWay = common->kernelY() == 1 && common->kernelX() == 1 && output->width() == input->width() && |
| 45 | output->height() == input->height() && common->strideX() == 1 && common->strideY() == 1; |
| 46 | |
| 47 | #ifdef MNN_LOW_MEMORY |
| 48 | if (lowMemory && nullptr != weightQuantInfo.get() && originWeightSize == 0) { |
| 49 | if (cpuBackend->memoryMode() == BackendConfig::Memory_Low) { |
| 50 | do { |
| 51 | if (!weightQuantInfo->canUseInt4) { |
| 52 | break; |
| 53 | } |
| 54 | auto convOp = op->main_as_Convolution2D(); |
| 55 | auto core = static_cast<CPUBackend*>(backend)->functions(); |
| 56 | int oc = convOp->common()->outputCount(); |
| 57 | int ic = convOp->common()->inputCount(); |
| 58 | |
| 59 | int blockNum = 1; |
| 60 | int dequantCnt = weightQuantInfo->alphaSize; |
| 61 | if (weightQuantInfo->asymmetric) { |
| 62 | dequantCnt /= 2; |
| 63 | } |
| 64 | blockNum = dequantCnt / oc; |
| 65 | |
| 66 | bool bAsym = weightQuantInfo->asymmetric; |
| 67 | size_t blkSize = blockNum == 1 ? 0 : ic / blockNum; |
| 68 | |
| 69 | KleidiAI::AccelType accelType = KleidiAI::getQIntAccelType(4, bAsym, blkSize, core->bytes); |
| 70 | |
| 71 | KleidiAI& kai = KleidiAI::getInstance(*MNNGetCPUInfo()); |
| 72 | if (!kai.canAccelerate(accelType, convOp->common())) { |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | if (!kai.isLoaded(accelType)) { |
| 77 | kai.setLoaded(accelType); |
| 78 | kai.printInfo(accelType); |
| 79 | } |
| 80 | |
| 81 | return new KleidiAIConvInt8(backend, op, weightQuantInfo, true, kai, accelType, blockNum); |
| 82 | } while (0); |
| 83 | } |
| 84 | |
| 85 | // Have not supported the quantized weight. |
| 86 | return nullptr; |
| 87 | } |
| 88 | #else |
| 89 | if (cpuBackend->memoryMode() == BackendConfig::Memory_Low) { |
| 90 | if (MNNGetCPUInfo()->sme2 && !weightQuantInfo) { |
| 91 | return new KleidiAIDenseConvolution(common, backend, originWeight, originWeightSize, bias, biasSize, |
| 92 | weightQuantInfo); |
| 93 | } |
no test coverage detected