Skip to content

[AMDGPU] Fix: apply amdgpu-ieee/amdgpu-dx10-clamp to all functions - #775

Open
paveltc wants to merge 1 commit into
Genesis-Embodied-AI:mainfrom
paveltc:fix/amdgpu-ieee-dx10-clamp-all-functions
Open

[AMDGPU] Fix: apply amdgpu-ieee/amdgpu-dx10-clamp to all functions#775
paveltc wants to merge 1 commit into
Genesis-Embodied-AI:mainfrom
paveltc:fix/amdgpu-ieee-dx10-clamp-all-functions

Conversation

@paveltc

@paveltc paveltc commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Backend-only AMDGPU codegen fix. No public API, no new user-tunable knobs, solver-agnostic. This PR is self-contained and does not depend on #774.

On gfx942 (MI300X), amdgpu-ieee=false and amdgpu-dx10-clamp=false must be applied to all functions, not only AMDGPU_KERNEL entries. LLVM's inliner refuses to inline a callee into a caller when they carry mismatching target-specific attributes, so applying them kernel-only leaves internal device functions (e.g. gpu_parallel_range_for and the body functions it dispatches) un-inlined. Without that inlining, InferAddressSpaces cannot follow the pointer chain from kernel parameters to field data and cannot promote flat_load/flat_store/flat_atomic to global_*, causing flat-atomic coherency issues and a ~4% throughput regression on MI300X.

Change

Single file (quadrants/runtime/amdgpu/jit_amdgpu.cpp): a small pass setting both attributes on every function, each guarded by !F.hasFnAttribute(...) for idempotency. +21 lines, no other files touched.

Independence from #774

An earlier version of this fix was stacked on #774 and reused its per-kernel fn_attrs registry. That coupling has been removed — this PR now applies against main directly as a self-contained backend change and can merge with or without #774.

@paveltc paveltc changed the title fix(amdgpu): propagate amdgpu-ieee and amdgpu-dx10-clamp to all functions [AMDGPU] Fix: propagate amdgpu-ieee and amdgpu-dx10-clamp to all functions Jul 10, 2026
@paveltc paveltc closed this Jul 12, 2026
@paveltc paveltc reopened this Aug 13, 2026
@paveltc

paveltc commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Note

Outdated (Aug 20, 2026): This comment no longer applies to the current PR. Keeping it for historical reference.

Depends on #774 — please review/merge that first.

This branch is stacked on #774: of its three commits, the first two (0f4410279, 9cb65ab3e) belong to #774's per-kernel fn_attrs work, and only the last one (23f2bb97b) is unique to this PR. That's why the diff currently shows ~+499/-8 — most of it is #774's code, not this change.

The actual change here is a single-file, +16/-6 edit to quadrants/runtime/amdgpu/jit_amdgpu.cpp: it moves the amdgpu-ieee / amdgpu-dx10-clamp function attributes out of the AMDGPU_KERNEL-only block so they apply to all functions (so the inliner will inline device body functions into kernels, letting InferAddressSpaces promote flat_* to global_*). It modifies the fn-attribute loop that #774 introduces in jit_amdgpu.cpp, so it cannot land on main independently.

Plan: once #774 merges, I'll rebase this onto main; it will then collapse to just the small jit_amdgpu.cpp change for a clean review.

@paveltc

