diff --git a/src/target/parsers/cpu.cc b/src/target/parsers/cpu.cc index 13f41e0e1c87..5fd5fdecccd1 100644 --- a/src/target/parsers/cpu.cc +++ b/src/target/parsers/cpu.cc @@ -29,10 +29,12 @@ namespace parsers { namespace cpu { Optional DetectSystemTriple() { +#ifdef TVM_LLVM_VERSION auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - if (pf->defined()) { - return (*pf)(); - } + ICHECK(pf != nullptr) << "The target llvm_get_system_triple was not found, " + "please compile with USE_LLVM = ON"; + return (*pf)(); +#endif return {}; } diff --git a/tests/cpp/target_test.cc b/tests/cpp/target_test.cc index b32af0e9c7de..2db4b572bf60 100644 --- a/tests/cpp/target_test.cc +++ b/tests/cpp/target_test.cc @@ -290,6 +290,7 @@ TEST(TargetCreation, ProcessStrings) { ASSERT_EQ(array7[1][1][0], "fred"); } +#ifdef TVM_LLVM_VERSION // Checks that malformed options cause an assertion. TEST(TargetCreation, LLVMCommandLineParseFatalDashDashDash) { tvm::codegen::LLVMInstance inst; @@ -448,6 +449,25 @@ TEST(TargetCreation, LLVMCommandLineSaveRestore) { ASSERT_FALSE(info.MatchesGlobalState()); } +TEST(TargetCreation, DetectSystemTriple) { + Map config = { + {"kind", String("llvm")}, + }; + + Target target = Target(config); + ICHECK_EQ(target->kind, TargetKind::Get("llvm").value()); + + auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); + if (pf == nullptr) { + GTEST_SKIP() << "LLVM is not available, skipping test"; + } + + Optional mtriple = target->GetAttr("mtriple"); + ASSERT_TRUE(mtriple.value() == String((*pf)())); +} + +#endif + TVM_REGISTER_TARGET_KIND("test_external_codegen_0", kDLCUDA) .set_attr(tvm::attr::kIsExternalCodegen, Bool(true)); @@ -498,21 +518,6 @@ TEST(TargetCreation, DeduplicateKeys) { ICHECK_EQ(target->GetAttr("device"), "arm_cpu"); } -TEST(TargetCreation, DetectSystemTriple) { - Map config = { - {"kind", String("llvm")}, - }; - - Target target = Target(config); - ICHECK_EQ(target->kind, TargetKind::Get("llvm").value()); - - Optional mtriple = target->GetAttr("mtriple"); - auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - if (!pf->defined()) { - GTEST_SKIP() << "LLVM is not available, skipping test"; - } -} - TEST(TargetKindRegistry, ListTargetKinds) { Array names = TargetKindRegEntry::ListTargetKinds(); ICHECK_EQ(names.empty(), false); diff --git a/tests/cpp/tir_scalable_datatype.cc b/tests/cpp/tir_scalable_datatype.cc index 4b4764555f7b..da30706e1355 100644 --- a/tests/cpp/tir_scalable_datatype.cc +++ b/tests/cpp/tir_scalable_datatype.cc @@ -19,11 +19,14 @@ #include #include -#include #include #include #include +#ifdef TVM_LLVM_VERSION +#include +#endif + #include "../../src/script/printer/utils.h" using ::testing::HasSubstr;