[metal] MslAstWalker + MetalBackend MSL codegen + device function hook + tests#1764
Closed
aditvenk wants to merge 1 commit intoaditvenk/stack/10from
Closed
[metal] MslAstWalker + MetalBackend MSL codegen + device function hook + tests#1764aditvenk wants to merge 1 commit intoaditvenk/stack/10from
aditvenk wants to merge 1 commit intoaditvenk/stack/10from
Conversation
f238861 to
e4ffd2c
Compare
152bb59 to
c9b78ba
Compare
This was referenced Mar 20, 2026
c9b78ba to
fdcf824
Compare
fdcf824 to
f3d9b96
Compare
6f5cc8a to
4843e8c
Compare
aditvenk
added a commit
that referenced
this pull request
Mar 21, 2026
…k + tests
- Add helion/_compiler/metal/ package:
- msl_ast_walker.py: MslAstWalker class with _generate_elementwise()
and AST-to-MSL C++ converter functions. Handles tl.cast, tl.where,
tl.full, tl.reshape, tl.sigmoid, tl.sqrt_rn, libdevice.*,
triton_helpers.maximum/minimum, select, ast.If for masked stores.
- Modify codegen_function_def to post-process for Metal: standard path
runs first (variable renames, constexpr inlining, scalar preambles),
then MetalBackend.generate_msl_function extracts the FunctionDef body,
creates an MslAstWalker, and replaces with a zero-arg function
returning (msl_source, kernel_name).
- Add MetalBackend methods: transform_host_arg (wraps scalar args as
float32 1-element buffer tensors), build_launcher_args, inline_constexpr,
generate_msl_function, and expression generators (program_id_expr,
cdiv_expr, sympy_printer_expr, grid_index_expr, inductor_op_overrides)
- In a subsequent change, we will avoid passing scalar args as 1-element
buffer tensors, and instead bake them directly into the MSL source.
- 26 tests: arithmetic (add/sub/mul/div/neg), scalar args (saxpy),
activations (relu/silu/gelu), math ops (exp/log/sqrt/abs/sin/cos/clamp),
dtypes (float16/bfloat16/int32), bounds masking (OOB sentinel checks,
codegen mask assertions)
stack-info: PR: #1764, branch: aditvenk/stack/11
f3d9b96 to
e578915
Compare
e578915 to
0bc0be3
Compare
a8863d9 to
7c001bc
Compare
7c001bc to
3cd1378
Compare
3cd1378 to
c5cdfa3
Compare
c5cdfa3 to
ec62c4d
Compare
…k + tests
- Add helion/_compiler/metal/ package:
- msl_ast_walker.py: MslAstWalker class with _generate_elementwise()
and AST-to-MSL C++ converter functions. Handles tl.cast, tl.where,
tl.full, tl.reshape, tl.sigmoid, tl.sqrt_rn, libdevice.*,
triton_helpers.maximum/minimum, select, ast.If for masked stores.
- Modify codegen_function_def to post-process for Metal: standard path
runs first (variable renames, constexpr inlining, scalar preambles),
then MetalBackend.generate_msl_function extracts the FunctionDef body,
creates an MslAstWalker, and replaces with a zero-arg function
returning (msl_source, kernel_name).
- Add MetalBackend methods: transform_host_arg (wraps scalar args as
float32 1-element buffer tensors), build_launcher_args, inline_constexpr,
generate_msl_function, and expression generators (program_id_expr,
cdiv_expr, sympy_printer_expr, grid_index_expr, inductor_op_overrides)
- In a subsequent change, we will avoid passing scalar args as 1-element
buffer tensors, and instead bake them directly into the MSL source.
- 26 tests: arithmetic (add/sub/mul/div/neg), scalar args (saxpy),
activations (relu/silu/gelu), math ops (exp/log/sqrt/abs/sin/cos/clamp),
dtypes (float16/bfloat16/int32), bounds masking (OOB sentinel checks,
codegen mask assertions)
stack-info: PR: #1764, branch: aditvenk/stack/11
ec62c4d to
9f36d70
Compare
Contributor
Author
|
Will shortly open a new PR that refactors the commits in the stack differently |
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.
Stacked PRs:
[metal] MslAstWalker + MetalBackend MSL codegen + device function hook + tests
and AST-to-MSL C++ converter functions. Handles tl.cast, tl.where,
tl.full, tl.reshape, tl.sigmoid, tl.sqrt_rn, libdevice.*,
triton_helpers.maximum/minimum, select, ast.If for masked stores.
runs first (variable renames, constexpr inlining, scalar preambles),
then MetalBackend.generate_msl_function extracts the FunctionDef body,
creates an MslAstWalker, and replaces with a zero-arg function
returning (msl_source, kernel_name).
float32 1-element buffer tensors), build_launcher_args, inline_constexpr,
generate_msl_function, and expression generators (program_id_expr,
cdiv_expr, sympy_printer_expr, grid_index_expr, inductor_op_overrides)
buffer tensors, and instead bake them directly into the MSL source.
activations (relu/silu/gelu), math ops (exp/log/sqrt/abs/sin/cos/clamp),
dtypes (float16/bfloat16/int32), bounds masking (OOB sentinel checks,
codegen mask assertions)