Skip to content

[metal] Add @metal_jit decorator for AST-to-MSL compilation#1991

Merged
aditvenk merged 1 commit intomainfrom
aditvenk/stack/25
Apr 13, 2026
Merged

[metal] Add @metal_jit decorator for AST-to-MSL compilation#1991
aditvenk merged 1 commit intomainfrom
aditvenk/stack/25

Conversation

@aditvenk
Copy link
Copy Markdown
Contributor

@aditvenk aditvenk commented Apr 9, 2026

Stacked PRs:


[metal] Add @metal_jit decorator for AST-to-MSL compilation

Add metal_jit decorator that JIT-compiles a Python function to an MSL
Metal shader. On each call the decorator:

  1. Parses the decorated function's source to recover the Python AST
  2. Infers tensor dtypes and scalar args from the actual call arguments
  3. Reads block sizes from module-level globals (_BLOCK_SIZE_N)
  4. Translates the AST body to MSL C++ via _generate_msl
  5. Compiles the MSL via torch.mps.compile_shader

No decorator arguments needed — all metadata is inferred at runtime.

@aditvenk aditvenk force-pushed the aditvenk/stack/25 branch from 276e63c to 951fddc Compare April 9, 2026 04:50
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 9, 2026
@aditvenk aditvenk marked this pull request as draft April 9, 2026 20:43
@aditvenk aditvenk changed the base branch from aditvenk/stack/13 to main April 9, 2026 20:43
@aditvenk aditvenk force-pushed the aditvenk/stack/25 branch from 951fddc to 67b7d10 Compare April 9, 2026 20:43
@aditvenk aditvenk changed the base branch from main to aditvenk/stack/13 April 9, 2026 20:43
@aditvenk aditvenk marked this pull request as ready for review April 9, 2026 20:43
@aditvenk aditvenk marked this pull request as draft April 9, 2026 20:57
@aditvenk aditvenk changed the base branch from aditvenk/stack/13 to main April 9, 2026 20:57
@aditvenk aditvenk force-pushed the aditvenk/stack/25 branch from 67b7d10 to 26519e4 Compare April 9, 2026 20:57
@aditvenk aditvenk changed the base branch from main to aditvenk/stack/13 April 9, 2026 20:57
@aditvenk aditvenk marked this pull request as ready for review April 9, 2026 20:58
@aditvenk aditvenk marked this pull request as draft April 9, 2026 21:49
@aditvenk aditvenk changed the base branch from aditvenk/stack/13 to main April 9, 2026 21:49
@aditvenk aditvenk force-pushed the aditvenk/stack/25 branch from 26519e4 to 0584fad Compare April 9, 2026 21:50
@aditvenk aditvenk changed the base branch from main to aditvenk/stack/13 April 9, 2026 21:50
@aditvenk aditvenk marked this pull request as ready for review April 9, 2026 21:50
Add metal_jit decorator that JIT-compiles a Python function to an MSL
Metal shader. On each call the decorator:
1. Parses the decorated function's source to recover the Python AST
2. Infers tensor dtypes and scalar args from the actual call arguments
3. Reads block sizes from module-level globals (_BLOCK_SIZE_N)
4. Translates the AST body to MSL C++ via _generate_msl
5. Compiles the MSL via torch.mps.compile_shader

No decorator arguments needed — all metadata is inferred at runtime.

stack-info: PR: #1991, branch: aditvenk/stack/25
@aditvenk aditvenk marked this pull request as draft April 13, 2026 02:14
@aditvenk aditvenk changed the base branch from aditvenk/stack/13 to main April 13, 2026 02:14
@aditvenk aditvenk force-pushed the aditvenk/stack/25 branch from 0584fad to 713507e Compare April 13, 2026 02:14
@aditvenk aditvenk marked this pull request as ready for review April 13, 2026 02:15
@aditvenk aditvenk merged commit b4423cd into main Apr 13, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants