iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.85k stars 620 forks source link

How to gradually reduce the. onnx file to LLVM dialect and finally generate LLVM IR? #18999

Open pyl3000 opened 3 weeks ago

pyl3000 commented 3 weeks ago

I couldn't find the corresponding conversion method in iree-opt andiree-translate tools.

ScottTodd commented 2 weeks ago

For some background, see these guides:

The sequence I think you are asking about is:

  1. iree-import-onnx ... converts from a .onnx file to .mlir
  2. iree-compile --iree-hal-target-backends=llvm-cpu ... compiles from .mlir to a .vmfb file (to users, this is a black box process)
  3. Running iree-compile with --mlir-print-ir-after-all, or --dump-compilation-phases-to, --iree-hal-dump-executable-files-to, or any of the other debugging flags lets you peek into that black box and see what the compiler is doing step by step
    • The "executable sources" phase of compilation and "executable intermediates" files involve the LLVM dialect and LLVM IR when using the llvm-cpu backend
    • Note that IREE is a whole program compiler that models both the host and device code. The LLVM IR that it generates is the device side code that is meant to be run using the host code that IREE also generates.
pyl3000 commented 2 weeks ago

Thank you, if we have an LLVM IR (.mlir file), how can we convert it into Risc-V executable binary code?

ScottTodd commented 2 weeks ago

Our RISC-V docs are:

When you compile with flags like these:

iree-compile \
  --iree-hal-target-backends=llvm-cpu \
  --iree-llvmcpu-target-triple=riscv64 \
  --iree-llvmcpu-target-abi=lp64d \
  --iree-llvmcpu-target-cpu-features="+m,+a,+f,+d,+zvl512b,+v" \
  --riscv-v-fixed-length-vector-lmul-max=8 \
  iree_input.mlir -o mobilenet_cpu.vmfb

the llvm-cpu backend uses LLVM to compile the LLVM IR to executable binary code for the riscv64 target