[water] Add BitcastOp and Scaled Dimensions - #1135
Conversation
808c72c to
26215d2
Compare
94d4061 to
993842a
Compare
Water Code Coverage |
There was a problem hiding this comment.
Pull request overview
This PR extends the Wave/Water stack to support a new wave.bitcast op and to represent “derived” symbolic dimensions (e.g. K/2) as symbolic hyperparameters via #wave.expr_list, enabling downstream resolution and validation.
Changes:
- Adds
BitcastOpend-to-end: Wave op definition, verifier/type+EPT propagation, lowering tovector.bitcast, and Python emitter support. - Extends
#wave.hyperparametersto allowWaveExprListAttrvalues (derived symbols), including recursive evaluation ingetSymbolValueand additional dialect verification. - Updates Python/CAPI bindings and adds MLIR/Python tests for bitcast + derived hyperparameters (including float4/float8 element types).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| wave_lang/kernel/wave/mlir_converter/water_emitter.py | Emits wave.bitcast, adds float4/6/8 dtype mapping, and generates derived-dimension symbol names + expr_list hyperparameters. |
| water/python/WaterExtensionNanobind.cpp | Allows WaveHyperparameterAttr.get() to accept non-int attribute values from Python. |
| water/lib/CAPI/Dialects.cpp | Permits WaveExprListAttr values in hyperparameter CAPI construction. |
| water/lib/Dialect/Wave/IR/WaveAttrs.cpp | Implements recursive resolution of derived hyperparameters via WaveExprListAttr. |
| water/lib/Dialect/Wave/IR/WaveDialect.cpp | Verifies expr_list hyperparameters (single-result maps; referenced symbols must exist). |
| water/include/water/Dialect/Wave/IR/WaveAttrs.td | Documents hyperparameters supporting integer or expr_list values. |
| water/include/water/Dialect/Wave/IR/WaveOps.td | Defines BitcastOp in the Wave dialect. |
| water/lib/Dialect/Wave/IR/WaveOps.cpp | Adds BitcastOp verifier + type/EPT propagation. |
| water/lib/Dialect/Wave/Transforms/LoweringPatterns.cpp | Lowers wave.bitcast to vector.bitcast. |
| water/test/Dialect/Wave/python_bindings.py | Adds Python binding tests for expr_list hyperparameters and parsing/printing wave.bitcast. |
| water/test/Dialect/Wave/ops.mlir | Adds textual IR tests for wave.bitcast. |
| water/test/Dialect/Wave/infer-types.mlir | Adds type inference tests and negative cases for bitcast dimension scaling. |
| water/test/Dialect/Wave/propagate-elements-per-thread.mlir | Adds EPT propagation test for bitcast scaling behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
3f873d5 to
ab7667a
Compare
3b760b1 to
a6504eb
Compare
ftynse
left a comment
There was a problem hiding this comment.
Generally make sense, but we need to iron out the bitcast semantics and tighten verification.
For bitcast, I'm not sure it is the last dimension that is being bitcasted. It may be whatever is the dimension we are (implicitly) vectorizing along, i.e., the dimension where the index expression step is other than 1 (or the last one when all are 1). This will be then consistent with EPT propagation (I don't see any other way) and clearly indicate that index expression propagation is not identity here (it can't be since it must be consistent with EPT propagation). With all that, I'm not sure how exactly to model that during type inference. It appears that type inference is not really possible, unless somehow run in conjunction with index expression inference, since we don't really know which dimension is being bitcast.
|
I didn't yet look at python bindings or tests pending design issues, but I notice some missing coverage for bitcast op error messages. |
ftynse
left a comment
There was a problem hiding this comment.
Reviewed python now. Nothing but nits, though the question of scaled dimension remains unresolved in the op definition.
0a22c8f to
53d5c77
Compare
12e6abc to
a251559
Compare
937152c to
809eb84
Compare
|
Can this land? |
|
yes |
312b6a6 to
8fe578f
Compare
8fe578f to
c405f9f
Compare
Introduces wave.bitcast, a new Water dialect op that reinterprets the raw bits of a register-resident tensor as a different element type. Unlike a plain type cast, bitcast preserves the total bit count by scaling exactly one tensor dimension by the source-to-destination element bitwidth ratio.
New dialect pieces
Hyperparameter extensions
Emitter
Lowering
fixes #922