omniprobe icon indicating copy to clipboard operation
omniprobe copied to clipboard

Triton PR #10849 will keep the target machine when an LLVM pass plugin is loaded: please evaluate impact

Open zhanglx13 opened this issue 2 months ago • 3 comments

Hi Omniprobe maintainers,

I plan to change how Triton builds its LLVM optimization pipeline when an LLVM-IR pass plugin is loaded, and I would appreciate your help evaluating whether it affects Omniprobe's Triton instrumentation before it merges.

The change

triton-lang/triton#10849 makes optimize_module create the target machine whenever arch is known, including when LLVM_PASS_PLUGIN_PATH is set. Today Triton drops the target machine whenever a plugin is loaded. That guard was added in triton-lang/triton#4669 specifically for instrumentation plugins that splice in externally (Clang-)compiled code, which is the pattern Omniprobe uses.

The motivation: without a target machine, loading any plugin changes how the kernel itself is optimized. For example, on gfx950 a vector-add kernel has 21 amdgpu-no-* attributes normally and 0 once any plugin is loaded, because AMDGPUAttributor no longer runs. Scheduler-style plugins also lose the target cost models.

Possible impact on Omniprobe

From reading the code (not tested), this is where I think it could matter:

  • libAMDGCNSubmitAddressMessages-triton.so registers at OptimizerLastEP, links the dh_comms bitcode, clones each kernel and injects calls.
  • With a target machine, AMDGPUTargetMachine::registerPassBuilderCallbacks adds AMDGPUAttributorPass at the same OptimizerLastEP, and it is registered before plugin callbacks. So the attributor would run first and could mark kernels with amdgpu-no-* attributes (for example no implicit-arg pointer, no workitem id y/z) that the cloned, instrumented kernels then violate.

If that is right, a small fix on the Omniprobe side, such as dropping amdgpu-no-* attributes from the functions you instrument, might be enough. But you know the plugin far better than I do.

How to test

The PR branch is zhanglx13:always-set-target-machine, currently merged with Triton main. The only change is in python/src/llvm.cc:

-        if (!arch.empty() && pluginFile.empty())
+        if (!arch.empty())
           targetMachine =
               createTargetMachine(mod, arch, enable_fp_fusion, features);

Could you run Omniprobe's Triton tests against that branch, or let me know if you would prefer a different approach, such as an opt-out environment variable for instrumentation plugins? I'm happy to adjust the PR based on what you find.

Thank you!

zhanglx13 avatar Sep 26 '26 02:09 zhanglx13

Update: I tested this, and the concern is real. The fix is small; I opened it as #44.

Mechanism. The target machine registers its pass-builder callbacks in the PassBuilder constructor, before any plugin is loaded, so at OptimizerLastEP the AMDGPU attributor always runs first. It marks kernels amdgpu-no-* for implicit inputs they do not use. cloneKernelWithExtraArg copies those onto the instrumented clone, and the injected dh_comms calls then read inputs the backend no longer sets up (workgroup id y/z, workitem id y/z, the implicit-argument pointer behind gridDim). Re-running the attributor would not help, because it treats existing amdgpu-no-* attributes as known facts.

Reproduction on gfx950 (Triton main plus triton-lang/triton#10849, Omniprobe's libAMDGCNSubmitAddressMessages-triton.so built against Triton's LLVM):

instrumented clone __amd_crk_vaddPv amdgpu-no-* workgroup id y SGPR kernarg size
Triton main today (no target machine) 0 enabled 312
with #10849, current Omniprobe 21 disabled 56
with #10849, Omniprobe + #44 0 enabled 312

A probe plugin that injects a non-inlined call reading workgroup_id.y and the hidden block count returns 32737 instead of 2 and 0 instead of 4 when the attributes are stale, and the correct values once they are removed.

Why this matters beyond Triton. The HIP device compile (including -fgpu-rdc) also runs the attributor before -fpass-plugin passes, so the HIP path is likely exposed to the same issue for kernels that do not use these inputs themselves. I have not tested the HIP path.

Two other things you will hit when moving past Triton v3.7.1, unrelated to #10849:

  1. Triton main now emits the triple amdgpu9.50-amd-amdhsa (v3.7-era builds emit amdgcn-amd-amdhsa), so validateAMDGPUTarget's exact string match skips every kernel. Checking M.getTargetTriple().isAMDGCN() instead worked in my test.
  2. The assert len(names) == 1 patch in triton_install.sh is still required.

With #44 in place, triton-lang/triton#10849 should be safe for Omniprobe, so I plan to proceed with it.

zhanglx13 avatar Sep 26 '26 06:09 zhanglx13

Thanks for filing this issue and for the corresponding PR. I'm out of office most of this week, but I plan to update Omniprobe to support the latest stable Triton version when I return, and I'll combine that with testing and merging the PR.

rwvo avatar Oct 05 '26 18:10 rwvo

Item 1 is fixed in e6db747: validateAMDGPUTarget now uses llvm::Triple(...).isAMDGCN() instead of the exact-string match, so it accepts the subarch-aware triples from triton-lang/triton#11532. Item 2 is already handled: containers/triton_install.sh applies the assert len(names) == 1 patch, and it still applies cleanly on v3.8.0, to which we've just moved. We'll merge #44 next. Thanks!

rwvo avatar Oct 27 '26 09:10 rwvo