Skip to content

Commit

Permalink
[mlir][test] Require JIT support in JIT tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rorth committed Aug 18, 2022
1 parent d7ac92f commit ca98e0d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
16 changes: 16 additions & 0 deletions mlir/lib/ExecutionEngine/JitRunner.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -317,6 +322,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};
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/CAPI/execution_engine.c
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions mlir/test/lit.cfg.py
Expand Up @@ -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')
2 changes: 1 addition & 1 deletion mlir/test/mlir-cpu-runner/lit.local.cfg
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion 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 *
Expand Down
19 changes: 13 additions & 6 deletions mlir/unittests/ExecutionEngine/Invoke.cpp
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ca98e0d

Please sign in to comment.