Skip to content

[BugFix][CUDA] Guard cp.async transfers by full source extent - #2842

Open
morluto wants to merge 8 commits into
tile-ai:mainfrom
morluto:audit/cpasync-transfer-range
Open

[BugFix][CUDA] Guard cp.async transfers by full source extent#2842
morluto wants to merge 8 commits into
tile-ai:mainfrom
morluto:audit/cpasync-transfer-range

Conversation

@morluto

@morluto morluto commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #2841.

Problem

LegalizeSafeMemoryAccess only checked the source base index of a direct ptx_cp_async call. A valid base plus an invalid transfer width could therefore lower to an unguarded global-memory read.

logical fp16 A: [0 ... 8]
copy request: A[8], 8 elements

before: validates A[8]       -> unguarded
after:  validates A[8 ...15] -> false predicate / zero-fill

The higher-level async-copy tail path already emits guards; this patch targets the direct low-level ptx_cp_async form.

Change

  • Flatten the physical source offset.
  • Check base + num_elems - 1 against the flattened source extent.
  • Reuse the existing predicate mechanism and deduplicate the equivalent condition for one-element transfers.

Regression coverage

The added case copies eight fp16 elements from A[8] of a logical A[9]. It fails on the base branch because the call remains unpredicated and passes with the final rebuilt candidate.

Validation

  • transfer-range and existing cp.async legalization tests against the final rebuilt library — 3 passed, 12 deselected
  • access-pointer codegen tests against the final rebuilt library — 7 passed
  • clang-format, Ruff format check, git diff --check, and exact-diff autoreview — passed

The candidate library was built with CUDA_HOME set to the detected pip CUDA root and includes the RTX 3060-compatible CUDA path.

Summary

  • Fixed direct ptx_cp_async source-range validation.
  • Flattened physical source offsets and validated the complete transfer range with base + num_elems - 1.
  • Reused existing predicate handling and deduplicated equivalent predicates for one-element transfers.
  • Added regression coverage for out-of-bounds 1D, rank-2, byte-pointer, offset, negative-index, partial-range, and unaligned-destination transfers.
  • Confirmed that legalization appends a false predicate and preserves the four ptx_cp_async call arguments.

C++ style / lint notes

  • The PR changes C++ implementation code.
  • It does not change rules documented in docs/developer_guide/cpp_style.md.
  • The C++ API Style Audit (warning only) remains advisory.
  • No correctness, build, or test issues are indicated.

@github-actions

github-actions Bot commented Aug 1, 2026

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 Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

cp.async legalization

Layer / File(s) Summary
Pointer metadata and transfer-size calculation
src/transform/legalize_safe_memory_access.cc
AccessPtrInfo preserves pointer element types and raw offsets. tvm_access_ptr offsets use backing-buffer element units. Helpers compute transfer sizes and buffer-element counts.
Complete source transfer validation
src/transform/legalize_safe_memory_access.cc, testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py
cp.async validation checks complete flattened source ranges. Narrower typed pointers use byte bounds. Tests cover transfer ranges, rank-2 sources, byte pointers, offsets, large ranges, and negative indices.
Destination fallback generation
src/transform/legalize_safe_memory_access.cc, testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py
Nonzero-safe-value fallbacks validate destination alignment and store each transferred element through reconstructed indices. Tests cover alignment errors and multi-element fallback stores.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ptx_cp_async
  participant LegalizeSafeMemoryAccess
  participant FallbackStoreGenerator
  ptx_cp_async->>LegalizeSafeMemoryAccess: submit typed source and destination ranges
  LegalizeSafeMemoryAccess->>LegalizeSafeMemoryAccess: validate complete source transfer
  LegalizeSafeMemoryAccess->>FallbackStoreGenerator: provide aligned destination transfer
  FallbackStoreGenerator-->>ptx_cp_async: emit predicated per-element safe-value stores
Loading

Possibly related PRs

Suggested reviewers: leiwang1999

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes destination validation, pointer layouts, alignment checks, and nonzero-safe-value fallbacks beyond the linked source-range objective. Split unrelated destination, pointer-layout, alignment, and fallback changes into separate pull requests, or document their required connection to issue #2841.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the CUDA bug fix for guarding complete cp.async source transfers.
Linked Issues check ✅ Passed The changes validate complete flattened cp.async source ranges, preserve base checks, deduplicate predicates, and add regression coverage for issue #2841.
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/transform/test_tilelang_transform_legalize_safe_memory_access.py (1)

255-296: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for flattening and one-element deduplication.

Add a rank-2 source case where each base coordinate is valid but the final contiguous element exceeds the flattened extent. Add a symbolic one-element case that expects one upper-bound predicate. The current rank-1, eight-element constant case cannot exercise either path.

🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`
around lines 255 - 296, Extend cp_async_access_ptr_transfer_range_legalize with
coverage for both missing paths: add a rank-2 source tensor whose base
coordinates are individually valid but whose final contiguous transfer exceeds
the flattened extent, and add a symbolic one-element transfer that expects a
single upper-bound predicate. Update the corresponding expected IR and
assertions in assert_cp_async_access_ptr_transfer_range_legalize, preserving the
existing rank-1 eight-element case.
🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`:
- Around line 255-296: Extend cp_async_access_ptr_transfer_range_legalize with
coverage for both missing paths: add a rank-2 source tensor whose base
coordinates are individually valid but whose final contiguous transfer exceeds
the flattened extent, and add a symbolic one-element transfer that expects a
single upper-bound predicate. Update the corresponding expected IR and
assertions in assert_cp_async_access_ptr_transfer_range_legalize, preserving the
existing rank-1 eight-element case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b166617-e511-48ec-abdd-8d9cf25a285c

📥 Commits

Reviewing files that changed from the base of the PR and between 6b81bb8 and c8950f7.

📒 Files selected for processing (2)
  • src/transform/legalize_safe_memory_access.cc
  • testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py

@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: c8950f70fa

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/transform/legalize_safe_memory_access.cc Outdated
Comment thread src/transform/legalize_safe_memory_access.cc Outdated

@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: ac755942d9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/transform/legalize_safe_memory_access.cc

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py (1)

255-296: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align ptx_cp_async predicates with the byte-count contract.

T.ptx_cp_async(..., 2) documents num_elems as logical element count, but LegalizeSafeMemoryAccess treats it as bytes and converts 2 bytes to one float16 element. That makes both expected unsafe-copy checks pass, not catch out-of-bounds access. Use a byte-sized unsafe transfer everywhere the pass treats the value as bytes, or keep element-count semantics and remove the byte-to-element conversion.

🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`
around lines 255 - 296, Align the cp_async access-range test with the pass’s
byte-count interpretation: update the unsafe transfer in
cp_async_access_ptr_transfer_range_legalize and its expected function so the
transfer size is byte-sized and still represents the intended out-of-bounds
case. Keep assert_cp_async_access_ptr_transfer_range_legalize validating the
four-argument legalized call and expected IR match.
🧹 Nitpick comments (1)
testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py (1)

332-334: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for one-element predicate deduplication.

The new fixtures use transfers of eight and two elements. Add a case with a dynamic valid base and num_elems=1. Assert that legalization emits one combined predicate instead of duplicate equivalent upper-bound conditions.

🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`
around lines 332 - 334, Add a test alongside
assert_cp_async_access_ptr_rank2_transfer_range_legalize for a dynamic valid
base with num_elems=1, using the existing legalization fixture and assertion
helpers. Ensure the expected legalized output contains a single combined
predicate without duplicate equivalent upper-bound conditions.
🤖 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.

Outside diff comments:
In
`@testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py`:
- Around line 255-296: Align the cp_async access-range test with the pass’s
byte-count interpretation: update the unsafe transfer in
cp_async_access_ptr_transfer_range_legalize and its expected function so the
transfer size is byte-sized and still represents the intended out-of-bounds
case. Keep assert_cp_async_access_ptr_transfer_range_legalize validating the
four-argument legalized call and expected IR match.

---

Nitpick comments:
In
`@testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py`:
- Around line 332-334: Add a test alongside
assert_cp_async_access_ptr_rank2_transfer_range_legalize for a dynamic valid
base with num_elems=1, using the existing legalization fixture and assertion
helpers. Ensure the expected legalized output contains a single combined
predicate without duplicate equivalent upper-bound conditions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fc6b0f26-e42c-42fd-b517-717ca36aa32d

📥 Commits

Reviewing files that changed from the base of the PR and between c8950f7 and ac75594.

📒 Files selected for processing (2)
  • src/transform/legalize_safe_memory_access.cc
  • testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/transform/legalize_safe_memory_access.cc

@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: 54f1f9ab9d

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/transform/legalize_safe_memory_access.cc
Comment thread src/transform/legalize_safe_memory_access.cc Outdated

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/transform/legalize_safe_memory_access.cc (1)

717-726: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use boolean equality for condition deduplication. CanProveEqual reduces operands with lhs - rhs == 0, but the TVM simplifier does not cancel subtraction for Bool(1). The one-element upper-bound condition can therefore remain duplicated. Use a boolean equality proof instead of CanProveEqual at line 719.

🤖 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 `@src/transform/legalize_safe_memory_access.cc` around lines 717 - 726, Update
the condition deduplication lambda push_distinct_condition to compare boolean
conditions using the analyzer’s boolean-equality proof rather than
CanProveEqual. Preserve the existing early return for equivalent conditions and
checker.PushCondition behavior for distinct conditions.
🧹 Nitpick comments (2)
src/transform/legalize_safe_memory_access.cc (2)

