onnx / onnx-mlir

Representation and Reference Lowering of ONNX Models in MLIR Compiler Infrastructure
Apache License 2.0
713 stars 306 forks source link

Cross compiling for aarch64 #2556

Open VariantXYZ opened 8 months ago

VariantXYZ commented 8 months ago

Hi, I've been experimenting with this project a little and have been able to use it to generate functional programs on my host PC (x86_64-unknown-linux-gnu), but am hitting some snags trying to port to other devices running aarch64. Apologies in advance if I missed something obvious.

Based on the installation instructions for Linux, I tacked on the Aarch64 build target and verified that I could emit the IR and objects, but linking fails since the libraries for onnx-mlir built are for the host platform.

Is there a standard way to build just the libraries for the target platform when it isn't the host?

AlexandreEichenberger commented 8 months ago

We have not looked much into the cross compiling; I use a M1 Mac and it works well targeting aarch64. Others use it on x86 directly. I would look into what LLVM recommends for cross compiling, and maybe you can find some help there. Let us know if there is something specific that needs to be changed, we can probably help if it's a small change. You are welcome to push PR as well, happy to take contributions from the community at large.

VariantXYZ commented 8 months ago

Thanks for the reply @AlexandreEichenberger .

The issue is more related to the onnx-mlir builds themselves rather than LLVM or clang. I can build those toolchains with the ability to target aarch64 and a specific CPU, and in fact I can even generate the MLIR for a particular onnx model. The issue is creating the onnx-mlir specific libraries for a non-host platform.

I've had to put this little venture down for a bit, but when I pick it back up I'll investigate a bit more. It seems like some build script hackery will get me far enough, but this issue was mostly to see if there were any more standard methods of doing so.

AlexandreEichenberger commented 8 months ago

@gongsu832 is our build expert, he may have a useful suggestion once you are ready to try again.

robben225 commented 8 months ago

@gongsu832 is our build expert, he may have a useful suggestion once you are ready to try again.

Hi, @gongsu832 , I am also facing the same problem now. I hope to run the ONNX-MLIR compiled model on the Android platform, which may involve cross compilation issues. Can you give me some suggestions on how to do this.

gongsu832 commented 8 months ago

Sorry I have no idea how you would build onnx-mlir runtime libraries for a non-host platform. It's more of a cross compilation issue than a build issue.

VariantXYZ commented 8 months ago

Worth mentioning the problem is that the tool needs to be built for the host, and the llvm part needs to be built with support for the target ABI/arch and finally the onnx-mlir static libraries need to be built for the target.

My thinking was to modify things such that you pass a cmake platform file (cross compile) and try to only build the static libraries and copy them in.