Skip to content

fix: validate memory_order per-operation for atomic_load/store (Fixes #2574)#2589

Open
muhamedfazalps wants to merge 2 commits into
tile-ai:mainfrom
muhamedfazalps:fix/atomic-memory-order-guard
Open

fix: validate memory_order per-operation for atomic_load/store (Fixes #2574)#2589
muhamedfazalps wants to merge 2 commits into
tile-ai:mainfrom
muhamedfazalps:fix/atomic-memory-order-guard

Conversation

@muhamedfazalps

@muhamedfazalps muhamedfazalps commented Jul 10, 2026

Copy link
Copy Markdown

Fixes #2574

Summary

T.atomic_load previously accepted memory_order="release" / "acq_rel" and T.atomic_store accepted memory_order="consume" / "acquire" / "acq_rel" — memory orders that are illegal for those operations in C++/libcu++. The kernel compiled cleanly but died with a device-side assert inside libcu++ at runtime:

Assertion `0` failed.
AcceleratorError: CUDA error: device-side assert triggered

C++ restricts which memory orders are legal per atomic operation:

  • load: relaxed / consume / acquire / seq_cst — never release or acq_rel
  • store: relaxed / release / seq_cst — never consume, acquire, or acq_rel

This PR adds per-operation legality checks in atomic_load and atomic_store that validate the memory_order against these rules before emitting the call. Illegal orders now raise a clear ValueError at compile time:

ValueError: atomic_load: memory_order='release' is illegal for a load;
use one of ['acquire', 'consume', 'relaxed', 'seq_cst']

Changes

  • tilelang/language/atomic.py: Added _LOAD_ORDERS and _STORE_ORDERS sets defining per-operation legal memory orders. Added validation in atomic_load() and atomic_store() before the _MEMORY_ORDER_ID_MAP lookup. Updated docstrings to list only the per-operation legal orders.
  • testing/python/language/test_tilelang_issue_2574.py: Added pytest tests that verify:
    • atomic_load rejects release and acq_rel
    • atomic_store rejects consume, acquire, and acq_rel
    • Legal orders still compile without error (regression guard)

Testing

  • Existing atomic tests for legal orders are unaffected.
  • New tests verify rejection of all 5 illegal (op, order) combinations and acceptance of all 7 legal ones.

Summary

  • Added operation-specific memory_order validation for T.atomic_load and T.atomic_store (only the C++/libcu++ legal orders per operation are accepted).
  • Invalid orders now raise clear ValueErrors during compilation/code-generation setup instead of failing with device-side assertions.
  • Updated atomic_load/atomic_store docstrings to list only supported memory orders and reflect the new error behavior.
  • Added regression tests for #2574 covering illegal and legal memory_order combinations for CUDA targets.

C++ style / lint notes

  • This PR does not modify C++ style documentation (docs/developer_guide/cpp_style.md) or any C++ sources.
  • The “C++ API Style Audit (warning only)” CI step exists in the workflow, but this PR does not touch or configure it; no new TLCPP003/TLCPP004 warnings are implicated by these changes.

…ile-ai#2574)

T.atomic_load previously accepted memory_order='release'/'acq_rel' and
T.atomic_store accepted 'consume'/'acquire'/'acq_rel' — memory orders
that are illegal for those operations in C++/libcu++. The kernel compiled
cleanly but died with a device-side assert inside libcu++ at runtime.

Add per-operation legality checks in atomic_load and atomic_store that
validate the memory_order against the C++ standard rules before emitting
the call. Illegal orders now raise a clear ValueError at compile time.

Also updated docstrings to list only the per-operation legal orders.
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7c159ce-4e17-41e1-94eb-2b1e47541571

📥 Commits

Reviewing files that changed from the base of the PR and between 6b2ba8f and fb8ffdd.

📒 Files selected for processing (1)
  • testing/python/language/test_tilelang_issue_2574.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • testing/python/language/test_tilelang_issue_2574.py

📝 Walkthrough

Walkthrough

Atomic loads and stores now validate operation-specific memory orders before code generation. A regression test module covers rejected orders and legal orders for CUDA compilation.

Changes

Atomic memory-order validation

Layer / File(s) Summary
Operation-specific atomic validation
tilelang/language/atomic.py
Defines legal memory-order sets, raises ValueError for invalid load/store orders, and updates the corresponding docstrings.
Atomic memory-order regression tests
testing/python/language/test_tilelang_issue_2574.py
Tests compilation rejection for illegal orders and successful compilation for legal load and store orders.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: LeiWang1999, chengyupku

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: per-operation memory-order validation for atomic_load/store.
Linked Issues check ✅ Passed The changes implement the issue's required frontend validation, doc updates, legal-order preservation, and regression tests.
Out of Scope Changes check ✅ Passed The diff appears scoped to atomic memory-order validation and its tests, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
testing/python/language/test_tilelang_issue_2574.py (1)

45-53: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding "consume" to the legal load orders test.

_LOAD_ORDERS includes "consume", but test_atomic_load_accepts_legal_orders only parametrizes over ["relaxed", "acquire", "seq_cst"]. Adding "consume" would close the coverage gap and ensure the legal-order path is fully exercised.

🧪 Suggested addition
-@pytest.mark.parametrize("order", ["relaxed", "acquire", "seq_cst"])
+@pytest.mark.parametrize("order", ["relaxed", "consume", "acquire", "seq_cst"])
 def test_atomic_load_accepts_legal_orders(order):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@testing/python/language/test_tilelang_issue_2574.py` around lines 45 - 53,
Expand the parameterization of test_atomic_load_accepts_legal_orders to include
"consume", matching the legal values defined in _LOAD_ORDERS and covering that
accepted load-order path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@testing/python/language/test_tilelang_issue_2574.py`:
- Around line 45-53: Expand the parameterization of
test_atomic_load_accepts_legal_orders to include "consume", matching the legal
values defined in _LOAD_ORDERS and covering that accepted load-order path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a0fc93e0-c5f4-40d6-a442-9e067f57e5f0

📥 Commits

Reviewing files that changed from the base of the PR and between 3b37333 and 6b2ba8f.

📒 Files selected for processing (2)
  • testing/python/language/test_tilelang_issue_2574.py
  • tilelang/language/atomic.py

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][Fuzzer][diagnostic] T.atomic_load/T.atomic_store accept an op-illegal memory order → device-side assert instead of a frontend reject

1 participant