Skip to content

Commit b630baf

Browse files
rorthtru
authored andcommitted
[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 ca98e0d)
1 parent 43fb0d7 commit b630baf

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

mlir/lib/ExecutionEngine/JitRunner.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "llvm/ADT/STLExtras.h"
2828
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
29+
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
2930
#include "llvm/IR/IRBuilder.h"
3031
#include "llvm/IR/LLVMContext.h"
3132
#include "llvm/IR/LegacyPassNameParser.h"
@@ -86,6 +87,10 @@ struct Options {
8687
llvm::cl::opt<std::string> objectFilename{
8788
"object-filename",
8889
llvm::cl::desc("Dump JITted-compiled object to file <input file>.o")};
90+
91+
llvm::cl::opt<bool> hostSupportsJit{"host-supports-jit",
92+
llvm::cl::desc("Report host JIT support"),
93+
llvm::cl::Hidden};
8994
};
9095

9196
struct CompileAndExecuteConfig {
@@ -316,6 +321,17 @@ int mlir::JitRunnerMain(int argc, char **argv, const DialectRegistry &registry,
316321
Options options;
317322
llvm::cl::ParseCommandLineOptions(argc, argv, "MLIR CPU execution driver\n");
318323

324+
if (options.hostSupportsJit) {
325+
auto J = llvm::orc::LLJITBuilder().create();
326+
if (J)
327+
llvm::outs() << "true\n";
328+
else {
329+
llvm::consumeError(J.takeError());
330+
llvm::outs() << "false\n";
331+
}
332+
return 0;
333+
}
334+
319335
Optional<unsigned> optLevel = getCommandLineOptLevel(options);
320336
SmallVector<std::reference_wrapper<llvm::cl::opt<bool>>, 4> optFlags{
321337
options.optO0, options.optO1, options.optO2, options.optO3};

mlir/test/CAPI/execution_engine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* RUN: mlir-capi-execution-engine-test 2>&1 | FileCheck %s
1111
*/
12-
/* REQUIRES: native
12+
/* REQUIRES: host-supports-jit
1313
*/
1414

1515
#include "mlir-c/Conversion.h"

mlir/test/lit.cfg.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,24 @@
124124
config.available_features.add('asserts')
125125
else:
126126
config.available_features.add('noasserts')
127+
128+
def have_host_jit_feature_support(feature_name):
129+
mlir_cpu_runner_exe = lit.util.which('mlir-cpu-runner', config.mlir_tools_dir)
130+
131+
if not mlir_cpu_runner_exe:
132+
return False
133+
134+
try:
135+
mlir_cpu_runner_cmd = subprocess.Popen(
136+
[mlir_cpu_runner_exe, '--host-supports-' + feature_name], stdout=subprocess.PIPE)
137+
except OSError:
138+
print('could not exec mlir-cpu-runner')
139+
return False
140+
141+
mlir_cpu_runner_out = mlir_cpu_runner_cmd.stdout.read().decode('ascii')
142+
mlir_cpu_runner_cmd.wait()
143+
144+
return 'true' in mlir_cpu_runner_out
145+
146+
if have_host_jit_feature_support('jit'):
147+
config.available_features.add('host-supports-jit')

mlir/test/mlir-cpu-runner/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if 'msan' in config.available_features:
99
config.unsupported = True
1010

1111
# Requires native execution.
12-
if 'native' not in config.available_features:
12+
if 'host-supports-jit' not in config.available_features:
1313
config.unsupported = True
1414

1515
config.available_features.add(

mlir/test/python/execution_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: %PYTHON %s 2>&1 | FileCheck %s
2-
# REQUIRES: native
2+
# REQUIRES: host-supports-jit
33
import gc, sys
44
from mlir.ir import *
55
from mlir.passmanager import *

mlir/unittests/ExecutionEngine/Invoke.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
#include "gmock/gmock.h"
3232

33+
// SPARC currently lacks JIT support.
34+
#ifdef __sparc__
35+
#define SKIP_WITHOUT_JIT(x) DISABLED_##x
36+
#else
37+
#define SKIP_WITHOUT_JIT(x) x
38+
#endif
39+
3340
using namespace mlir;
3441

3542
// The JIT isn't supported on Windows at that time
@@ -54,7 +61,7 @@ static LogicalResult lowerToLLVMDialect(ModuleOp module) {
5461
return pm.run(module);
5562
}
5663

57-
TEST(MLIRExecutionEngine, AddInteger) {
64+
TEST(MLIRExecutionEngine, SKIP_WITHOUT_JIT(AddInteger)) {
5865
std::string moduleStr = R"mlir(
5966
func.func @foo(%arg0 : i32) -> i32 attributes { llvm.emit_c_interface } {
6067
%res = arith.addi %arg0, %arg0 : i32
@@ -80,7 +87,7 @@ TEST(MLIRExecutionEngine, AddInteger) {
8087
ASSERT_EQ(result, 42 + 42);
8188
}
8289

83-
TEST(MLIRExecutionEngine, SubtractFloat) {
90+
TEST(MLIRExecutionEngine, SKIP_WITHOUT_JIT(SubtractFloat)) {
8491
std::string moduleStr = R"mlir(
8592
func.func @foo(%arg0 : f32, %arg1 : f32) -> f32 attributes { llvm.emit_c_interface } {
8693
%res = arith.subf %arg0, %arg1 : f32
@@ -106,7 +113,7 @@ TEST(MLIRExecutionEngine, SubtractFloat) {
106113
ASSERT_EQ(result, 42.f);
107114
}
108115

109-
TEST(NativeMemRefJit, ZeroRankMemref) {
116+
TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(ZeroRankMemref)) {
110117
OwningMemRef<float, 0> a({});
111118
a[{}] = 42.;
112119
ASSERT_EQ(*a->data, 42);
@@ -136,7 +143,7 @@ TEST(NativeMemRefJit, ZeroRankMemref) {
136143
EXPECT_EQ(&elt, &(a[{}]));
137144
}
138145

139-
TEST(NativeMemRefJit, RankOneMemref) {
146+
TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(RankOneMemref)) {
140147
int64_t shape[] = {9};
141148
OwningMemRef<float, 1> a(shape);
142149
int count = 1;
@@ -176,7 +183,7 @@ TEST(NativeMemRefJit, RankOneMemref) {
176183
}
177184
}
178185

179-
TEST(NativeMemRefJit, BasicMemref) {
186+
TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(BasicMemref)) {
180187
constexpr int k = 3;
181188
constexpr int m = 7;
182189
// Prepare arguments beforehand.
@@ -236,7 +243,7 @@ static void memrefMultiply(::StridedMemRefType<float, 2> *memref,
236243
#if __has_feature(memory_sanitizer)
237244
#define MAYBE_JITCallback DISABLED_JITCallback
238245
#else
239-
#define MAYBE_JITCallback JITCallback
246+
#define MAYBE_JITCallback SKIP_WITHOUT_JIT(JITCallback)
240247
#endif
241248
TEST(NativeMemRefJit, MAYBE_JITCallback) {
242249
constexpr int k = 2;

0 commit comments

Comments
 (0)