Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime][LLVM] Fix errors during loading of target tags #16808

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/tvm/target/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def register_tag(name: str, config: Dict[str, Any], override: bool = False) -> O
return None


# To check the correctness of all registered tags, the call is made in library loading time.
list_tags()

# We purposely maintain all tags in the C++ side to support pure C++ use cases,
# and the Python API is only used for fast prototyping.
register_tag(
Expand All @@ -79,3 +76,6 @@ def register_tag(name: str, config: Dict[str, Any], override: bool = False) -> O
"arch": "sm_61",
},
)

# To check the correctness of all registered tags, the call is made in library loading time.
list_tags()
4 changes: 4 additions & 0 deletions src/target/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,11 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const BroadcastNode* op) {
value = builder_->CreateInsertElement(undef, value, zero);
#if TVM_LLVM_VERSION >= 110
llvm::ElementCount ec =
#if TVM_LLVM_VERSION >= 120
llvm::ElementCount::get(dtype.get_lanes_or_vscale_factor(), dtype.is_scalable_vector());
#else
llvm::ElementCount(dtype.get_lanes_or_vscale_factor(), dtype.is_scalable_vector());
#endif
lhutton1 marked this conversation as resolved.
Show resolved Hide resolved
llvm::Constant* mask = llvm::ConstantVector::getSplat(ec, zero);
#else
ICHECK(!dtype.is_scalable_vector())
Expand Down
4 changes: 3 additions & 1 deletion src/target/llvm/llvm_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance, const TargetJSON& target)
if (!has_arch) {
// Flag an error, but don't abort. This mimicks the behaviour of 'llc' to
// give the code a chance to run with a less-specific target.
LOG(ERROR) << "LLVM cpu architecture `-mcpu=" << cpu_
LOG(ERROR) << "Using LLVM " << LLVM_VERSION_STRING << " with `-mcpu=" << cpu_
<< "` is not valid in `-mtriple=" << triple_ << "`"
<< ", using default `-mcpu=" << String(defaults::cpu) << "`";
// LLVM default cpu fallback
cpu_ = String(defaults::cpu);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/target/tag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TVM_REGISTER_TARGET_TAG("raspberry-pi/4b-aarch64")
{"mattr", Array<String>{"+neon"}},
{"num-cores", Integer(4)}}}});

#if TVM_LLVM_VERSION >= 110
TVM_REGISTER_TARGET_TAG("nvidia/jetson-agx-xavier")
.set_config({{"kind", String("cuda")},
{"arch", String("sm_72")},
Expand Down Expand Up @@ -129,6 +130,7 @@ TVM_REGISTER_TARGET_TAG("nvidia/jetson-agx-orin-64gb")
{"mtriple", String("aarch64-linux-gnu")},
{"mcpu", String("cortex-a78")},
{"num-cores", Integer(12)}}}});
#endif

#define TVM_REGISTER_CUDA_TAG(Name, Arch, SharedMem, RegPerBlock) \
TVM_REGISTER_TARGET_TAG(Name).set_config({ \
Expand Down
6 changes: 4 additions & 2 deletions tests/python/target/test_llvm_features_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ def test_llvm_targets(capfd):
tvm.target.Target("llvm -mtriple=x86_64-linux-gnu -mcpu=dummy")
)
expected_str = (
"Error: LLVM cpu architecture `-mcpu=dummy` is not valid in "
" with `-mcpu=dummy` is not valid in "
"`-mtriple=x86_64-linux-gnu`, using default `-mcpu=generic`"
)
assert expected_str in capfd.readouterr().err
readout_error = capfd.readouterr().err
assert "Error: Using LLVM " in readout_error
assert expected_str in readout_error


min_llvm_version, llvm_target, cpu_arch, cpu_features, is_supported = tvm.testing.parameters(
Expand Down
Loading