已开启
[Bugfix] Scope cached CCU kernel handles by instance and die #234
[Bugfix] Scope cached CCU kernel handles by instance and die #234
已开启
KaranocaVe创建于 7 天前
KaranocaVe
KaranocaVe
7 天前

[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
合并受阻
KaranocaVeKaranocaVe
7 天前 创建了 pull request,commit bdd50f76
KaranocaVeKaranocaVe
7 天前 关联了issue:CCU kernel cache reuses handles across instances
atomgit-bot
atomgit-bot
7 天前 评论:

变更摘要

本 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
7 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
7 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
src ❌ (0/2)(You can also ask: YeZZzzz1, 李东锋, chenma, bianque, bluesky901) ❌ (0/1)(You can also ask: changxianyu, 肖婷, YeZZzzz1, 闫庆尚, 石楠翔)
tests ❌ (0/2)(You can also ask: bianque, YeZZzzz1, hyolee, kong0808, dengjing_aoe) ❌ (0/1)(You can also ask: 苏建加, 肖婷, 闫庆尚, YeZZzzz1, qin437231)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

KaranocaVe, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
KaranocaVe
KaranocaVe
7 天前 评论:

/compile

likedislike
KaranocaVeKaranocaVe
7 天前 预合并成功(commit_id: 39fe392d5374efcde2fd7e9faffcb2e222e49997)
CANN-robot
CANN-robot成员
7 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:ci-pipeline-running
此处折叠了6条事件消息 查看更多
CANN-robotCANN-robot成员
2 天前 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
2 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robot成员
2 天前 添加了label:cann-cla/yes
KaranocaVe
KaranocaVe
2 天前 评论:

/compile

likedislike
KaranocaVeKaranocaVe
2 天前 预合并成功(commit_id: 6c8902720fbf98ddd4c8cb6bb2a7cd04f7783338)
CANN-robot
CANN-robot成员
2 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
2 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
2 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
2 天前 添加了label:ci-pipeline-passed