Skip to content

Commit 128bf5d

Browse files
committed
address reviews
1 parent 28d752c commit 128bf5d

File tree

8 files changed

+16
-24
lines changed

8 files changed

+16
-24
lines changed

mlir/include/mlir-c/ExecutionEngine.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ DEFINE_C_API_STRUCT(MlirExecutionEngine, void);
4242
/// that will be loaded are specified via `numPaths` and `sharedLibPaths`
4343
/// respectively.
4444
/// TODO: figure out other options.
45-
MLIR_CAPI_EXPORTED MlirExecutionEngine
46-
mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths,
47-
const MlirStringRef *sharedLibPaths,
48-
bool enableObjectDump, bool shouldInitialize);
45+
MLIR_CAPI_EXPORTED MlirExecutionEngine mlirExecutionEngineCreate(
46+
MlirModule op, int optLevel, int numPaths,
47+
const MlirStringRef *sharedLibPaths, bool enableObjectDump);
4948

5049
/// Execute the global constructors from the module.
5150
MLIR_CAPI_EXPORTED void mlirExecutionEngineInitialize(MlirExecutionEngine jit);

mlir/include/mlir/ExecutionEngine/ExecutionEngine.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ struct ExecutionEngineOptions {
9999
/// If `enablePerfNotificationListener` is set, the JIT compiler will notify
100100
/// the llvm's global Perf notification listener.
101101
bool enablePerfNotificationListener = true;
102-
103-
/// Setting initialize=false to defer initialization
104-
bool shouldInitialize = true;
105102
};
106103

107104
/// JIT-backed execution engine for MLIR. Assumes the IR can be converted to

