Skip to content

Rework cross-compilation to be standard cmake as much as possible #4323

Closed

Description

@ScottTodd

The extra complexity around options like IREE_BUILD_COMPILER has led some configuration crossing multiple files in confusing ways (e.g. #4320)

These sections in particular would help to be refactored (or eliminated if possible):

https://github.com/google/iree/blob/main/build_tools/cmake/iree_cross_compile.cmake
https://github.com/google/iree/blob/37c17e63b3e13d1368280f1a774f48b1a28309ef/CMakeLists.txt#L182-L228

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.

Activity

  1. added
    platform/android 🤖
    ew 🤮
    on Dec 28, 2020
  2. benvanik commented on Dec 28, 2020

    @benvanik
    Collaborator

    +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).

  3. antiagainst commented on Jan 5, 2021

    @antiagainst
    Member

    +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.

  4. self-assigned this
    on Jan 20, 2021
  5. ScottTodd commented on Jan 20, 2021

    @ScottTodd
    MemberAuthor

    I'm starting to work on this now. My general plan is:

    1. Cut out all if(CMAKE_CROSSCOMPILING) / iree_host_* code
    2. Build/install for the host configuration in one build directory
    3. 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.)
    4. 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.)
    5. Once that is working, wrap the cmake configure/build commands in a [Python] script for developers and CI to use

    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.exe from the host build/install, but I don't see it listed there yet:

    λ cmake -G Ninja -B ..\iree-build-host\ . -DIREE_BUILD_COMPILER=ON -DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_TESTS=OFF -DIREE_TARGET_BACKENDS_TO_BUILD=vmla;vulkan-spirv -DIREE_HAL_DRIVERS_TO_BUILD=vmla;vulkan
     <configure output>
    λ cmake --build ..\iree-build-host
     <build output>
    λ cmake --install ..\iree-build-host
    -- Install configuration: "Debug"
    -- Installing: D:/dev/projects/iree-build-host/install/bin/generate_cc_embed_data.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-dump-module.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-run-module.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-tblgen.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-translate.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-opt.exe
    -- Installing: D:/dev/projects/iree-build-host/install/bin/iree-run-mlir.exe
    
  6. benvanik commented on Jan 20, 2021

    @benvanik
    Collaborator

    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).

  7. benvanik commented on Jan 20, 2021

    @benvanik
    Collaborator

    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).

  8. GMNGeoffrey commented on Jan 20, 2021

    @GMNGeoffrey
    Member

    I think it's worth checking out the toolchain files for cross compilation as that seems to be the "modern cmake" way

  9. ScottTodd commented on Jan 21, 2021

    @ScottTodd
    MemberAuthor

    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

  10. benvanik commented on Jan 21, 2021

    @benvanik
    Collaborator

    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 :)

  11. ScottTodd commented on Jan 21, 2021

    @ScottTodd
    MemberAuthor

    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

    FAILED: iree/test/e2e/xla_ops/check_vmla_vmla_dot_general.mlir_module.module
    cmd.exe /C "cd /D D:\dev\projects\iree-build-android\iree\test\e2e\xla_ops && D:\dev\projects\iree-build-host\install\bin\iree-translate.exe -iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vmla --iree-llvm-target-triple=aarch64-none-linux-android30 D:/dev/projects/iree/iree/test/e2e/xla_ops/dot_general.mlir -o check_vmla_vmla_dot_general.mlir_module.module"
    iree-translate.exe: Unknown command line argument '--iree-llvm-target-triple=aarch64-none-linux-android30'.  Try: 'D:\dev\projects\iree-build-host\install\bin\iree-translate.exe --help'
    

    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.

  12. benvanik commented on Jan 21, 2021

    @benvanik
    Collaborator

    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.

  13. added
    infrastructure
    on May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ew 🤮infrastructureplatform/android 🤖

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions