Merged
fix(pass): Identify sanitizer entry by function type instead of name #6767
fix(pass): Identify sanitizer entry by function type instead of name #6767
Merged
zhengyaoff12Add on Sep 29
zhengyaoff12
zhengyaoff12Collaborators
Sep 29

The sanitizer pass identified the kernel entry function by comparing func->name_ with program->name_. When @pl.jit(name=...) differs from the kernel function name (e.g. @pl.jit(sanitizer=True, name="foo") decorating def kern(...)), no function in the program ever matched, and:

  • instrumentation was silently skipped: no block.sanitizer_log records were injected;
  • the hidden sanitizer_log / sanitizer_log_capacity parameters were not appended to the kernel signature, while the launcher still passed them on every launch;
  • every launch then failed with a misleading InvalidType: Expected 2 args, got 4.

Changes:

  • Identify the entry structurally instead: it is the Opaque function the frontend always builds for the kernel body, the same criterion the host side already uses to derive the launch ABI (_get_kernel_ir_function), so the pass and the launch ABI can no longer disagree
  • Add an internal check that rejects programs not carrying exactly one Opaque entry function, so a skipped instrumentation can no longer stay silent
  • Add a regression test (test_named_kernel_sanitizer_instrumented) that launches a named @pl.jit(sanitizer=True) kernel whose name differs from the function name

Verification on Ascend950PR, full python/tests/st/pypto_pro/frontend/sanitizer/test_sanitizer.py:

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhengyaoff12's contribution.)
zhengyaoff12zhengyaoff12Collaborators
Sep 29 Created pull request, commit 0a3d3530
atomgit-bot
atomgit-bot
Sep 29 Comments:

变更摘要

本 PR 修复 sanitizer pass 对内核入口函数的识别方式。原先 SanitizerInstrumenter::Instrument 通过 func->name_ != program->name_ 判断入口,当 @pl.jit(name=...) 指定的名字与内核函数名不一致时无法匹配任何函数,导致插桩被静默跳过、隐藏的 sanitizer_log 与 sanitizer_log_capacity 参数未追加,而启动侧仍按新 ABI 传参,最终抛出误导性的 InvalidType: Expected 2 args, got 4。改动改为按函数类型结构性识别入口(前端为内核主体构建的 Opaque 函数),并新增入口唯一性校验与回归测试。

主要改动

  • 入口识别改为按函数类型判定: sanitizer_pass.cpp 中将入口条件由 func->name_ != program->name_(并显式排除 SIMT_VF/SIMT_CALLEE)改为 func->funcType_ != FunctionType::OPAQUE,使插桩入口与宿主侧定位内核入口的判据一致,避免因命名不一致而跳过插桩、破坏启动 ABI。
  • 新增入口数量内部校验: 在 Instrument 中累加 entry_count,并通过 PRO_PASS_INTERNAL_CHECK 断言程序必须恰好包含一个 Opaque 入口函数,使插桩被跳过时不再静默。
  • 补充命名内核回归测试: test_sanitizer.py 新增 named_clean_kernel(@pl.jit(sanitizer=True, auto_mutex=True, name="sanitizer_named_entry_kernel"))与 test_named_kernel_sanitizer_instrumented,验证 name= 与函数名不一致时仍能完成插桩并正常启动、结果正确。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 29 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 29 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 29 Comments:

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

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
9.2.0 ✅ gcw_kUomxQ2l, gaoxiang618 (2/2) ✅ gcw_kUomxQ2l (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
42 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 30 Added label: approved
gaoxiang618
gaoxiang618Collaborators
Sep 30 Comments:

/approve
/lgtm

likedislike
CANN-robot
CANN-robotCollaborators
Sep 30 Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: gaoxiang618

likedislike
CANN-robotCANN-robotCollaborators
Sep 30 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 30 Merged pull request