[Enh] Ensure type closure for primitive func#552
Open
sjfeng1999 wants to merge 2 commits into
Open
Conversation
Collaborator
Author
|
may need update the same aiter kernels simultaneously. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates FlyDSL’s Python expression-layer wrappers to better preserve (“close over”) DSL types (e.g., Numeric, Vector) when calling primitive ops, and adjusts affected tests/kernels to use the new return-value behavior.
Changes:
- Wrap primitive-op scalar results back into
Numerictypes (and propagate this through helpers likeget_scalar,get_leaves,ptr_load,memref_load). - Centralize
memref_load_vecto return aVectorwith shape/dtype metadata, and simplifyTensor.load()accordingly. - Update unit tests and a few kernel utilities to align with the revised scalar/vector return types and pipeline string formatting.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_static_vs_dynamic.py | Adjusts dynamic-layout tests to return i32 scalars directly and simplifies pipeline string formatting. |
| tests/unit/test_layout_algebra.py | Updates dynamic test functions to return i32 scalars from fx.get_scalar(...).ir_value() and simplifies pipeline string formatting. |
| python/flydsl/expr/typing.py | Updates IntTuple reconstruction and makes Tensor.load() rely on the updated memref_load_vec wrapper. |
| python/flydsl/expr/primitive.py | Introduces numeric re-wrapping helper and applies it across several primitive ops; moves vector wrapping into memref_load_vec. |
| python/flydsl/expr/math.py | Extends traced math-op wrapping to preserve DSL closure for both Numeric and Vector inputs. |
| kernels/silu_and_mul_fq.py | Simplifies scale-offset computation by relying on the updated fx.get_scalar behavior. |
| kernels/mfma_preshuffle_pipeline.py | Updates crd2idx helper to unwrap int-tuples and cast to index type using the new scalar typing behavior. |
| kernels/layout_utils.py | Updates dynamic-layout crd2idx fallback to unwrap/cast through fx.get_scalar(...).ir_value(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| scalar = _arith.IndexCastOp(T.index, scalar).result | ||
| return scalar | ||
| """crd2idx returning an index-typed ir.Value (unwraps fly.int_tuple).""" | ||
| scalar = fx.get_scalar(fx.crd2idx(crd, layout)).ir_value() |
Comment on lines
+253
to
+256
| if not isinstance(value, ir.Value): | ||
| return value | ||
| if isinstance(value, Numeric): | ||
| return value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist