fix(codegen): wrap scalar cacheinvalid in make_tensor_view for ptoas 0.50 - #2137
fix(codegen): wrap scalar cacheinvalid in make_tensor_view for ptoas 0.50#2137georgebisbas wants to merge 1 commit into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe scalar ChangesScalar cache invalidation
Estimated code review effort: 2 (Simple) | ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/backend/common/pto_ops_memory.cpp (1)
861-865: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd assertions for the new typed scalar view.
The scalar regression test currently verifies only
single_cache_lineand the absence ofpartition_tensor_view; it would also pass with the old raw-pointer emission. Assert that the generated IR containspto.make_tensor_viewwith[1]/[1]and thatcacheinvalidincludes: !pto.tensor_view<1x...>so this fix is protected.🤖 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/backend/common/pto_ops_memory.cpp` around lines 861 - 865, Add regression-test assertions for the scalar view emitted around `scalar_view` and `view_type`: verify the generated IR contains `pto.make_tensor_view` with shape `[1]` and strides `[1]`, and that `pto.cmo.cacheinvalid` includes the typed `!pto.tensor_view<1x...>` result. Preserve the existing `single_cache_line` and `partition_tensor_view` assertions.
🤖 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 `@src/backend/common/pto_ops_memory.cpp`:
- Around line 861-865: Add regression-test assertions for the scalar view
emitted around `scalar_view` and `view_type`: verify the generated IR contains
`pto.make_tensor_view` with shape `[1]` and strides `[1]`, and that
`pto.cmo.cacheinvalid` includes the typed `!pto.tensor_view<1x...>` result.
Preserve the existing `single_cache_line` and `partition_tensor_view`
assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1b9476c8-ff48-4457-964c-723581990f6d
📒 Files selected for processing (1)
src/backend/common/pto_ops_memory.cpp
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af8c5b1a75
ℹ️ 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".
| const std::string scalar_view = codegen.NewTemp(); | ||
| const std::string view_type = "!pto.tensor_view<1x" + dtype_str + ">"; | ||
| codegen.Emit(scalar_view + " = pto.make_tensor_view " + write_ptr + | ||
| ", shape = [1], strides = [1] {layout = #pto.layout<nd>} : " + view_type); |
There was a problem hiding this comment.
Emit SSA index constants for scalar tensor view
When the scalar system.cacheinvalid path is taken, this emits pto.make_tensor_view with bare 1 literals in the shape and strides operand lists. The rest of PTO codegen materializes even static tensor-view dimensions as index SSA values (for example %c1_index) before printing make_tensor_view, so this scalar path will generate MLIR that PTOAS cannot parse for all-ones cacheinvalid regions; please emit/reuse an index constant for 1 and use that SSA name in both lists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d81e09d: replaced raw 1 literals with codegen.GetOrEmitConstant(static_cast<int64_t>(1), DataType::INDEX) producing %c1_index, matching the pattern used in EmitMakeTensorViews and EmitCommRemoteView. All 7722 UTs pass.
georgebisbas
left a comment
There was a problem hiding this comment.
Addressed in d81e09d: test_cacheinvalid_scalar_write_emits_scalar_view (renamed from _ptr) now asserts pto.make_tensor_view presence and : !pto.tensor_view<1x in the cmo line, which would have caught both the missing view wrapping and the raw integer literal regressions.
…id emit Three polish items from PR hw-native-sys#2137 review: 1. Extract EmitScalarTensorViewPTO helper that consolidates the addptr + make_tensor_view(1xT) pattern for 1-element scalar views. 2. DRY the system.cacheinvalid handler: both scalar and partition-view branches now compute (view_ssa, view_type) and converge to a single shared pto.cmo.cacheinvalid emit — future PTOAS syntax changes only need one emit site update. 3. Strengthen test_cacheinvalid_scalar_write_emits_scalar_view to assert SSA index constants (shape = [%c1_index]) in the scalar make_tensor_view, catching raw integer literal regressions.
69f5146 to
37e3448
Compare
… 0.50 The scalar-write branch of system.cacheinvalid codegen in pto_ops_memory.cpp had two PTOAS 0.50 incompatibilities: 1. Missing view operand: emitted pto.cmo.cacheinvalid against a raw !pto.ptr<T> without a type annotation. PTOAS 0.50+ requires a typed tensor_view or partition_view operand. 2. Raw integer literals in make_tensor_view: shape = [1], strides = [1] used bare 1 literals instead of SSA index constants (%c1_index). Fix: extract EmitScalarTensorViewPTO helper that consolidates the addptr + make_tensor_view(1xT) pattern. Both scalar and partition-view branches now converge to a single shared pto.cmo.cacheinvalid emit. Test: strengthen test_cacheinvalid_scalar_write_emits_scalar_view to assert pto.make_tensor_view presence, typed view operand, and SSA index constants in shape/strides — catching the exact regressions that the two PTOAS 0.50 incompatibilities introduced. Fixes: hw-native-sys#2136
37e3448 to
d4dcf71
Compare
There was a problem hiding this comment.
Pull request overview
Fixes PTOAS 0.50 compatibility for scalar cacheinvalid code generation.
Changes:
- Wraps scalar pointers in typed one-element tensor views using SSA index constants.
- Unifies scalar and partition-view
cacheinvalidemission. - Strengthens regression coverage for generated PTO syntax.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/backend/common/pto_ops_memory.cpp |
Adds scalar tensor-view emission and typed cache invalidation. |
tests/ut/codegen/test_pto_codegen_ops.py |
Verifies scalar views, type annotations, and SSA constants. |
The scalar-write branch of
system.cacheinvalidcodegen inpto_ops_memory.cpphad two PTOAS 0.50 incompatibilities:Missing view operand: emitted
pto.cmo.cacheinvalidagainst a raw!pto.ptr<T>without a type annotation. PTOAS 0.50+ requires a typedtensor_vieworpartition_viewoperand.Raw integer literals in
make_tensor_view:shape = [1], strides = [1]used bare1literals instead of SSA index constants (%c1_index), which PTOAS 0.50 cannot parse.Fix (
src/backend/common/pto_ops_memory.cpp):Extracted
EmitScalarTensorViewPTOhelper that consolidates theaddptr + make_tensor_view(1xT)3-step pattern for 1-element scalar views. Both scalar and partition-view branches now compute(view_ssa, view_type)and converge to a single sharedpto.cmo.cacheinvalidemit — future PTOAS syntax changes only need one emit site update.Generated PTO:
Test (
tests/ut/codegen/test_pto_codegen_ops.py):Strengthened
test_cacheinvalid_scalar_write_emits_scalar_view(renamed from_ptr) to assertpto.make_tensor_viewpresence, typed view operand (: !pto.tensor_view<1x...>), and SSA index constants (shape = [%c1_index],strides = [%c1_index]) — catching both regressions that the two PTOAS 0.50 incompatibilities introduced.The bug only triggers when
valid_shape=[1, 1](size=1 tests), e.g.test_l3_tensor_allreduce_intrinsic[2-1].Fixes: #2136