feat: extract Metal (.metal) kernels into the graph#1450
Closed
GoodOlClint wants to merge 1 commit into
Closed
Conversation
Metal Shading Language is C++14, so .metal routes through the existing cpp extractor — the same reuse pattern CUDA's .cu/.cuh already follow. No dedicated Metal grammar; ERROR nodes around Metal qualifiers are expected and harmless. Lets MLX/Metal kernels join the code graph instead of being skipped as non-code. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
safishamsi
pushed a commit
that referenced
this pull request
Jun 27, 2026
Metal Shading Language is C++14, so .metal files are classified as code and routed through the existing C++ extractor, mirroring the CUDA .cu/.cuh reuse. Also adds .cu/.cuh/.metal to build.py's _LANG_FAMILY map (they were all missing), so the cross-language phantom-`calls`-edge filter treats them as C++. README language table updated. Ported from PR #1480 by @jiangyq9. This supersedes the earlier #1450 by @GoodOlClint (same .metal -> C++ approach and fixture) — credit to @GoodOlClint for the original; #1480 additionally closes the CUDA family-map gap and updates the docs, and merges clean against current v8. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
Thanks @GoodOlClint, and apologies for the overlap. Metal support has landed on |
safishamsi
pushed a commit
that referenced
this pull request
Jun 27, 2026
Metal Shading Language is C++14, so .metal files are classified as code and routed through the existing C++ extractor, mirroring the CUDA .cu/.cuh reuse. Also adds .cu/.cuh/.metal to build.py's _LANG_FAMILY map (they were all missing), so the cross-language phantom-`calls`-edge filter treats them as C++. README language table updated. Ported from PR #1480 by @jiangyq9. This supersedes the earlier #1450 by @GoodOlClint (same .metal -> C++ approach and fixture) — credit to @GoodOlClint for the original; #1480 additionally closes the CUDA family-map gap and updates the docs, and merges clean against current v8. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Adds Metal Shading Language (
.metal) support to graphify by routing it throughthe existing C++ extractor — the exact reuse pattern CUDA's
.cu/.cuhalready follow. MSL is C++14, so
extract_cpp(tree-sitter-cpp) handles it withno new grammar. ERROR nodes around Metal-specific qualifiers (
kernel,[[buffer(0)]]) are expected and harmless, just as they are for CUDA's__global__/__device__.Why
Before this change graphify classified
.metalas non-code and skipped itentirely, so MLX/Metal compute kernels never appeared in the graph. This lets
them join it like any other source.
Approach
Mirror CUDA. No dedicated Metal grammar — deferred. ~3-line change across the
same three touchpoints CUDA uses.
Edits (3 touchpoints)
graphify/detect.py—'.metal'added toCODE_EXTENSIONS(next to.cu/.cuh).graphify/extract.py—".metal": extract_cppin the extension→extractor dict.graphify/build.py—".metal": "cpp"in_LANG_FAMILY, so Metal↔C++ countas one family for cross-language seam / import resolution.
Plus a contract test +
tests/fixtures/sample.metal(a real MSL snippet: astruct+ adot3function + asaxpykernel).Evidence (before → after)
Contract test (
tests/test_languages.py, mirrors the cpp/CUDA tests):extract_cpp(FIXTURES / "sample.metal")—errorabsent,Vec3struct anddot3function both appear in nodes. Symbols graphify produced nothing for before.E2e —
GRAPHIFY_OUT=<tmp> graphify update <dir-with-.metal>on a dircontaining one
kernel.metal:No code files found - nothing to rebuildRebuilt: 11 nodes, 10 edges, 4 communitiesAfter-state metal nodes:
kernel.metal,Vec3,x,y,z,dot3(),saxpy().Test gate —
uv run pytest(full suite): 2351 passed, 28 skipped(includes 3 new
test_metal_*).ruff checkon changed files: clean.Notes
extract_cppis the point.v8; pushed to forkGoodOlClint. PR not opened.