Skip to content

fix(ptoas): clamp host -target-cpu for bisheng host stub compile#959

Merged
KurrinQu merged 1 commit into
hw-native-sys:mainfrom
KurrinQu:qkl/fix-ptoas-host-cpu-clamp
Jul 20, 2026
Merged

fix(ptoas): clamp host -target-cpu for bisheng host stub compile#959
KurrinQu merged 1 commit into
hw-native-sys:mainfrom
KurrinQu:qkl/fix-ptoas-host-cpu-clamp

Conversation

@KurrinQu

Copy link
Copy Markdown
Collaborator

ptoas passes llvm::sys::getHostCPUName() from the (newer) LLVM it is built against straight to 'bisheng -cc1 -target-cpu', but bisheng's Clang 15 only recognizes up to znver3, so every target="pto" compile fails on Zen 4/Zen 5 hosts with 'unknown target CPU'.

Add resolveHostCPUName(): clamp znver4/znver5 to znver3 and allow PTOAS_HOST_CPU to override detection. Marked as WORKAROUND to drop once bisheng upgrades to LLVM 21.

Fixes #958

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a workaround in tools/ptoas/ObjectEmission.cpp to resolve host CPU names, clamping znver4 and znver5 to znver3 to accommodate bisheng's Clang 15, and allowing overrides via the PTOAS_HOST_CPU environment variable. The review feedback suggests two minor improvements: utilizing a C++17 init-statement in the environment variable check, and performing comparisons directly on llvm::StringRef to avoid premature std::string allocations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tools/ptoas/ObjectEmission.cpp Outdated
Comment on lines +127 to +129
if (const char *env = std::getenv("PTOAS_HOST_CPU"))
if (*env)
return std::string(env);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since you are using C++17, you can combine the check for the environment variable into a single if statement with an initializer. This can improve readability slightly.

Suggested change
if (const char *env = std::getenv("PTOAS_HOST_CPU"))
if (*env)
return std::string(env);
if (const char *env = std::getenv("PTOAS_HOST_CPU"); env && *env) {
return std::string(env);
}

Comment thread tools/ptoas/ObjectEmission.cpp Outdated
Comment on lines +130 to +133
std::string cpu = llvm::sys::getHostCPUName().str();
if (cpu == "znver4" || cpu == "znver5")
return "znver3";
return cpu;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For a minor performance improvement, you can avoid creating a std::string from the result of llvm::sys::getHostCPUName() until it's actually needed. llvm::sys::getHostCPUName() returns a StringRef, which is a non-owning view of a string. You can perform the comparisons on the StringRef directly and only convert to std::string when returning the original CPU name.

Suggested change
std::string cpu = llvm::sys::getHostCPUName().str();
if (cpu == "znver4" || cpu == "znver5")
return "znver3";
return cpu;
llvm::StringRef cpu = llvm::sys::getHostCPUName();
if (cpu == "znver4" || cpu == "znver5")
return "znver3";
return std::string(cpu);

@mouliangyu mouliangyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ptoas passes llvm::sys::getHostCPUName() from the (newer) LLVM it is
built against straight to 'bisheng -cc1 -target-cpu', but bisheng's
Clang 15 only recognizes up to znver3, so every target="pto" compile
fails on Zen 4/Zen 5 hosts with 'unknown target CPU'.

Add resolveHostTargetCPU(): clamp znver4/znver5 to znver3 and
cortex-x925 to tsv200m, and allow PTOAS_HOST_TARGET_CPU to override
detection. Implementation matches mly/feature-vmi to avoid a textual
conflict when that branch lands.

Fixes hw-native-sys#958
@KurrinQu
KurrinQu force-pushed the qkl/fix-ptoas-host-cpu-clamp branch from f8f748e to 0e3113f Compare July 20, 2026 04:28
@KurrinQu
KurrinQu merged commit d9becdc into hw-native-sys:main Jul 20, 2026
20 of 25 checks passed
@reedhecre

Copy link
Copy Markdown

A5 板测成功

  • 触发方式:merged
  • 源码提交:d9becdc72b17
  • 结果汇总:OK 21 / FAIL 0 / SKIP 0
  • 日志:/root/ptoas-board-monitor-a5/logs/20260720_141906_merged_pr959.log
  • 结果 TSV:/root/ptoas-board-monitor-a5/logs/20260720_141906_merged_pr959.tsv

@reedhecre

Copy link
Copy Markdown

A3 板测失败

  • 触发方式:merged
  • 源码提交:d9becdc72b17
  • 结果汇总:OK 219 / FAIL 2 / SKIP 2
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260719_232331_merged_pr959.log
  • 失败阶段:board-validation / exit=1

失败用例

  • comm_p2p_binding_variants (run, exit=1)
  • comm_p2p (run, exit=1)

@reedhecre

Copy link
Copy Markdown

A3 板测失败详情:PR #959

comm_p2p_binding_variants

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507035 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260719_232331_merged_pr959/npu_validation/CommSync/comm_p2p_binding_variants/main.cpp:122)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 2286201] 2026-07-19-23:59:43.466.694 (EZ9999):  The error from device(chipId:1, dieId:0), serial number is 601, there is an exception of aivec error, core id is 29, error code = 0x10, dump info: pc start: 0x124400000000, current: 0x124400000164, vec error info: 0xb1000000ab, mte error info: 0xbb030000d8, ifu error info: 0x212c085600b40, ccu error info: 0x4f, cube error info: 0, biu error info: 0, aic error mask: 0x6500020bd00028c, para base: 0x12c100000000.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:645]
        TraceBack (most recent call last):
       The extend info: errcode:(0x10, 0, 0) errorStr: Illegal instruction, which is usually caused by unaligned UUB addresses. fixp_error0 info: 0x30000d8, fixp_error1 info: 0xbb, fsmId:0, tslot:0, thread:0, ctxid:0, blk:0, sublk:0, subErrType:4.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:658]
       Kernel task happen error, retCode=0x31, [vector core exception].[FUNC:PreCheckTaskErr][FILE:davinci_kernel_task.cc][LINE:1729]
       AIV Kernel happen error, retCode=0x31.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [AIC_INFO] after execute:args print end[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [DFX_INFO]Aicore kernel execute failed, device_id=2, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=comm_p2p_binding_variants_kernel, fault kernel info ext=comm_p2p_binding_variants_kernel, program id=0, hash=16541545288638093324.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       rtStreamSynchronize execution failed, reason=vector core exception[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:65]
       synchronize stream failed, runtime result = 507035[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:148]
[2026-07-19 23:59:44] ERROR: testcase failed (exit 1): comm_p2p_binding_variants
comm_p2p

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507035 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260719_232331_merged_pr959/npu_validation/CommSync/comm_p2p/main.cpp:122)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 2295823] 2026-07-20-00:00:02.019.153 (EZ9999):  The error from device(chipId:1, dieId:0), serial number is 602, there is an exception of aivec error, core id is 34, error code = 0x10, dump info: pc start: 0x124400000000, current: 0x124400000168, vec error info: 0xe400000055, mte error info: 0xbb030000d8, ifu error info: 0x212c084080100, ccu error info: 0x4f, cube error info: 0, biu error info: 0, aic error mask: 0x6500020bd00028c, para base: 0x12c100000000.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:645]
        TraceBack (most recent call last):
       The extend info: errcode:(0x10, 0, 0) errorStr: Illegal instruction, which is usually caused by unaligned UUB addresses. fixp_error0 info: 0x30000d8, fixp_error1 info: 0xbb, fsmId:0, tslot:0, thread:0, ctxid:0, blk:0, sublk:0, subErrType:4.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:658]
       Kernel task happen error, retCode=0x31, [vector core exception].[FUNC:PreCheckTaskErr][FILE:davinci_kernel_task.cc][LINE:1729]
       AIV Kernel happen error, retCode=0x31.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [AIC_INFO] after execute:args print end[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [DFX_INFO]Aicore kernel execute failed, device_id=2, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=comm_p2p_kernel, fault kernel info ext=comm_p2p_kernel, program id=0, hash=6260346515940177617.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       rtStreamSynchronize execution failed, reason=vector core exception[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:65]
       synchronize stream failed, runtime result = 507035[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:148]
[2026-07-20 00:00:03] ERROR: testcase failed (exit 1): comm_p2p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ptoas 将运行时探测的 host CPU 传给 bisheng -cc1,Zen 4/Zen 5 机器上因 bisheng 不支持而失败

3 participants