MatmulPrelu算子实现问题
收藏回复举报
MatmulPrelu算子实现问题
t('forum.solved') 已解决
发表于2026-07-24 18:21:57
0 查看

Atlas 800I A2服务器上尝试编写MatmulPrelu,参考MatmulLeaklyRelu进行修改。发现reluOutQueue已经占用了 256*128*4=128K的UB空间,查询得知当前使用的芯片只有192K的UB空间,再申请一个临时变量空间存放结果矩阵是不够用了。

然后我就在PreluCompute中定义了两个LocalTensor使用,编译没报错。但是在调用Maxs接口的时候会把我src上的数据也覆盖掉。我感觉是LocalTensor没申请空间写错了内存导致的,但是UB空间不够再申请了,内存复用从逻辑上又实现不了。必须保留原始数据计算min/max。

这个问题折磨我三天了,恳请大佬指点一二!!!

这里是我的PreluCompute实现:

template <typename aType, typename bType, typename cType, typename biasType>
__aicore__ inline void MatmulPreluKernel<aType, bType, cType, biasType>::PreluCompute()
{
    // 考生自行补齐
    // LeakyRelu(reluOutLocal, reluOutLocal, this->alpha, tiling.baseM * tiling.baseN);
    // reluOutQueue.EnQue(reluOutLocal);
    uint32_t totalElements = tiling.baseM * tiling.baseN;
    AscendC::LocalTensor<cType> positivePart;
    AscendC::LocalTensor<cType> negativePart;
    AscendC::DumpTensor(reluOutLocal, 123, totalElements);
    AscendC::Maxs(positivePart, reluOutLocal, static_cast<cType>(0), totalElements);
    AscendC::DumpTensor(reluOutLocal, 125, totalElements);
    AscendC::DumpTensor(positivePart, 126, totalElements);
    AscendC::Mins(negativePart, reluOutLocal, static_cast<cType>(0), totalElements);
    AscendC::Muls(negativePart, negativePart, this->alpha, totalElements);
    AscendC::Add(reluOutLocal, positivePart, negativePart, totalElements);
    reluOutQueue.EnQue(reluOutLocal);
}

这里是dump出的结果:

cke_27484.png

cke_28545.png

本帖最后由 匿名用户 于 2026/07/28 09:12:42 编辑

我要发帖子