mlir/lib/Bindings/Python/ExecutionEngineModule.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ NB_MODULE(_mlirExecutionEngine, m) {
7575
"__init__",
7676
[](PyExecutionEngine &self, MlirModule module, int optLevel,
7777
const std::vector<std::string> &sharedLibPaths,
78-
bool enableObjectDump, bool shouldInitialize) {
78+
bool enableObjectDump) {
7979
llvm::SmallVector<MlirStringRef, 4> libPaths;
8080
for (const std::string &path : sharedLibPaths)
8181
libPaths.push_back({path.c_str(), path.length()});
82-
MlirExecutionEngine executionEngine = mlirExecutionEngineCreate(
83-
module, optLevel, libPaths.size(), libPaths.data(),
84-
enableObjectDump, shouldInitialize);
82+
MlirExecutionEngine executionEngine =
83+
mlirExecutionEngineCreate(module, optLevel, libPaths.size(),
84+
libPaths.data(), enableObjectDump);
8585
if (mlirExecutionEngineIsNull(executionEngine))
8686
throw std::runtime_error(
8787
"Failure while creating the ExecutionEngine.");
@@ -90,7 +90,6 @@ NB_MODULE(_mlirExecutionEngine, m) {
9090
nb::arg("module"), nb::arg("opt_level") = 2,
9191
nb::arg("shared_libs") = nb::list(),
9292
nb::arg("enable_object_dump") = true,
93-
nb::arg("should_initialize") = true,
9493
"Create a new ExecutionEngine instance for the given Module. The "
9594
"module must contain only dialects that can be translated to LLVM. "
9695
"Perform transformations and code generation at the optimization "

mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace mlir;
2222
extern "C" MlirExecutionEngine
2323
mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths,
2424
const MlirStringRef *sharedLibPaths,
25-
bool enableObjectDump, bool shouldInitialize) {
25+
bool enableObjectDump) {
2626
static bool initOnce = [] {
2727
llvm::InitializeNativeTarget();
2828
llvm::InitializeNativeTargetAsmParser(); // needed for inline_asm
@@ -60,7 +60,6 @@ mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths,
6060
jitOptions.jitCodeGenOptLevel = static_cast<llvm::CodeGenOptLevel>(optLevel);
6161
jitOptions.sharedLibPaths = libPaths;
6262
jitOptions.enableObjectDump = enableObjectDump;
63-
jitOptions.shouldInitialize = shouldInitialize;
6463
auto jitOrError = ExecutionEngine::create(unwrap(op), jitOptions);
6564
if (!jitOrError) {
6665
consumeError(jitOrError.takeError());
@@ -111,9 +110,8 @@ extern "C" void mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit,
111110
void *sym) {
112111
unwrap(jit)->registerSymbols([&](llvm::orc::MangleAndInterner interner) {
113112
llvm::orc::SymbolMap symbolMap;
114-
symbolMap[interner(unwrap(name))] =
115-
{ llvm::orc::ExecutorAddr::fromPtr(sym),
116-
llvm::JITSymbolFlags::Exported };
113+
symbolMap[interner(unwrap(name))] = {llvm::orc::ExecutorAddr::fromPtr(sym),
114+
llvm::JITSymbolFlags::Exported};
117115
return symbolMap;
118116
});
119117
}

mlir/lib/ExecutionEngine/ExecutionEngine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@ ExecutionEngine::create(Operation *m, const ExecutionEngineOptions &options,
400400
return symbolMap;
401401
};
402402
engine->registerSymbols(runtimeSymbolMap);
403-
if (options.shouldInitialize)
404-
engine->initialize();
405403
return std::move(engine);
406404
}
407405

@@ -437,6 +435,7 @@ Expected<void *> ExecutionEngine::lookup(StringRef name) const {
437435

438436
Error ExecutionEngine::invokePacked(StringRef name,
439437
MutableArrayRef<void *> args) {
438+
initialize();
440439
auto expectedFPtr = lookupPacked(name);
441440
if (!expectedFPtr)
442441
return expectedFPtr.takeError();

mlir/lib/ExecutionEngine/JitRunner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ compileAndExecute(Options &options, Operation *module, StringRef entryPoint,
202202

203203
auto engine = std::move(*expectedEngine);
204204

205+
engine->initialize();
206+
205207
auto expectedFPtr = engine->lookupPacked(entryPoint);
206208
if (!expectedFPtr)
207209
return expectedFPtr.takeError();

mlir/test/CAPI/execution_engine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void testSimpleExecution(void) {
6969
mlirRegisterAllLLVMTranslations(ctx);
7070
MlirExecutionEngine jit = mlirExecutionEngineCreate(
7171
module, /*optLevel=*/2, /*numPaths=*/0, /*sharedLibPaths=*/NULL,
72-
/*enableObjectDump=*/false, /*shouldInitialize=*/true);
72+
/*enableObjectDump=*/false);
7373
if (mlirExecutionEngineIsNull(jit)) {
7474
fprintf(stderr, "Execution engine creation failed");
7575
exit(2);
@@ -125,7 +125,7 @@ void testOmpCreation(void) {
125125
// against the OpenMP library.
126126
MlirExecutionEngine jit = mlirExecutionEngineCreate(
127127
module, /*optLevel=*/2, /*numPaths=*/0, /*sharedLibPaths=*/NULL,
128-
/*enableObjectDump=*/false, /*shouldInitialize=*/true);
128+
/*enableObjectDump=*/false);
129129
if (mlirExecutionEngineIsNull(jit)) {
130130
fprintf(stderr, "Engine creation failed with OpenMP");
131131
exit(2);
@@ -169,7 +169,7 @@ void testGlobalCtorJitCallback(void) {
169169
// Create execution engine with initialization disabled
170170
MlirExecutionEngine jit = mlirExecutionEngineCreate(
171171
module, /*optLevel=*/2, /*numPaths=*/0, /*sharedLibPaths=*/NULL,
172-
/*enableObjectDump=*/false, /*shouldInitialize=*/false);
172+
/*enableObjectDump=*/false);
173173

174174
if (mlirExecutionEngineIsNull(jit)) {
175175
fprintf(stderr, "Execution engine creation failed");

mlir/unittests/ExecutionEngine/Invoke.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ TEST(GlobalCtorJit, MAYBE_JITCallback) {
339339
ASSERT_TRUE(!!module);
340340
ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module)));
341341
ExecutionEngineOptions jitOptions;
342-
// Defer the initialization to register symbols used in ctors.
343-
jitOptions.shouldInitialize = false;
344342
auto jitOrError = ExecutionEngine::create(*module, jitOptions);
345343
ASSERT_TRUE(!!jitOrError);
346344
auto jit = std::move(jitOrError.get());

0 commit comments

Comments
 (0)