onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

How to generate the Executable File in x86-linux

Open CHUNERnubi opened this issue 5 years ago • 10 comments

I've finished the build add.onnx, and then step by step down the dialect, and finally down to llvm IR, get the llvm IR file. If I want to generate executable files on the x86-Linux platform, what should I do?

I try to use the tool chain in llvm ./mlir-translate. I want to talk about that llvm IR is first converted into an object file, then C program is used to call the C interface in the object file, and finally link and compile to generate an executable file.

Thank you in advance.

CHUNERnubi avatar Feb 04 '21 03:02 CHUNERnubi

You might find this tutorial helpful: http://onnx.ai/onnx-mlir//doxygen_html/index.html

tjingrant avatar Feb 04 '21 05:02 tjingrant

@tjingrant thanks a lot~

CHUNERnubi avatar Feb 04 '21 05:02 CHUNERnubi

@tjingrant Thanks for the web link, I have successfully generated the executable file, and can run the correct results. However, this method can not see the whole process of gradual decline of dialect clearly. I also read your paper about this project. I still want to reduce dialect step by step, and be able to see the result of every decline. Do you have any suggestions? Thank you very much.

CHUNERnubi avatar Feb 07 '21 06:02 CHUNERnubi

@CHUNERnubi i'm not sure what's stopping you from seeing the intermediate results of gradual lowering. Do you mean that you want to "edit" the intermediate results and then continue? (which is only possible currently using onnx-mlir-opt)

tjingrant avatar Feb 11 '21 02:02 tjingrant

I just want to know is there any way or method can generate .so file from LLVM IR Dialect file, using the toolchain which is builded by this project. Thanks a lot.

CHUNERnubi avatar Mar 04 '21 02:03 CHUNERnubi

@CHUNERnubi Starting with an onnx file, "fn", you can use "onnx-mlir --EmitLib fn.onnx" to generate a "fn.so". If you want to start from an arbitrary mlir file, you would need to use onnx-mlir-opt, specifying all the passes you want to run and ending with an LLVM IR bitcode file. You could then take the bitcode file and use llopt and llc to generate the .so. Currently the end-to-end compilation only starts from and onnx file. If you feed it an mlir file, it wouldn't in general know what passes to run on that.

If you want just to start from an onnx file and see the intermediate results after each pass, you can use these options: --print-ir-after= - Print IR after specified passes --print-ir-after-all - Print IR after each pass --print-ir-after-change - When printing the IR after a pass, only print if the IR changed --print-ir-before= - Print IR before specified passes --print-ir-before-all - Print IR before each pass --print-ir-module-scope - When printing IR for print-ir-[before|after]{-all} always print the top-level operation

caoimhinuibrian avatar Mar 04 '21 03:03 caoimhinuibrian

I want to implement the end-to-end process with the following process, but there are some problems in the end. First, use . /onnx-mlir -- EmitLLVMIR to generate LLVM IR dialect file from .onnx file. Then, use ./mlir-translate --mlir-to-llvmir to generate the .ll file. Then, use ./llvm-as to generate .ll into .bc file, which is bitcode file. Then, use ./llc to generate the .so file. Finally, the executable file add is generated by gcc and main.c. But there is a problem here: file format not recognized; treating as linker script. How can I solve it? Thank you in advance.

CHUNERnubi avatar Mar 11 '21 16:03 CHUNERnubi

I am a novice in this area, do face some difficulties, I can not solve it myself, hope to get help, thank you very much.

CHUNERnubi avatar Mar 15 '21 14:03 CHUNERnubi

It seems that this is really a question for MLIR as you are trying to merge your add to the mlir-generated path. However, you can look at what we do in onnx-mlir to find a solution to your problem. Look at our src/Runtime. This is exactly the same as you are trying to do. Onnx-mlir generates calls to our runtime functions, and then we link them towards the end. We invoke many of the calls you describe above in our src/Compiler/CompilerUtils.cpp

I suggest that you try compiling everything using LLVM.

AlexandreEichenberger avatar Jul 06 '22 20:07 AlexandreEichenberger

See also issue #1530

AlexandreEichenberger avatar Jul 06 '22 21:07 AlexandreEichenberger