[FIX] Skip metal target tag registration for unsupported LLVM CPUs#19427
Open
tqchen wants to merge 2 commits intoapache:mainfrom
Open
[FIX] Skip metal target tag registration for unsupported LLVM CPUs#19427tqchen wants to merge 2 commits intoapache:mainfrom
tqchen wants to merge 2 commits intoapache:mainfrom
Conversation
…CPUs This PR silences the LOG(ERROR) warning about invalid CPU names that appears on `import tvm` when the system LLVM version does not recognize newer Apple CPU names (e.g. apple-m2 on LLVM 15). Main changes: - Add `target.llvm_is_valid_cpu` FFI function to check CPU validity - Expose it as `llvm_is_valid_cpu()` in `python/tvm/target/codegen.py` - Guard `_register_metal_tag` to skip registration when the CPU is not recognized by the current LLVM version
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a CPU validation utility for LLVM targets, adding llvm_is_valid_cpu to the Python API and its corresponding C++ implementation. This utility is integrated into the Metal tag registration process to verify CPU compatibility before registration. Feedback suggests wrapping the target configuration in a Target object within the C++ implementation to ensure proper validation and initialization of default attributes.
tlopex
approved these changes
Apr 21, 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.
Summary
target.llvm_is_valid_cpu(cpu, triple)FFI function to check if a CPU name is recognized by the installed LLVM versionLOG(ERROR)on every importMotivation
On LLVM 15,
import tvmemits a noisy error:This happens because
_register_metal_tagregistersapple/m2-gpuwithmcpu=apple-m2, which LLVM 15 doesn't recognize.Changes
src/target/llvm/llvm_module.cc-- Registertarget.llvm_is_valid_cpuinLLVMReflectionRegister()python/tvm/target/codegen.py-- Addllvm_is_valid_cpu()Python wrapperpython/tvm/target/tag_registry/metal.py-- Skip registration for invalid CPUsTest plan
import tvmproduces no LOG(ERROR) about invalid CPU