738-750: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document the 8-bit constant.

transfer_elem_bits = 8 encodes that builtin::ptx_cp_async counts bytes while tl::ptx_cp_async counts typed elements. That divergence is not obvious at the call sites. Add a short comment so a future reader does not treat the constant as a default.

♻️ Suggested comment
     PrimExpr num_elems = call->args[2];
+    // builtin::ptx_cp_async counts bytes; tl::ptx_cp_async counts elements of
+    // the access-pointer element type.
     int transfer_elem_bits = 8;
🤖 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 `@src/transform/legalize_safe_memory_access.cc` around lines 738 - 750, Add a
brief explanatory comment next to the initial transfer_elem_bits value in
GetCPAsyncTransferBits, stating that builtin::ptx_cp_async counts bytes and
therefore uses 8 bits, while tl::ptx_cp_async counts typed elements and follows
the element dtype calculation. Keep the existing logic unchanged.

648-681: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rename the bit-valued variables that are named "byte".

byte_offset holds a bit count, not a byte count. GetCPAsyncTransferBits returns bits, and flattened_extent_bits is in bits, so the comparison is correct. The name is misleading and invites a future unit mismatch. The same name is used in CanMakeCPAsyncFallbackStores at Lines 802-815.

♻️ Suggested rename
-      PrimExpr byte_offset = src_info.raw_element_offset.value() *
-                             IntImm(src_info.raw_element_offset.value().dtype(),
-                                    src_pointer_elem_bits);
+      PrimExpr bit_offset = src_info.raw_element_offset.value() *
+                            IntImm(src_info.raw_element_offset.value().dtype(),
+                                   src_pointer_elem_bits);

Apply the same rename to the remaining uses in this block and in CanMakeCPAsyncFallbackStores.

🤖 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 `@src/transform/legalize_safe_memory_access.cc` around lines 648 - 681, Rename
the bit-valued variable byte_offset to a bit-oriented name throughout this
validation block, including its declarations, casts, arithmetic, conditions, and
related dtype conversions. Apply the same rename consistently to the
corresponding variable and all uses in CanMakeCPAsyncFallbackStores, while
leaving the existing bit-based calculations unchanged.
🤖 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.

Inline comments:
In `@src/transform/legalize_safe_memory_access.cc`:
- Around line 857-893: Update MakeCPAsyncFallbackStores around fallback_offset
and the returned For to constrain fallback stores to the destination extent,
accounting for the initial linear_index offset. Add a destination-range
predicate or clamp num_elems so generated dst_indices never address beyond
flattened_dst_buffer->shape, while preserving valid fallback stores and existing
predicate handling.

---

Outside diff comments:
In `@src/transform/legalize_safe_memory_access.cc`:
- Around line 717-726: Update the condition deduplication lambda
push_distinct_condition to compare boolean conditions using the analyzer’s
boolean-equality proof rather than CanProveEqual. Preserve the existing early
return for equivalent conditions and checker.PushCondition behavior for distinct
conditions.

---

Nitpick comments:
In `@src/transform/legalize_safe_memory_access.cc`:
- Around line 738-750: Add a brief explanatory comment next to the initial
transfer_elem_bits value in GetCPAsyncTransferBits, stating that
builtin::ptx_cp_async counts bytes and therefore uses 8 bits, while
tl::ptx_cp_async counts typed elements and follows the element dtype
calculation. Keep the existing logic unchanged.
- Around line 648-681: Rename the bit-valued variable byte_offset to a
bit-oriented name throughout this validation block, including its declarations,
casts, arithmetic, conditions, and related dtype conversions. Apply the same
rename consistently to the corresponding variable and all uses in
CanMakeCPAsyncFallbackStores, while leaving the existing bit-based calculations
unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fe878464-0ff4-4845-8f59-1f00dd626a6c

📥 Commits

Reviewing files that changed from the base of the PR and between ac75594 and 54f1f9a.

📒 Files selected for processing (2)
  • src/transform/legalize_safe_memory_access.cc
  • testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py

Comment thread src/transform/legalize_safe_memory_access.cc Outdated

@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: 9b9b9362f5

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +955 to +961
if (!CanMakeCPAsyncFallbackStores(dst_info, call)) {
LOG(FATAL)
<< "cp.async nonzero safe-value fallback requires a destination byte "
"range aligned to backing-buffer elements; byte-granular "
"fallback stores are unsupported because a BufferStore could "
"overwrite bytes outside the transfer. Got "
<< call;

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 Honor false predicates before rejecting fallback stores

When a nonzero safe value is configured but the existing cp.async predicate is provably false, the intrinsic only zero-fills the destination and never needs the nonzero fallback; nevertheless this check rejects any transfer not aligned to the destination buffer's element width. For example, a predicated-false 4-byte copy into a float64 backing buffer with a potentially out-of-range source now raises this LOG(FATAL), even though the existing predicate makes the operation safely zero-fillable. Simplify the existing predicate first and use the native zero-fill path when it is false before requiring element-aligned fallback stores.

Useful? React with 👍 / 👎.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py (1)

483-487: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert that the unpredicated cp.async call is preserved.

_count_if_then_else(...) == 0 proves only that no conditional node exists. It does not prove that the transformed body still contains the intended three-argument tl.ptx_cp_async call with the original operands. Use _assert_legalize_matches_expected at Lines [70]-[79], or visit the transformed body and assert the call and its three arguments.

Based on learnings: transform tests should assert structural behavior instead of relying on particular numeric literals.

Also applies to: 513-517

🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`
around lines 483 - 487, Strengthen
assert_cp_async_access_ptr_elem_offset_legalize by verifying the transformed
body preserves the unpredicated three-argument tl.ptx_cp_async call and its
original operands, rather than only counting conditional nodes. Reuse
_assert_legalize_matches_expected or inspect the transformed body directly, and
apply the same structural assertion to the corresponding test near the second
referenced location.

Source: Learnings

🤖 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.

Inline comments:
In
`@testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py`:
- Around line 314-325: Update the main test fixture’s source transfer to use an
eight-element tensor and start the copy at A[0], while retaining the
four-element A_shared destination so destination-range validation is exercised.

---

Nitpick comments:
In
`@testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py`:
- Around line 483-487: Strengthen
assert_cp_async_access_ptr_elem_offset_legalize by verifying the transformed
body preserves the unpredicated three-argument tl.ptx_cp_async call and its
original operands, rather than only counting conditional nodes. Reuse
_assert_legalize_matches_expected or inspect the transformed body directly, and
apply the same structural assertion to the corresponding test near the second
referenced location.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ea3f1e7-a298-409b-8aea-e44d011ff4e1

📥 Commits

Reviewing files that changed from the base of the PR and between 54f1f9a and 9b9b936.

📒 Files selected for processing (2)
  • src/transform/legalize_safe_memory_access.cc
  • testing/python/transform/test_tilelang_transform_legalize_safe_memory_access.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/transform/legalize_safe_memory_access.cc

Comment on lines +314 to +325
def main(
A: T.Tensor((4,), dtype=dtype),
):
with T.sblock("root"):
T.reads()
T.writes()
T.sblock_attr({"safe_value_map": {A.data: T.float16(3)}})
A_shared = T.sblock_alloc_buffer((4,), dtype=dtype, scope="shared")
T.ptx_cp_async(
T.access_ptr(A_shared[0], "w", 8),
T.access_ptr(A[4], "r", 8),
8,

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use a valid source transfer in the destination-range test.

A[4] is out of bounds for A: T.Tensor((4,), ...). The source range is invalid before destination validation runs. The test can therefore pass even if destination-range validation is missing or broken. Use an eight-element source and copy from A[0], while keeping A_shared at four elements.

Suggested fixture correction
     def main(
-        A: T.Tensor((4,), dtype=dtype),
+        A: T.Tensor((8,), dtype=dtype),
     ):
...
-                T.access_ptr(A[4], "r", 8),
+                T.access_ptr(A[0], "r", 8),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def main(
A: T.Tensor((4,), dtype=dtype),
):
with T.sblock("root"):
T.reads()
T.writes()
T.sblock_attr({"safe_value_map": {A.data: T.float16(3)}})
A_shared = T.sblock_alloc_buffer((4,), dtype=dtype, scope="shared")
T.ptx_cp_async(
T.access_ptr(A_shared[0], "w", 8),
T.access_ptr(A[4], "r", 8),
8,
def main(
A: T.Tensor((8,), dtype=dtype),
):
with T.sblock("root"):
T.reads()
T.writes()
T.sblock_attr({"safe_value_map": {A.data: T.float16(3)}})
A_shared = T.sblock_alloc_buffer((4,), dtype=dtype, scope="shared")
T.ptx_cp_async(
T.access_ptr(A_shared[0], "w", 8),
T.access_ptr(A[0], "r", 8),
8,
🤖 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/transform/test_tilelang_transform_legalize_safe_memory_access.py`
around lines 314 - 325, Update the main test fixture’s source transfer to use an
eight-element tensor and start the copy at A[0], while retaining the
four-element A_shared destination so destination-range validation is exercised.

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] Validate the complete cp.async source transfer range

1 participant