catalyst
catalyst copied to clipboard
Generating C executable that accesses the shared object file without Python
Context:
- Add
debug.compiler_functions.compile_cmainto compiler a c main wrapper into an executable. - (Mainly for testing) Add
debug.compiler_functions.run_cmain_executableto run the generate executable with the shared object from MLIR/LLVM. - Support multi-dimensional arrays in c generation.
Changes
compile_cmain(fn: QJIT, *args) -> str, str takes a qjit decorated function and arguments for that function. It returns a string of LD_LIBRARY_PATH and the path to the output binary file.
run_cmain_executable(ld_env: str, binary_file: str) -> str takes a string of LD_LIBRARY_PATH and the path to the output binary file. The return is a string containing stdout. Users can use debug.print_memref to make values appear there.
@qjit
def f(x):
y = x*x
debug.print_memref(y)
return y
f(5)
>>> MemRef: base@ = 0x64fc9dd5ffc0 rank = 0 offset = 0 sizes = [] strides = [] data =
25
25
ld_env, binary = compile_cmain(f, 1)
result = run_cmain_executable(ld_env, binary)
result.stdout
>>> MemRef: base@ = 0x5df35987b780 rank = 0 offset = 0 sizes = [] strides = [] data =
25
Related GitHub Issues: [sc-67088] [sc-70777]