Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mlir/lib/ExecutionEngine/CRunnerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ extern "C" double rtclock() {
#endif // _WIN32
}

extern "C" void *mlirAlloc(uint64_t size) { return malloc(size); }
// NOLINTBEGIN(*-identifier-naming)

extern "C" void *mlirAlignedAlloc(uint64_t alignment, uint64_t size) {
extern "C" void *_mlir_alloc(uint64_t size) { return malloc(size); }
extern "C" void *_mlir_malloc(uint64_t size) { return malloc(size); }
extern "C" void *_mlir_aligned_alloc(uint64_t alignment, uint64_t size) {
#ifdef _WIN32
return _aligned_malloc(size, alignment);
#elif defined(__APPLE__)
Expand All @@ -163,9 +165,9 @@ extern "C" void *mlirAlignedAlloc(uint64_t alignment, uint64_t size) {
#endif
}

extern "C" void mlirFree(void *ptr) { free(ptr); }
extern "C" void _mlir_free(void *ptr) { free(ptr); }

extern "C" void mlirAlignedFree(void *ptr) {
extern "C" void _mlir_aligned_free(void *ptr) {
#ifdef _WIN32
_aligned_free(ptr);
#else
Expand Down Expand Up @@ -213,4 +215,6 @@ IMPL_STDSORT(F64, double)
IMPL_STDSORT(F32, float)
#undef IMPL_STDSORT

// NOLINTEND(*-identifier-naming)

#endif // MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS
30 changes: 26 additions & 4 deletions mlir/test/python/execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def testNanoTime():
run(testNanoTime)


# Test that nano time clock is available.
# Test dump to object file.
# CHECK-LABEL: TEST: testDumpToObjectFile
def testDumpToObjectFile():
fd, object_path = tempfile.mkstemp(suffix=".o")
Expand All @@ -787,13 +787,35 @@ def testDumpToObjectFile():
module = Module.parse(
"""
module {
func.func @main() attributes { llvm.emit_c_interface } {
return
func.func @main(%arg0: memref<1xf32>) -> memref<1xf32> attributes {llvm.emit_c_interface} {
%out_memref = memref.alloc() : memref<1xf32>
%c0 = arith.constant 0 : index
%load_value = memref.load %arg0[%c0] : memref<1xf32>
memref.store %load_value, %out_memref[%c0] : memref<1xf32>
func.return %out_memref : memref<1xf32>
}
}"""
)

execution_engine = ExecutionEngine(lowerToLLVM(module), opt_level=3)
if sys.platform == "win32":
shared_libs = [
"../../../../bin/mlir_runner_utils.dll",
"../../../../bin/mlir_c_runner_utils.dll",
]
elif sys.platform == "darwin":
shared_libs = [
"../../../../lib/libmlir_runner_utils.dylib",
"../../../../lib/libmlir_c_runner_utils.dylib",
]
else:
shared_libs = [
MLIR_RUNNER_UTILS,
MLIR_C_RUNNER_UTILS,
]

execution_engine = ExecutionEngine(
lowerToLLVM(module), opt_level=3, shared_libs=shared_libs
)

# CHECK: Object file exists: True
print(f"Object file exists: {os.path.exists(object_path)}")
Expand Down
Loading