From f250c8cca503c7c372ed156f6608d1599cf6f925 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:59:09 +0800 Subject: [PATCH] fix(gpu): accept PTX compute target aliases Preserve the source spelling of NVIDIA's documented compute_xx target synonym. Fixes #6494 --- docs/gpu-code-objects.md | 2 ++ src/gpu/PtxKernels.ts | 2 +- tests/acceptance/gpuCodeObjectsCli.test.ts | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/gpu-code-objects.md b/docs/gpu-code-objects.md index ead60041c9..0c377c216c 100644 --- a/docs/gpu-code-objects.md +++ b/docs/gpu-code-objects.md @@ -81,6 +81,8 @@ Kernel representations have different meanings: - PTX reports parameter declarations and virtual registers. Shared bytes cover supported static declarations inside that entry; they do not establish module shared memory, dynamic allocation or physical device resources. + A `.target compute_xx` spelling is retained as written; NVIDIA PTX defines it + as a synonym for `.target sm_xx`. Scalar register declarations count each bare or percent-prefixed name and each parameterized range. Unsupported declaration forms or overflowing totals retain an unknown count and partial decoding coverage. Unsupported parameter diff --git a/src/gpu/PtxKernels.ts b/src/gpu/PtxKernels.ts index 008f52942b..b1edccf59c 100644 --- a/src/gpu/PtxKernels.ts +++ b/src/gpu/PtxKernels.ts @@ -406,7 +406,7 @@ export const readPtxTarget = (text: string): string | null => { if (token.value === ".target") { const value = stream.next(); target = - !value.done && /^sm_[0-9]+[a-z]?$/u.test(value.value.value) + !value.done && /^(?:sm|compute)_[0-9]+[a-z]?$/u.test(value.value.value) ? value.value.value : null; } diff --git a/tests/acceptance/gpuCodeObjectsCli.test.ts b/tests/acceptance/gpuCodeObjectsCli.test.ts index 1579d6ad05..4483c6a445 100644 --- a/tests/acceptance/gpuCodeObjectsCli.test.ts +++ b/tests/acceptance/gpuCodeObjectsCli.test.ts @@ -111,6 +111,25 @@ cliTest( }, ); +cliTest("accepts the PTX compute_xx .target synonym verbatim", async ({ cli }) => { + const root = await createTestTempDirectory("rea-ptx-target-cli-"); + const text = `.version 8.8\n.target compute_80\n.address_size 64\n.entry kernel() {\nret;\n}\n`; + const path = join(root, "target.ptx"); + await writeFile(path, text); + const response = await cli.run({ + arguments: ["inspect-gpu-code-objects", path, "--json"], + }); + expect(response.exitCode, response.stderr).toBe(0); + const evidence = parseEvidence( + toolContract("inspect_gpu_code_objects").outputSchema.parse(response.json), + ); + const report = gpuCodeObjectsSchema.parse(evidence.normalized_result); + expect(report.objects[0]!.target).toBe("compute_80"); + expect(report.ptx_artifacts[0]!.sha256).toBe( + createHash("sha256").update(text).digest("hex"), + ); +}); + cliTest( "attributes malformed selector JSON to its actual CLI option", async ({ cli }) => {