Skip to content
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

Can we have the python harness to emit directly the LLVM ll file? #92

Closed
giuseros opened this issue Dec 8, 2021 · 3 comments
Closed

Comments

@giuseros
Copy link
Collaborator

giuseros commented Dec 8, 2021

This stemmed from the discussion in #83 (comment)

It would be great to have the llvm file from the harness to pass it down to llc. It would be also nice if the harness could compile the executable without going through mlir-c-runner.

@ftynse
Copy link
Contributor

ftynse commented Dec 8, 2021

Getting LLVM IR out is a bit annoying because it is not even visible at the Python level. However, you can dump LLVM Dialect using https://github.com/google/iree-llvm-sandbox/blob/main/python/examples/core/harness.py#L123 and call mlir-translate before calling llc.

I am not sure what mlir-c-runner refers to here, there is libmlir_c_runner_utils.so and mlir-cpu-runner.

@nicolasvasilache
Copy link
Contributor

nicolasvasilache commented Dec 8, 2021

There is also the tools/llvm-mca.py script that I use successfully to cross-compile and pipe through llvm-mca.
It generates all the interim files and can start from either the mlir in llvm-dialect form or from the jitt'ed .o

The part that is trickier is producing the .o without running as it needs to happen in ExecutionEngine.
Then there is the problem that the LLVM passes in the JIT will differ from what you do on the CLI:
I do not get the same binary using the llvm-mca.py if I start form .mlir or from .o and I do not have a good way to reconcile those atm.

Usage of llvm-mca.py:

(cd ${IREE_LLVM_SANDBOX_SOURCE_DIR}; python -m python.tools.llvm_mca -mlir-translate=${LLVM_BUILD_DIR}/bin/mlir-translate -llvm-objdump=${LLVM_BUILD_DIR}/bin/llvm-objdump \
  -llvm-llc=${LLVM_BUILD_DIR}/bin/llc -llvm-opt=${LLVM_BUILD_DIR}/bin/opt -llvm-mca=${LLVM_BUILD_DIR}/bin/llvm-mca -mlir-file=/tmp/abc.mlir -f=transpose_2d_on_tensors; \
    less /tmp/abc.mlir_llvm_mca.out)

You need to pass the proper -mlir-file=/tmp/abc.mlir -f=transpose_2d_on_tensors for your use case.
This will create all the /tmc/abc.mlirxxx files needed (.ll, .o etc).

This should compose well with the other functionality that dump LLVM dialect to file.

@giuseros
Copy link
Collaborator Author

This has also been done. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants