Conversation
Query each Metal device once for the facts that decide what codegen may
emit: the highest Metal Shading Language version it compiles, bfloat16,
SIMD-group permute/reduction/matrix support, and the Metal 4 family.
Expose them through "device_api.metal.get_target_property", mirroring the
Vulkan device API, and register the matching attributes on the "metal"
target kind so Target.from_device("metal") reports them. Serve the
threadgroup memory limit through GetAttr instead of hard-coding 32 KB in
target detection.
Carry the MSL version on the Metal module so runtime compilation uses the
version codegen generated for, instead of choosing one from the device at
compile time. The module byte format gains one field after "fmt".
anerli
marked this pull request as ready for review
September 12, 2026 21:48
This was referenced Sep 15, 2026
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.
Problem
Metal targets are assembled from constants.
Target.from_device("metal")hard-codes 32 KB of threadgroup memory becauseGetAttr(kMaxSharedMemoryPerBlock)is a stub, and nothing reports whether a device supports bfloat16, SIMD-group permute/reduction/matrix operations, or the Metal 4 family. Codegen consumers such as TileLang have had to guess fromxcrun/sysctloutput. Separately,MetalModuleNodechooses the MSL language version from the device at compile time, so a module can be compiled with a different language version than the one codegen generated for.Change
MetalDeviceProperties, queried once per device whenMetalWorkspaceinitializes, and expose it throughdevice_api.metal.get_target_property, mirroringdevice_api.vulkan.get_target_property.metaltarget kind:metal_language_version(major * 10 + minor, default 23),supports_bfloat16,supports_simdgroup_permute,supports_simdgroup_reduction,supports_simdgroup_matrix,supports_metal4. Existing attribute defaults are unchanged.kMaxSharedMemoryPerBlockfrommaxThreadgroupMemoryLength, and makeTarget.from_device("metal")read it and the new properties.metal_language_versionon the Metal module. The runtime compilesfmt="metal"sources with exactly that version and rejects a module that needs a newer MSL than the device provides.ffi.Module.create.metalgains a trailingint, and the serialized module format gains one field afterfmt; the codegen-side fallback module mirrors both.Tests
tests/python/codegen/test_target_codegen_metal.pytest_target_from_device_reports_device_properties: detection matchesDeviceattributes and exposes every new property.test_module_compiles_with_target_language_version: the version survives export and load, and a module generated for a newer MSL than the device compiles is rejected.clang -fsyntax-onlywith the project's build flags. The Python tests still need a run against a rebuilt library before this leaves draft.Follow-up in TileLang
Once this merges and TileLang bumps
3rdparty/tvm, a TileLang PR titled "[Metal] Resolve Metal targets from device properties" (branchpr/metal-target-resolution) will:xcrun/sysctldetection intilelang/metal/target.pywithTarget.from_deviceand fill device facts into user-suppliedmetaltargets,subgroup_exchange) on these attributes,supports_simdgroup_matrixandsupports_bfloat16in the Metal GEMM lowering instead of assuming them,supports_metal4from the attribute instead of themetal4target key,metal_language_versionfromsrc/metal/codegen/codegen_metal.ccinto the module.