You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rework cross-compilation to be standard cmake as much as possible #4323
ew 🤮That shouldn't be that way and needs cleanupinfrastructureRelating to build systems, CI, or testingplatform/android 🤖Android-specific build, execution, benchmarking, and deployment
Do we actually need for cmake to run the full cross compilation as part of a single cmake command? It seems like we could replace this with a script that invokes cmake twice? We should be able to set host and target flags independently.
+100 - we should definitely remove the configuration-change-during-build and just invoke the build multiple times. Packaging with vcpkg will require that we can fan out builds (build host once, then build cross-compilation targets N times) and it's how anyone using cmake assumes it works already (I couldn't find projects that didn't just invoke cmake for each target). I've been bit several times by the cross compilation process/configuration when modifying build logic unrelated to cross compilation and avoiding that spidering spooky-action-at-a-distance would really help improve maintainability and make it easier for others to work with - especially when integrating into their own existing cmake workflows (where the current approach is just not possible to integrate).
+1. I'll all for cleaner and better structures. The current implementation mirrors LLVM so it inherts baggages there. Changing the file-based dependency between the host and target builds into CMake import/export or CLI-binary-based would be nice. Having proper CMake import/export may need changing stuff in LLVM to facilitate.
I'm starting to work on this now. My general plan is:
Cut out all if(CMAKE_CROSSCOMPILING) / iree_host_* code
Build/install for the host configuration in one build directory
Build for the target configuration in another build directory, pointing -DIREE_HOST_BINARY_ROOT at the host's install directory (or vcpkg, or folder from binary releases, etc.)
Figure out how to bring tests back one by one (might just be a matter of using iree_get_executable_path as we have it now, or might involve some target triple config, etc.)
Once that is working, wrap the cmake configure/build commands in a [Python] script for developers and CI to use
I think that's a really good way to go about it - especially because it'll be shared work with installables (vcpkg/etc like you mention) which means less build goo and more coverage (we implicitly are testing the installable out-of-tree build path whenever we cross compile, etc).
I'd say mark flatcc_cli as installable - it's as useful as generate_cc_embed_data and something users may want to use (along with some other flatcc tools we may want to add, like flatbuffer<->json and such).
I'm also not entirely sure, but it may be worth it to rename generate_cc_embed_data.exe to iree-cc-embed-data and flatcc_cli to iree-flatcc or something - just to be consistent and make things easier on users if they add the bin/ dir to their PATH or install to /usr/local/bin/ etc - not conflicting with tools they may already have and making it easy to see where things came from is useful (vs polluting bin dirs).
Nice files - hadn't seen those particular ones! My hope is that we too don't have a host/device split, only "things often only built for the host" and "things often built specifically for particular devices". Building our compiler tools for jetson/raspberry pi/android is valid, for example, as would be building a large chunk of the code for the compiler for emscripten (even if we have a different wrapper for using it vs. an executable). We can still deem certain uses as unsupported - like the compiler on android is not something we will really test or recommend people use.
cmake install targets can help here similar to filegroups in bazel: we can group together targets that are built together and then have any number of sets ("install compiler developer tools, including iree-translate and iree-check-module" vs "install compiled test modules to benchmark" vs "install runtime testing tools like the CTS and iree-benchmark-module", etc. Things like vcpkg help users here in that each of those becomes a feature; vcpkg install iree[import-tflite,import-onnx,binding-tflite,hal-benchmarks] would just be a cmake install of each of those groups. Hand waving for now of course, but to get to that point having toolchains and targets orthogonal is a requirement :)
at least when using -DIREE_TARGET_BACKENDS_TO_BUILD=vmla;vulkan-spirv -DIREE_HAL_DRIVERS_TO_BUILD=vmla;vulkan
The part that I don't think we can avoid a host/device split is for our (developer) tests, which need the host compiler and target runtime. For users, install targets for each should be enough.
Ack - this is why I'm hoping we can spin up a few CI builds with these options configured - so easy for them to bitrot (I found the same when trying to disable the metal/vulkan drivers, etc). We really shouldn't be unconditionally using conditionally enabled features anywhere.
ew 🤮That shouldn't be that way and needs cleanupinfrastructureRelating to build systems, CI, or testingplatform/android 🤖Android-specific build, execution, benchmarking, and deployment
Activity
benvanik commentedon Dec 28, 2020
+100 - we should definitely remove the configuration-change-during-build and just invoke the build multiple times. Packaging with vcpkg will require that we can fan out builds (build host once, then build cross-compilation targets N times) and it's how anyone using cmake assumes it works already (I couldn't find projects that didn't just invoke cmake for each target). I've been bit several times by the cross compilation process/configuration when modifying build logic unrelated to cross compilation and avoiding that spidering spooky-action-at-a-distance would really help improve maintainability and make it easier for others to work with - especially when integrating into their own existing cmake workflows (where the current approach is just not possible to integrate).
antiagainst commentedon Jan 5, 2021
+1. I'll all for cleaner and better structures. The current implementation mirrors LLVM so it inherts baggages there. Changing the file-based dependency between the host and target builds into CMake import/export or CLI-binary-based would be nice. Having proper CMake import/export may need changing stuff in LLVM to facilitate.
GMNGeoffrey commentedon Jan 20, 2021
See also https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1#use-toolchain-files-for-cross-compiling and https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
ScottTodd commentedon Jan 20, 2021
I'm starting to work on this now. My general plan is:
if(CMAKE_CROSSCOMPILING)/iree_host_*code-DIREE_HOST_BINARY_ROOTat the host's install directory (or vcpkg, or folder from binary releases, etc.)iree_get_executable_pathas we have it now, or might involve some target triple config, etc.)The first bump I hit is this: https://github.com/google/iree/blob/ead787a186dc02ec11a1709bffae7336641fcc7d/build_tools/cmake/flatbuffer_c_library.cmake#L112-L113
coming from here:
https://github.com/google/iree/blob/ead787a186dc02ec11a1709bffae7336641fcc7d/CMakeLists.txt#L451-L473
I'd like to use
flatcc_cli.exefrom the host build/install, but I don't see it listed there yet:benvanik commentedon Jan 20, 2021
I think that's a really good way to go about it - especially because it'll be shared work with installables (vcpkg/etc like you mention) which means less build goo and more coverage (we implicitly are testing the installable out-of-tree build path whenever we cross compile, etc).
I'd say mark flatcc_cli as installable - it's as useful as generate_cc_embed_data and something users may want to use (along with some other flatcc tools we may want to add, like flatbuffer<->json and such).
benvanik commentedon Jan 20, 2021
I'm also not entirely sure, but it may be worth it to rename generate_cc_embed_data.exe to iree-cc-embed-data and flatcc_cli to iree-flatcc or something - just to be consistent and make things easier on users if they add the bin/ dir to their PATH or install to /usr/local/bin/ etc - not conflicting with tools they may already have and making it easy to see where things came from is useful (vs polluting bin dirs).
GMNGeoffrey commentedon Jan 20, 2021
I think it's worth checking out the toolchain files for cross compilation as that seems to be the "modern cmake" way
ScottTodd commentedon Jan 21, 2021
ncnn has some toolchain files that look good to reference: https://github.com/Tencent/ncnn/tree/master/toolchains
I don't see any sort of host/target split in the way that we have it in their build instructions though :p
benvanik commentedon Jan 21, 2021
Nice files - hadn't seen those particular ones! My hope is that we too don't have a host/device split, only "things often only built for the host" and "things often built specifically for particular devices". Building our compiler tools for jetson/raspberry pi/android is valid, for example, as would be building a large chunk of the code for the compiler for emscripten (even if we have a different wrapper for using it vs. an executable). We can still deem certain uses as unsupported - like the compiler on android is not something we will really test or recommend people use.
cmake install targets can help here similar to filegroups in bazel: we can group together targets that are built together and then have any number of sets ("install compiler developer tools, including iree-translate and iree-check-module" vs "install compiled test modules to benchmark" vs "install runtime testing tools like the CTS and iree-benchmark-module", etc. Things like vcpkg help users here in that each of those becomes a feature;
vcpkg install iree[import-tflite,import-onnx,binding-tflite,hal-benchmarks]would just be a cmake install of each of those groups. Hand waving for now of course, but to get to that point having toolchains and targets orthogonal is a requirement :)ScottTodd commentedon Jan 21, 2021
Okay, steps 1-3 from #4323 (comment) are done, with a bunch of commented-out-and-soon-to-be-deleted code on ScottTodd@90b40ff.
Next issue I found when getting tests building is this:
https://github.com/google/iree/blob/26eb3146746faeac5d3b058bb9cc286049020b70/build_tools/cmake/iree_check_test.cmake#L67-L68
at least when using
-DIREE_TARGET_BACKENDS_TO_BUILD=vmla;vulkan-spirv -DIREE_HAL_DRIVERS_TO_BUILD=vmla;vulkanThe part that I don't think we can avoid a host/device split is for our (developer) tests, which need the host compiler and target runtime. For users, install targets for each should be enough.
benvanik commentedon Jan 21, 2021
Ack - this is why I'm hoping we can spin up a few CI builds with these options configured - so easy for them to bitrot (I found the same when trying to disable the metal/vulkan drivers, etc). We really shouldn't be unconditionally using conditionally enabled features anywhere.
Remove custom CMake cross compilation for Android. (#4584)