From a236e3ff6e9bfdcb413b7a509553aabcfef2a25c Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Thu, 21 Mar 2024 17:59:01 +0100 Subject: [PATCH 1/8] Added null check --- src/target/parsers/cpu.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/parsers/cpu.cc b/src/target/parsers/cpu.cc index 13f41e0e1c87..41cce674106f 100644 --- a/src/target/parsers/cpu.cc +++ b/src/target/parsers/cpu.cc @@ -30,7 +30,7 @@ namespace cpu { Optional DetectSystemTriple() { auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - if (pf->defined()) { + if (pf != 0 && pf->defined()) { return (*pf)(); } return {}; From b97355e6539240782bc251a7a78860ff02e1b5cf Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Fri, 22 Mar 2024 12:16:54 +0100 Subject: [PATCH 2/8] Changed fix to use compile guards --- src/target/parsers/cpu.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/target/parsers/cpu.cc b/src/target/parsers/cpu.cc index 41cce674106f..1177d42994d1 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_INFO_USE_LLVM auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - if (pf != 0 && pf->defined()) { + if (pf->defined()) { return (*pf)(); } + #endif return {}; } From 9f1374f354839cc5d26f1b8383bff4467734e70e Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Fri, 22 Mar 2024 12:17:21 +0100 Subject: [PATCH 3/8] Added compile guards for LLVM to cpptest --- tests/cpp/target_test.cc | 2 ++ tests/cpp/tir_scalable_datatype.cc | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/cpp/target_test.cc b/tests/cpp/target_test.cc index b32af0e9c7de..5c77ecd7455f 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_INFO_USE_LLVM // Checks that malformed options cause an assertion. TEST(TargetCreation, LLVMCommandLineParseFatalDashDashDash) { tvm::codegen::LLVMInstance inst; @@ -447,6 +448,7 @@ TEST(TargetCreation, LLVMCommandLineSaveRestore) { // Check that we restored global state. ASSERT_FALSE(info.MatchesGlobalState()); } +#endif TVM_REGISTER_TARGET_KIND("test_external_codegen_0", kDLCUDA) .set_attr(tvm::attr::kIsExternalCodegen, Bool(true)); diff --git a/tests/cpp/tir_scalable_datatype.cc b/tests/cpp/tir_scalable_datatype.cc index 4b4764555f7b..a31421571b8b 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_INFO_USE_LLVM + #include +#endif + #include "../../src/script/printer/utils.h" using ::testing::HasSubstr; From 62e1d2446fec1d162129e05c899e957fedb715cb Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Mon, 8 Apr 2024 20:55:32 +0200 Subject: [PATCH 4/8] Moved test and made it better --- tests/cpp/target_test.cc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/cpp/target_test.cc b/tests/cpp/target_test.cc index 5c77ecd7455f..19d8668eb853 100644 --- a/tests/cpp/target_test.cc +++ b/tests/cpp/target_test.cc @@ -448,6 +448,20 @@ TEST(TargetCreation, LLVMCommandLineSaveRestore) { // Check that we restored global state. ASSERT_FALSE(info.MatchesGlobalState()); } + +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"); + ASSERT_TRUE(pf->defined()); +} + #endif TVM_REGISTER_TARGET_KIND("test_external_codegen_0", kDLCUDA) @@ -500,21 +514,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); From 1e231e2957590bc746e043be63f9dca080cd6ecb Mon Sep 17 00:00:00 2001 From: Otto Rasmussen <34154515+OttoWRas@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:52:42 +0200 Subject: [PATCH 5/8] Update tests/cpp/target_test.cc Co-authored-by: Luke Hutton --- tests/cpp/target_test.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/cpp/target_test.cc b/tests/cpp/target_test.cc index 19d8668eb853..71fd87ffac4c 100644 --- a/tests/cpp/target_test.cc +++ b/tests/cpp/target_test.cc @@ -457,9 +457,13 @@ TEST(TargetCreation, DetectSystemTriple) { 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"); - ASSERT_TRUE(pf->defined()); + if (pf == nullptr) { + GTEST_SKIP() << "LLVM is not available, skipping test"; + } + + Optional mtriple = target->GetAttr("mtriple"); + ASSERT_TRUE(mtriple.value() == String((*pf)())); } #endif From c4587b7ddadcc2b46f0fe1b8d7c3768dda697bb1 Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Tue, 9 Apr 2024 22:17:53 +0200 Subject: [PATCH 6/8] Changed function to use ICHECK --- src/target/parsers/cpu.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/target/parsers/cpu.cc b/src/target/parsers/cpu.cc index 1177d42994d1..0f93ec9ecb94 100644 --- a/src/target/parsers/cpu.cc +++ b/src/target/parsers/cpu.cc @@ -29,13 +29,11 @@ namespace parsers { namespace cpu { Optional DetectSystemTriple() { - #ifdef TVM_INFO_USE_LLVM auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - if (pf->defined()) { - return (*pf)(); - } - #endif - return {}; + ICHECK (pf != nullptr) + << "The target llvm_get_system_triple was not found, " + "please compile with USE_LLVM = ON"; + return (*pf)(); } TargetJSON ParseTarget(TargetJSON target) { From e5b03ca22d34202c78941db52c88cee921b05c81 Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Tue, 9 Apr 2024 22:18:23 +0200 Subject: [PATCH 7/8] Changed compile guards to use LLVM_VERSION --- tests/cpp/target_test.cc | 2 +- tests/cpp/tir_scalable_datatype.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cpp/target_test.cc b/tests/cpp/target_test.cc index 71fd87ffac4c..2db4b572bf60 100644 --- a/tests/cpp/target_test.cc +++ b/tests/cpp/target_test.cc @@ -290,7 +290,7 @@ TEST(TargetCreation, ProcessStrings) { ASSERT_EQ(array7[1][1][0], "fred"); } -#ifdef TVM_INFO_USE_LLVM +#ifdef TVM_LLVM_VERSION // Checks that malformed options cause an assertion. TEST(TargetCreation, LLVMCommandLineParseFatalDashDashDash) { tvm::codegen::LLVMInstance inst; diff --git a/tests/cpp/tir_scalable_datatype.cc b/tests/cpp/tir_scalable_datatype.cc index a31421571b8b..c09d4208439b 100644 --- a/tests/cpp/tir_scalable_datatype.cc +++ b/tests/cpp/tir_scalable_datatype.cc @@ -23,7 +23,7 @@ #include #include -#ifdef TVM_INFO_USE_LLVM +#ifdef TVM_LLVM_VERSION #include #endif From a2871f63d95bde11a68305f34b5bd4f534745147 Mon Sep 17 00:00:00 2001 From: "Otto W. Rasmussen" Date: Wed, 10 Apr 2024 14:13:50 +0200 Subject: [PATCH 8/8] Added ICHECK, changed compile guard to LLVM_VERSION, Lint --- src/target/parsers/cpu.cc | 8 +++++--- tests/cpp/tir_scalable_datatype.cc | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/target/parsers/cpu.cc b/src/target/parsers/cpu.cc index 0f93ec9ecb94..5fd5fdecccd1 100644 --- a/src/target/parsers/cpu.cc +++ b/src/target/parsers/cpu.cc @@ -29,11 +29,13 @@ namespace parsers { namespace cpu { Optional DetectSystemTriple() { +#ifdef TVM_LLVM_VERSION auto pf = tvm::runtime::Registry::Get("target.llvm_get_system_triple"); - ICHECK (pf != nullptr) - << "The target llvm_get_system_triple was not found, " - "please compile with USE_LLVM = ON"; + ICHECK(pf != nullptr) << "The target llvm_get_system_triple was not found, " + "please compile with USE_LLVM = ON"; return (*pf)(); +#endif + return {}; } TargetJSON ParseTarget(TargetJSON target) { diff --git a/tests/cpp/tir_scalable_datatype.cc b/tests/cpp/tir_scalable_datatype.cc index c09d4208439b..da30706e1355 100644 --- a/tests/cpp/tir_scalable_datatype.cc +++ b/tests/cpp/tir_scalable_datatype.cc @@ -24,7 +24,7 @@ #include #ifdef TVM_LLVM_VERSION - #include +#include #endif #include "../../src/script/printer/utils.h"