已合并
[Bugfix] Scope cached CCU kernel handles by instance and die #234
[Bugfix] Scope cached CCU kernel handles by instance and die #234
已合并
KaranocaVe创建于 9月27日
KaranocaVe
KaranocaVe
9月27日

[Bugfix] Scope cached CCU kernel handles by instance and die

Problem

The host launch cache is keyed only by binary_cache_tag. When two CCU
instances use the same tag, the second launch reuses the kernel handle
registered for the first instance. The same issue occurs across physical dies.

Reproduction

Launch the same kernel with the same binary_cache_tag first on one CCU
instance and then on a different instance, or use a different physical die.
The second launch reuses the first registration instead of registering the
kernel for its own instance and die.

Expected and actual behavior

  • Expected: registrations are reused only when the binary tag, CCU instance,
    and physical die are the same.
  • Actual: the binary tag alone selects the cached handle, so a handle from a
    different instance or die is reused.

Impact

Kernel launches can use a handle registered for the wrong CCU instance or
physical die when identical binary cache tags are used.

Fix

Include the CCU instance identity and physical die mask in the cache key, and
cover same-instance reuse and cross-instance/die isolation in the host unit
test.

Verification

The regression fails on the original implementation and passes with the fix.
The asccomm_ut_ccu_host_launch suite passes all 12 tests.

关联 Issue: https://gitcode.com/cann/asc-comm/issues/48

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 KaranocaVe 的贡献)
KaranocaVeKaranocaVe
9月27日 创建了 pull request,commit bdd50f76
KaranocaVeKaranocaVe
9月27日 关联了issue:CCU kernel cache reuses handles across instances
atomgit-bot
atomgit-bot
9月27日 评论:

变更摘要

本 PR 修复主机侧启动缓存仅以 binary_cache_tag 作为键导致跨 CCU 实例、跨物理 die 复用错误 kernel handle 的问题。核心改动集中在 src/ccu/ccu_host_launch.cpp 的 KernelHandleCache:在缓存键中引入 CCU 实例身份与物理 die 掩码,使 kernel 注册仅在二进制标签、CCU 实例、物理 die 三者一致时才复用;tests/ut/ccu/test_ccu_host_launch.cpp 增加了对应的宿主单元测试。

主要改动

  • 缓存键结构重构:新增 KernelCacheKey 结构,包含 binaryCacheTag、CcuInstanceCacheIdentity instance、phyDieMask 三个字段,并定义 operator== 用于精确匹配缓存条目。
  • 实例身份提取机制:新增 CcuInstanceCacheIdentity 及 CcuInstanceCacheIdentityTraits 模板,通过 SFINAE 从 CcuInsHandle 中提取 ccuInsKey 与 ccuInsPtr,缺省情况下回退为 handle 与 0,从而把 CCU 实例身份纳入缓存键。
  • 缓存容器类型变更:KernelHandleCache 内部缓存由 std::unordered_map<uint64_t, CcuKernelHandle> 改为 std::unordered_map<KernelCacheKey, CcuKernelHandle, KernelCacheKeyHash>,并新增 KernelCacheKeyHash 哈希实现。
  • 匹配流程调整:KernelHandleCache::Match 中改为根据 cacheTag、cfg->ccu_ins 实例身份和 cfg->ccu_schd.phy_die_mask 构造 cacheKey 进行查找与写入,取代原先仅以 cacheTag 索引。
  • 单测覆盖扩展:测试桩 HcommCcuKernelRegister 增加记录 insHandle 与 dieId 的 g_observedRegisterIns、g_observedRegisterDie 及调用计数 g_registerKernelCallCount,并新增 BinaryCacheTagIsScopedToCcuInstance 用例验证同实例复用与跨实例/跨 die 隔离。
likedislike
不准确?
atomgit-bot
atomgit-bot
9月27日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
9月27日 添加了label:cann-cla/yes
此处折叠了77条消息 查看更多
KaranocaVe
KaranocaVe
15 天前 评论:

@dengjing_aoe @YeZZzzz1 @DragonBornHD84 @jiangxinyu3 @qin437231 @chenma @shi_nanxiang @houyuyang @changxianyu @suqwe @bianque @yanqingshang

昨天已请各位审核,这里再跟进一下:麻烦抽空看一下这个 PR。如有需要修改的地方,请直接留言;确认没有问题后,烦请按仓库规则补齐所需的 /lgtm 和 /approve,协助推进合入。谢谢!

likedislike
changxianyu成员
14 天前 评论:

/lgtm

likedislike
YeZZzzz1成员
14 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
14 天前 添加了label:lgtmapproved
CANN-robotCANN-robot成员
14 天前 合入了pull request