[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
This commit is contained in:
Rainer Orth 2022-08-18 11:26:07 +02:00
parent d7ac92f27b
commit ca98e0dd6c
6 changed files with 53 additions and 9 deletions

View File

@ -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 {
@ -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};

View File

@ -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"

View File

@ -124,3 +124,24 @@ if config.enable_assertions:
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')

View File

@ -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(

View File

@ -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 *

View File

@ -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;