-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit method call #153524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joker-eph
merged 18 commits into
llvm:main
from
jackalcooper:split-exe-engine-init-into-explicit-method
Aug 17, 2025
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
975a39e
port changes from last PR
jackalcooper 793e83a
update GPU docs to reflect latest impl
jackalcooper e948795
add module symbol->ptr load
jackalcooper fe4d555
__has_feature(address_sanitizer)
jackalcooper 0a55a9b
remove test in C
jackalcooper 637e13f
better test naming
jackalcooper 25db89b
skip asserts for AArch64
jackalcooper 4135510
add more sanitizers to skip
jackalcooper 03a62ac
fix typo
jackalcooper b5a4244
py version test
jackalcooper acf71c4
doc @binary_unload()
jackalcooper 5dd9b20
fmt
jackalcooper 6a78eea
restore c tests
jackalcooper 1a0e331
refine C++ and Python tests
jackalcooper c8ac9dc
fix fmt
jackalcooper 05b0d0c
fix cond
jackalcooper 44df150
Update mlir/unittests/ExecutionEngine/Invoke.cpp
jackalcooper eae73d5
mv TODO to skip msg & fmt
jackalcooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,23 +339,61 @@ def callback(a): | |
|
||
run(testUnrankedMemRefWithOffsetCallback) | ||
|
||
# Test JIT callback in global constructor | ||
# CHECK-LABEL: TEST: testJITCallbackInGlobalCtor | ||
def testJITCallbackInGlobalCtor(): | ||
|
||
init_cnt = 0 | ||
|
||
@ctypes.CFUNCTYPE(None) | ||
def initCallback(): | ||
nonlocal init_cnt | ||
init_cnt += 1 | ||
|
||
with Context(): | ||
module = Module.parse(r""" | ||
llvm.mlir.global_ctors ctors = [@ctor], priorities = [0 : i32], data = [#llvm.zero] | ||
llvm.func @ctor() { | ||
func.call @init_callback() : () -> () | ||
llvm.return | ||
} | ||
func.func private @init_callback() attributes { llvm.emit_c_interface } | ||
""") | ||
|
||
# Setup execution engine | ||
execution_engine = ExecutionEngine(lowerToLLVM(module)) | ||
|
||
# Validate initialization hasn't run yet | ||
assert init_cnt == 0 | ||
|
||
# # Register callback | ||
execution_engine.register_runtime("init_callback", initCallback) | ||
|
||
# # Initialize and verify | ||
execution_engine.initialize() | ||
assert init_cnt == 1 | ||
# # Second initialization should be no-op | ||
execution_engine.initialize() | ||
assert init_cnt == 1 | ||
|
||
run(testJITCallbackInGlobalCtor) | ||
|
||
# Test addition of two memrefs. | ||
# CHECK-LABEL: TEST: testMemrefAdd | ||
def testMemrefAdd(): | ||
with Context(): | ||
module = Module.parse( | ||
""" | ||
module { | ||
func.func @main(%arg0: memref<1xf32>, %arg1: memref<f32>, %arg2: memref<1xf32>) attributes { llvm.emit_c_interface } { | ||
%0 = arith.constant 0 : index | ||
%1 = memref.load %arg0[%0] : memref<1xf32> | ||
%2 = memref.load %arg1[] : memref<f32> | ||
%3 = arith.addf %1, %2 : f32 | ||
memref.store %3, %arg2[%0] : memref<1xf32> | ||
return | ||
} | ||
} """ | ||
r""" | ||
module { | ||
func.func @main(%arg0: memref<1xf32>, %arg1: memref<f32>, %arg2: memref<1xf32>) attributes { llvm.emit_c_interface } { | ||
%0 = arith.constant 0 : index | ||
%1 = memref.load %arg0[%0] : memref<1xf32> | ||
%2 = memref.load %arg1[] : memref<f32> | ||
%3 = arith.addf %1, %2 : f32 | ||
memref.store %3, %arg2[%0] : memref<1xf32> | ||
return | ||
} | ||
} | ||
""" | ||
) | ||
arg1 = np.array([32.5]).astype(np.float32) | ||
arg2 = np.array(6).astype(np.float32) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.