[Mlir-commits] [mlir] [MLIR][JitRunner] Correctly register symbol map (PR #90381)
Mehdi Amini
llvmlistbot at llvm.org
Mon May 6 04:50:27 PDT 2024
================
@@ -295,4 +296,66 @@ TEST(NativeMemRefJit, MAYBE_JITCallback) {
ASSERT_EQ(elt, coefficient * count++);
}
+namespace {
+struct TestFile {
+ SmallString<256> filename;
+ std::error_code ec;
+ TestFile(StringRef filename, StringRef contents) : filename{filename} {
+ llvm::raw_fd_ostream outf{filename, ec, llvm::sys::fs::OF_None};
+ if (!ec) {
+ outf << contents;
+ }
+ }
+ ~TestFile() {
+ if (!ec) {
+ llvm::sys::fs::remove(filename);
+ }
+ }
+};
+static int32_t callbackval = 0;
+static void intcallback(int32_t v) { callbackval = v; }
+} // namespace
+
+TEST(MLIRExecutionEngine, SKIP_WITHOUT_JIT(JitRunnerSymbol)) {
+ std::string moduleStr = R"mlir(
+module {
+ llvm.func @callback(i32) attributes {sym_visibility = "private"}
+ llvm.func @caller_for_callback() attributes {llvm.emit_c_interface} {
+ %0 = llvm.mlir.constant(114514 : i32) : i32
+ llvm.call @callback(%0) : (i32) -> ()
+ llvm.return
+ }
+ llvm.func @_mlir_ciface_caller_for_callback() attributes {llvm.emit_c_interface} {
+ llvm.call @caller_for_callback() : () -> ()
+ llvm.return
+ }
+}
+ )mlir";
+ char path[] = "mlir_executionengine_jitrunnertest.mlir";
+ TestFile testfile{path, moduleStr};
+ ASSERT_TRUE(!testfile.ec);
+ DialectRegistry registry;
+ registerAllDialects(registry);
+ registerBuiltinDialectTranslation(registry);
+ registerLLVMDialectTranslation(registry);
+ mlir::JitRunnerConfig config;
+ config.runtimesymbolMap = [](llvm::orc::MangleAndInterner interner) {
+ llvm::orc::SymbolMap symbolMap;
+ symbolMap[interner("callback")] = {
+ llvm::orc::ExecutorAddr::fromPtr(intcallback),
+ llvm::JITSymbolFlags::Exported};
+ return symbolMap;
+ };
+
+ char S_toolname[] = "test-runner";
+ char S_e[] = "-e";
+ char S_main[] = "caller_for_callback";
+ char S_entryPoint[] = "-entry-point-result=void";
+ char *argv[] = {S_toolname, path, S_e, S_main, S_entryPoint};
+ int exitcode = mlir::JitRunnerMain(sizeof(argv) / sizeof(argv[0]), argv,
+ registry, config);
----------------
joker-eph wrote:
I don't think we should have unit tests around this function.
It is meant to be exposed for command line tools, and so should be testable through command line tool.
More importantly, I only see the `JitRunnerConfig` used by `mlir-spirv-cpu-runner` and `mlir-vulkan-cpu-runner` which are both deprecated as far as I know.
That means that `JitRunnerConfig` may instead go away entirely.
I don't see any use of `runtimesymbolMap` upstream, maybe we should just remove this right now already.
https://github.com/llvm/llvm-project/pull/90381
More information about the Mlir-commits
mailing list