Skip to content

[FIX] Skip metal target tag registration for unsupported LLVM CPUs#19427

Open
tqchen wants to merge 2 commits intoapache:mainfrom
tqchen:fix-llvm-invalid-cpu-warning
Open

[FIX] Skip metal target tag registration for unsupported LLVM CPUs#19427
tqchen wants to merge 2 commits intoapache:mainfrom
tqchen:fix-llvm-invalid-cpu-warning

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented Apr 21, 2026

Summary

  • Add target.llvm_is_valid_cpu(cpu, triple) FFI function to check if a CPU name is recognized by the installed LLVM version
  • Guard metal target tag registration with CPU validity check
  • Silently skip tags with unrecognized CPUs instead of emitting LOG(ERROR) on every import

Motivation

On LLVM 15, import tvm emits a noisy error:

Error: Using LLVM 15.0.7 with -mcpu=apple-m2 is not valid in -mtriple=arm64-apple-macos

This happens because _register_metal_tag registers apple/m2-gpu with mcpu=apple-m2, which LLVM 15 doesn't recognize.

Changes

  • src/target/llvm/llvm_module.cc -- Register target.llvm_is_valid_cpu in LLVMReflectionRegister()
  • python/tvm/target/codegen.py -- Add llvm_is_valid_cpu() Python wrapper
  • python/tvm/target/tag_registry/metal.py -- Skip registration for invalid CPUs

Test plan

  • import tvm produces no LOG(ERROR) about invalid CPU
  • On LLVM 15: apple-m1 valid, apple-m2 invalid (silently skipped)
  • Metal tags registered: apple/m1-gpu, apple/m1-gpu-restricted
  • pre-commit passes

…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
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/target/llvm/llvm_module.cc Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants