[llvm-branch-commits] [mlir] b630baf - [mlir][test] Require JIT support in JIT tests

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 22 02:36:51 PDT 2022


Author: Rainer Orth
Date: 2022-08-22T11:35:40+02:00
New Revision: b630bafb3cfd30ac7b39a61aeb5dfba568e2937e

URL: https://github.com/llvm/llvm-project/commit/b630bafb3cfd30ac7b39a61aeb5dfba568e2937e
DIFF: https://github.com/llvm/llvm-project/commit/b630bafb3cfd30ac7b39a61aeb5dfba568e2937e.diff

LOG: [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

(cherry picked from commit ca98e0dd6cf59907f07201c4282dcafeeea11a91)

Added: 
    

Modified: 
    mlir/lib/ExecutionEngine/JitRunner.cpp
    mlir/test/CAPI/execution_engine.c
    mlir/test/lit.cfg.py
    mlir/test/mlir-cpu-runner/lit.local.cfg
    mlir/test/python/execution_engine.py
    mlir/unittests/ExecutionEngine/Invoke.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp
index 53fdde6789f3d..499d012a4e74c 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<std::string> objectFilename{
       "object-filename",
       llvm::cl::desc("Dump JITted-compiled object to file <input file>.o")};
+
+  llvm::cl::opt<bool> hostSupportsJit{"host-supports-jit",
+                                      llvm::cl::desc("Report host JIT support"),
+                                      llvm::cl::Hidden};
 };
 
 struct CompileAndExecuteConfig {
@@ -316,6 +321,17 @@ int mlir::JitRunnerMain(int argc, char **argv, const DialectRegistry &registry,
   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<unsigned> optLevel = getCommandLineOptLevel(options);
   SmallVector<std::reference_wrapper<llvm::cl::opt<bool>>, 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 662f9f25863a0..60171db018fac 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 1d009afe99729..7c3d086009376 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 5df5b0a38bc6c..cd31376e1136a 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 ea08a854fdaea..64d7ee079e567 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 febfbd139b6ea..60b5be6198ee6 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<float, 0> 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<float, 1> 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<float, 2> *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;


        


More information about the llvm-branch-commits mailing list