From ca98e0dd6cf59907f07201c4282dcafeeea11a91 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Thu, 18 Aug 2022 11:26:07 +0200 Subject: [PATCH] [mlir][test] Require JIT support in JIT tests A number of mlir tests `FAIL` on Solaris/sparcv9 with `Target has no JIT support`. This patch fixes that by mimicing `clang/test/lit.cfg.py` which implements a `host-supports-jit` keyword for this. The gtest-based unit tests don't support `REQUIRES:`, so lack of support needs to be hardcoded there. Tested on `amd64-pc-solaris2.11` (`check-mlir` results unchanged) and `sparcv9-sun-solaris2.11` (only one unrelated failure left). Differential Revision: https://reviews.llvm.org/D131151 --- mlir/lib/ExecutionEngine/JitRunner.cpp | 16 ++++++++++++++++ mlir/test/CAPI/execution_engine.c | 2 +- mlir/test/lit.cfg.py | 21 +++++++++++++++++++++ mlir/test/mlir-cpu-runner/lit.local.cfg | 2 +- mlir/test/python/execution_engine.py | 2 +- mlir/unittests/ExecutionEngine/Invoke.cpp | 19 +++++++++++++------ 6 files changed, 53 insertions(+), 9 deletions(-) diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp index 94c86a5a870e17..362e60aafe4d0d 100644 --- a/mlir/lib/ExecutionEngine/JitRunner.cpp +++ b/mlir/lib/ExecutionEngine/JitRunner.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" +#include "llvm/ExecutionEngine/Orc/LLJIT.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" @@ -86,6 +87,10 @@ struct Options { llvm::cl::opt objectFilename{ "object-filename", llvm::cl::desc("Dump JITted-compiled object to file .o")}; + + llvm::cl::opt hostSupportsJit{"host-supports-jit", + llvm::cl::desc("Report host JIT support"), + llvm::cl::Hidden}; }; struct CompileAndExecuteConfig { @@ -317,6 +322,17 @@ int mlir::JitRunnerMain(int argc, char **argv, const DialectRegistry ®istry, Options options; llvm::cl::ParseCommandLineOptions(argc, argv, "MLIR CPU execution driver\n"); + if (options.hostSupportsJit) { + auto J = llvm::orc::LLJITBuilder().create(); + if (J) + llvm::outs() << "true\n"; + else { + llvm::consumeError(J.takeError()); + llvm::outs() << "false\n"; + } + return 0; + } + Optional optLevel = getCommandLineOptLevel(options); SmallVector>, 4> optFlags{ options.optO0, options.optO1, options.optO2, options.optO3}; diff --git a/mlir/test/CAPI/execution_engine.c b/mlir/test/CAPI/execution_engine.c index 662f9f25863a0c..60171db018facb 100644 --- a/mlir/test/CAPI/execution_engine.c +++ b/mlir/test/CAPI/execution_engine.c @@ -9,7 +9,7 @@ /* RUN: mlir-capi-execution-engine-test 2>&1 | FileCheck %s */ -/* REQUIRES: native +/* REQUIRES: host-supports-jit */ #include "mlir-c/Conversion.h" diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py index 1d009afe997296..7c3d0860093764 100644 --- a/mlir/test/lit.cfg.py +++ b/mlir/test/lit.cfg.py @@ -124,3 +124,24 @@ config.available_features.add('asserts') else: config.available_features.add('noasserts') + +def have_host_jit_feature_support(feature_name): + mlir_cpu_runner_exe = lit.util.which('mlir-cpu-runner', config.mlir_tools_dir) + + if not mlir_cpu_runner_exe: + return False + + try: + mlir_cpu_runner_cmd = subprocess.Popen( + [mlir_cpu_runner_exe, '--host-supports-' + feature_name], stdout=subprocess.PIPE) + except OSError: + print('could not exec mlir-cpu-runner') + return False + + mlir_cpu_runner_out = mlir_cpu_runner_cmd.stdout.read().decode('ascii') + mlir_cpu_runner_cmd.wait() + + return 'true' in mlir_cpu_runner_out + +if have_host_jit_feature_support('jit'): + config.available_features.add('host-supports-jit') diff --git a/mlir/test/mlir-cpu-runner/lit.local.cfg b/mlir/test/mlir-cpu-runner/lit.local.cfg index 5df5b0a38bc6cd..cd31376e1136ad 100644 --- a/mlir/test/mlir-cpu-runner/lit.local.cfg +++ b/mlir/test/mlir-cpu-runner/lit.local.cfg @@ -9,7 +9,7 @@ if 'msan' in config.available_features: config.unsupported = True # Requires native execution. -if 'native' not in config.available_features: +if 'host-supports-jit' not in config.available_features: config.unsupported = True config.available_features.add( diff --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py index ea08a854fdaea8..64d7ee079e5673 100644 --- a/mlir/test/python/execution_engine.py +++ b/mlir/test/python/execution_engine.py @@ -1,5 +1,5 @@ # RUN: %PYTHON %s 2>&1 | FileCheck %s -# REQUIRES: native +# REQUIRES: host-supports-jit import gc, sys from mlir.ir import * from mlir.passmanager import * diff --git a/mlir/unittests/ExecutionEngine/Invoke.cpp b/mlir/unittests/ExecutionEngine/Invoke.cpp index febfbd139b6ea0..60b5be6198ee61 100644 --- a/mlir/unittests/ExecutionEngine/Invoke.cpp +++ b/mlir/unittests/ExecutionEngine/Invoke.cpp @@ -30,6 +30,13 @@ #include "gmock/gmock.h" +// SPARC currently lacks JIT support. +#ifdef __sparc__ +#define SKIP_WITHOUT_JIT(x) DISABLED_##x +#else +#define SKIP_WITHOUT_JIT(x) x +#endif + using namespace mlir; // The JIT isn't supported on Windows at that time @@ -54,7 +61,7 @@ static LogicalResult lowerToLLVMDialect(ModuleOp module) { return pm.run(module); } -TEST(MLIRExecutionEngine, AddInteger) { +TEST(MLIRExecutionEngine, SKIP_WITHOUT_JIT(AddInteger)) { std::string moduleStr = R"mlir( func.func @foo(%arg0 : i32) -> i32 attributes { llvm.emit_c_interface } { %res = arith.addi %arg0, %arg0 : i32 @@ -80,7 +87,7 @@ TEST(MLIRExecutionEngine, AddInteger) { ASSERT_EQ(result, 42 + 42); } -TEST(MLIRExecutionEngine, SubtractFloat) { +TEST(MLIRExecutionEngine, SKIP_WITHOUT_JIT(SubtractFloat)) { std::string moduleStr = R"mlir( func.func @foo(%arg0 : f32, %arg1 : f32) -> f32 attributes { llvm.emit_c_interface } { %res = arith.subf %arg0, %arg1 : f32 @@ -106,7 +113,7 @@ TEST(MLIRExecutionEngine, SubtractFloat) { ASSERT_EQ(result, 42.f); } -TEST(NativeMemRefJit, ZeroRankMemref) { +TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(ZeroRankMemref)) { OwningMemRef a({}); a[{}] = 42.; ASSERT_EQ(*a->data, 42); @@ -136,7 +143,7 @@ TEST(NativeMemRefJit, ZeroRankMemref) { EXPECT_EQ(&elt, &(a[{}])); } -TEST(NativeMemRefJit, RankOneMemref) { +TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(RankOneMemref)) { int64_t shape[] = {9}; OwningMemRef a(shape); int count = 1; @@ -176,7 +183,7 @@ TEST(NativeMemRefJit, RankOneMemref) { } } -TEST(NativeMemRefJit, BasicMemref) { +TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(BasicMemref)) { constexpr int k = 3; constexpr int m = 7; // Prepare arguments beforehand. @@ -236,7 +243,7 @@ static void memrefMultiply(::StridedMemRefType *memref, #if __has_feature(memory_sanitizer) #define MAYBE_JITCallback DISABLED_JITCallback #else -#define MAYBE_JITCallback JITCallback +#define MAYBE_JITCallback SKIP_WITHOUT_JIT(JITCallback) #endif TEST(NativeMemRefJit, MAYBE_JITCallback) { constexpr int k = 2;