paveltc commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23f2bb97b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread quadrants/runtime/amdgpu/jit_amdgpu.cpp Outdated
Comment on lines +40 to +42
if (this->config_.fast_math) {
F.addFnAttr("unsafe-fp-math", "true");
F.addFnAttr("no-signed-zeros-fp-math", "true");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Split unrelated AMDGPU behavior out of this fix

The stated inlining fix only requires propagating amdgpu-ieee and amdgpu-dx10-clamp, but this commit also changes fast-math attributes, scheduling and work-group heuristics, DAZ behavior, cache keys, bindings, and the public kernel API. These independent semantic changes greatly increase the regression surface of the backport; please partition them into separate changes and keep this fix localized to the two attributes.

AGENTS.md reference: AGENTS.md:L7-L13

Useful? React with 👍 / 👎.

Comment thread python/quadrants/lang/kernel_impl.py Outdated
fastcache: bool = False,
graph: bool = False,
checkpoints: bool = False,
cuda_graph: bool = False,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the new cuda_graph decorator argument

This adds cuda_graph to the public @qd.kernel API and gives it deprecation and graph-enabling behavior, but neither the updated user guide nor this function's Args section documents it. Users therefore cannot discover its semantics or migration path from the public documentation; add the corresponding docs/ update if this alias remains.

AGENTS.md reference: AGENTS.md:L15-L22

Useful? React with 👍 / 👎.

Comment thread quadrants/program/fn_attrs_registry.h Outdated
Comment on lines +23 to +27
"amdgpu-max-num-workgroups",
"amdgpu-agpr-alloc",
"amdgpu-waves-per-eu",
"amdgpu-flat-work-group-size",
"amdgpu-sched-strategy",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow the guarded AMDGPU attributes through validation

When a user tries to override amdgpu-ieee or amdgpu-dx10-clamp through fn_attrs, _validate_fn_attrs rejects the decorator because neither name is registered here. This makes the new JIT hasFnAttribute guards—and the documented claim that user-supplied values win—unreachable for the two attributes central to this change; register both names or remove the unsupported override claim.

Useful? React with 👍 / 👎.

paveltc pushed a commit to paveltc/quadrants that referenced this pull request Aug 17, 2026
These two attributes are applied to all functions in jit_amdgpu.cpp behind
`!F.hasFnAttribute(key)` guards, and the PR documents that a user-supplied
value via @qd.kernel(fn_attrs=...) wins over the default. But neither name
was in the fn_attrs registry, so _validate_fn_attrs rejected any attempt to
override them, making that override path unreachable (Codex Genesis-Embodied-AI#775 P2).

Register both names so the guards are actually reachable.

Co-authored-by: Cursor <cursoragent@cursor.com>
@paveltc

paveltc commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @codex. Quick disposition of the three comments:

P1 — "Split unrelated AMDGPU behavior out of this fix" (jit_amdgpu.cpp) and
P1 — "Document the new cuda_graph decorator argument" (kernel_impl.py)

Both of these are from the inherited #774 commits, not this PR's actual change. This branch is stacked on #774: of its three commits, the first two (0f4410279, 9cb65ab3e) are #774's per-kernel fn_attrs work (fast-math gating, scheduling/work-group heuristics, the cuda_graph alias, bindings, public API, cache keys), and only the last commit (23f2bb97b) is unique to this PR — a single-file +16/−6 edit to jit_amdgpu.cpp that moves amdgpu-ieee/amdgpu-dx10-clamp out of the AMDGPU_KERNEL-only block. That's why the diff currently reads ~+499/−8.

So the fix is already localized to the two attributes as requested; the extra surface Codex is flagging lives in #774. Once #774 merges, I'll rebase this onto main and the diff collapses to just the jit_amdgpu.cpp change (and the cuda_graph docs point is tracked on #774, where that change actually lives).

P2 — "Allow the guarded AMDGPU attributes through validation" (fn_attrs_registry.h)

Good catch — this one is real and specific to this PR's claim. Fixed in d62feedfb: amdgpu-ieee and amdgpu-dx10-clamp are now registered, so _validate_fn_attrs accepts them and the !F.hasFnAttribute(key) guards (and the "user-supplied values win" contract) are actually reachable.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Set amdgpu-ieee=false and amdgpu-dx10-clamp=false on all functions in the
AMDGPU module rather than only AMDGPU_KERNEL entries.

LLVM's inliner refuses to inline a callee into a caller when they carry
mismatching target-specific attributes. Applying these attributes to kernels
only leaves internal runtime device functions (e.g. gpu_parallel_range_for and
the body functions it dispatches) with a mismatching attribute set, so they are
not inlined into the kernel entry. Without that inlining, InferAddressSpaces
cannot follow the pointer chain from kernel parameters to field data and cannot
promote flat_load/flat_store/flat_atomic to global_*, causing flat-atomic
coherency issues and a ~4% throughput regression on gfx942 (MI300X).

Applying the two attributes uniformly restores inlining and lets
InferAddressSpaces emit global_load/global_store/global_atomic. Each write is
guarded by hasFnAttribute so it remains idempotent.

Self-contained backend change: single file, no public API, no dependency on
the per-kernel fn_attrs work in Genesis-Embodied-AI#774.

Co-authored-by: Cursor <cursoragent@cursor.com>
@paveltc
paveltc force-pushed the fix/amdgpu-ieee-dx10-clamp-all-functions branch from d62feed to 99a4eba Compare August 19, 2026 21:40
@paveltc paveltc changed the title [AMDGPU] Fix: propagate amdgpu-ieee and amdgpu-dx10-clamp to all functions [AMDGPU] Fix: apply amdgpu-ieee/amdgpu-dx10-clamp to all functions Aug 19, 2026
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.

2 participants