已关闭
[Bug-Report|缺陷反馈]: DynamicQuant 算子 优化建议,消除冗余代码,提升代码可维护性 #2294
LetsAiGo创建于  4月24日关闭于  4月25日
LetsAiGo
4月24日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

原始代码:
aicore inline void CopyOut(int32_t multiRow, int32_t loopCount)
{
LocalTensor outLocal = outQueue.DeQue();
LocalTensor scaleLocal = scaleQueue.DeQue();
LocalTensor offsetLocal;
if (isAsymmetrical) {
offsetLocal = offsetQueue.DeQue();
}

DataCopyExtParams copyParams{(uint16_t)multiRow, (uint16_t)(tilingData_.rowLen * sizeof(yDtype)), 0, 0, 0};
if constexpr (IsSameType<yDtype, int4b_t>::value) {
copyParams.blockLen = copyParams.blockLen >> 1;
uint32_t index = loopCount * lenGMMultiRow;
DataCopyPad(outGm[index], outLocal, copyParams);
} else {
DataCopyPad(outGm[loopCount * lenGMMultiRow], outLocal, copyParams);
}

    DataCopyParams copyParams1{1, (uint16_t)(multiRow * sizeof(float)), 0, 0};
    DataCopyPad(scaleGm[loopCount * multiRowNum], scaleLocal, copyParams1);
    if (isAsymmetrical) {
        DataCopyPad(offsetGm[loopCount * multiRowNum], offsetLocal, copyParams1);
        offsetQueue.FreeTensor(offsetLocal);
    }
    outQueue.FreeTensor(outLocal);
    scaleQueue.FreeTensor(scaleLocal);
}

建议代码:

  __aicore__ inline void CopyOut(int32_t multiRow, int32_t loopCount)
{
    LocalTensor<yDtype> outLocal = outQueue.DeQue<yDtype>();
    LocalTensor<float> scaleLocal = scaleQueue.DeQue<float>();

    DataCopyExtParams copyParams{(uint16_t)multiRow, (uint16_t)(tilingData_.rowLen * sizeof(yDtype)), 0, 0, 0};
    if constexpr (IsSameType<yDtype, int4b_t>::value) {
        copyParams.blockLen = copyParams.blockLen >> 1;
    }  
    <span style="background-color:#e60000;">DataCopyPad(outGm[loopCount * lenGMMultiRow], outLocal, copyParams);</span>

    DataCopyParams copyParams1{1, (uint16_t)(multiRow * sizeof(float)), 0, 0};
    DataCopyPad(scaleGm[loopCount * multiRowNum], scaleLocal, copyParams1);
    if (isAsymmetrical) {
        <span style="color:#e60000;">LocalTensor<float> offsetLocal = offsetQueue.DeQue<float>();</span>
        DataCopyPad(offsetGm[loopCount * multiRowNum], offsetLocal, copyParams1);
        offsetQueue.FreeTensor(offsetLocal);
    }

    outQueue.FreeTensor(outLocal);
    scaleQueue.FreeTensor(scaleLocal);
}

Environment / 环境信息 (Mandatory / 必填)

代码优化建议,消除冗余代码,提升代码可维护性

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

代码优化建议,消除冗余代码,提升代码可维护性

Describe the expected behavior / 预期结果 (Mandatory / 必填)

代码优化建议,消除冗余代码,提升代码可维护性

代码优化建议,消除冗余代码,提升代码可维护性

Special notes for this issue/备注 (Optional / 选填)

likedislike
oscillatedoscillated成员
4月24日 将 liujie12345678 设为负责人
oscillated
oscillated成员
4月24日 评论:

您好,感谢反馈,问题已收到,正在处理。

likedislike
Lliujie12345678成员
4月25日 将 cuijie25 设为负责人
cuijie成员
4月25日 评论:

修复pr已合入,此issue关闭

likedislike
cuijie成员
4月25日 评论:

/close

likedislike
CANN-robot
CANN-robot成员
4月25日 评论:

Notice

@cuijie25 , you can't close an issue unless you are the author of it or a collaborator.

likedislike
Ccuijie成员
4月25日 issue状态由 进行中 改变为 已完成
Ccuijie成员
4月25日 关闭了 issue
CANN-robotCANN-robot成员
4月25日 添加了label:Accepted
CANN-robotCANN-robot成员
4月25日 添加了label:resolved