catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Generating C executable that accesses the shared object file without Python

Open tzunghanjuang opened this issue 1 year ago • 1 comments

Context:

  • Add debug.compiler_functions.compile_cmain to compiler a c main wrapper into an executable.
  • (Mainly for testing) Add debug.compiler_functions.run_cmain_executable to 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]

tzunghanjuang avatar Aug 07 '24 18:08 tzunghanjuang

Codecov Report

Attention: Patch coverage is 97.05882% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.88%. Comparing base (565222e) to head (d440c66). Report is 208 commits behind head on main.

Files with missing lines Patch % Lines
frontend/catalyst/debug/compiler_functions.py 95.23% 0 Missing and 2 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1003      +/-   ##
==========================================
- Coverage   97.88%   97.88%   -0.01%     
==========================================
  Files          75       75              
  Lines       10704    10758      +54     
  Branches     1236     1244       +8     
==========================================
+ Hits        10478    10530      +52     
  Misses        177      177              
- Partials       49       51       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

codecov[bot] avatar Aug 07 '24 18:08 codecov[bot]