登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
仓库状态说明
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
68
Star
258
Fork
191
Ascend
/
modelzoo
暂停
代码
Issues
157
Pull Requests
9
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
[CANN 5.0.3.alpha002][TIK Compiler] Code generation error
DONE
#I4E3MM
Bug-Report
antoniocipolletta
创建于
2021-10-15 22:56
## Problem description The TIK compiler generates incorrect code in the following case. ```python3 import te.tik as tik def reshape(inst, im_in_ub, im_in_reshaped_ub, dim): # Assuming im_in_ub = (2*dim + 2, 16) if dim // 8 > 0: with inst.for_range(0, dim // 8) as i_rw: src_list = [ im_in_ub[2 * i_scatter + i_rw * 8 * 2, 0] for i_scatter in range(8) ] dst_list = [ im_in_reshaped_ub[0, 8 * i_rw + i_scatter, 0] for i_scatter in range(8) ] inst.scatter_vector_mov(128, dst_list, src_list, 4, (16 * dim) // 16, 16 // 16) tail = dim % 8 if tail > 0: i_rw = dim // 8 src_list = [ im_in_ub[2 * i_scatter + i_rw * 8 * 2, 0] for i_scatter in range(tail) ] dst_list = [ im_in_reshaped_ub[0, 8 * i_rw + i_scatter, 0] for i_scatter in range(tail) ] inst.scatter_vector_mov(tail * 16, dst_list, src_list, 4, (16 * dim) // 16, 16 // 16) tik_instance = tik.Tik(tik.Dprofile('v100', 'cloud')) dim = 12 src_shape = (2 * dim + 2, 16) dst_shape = (4, dim, 16) src_gm = tik_instance.Tensor('float16', src_shape, tik.scope_gm, 'src_gm') src_ub = tik_instance.Tensor('float16', src_shape, tik.scope_ubuf, 'src_ub') src_reshaped_ub_shape = (4, dim, 16) src_reshaped_ub = tik_instance.Tensor('float16', src_reshaped_ub_shape, name='reshaped_ub', scope=tik.scope_ubuf) dst_gm = tik_instance.Tensor('float16', dst_shape, tik.scope_gm, 'dst_gm') tik_instance.data_move(src_ub, src_gm, 0, 1, (2 * dim + 2) * 16 // 16, 0, 0) with tik_instance.for_range(0, 10): reshape(tik_instance, src_ub, src_reshaped_ub, dim) tik_instance.data_move(dst_gm, src_reshaped_ub, 0, 1, (4 * dim) * 16 // 16, 0, 0) tik_instance.BuildCCE(kernel_name='test', inputs=[src_gm], outputs=[dst_gm], config={'save_temp_cce_file': True}) ``` Specifically, this code works in the simulator, but it doesn't work on the device. Looking at the CCE code generated, the vector mask is set with the instruction `set_vector_mask(0x0, 0xffffffffffffffff)` only once before the loops. However, the two vector instructions use **two different masks**. The generated CCE code is reported below. ``` #ifdef __CCE_KT_TEST__ #define __aicore__ #else #define __aicore__ [aicore] #endif extern "C" __global__ __aicore__ void test__kernel0(__gm__ uint8_t* __restrict__ src_gm, __gm__ uint8_t* __restrict__ dst_gm) { set_atomic_none(); __ubuf__ uint8_t* src_ub = (__ubuf__ uint8_t *)get_imm(0); __ubuf__ uint8_t* reshaped_ub = (__ubuf__ uint8_t *)get_imm(832); // "aicore arch: Ascend910" copy_gm_to_ubuf(((__ubuf__ half *)src_ub), ((__gm__ half *)src_gm), 0, 1, 26, 0, 0); set_flag(PIPE_MTE2, PIPE_V, EVENT_ID0); set_vector_mask(0x0, 0xffffffffffffffff); wait_flag(PIPE_MTE2, PIPE_V, EVENT_ID0); for (int32_t i = 0; i < 10; ++i) { pipe_barrier(PIPE_V); uint64_t va_reg_array_1[8] = {((uint64_t)((__ubuf__ half *)reshaped_ub)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 16)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 32)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 48)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 64)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 80)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 96)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 112))};set_va_reg_sb(VA3, va_reg_array_1); uint64_t va_reg_array_2[8] = {((uint64_t)((__ubuf__ half *)src_ub)), ((uint64_t)((__ubuf__ half *)src_ub + 32)), ((uint64_t)((__ubuf__ half *)src_ub + 64)), ((uint64_t)((__ubuf__ half *)src_ub + 96)), ((uint64_t)((__ubuf__ half *)src_ub + 128)), ((uint64_t)((__ubuf__ half *)src_ub + 160)), ((uint64_t)((__ubuf__ half *)src_ub + 192)), ((uint64_t)((__ubuf__ half *)src_ub + 224))};set_va_reg_sb(VA4, va_reg_array_2); scatter_vector_mov_f16(VA3, VA4, (int64_t)288230376151777292); uint64_t va_reg_array_3[8] = {((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 144)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 160)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 176)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128))};set_va_reg_sb(VA3, va_reg_array_3); uint64_t va_reg_array_4[8] = {((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 288)), ((uint64_t)((__ubuf__ half *)src_ub + 320)), ((uint64_t)((__ubuf__ half *)src_ub + 352)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256))};set_va_reg_sb(VA4, va_reg_array_4); scatter_vector_mov_f16(VA3, VA4, (int64_t)288230376151777292); } set_flag(PIPE_V, PIPE_MTE3, EVENT_ID0); wait_flag(PIPE_V, PIPE_MTE3, EVENT_ID0); copy_ubuf_to_gm(((__gm__ half *)dst_gm), ((__ubuf__ half *)reshaped_ub), 0, 1, 48, 0, 0); pipe_barrier(PIPE_ALL); pipe_barrier(PIPE_ALL); } ``` ## FIX Suggestion The problem seems to be introduced by the pass `SequenceSprInsn`, which performs code motion of the `set_vector_mask` instruction from the loop body.
## Problem description The TIK compiler generates incorrect code in the following case. ```python3 import te.tik as tik def reshape(inst, im_in_ub, im_in_reshaped_ub, dim): # Assuming im_in_ub = (2*dim + 2, 16) if dim // 8 > 0: with inst.for_range(0, dim // 8) as i_rw: src_list = [ im_in_ub[2 * i_scatter + i_rw * 8 * 2, 0] for i_scatter in range(8) ] dst_list = [ im_in_reshaped_ub[0, 8 * i_rw + i_scatter, 0] for i_scatter in range(8) ] inst.scatter_vector_mov(128, dst_list, src_list, 4, (16 * dim) // 16, 16 // 16) tail = dim % 8 if tail > 0: i_rw = dim // 8 src_list = [ im_in_ub[2 * i_scatter + i_rw * 8 * 2, 0] for i_scatter in range(tail) ] dst_list = [ im_in_reshaped_ub[0, 8 * i_rw + i_scatter, 0] for i_scatter in range(tail) ] inst.scatter_vector_mov(tail * 16, dst_list, src_list, 4, (16 * dim) // 16, 16 // 16) tik_instance = tik.Tik(tik.Dprofile('v100', 'cloud')) dim = 12 src_shape = (2 * dim + 2, 16) dst_shape = (4, dim, 16) src_gm = tik_instance.Tensor('float16', src_shape, tik.scope_gm, 'src_gm') src_ub = tik_instance.Tensor('float16', src_shape, tik.scope_ubuf, 'src_ub') src_reshaped_ub_shape = (4, dim, 16) src_reshaped_ub = tik_instance.Tensor('float16', src_reshaped_ub_shape, name='reshaped_ub', scope=tik.scope_ubuf) dst_gm = tik_instance.Tensor('float16', dst_shape, tik.scope_gm, 'dst_gm') tik_instance.data_move(src_ub, src_gm, 0, 1, (2 * dim + 2) * 16 // 16, 0, 0) with tik_instance.for_range(0, 10): reshape(tik_instance, src_ub, src_reshaped_ub, dim) tik_instance.data_move(dst_gm, src_reshaped_ub, 0, 1, (4 * dim) * 16 // 16, 0, 0) tik_instance.BuildCCE(kernel_name='test', inputs=[src_gm], outputs=[dst_gm], config={'save_temp_cce_file': True}) ``` Specifically, this code works in the simulator, but it doesn't work on the device. Looking at the CCE code generated, the vector mask is set with the instruction `set_vector_mask(0x0, 0xffffffffffffffff)` only once before the loops. However, the two vector instructions use **two different masks**. The generated CCE code is reported below. ``` #ifdef __CCE_KT_TEST__ #define __aicore__ #else #define __aicore__ [aicore] #endif extern "C" __global__ __aicore__ void test__kernel0(__gm__ uint8_t* __restrict__ src_gm, __gm__ uint8_t* __restrict__ dst_gm) { set_atomic_none(); __ubuf__ uint8_t* src_ub = (__ubuf__ uint8_t *)get_imm(0); __ubuf__ uint8_t* reshaped_ub = (__ubuf__ uint8_t *)get_imm(832); // "aicore arch: Ascend910" copy_gm_to_ubuf(((__ubuf__ half *)src_ub), ((__gm__ half *)src_gm), 0, 1, 26, 0, 0); set_flag(PIPE_MTE2, PIPE_V, EVENT_ID0); set_vector_mask(0x0, 0xffffffffffffffff); wait_flag(PIPE_MTE2, PIPE_V, EVENT_ID0); for (int32_t i = 0; i < 10; ++i) { pipe_barrier(PIPE_V); uint64_t va_reg_array_1[8] = {((uint64_t)((__ubuf__ half *)reshaped_ub)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 16)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 32)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 48)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 64)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 80)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 96)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 112))};set_va_reg_sb(VA3, va_reg_array_1); uint64_t va_reg_array_2[8] = {((uint64_t)((__ubuf__ half *)src_ub)), ((uint64_t)((__ubuf__ half *)src_ub + 32)), ((uint64_t)((__ubuf__ half *)src_ub + 64)), ((uint64_t)((__ubuf__ half *)src_ub + 96)), ((uint64_t)((__ubuf__ half *)src_ub + 128)), ((uint64_t)((__ubuf__ half *)src_ub + 160)), ((uint64_t)((__ubuf__ half *)src_ub + 192)), ((uint64_t)((__ubuf__ half *)src_ub + 224))};set_va_reg_sb(VA4, va_reg_array_2); scatter_vector_mov_f16(VA3, VA4, (int64_t)288230376151777292); uint64_t va_reg_array_3[8] = {((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 144)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 160)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 176)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128)), ((uint64_t)((__ubuf__ half *)reshaped_ub + 128))};set_va_reg_sb(VA3, va_reg_array_3); uint64_t va_reg_array_4[8] = {((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 288)), ((uint64_t)((__ubuf__ half *)src_ub + 320)), ((uint64_t)((__ubuf__ half *)src_ub + 352)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256)), ((uint64_t)((__ubuf__ half *)src_ub + 256))};set_va_reg_sb(VA4, va_reg_array_4); scatter_vector_mov_f16(VA3, VA4, (int64_t)288230376151777292); } set_flag(PIPE_V, PIPE_MTE3, EVENT_ID0); wait_flag(PIPE_V, PIPE_MTE3, EVENT_ID0); copy_ubuf_to_gm(((__gm__ half *)dst_gm), ((__ubuf__ half *)reshaped_ub), 0, 1, 48, 0, 0); pipe_barrier(PIPE_ALL); pipe_barrier(PIPE_ALL); } ``` ## FIX Suggestion The problem seems to be introduced by the pass `SequenceSprInsn`, which performs code motion of the `set_vector_mask` instruction from the loop body.
评论 (
10
)
登录
后才可以发表评论
状态
DONE
TODO
Analysing
ACCEPTED
WIP
Feedback
TEST
DONE
REJECTED
负责人
未设置
许业涛
xyttaotao
负责人
协作者
+负责人
+协作者
标签
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(4)
1
https://gitee.com/ascend/modelzoo.git
git@gitee.com:ascend/modelzoo.git
ascend
modelzoo
modelzoo
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册