Skip to content

Move compilation tests from build-time to test-time #11354

Closed as not planned
Closed as not planned

Description

@ScottTodd

We have many tests that invoke IREE's compiler at build time (using iree_bytecode_module) and then run the compiled program at test time (e.g. iree_check_test). We'd like to instead invoke the compiler at test time. Along with this, I'd like a way to add compilation-only tests (prompted by this discussion: #11327 (comment)).

Tests in CMake can depend on other tests:

This could be tricky with cross compilation - the compiler [tests] should be running on the host, then execution should happen on the target platform (e.g. Android, web, GPU machine).

Activity

  1. added
    infrastructure
    on Nov 29, 2022
  2. GMNGeoffrey commented on Nov 29, 2022

    @GMNGeoffrey
    Member

    Note that this would be for CMake only. Bazel doesn't have a way to have dependencies between tests. Good point about cross-compilation making this tricky...

  3. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    Yeah, I'm pretty sure we don't want to do this. Compiling the artifacts is a build stage of the process and something we don't want happening concurrently with tests that are running (we want build tasks running through build systems, not ctest which isn't even a good test system lol).

  4. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    (note also that ctest can't cache - needing to regenerate all test inputs every time tests are run is not great given that they can sometimes take minutes to compile)

  5. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    All good points...

    The iree-test-deps target is a bit of a hack. For our suite of e2e tests, it would be nice if "running the tests" included both running the compiler and executing the compiled programs. That target at least makes it so a build of all doesn't fail if an individual test fails compilation.

    For the WebAssembly and WebGPU tests, I'm currently using iree_check_single_backend_test_suite with no driver arg, which just drops down to a loop around iree_bytecode_module. I could

    • keep that setup
    • add a new iree_compile_test that either uses iree_bytecode_module in a similar way or runs the compiler at test time
    • use lit somehow (without modifying the .mlir files like tests/e2e/xla_ops/abs.mlir)
  6. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    Are there any long-term situations where we'd want this or is this just transient during WebGPU bringup? Tests for the compiler belong in compiler lit tests and if testing these e2e integration-style tests then executing them is critical. I'm not sure exclusively testing "compiler didn't crash" is worth supporting outside of bringup where you can't run anything anywhere.

  7. GMNGeoffrey commented on Nov 29, 2022

    @GMNGeoffrey
    Member

    Good points Ben. Stella had previously complained about all the compilation using the IREE compiler happening at build time and suggested it move to test time. I think the middle ground we ended up with is the iree-test-deps target, which has caused confusion on multiple occasions. Part of the trouble is that in CMake you can declare a dependency between two build targets or between two tests, but not between a test and a build target. One option would be to actually do the reverse and make all our tests build targets. I think this is what check-llvm does except really it's just delegating to lit. But the console output of build rules isn't really ideal for testing. It would be nice to get test caching though. This is starting to sound kind of like how Bazel works :-P

    I think the particular thing tripping Scott up on this one though is that the way we do cross-compiling is weird and involves a bunch of hacks. I would love to see us rethink that as well.

  8. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    Are there any long-term situations where we'd want this or is this just transient during WebGPU bringup?

    I think it's transient, but I could imagine other bringup that would benefit from some restructuring. There have been many times now where I've wanted to "just compile the test suite" (and then run it if I have a way to do that) on a particular configuration, but "the test suite" is pretty nebulous - it's split between "benchmarks", "e2e tests", and even other repositories (like https://github.com/iree-org/iree-samples/tree/main/tflitehub).

  9. GMNGeoffrey commented on Nov 29, 2022

    @GMNGeoffrey
    Member

    Also the situation we have right now where you want to run tests, but your IREE host compiler may not support all backends seems pretty reasonable. The fact that my host compiler doesn't support Cuda shouldn't prevent me from building using the LLVM backend for Android. Maybe we should use the TARGET_BACKEND cmake options (or separate new options) even when the build of the compiler is off to indicate which backends to use when creating artifacts.

  10. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    May be a case here of trying to do too much with a mechanism not really meant to do anything well. For example, something like a compiler_commands-equivalent for compiler and test invocations would let you build quite a bit of these things without trying to shove that all into ctest.

    +1 to using the target backend flags to filter things for compilation and HAL drivers to filter things for execution - I'm kind of surprised we aren't doing that already?

  11. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    +1 to using the target backend flags to filter things for compilation and HAL drivers to filter things for execution - I'm kind of surprised we aren't doing that already?

    We do, but when cross compiling IREE_BUILD_COMPILER is set to OFF, which flips all IREE_TARGET_BACKEND_* options to OFF also:

    iree/CMakeLists.txt

    Lines 207 to 208 in 72e0d3c

    # The VMVX backend is always enabled.
    cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)

    That, combined with being able to set IREE_HOST_BINARY_ROOT to anything (pip install, bazel build, etc.), led to this logic:

    if(DEFINED IREE_HOST_BINARY_ROOT)
    # If we're not building the host tools from source under this configuration,
    # such as when cross compiling, then we can't easily check for which
    # compiler target backends are enabled. Just assume all are enabled and only
    # rely on the runtime HAL driver check above for filtering.
    # No driver, so this is a special configuration. The assumption above
    # might not be true, so skip (these tests are _probably_ already being
    # built on the host anyway, so no need to build when cross compiling).
    # TODO(#11354): Use a different test function / move compile to test-time
    if(NOT DEFINED _RULE_DRIVER)
    return()
    endif()
    else()
    # We are building the host tools, so check enabled compiler target backends.
    if(NOT IREE_TARGET_BACKEND_${_NORMALIZED_TARGET_BACKEND})
    return()
    endif()
    endif()

  12. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    "we can't easily check for which compiler target backends are enabled" is a bit different now that #10629 added --iree-hal-list-target-backends though:

    λ iree-compile.exe --iree-hal-list-target-backends
    Registered target backends:
      cuda
      llvm-cpu
      metal
      metal-spirv
      vmvx
      vmvx-inline
      vulkan
      vulkan-spirv
      webgpu
      webgpu-wgsl
    

    We could have CMake run the tool and check against the list.

  13. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    That's probably just because there are places only checking the IREE_TARGET_ flags that could be changed to AND IREE_BUILD_COMPILER - we could fix that such that the target backends are ON/OFF based on availability... ah, your new comment was what I was about to say :P doing that one as a cached configure-time check step would also let us verify the user-provided compiler was working.

  14. GMNGeoffrey commented on Nov 29, 2022

    @GMNGeoffrey
    Member

    We could have CMake run the tool and check against the list.

    Yeah I think I suggested that in your PR, but I'm a bit wary of automagically turning things off because they aren't supported. In my experience that frequently leads to things not getting tested that you thought were getting tested. I think my preference would be to have the IREE_TARGET_BACKEND_* flags used even when IREE_BUILD_COMPILER=OFF. I think the entire compiler directory is gated on IREE_BUILD_COMPILER, so I'd actually be a bit surprised if there are many places that need to do the "and"

  15. ScottTodd commented on Dec 1, 2022

    @ScottTodd
    MemberAuthor

    I think my preference would be to have the IREE_TARGET_BACKEND_* flags used even when IREE_BUILD_COMPILER=OFF.

    I'd rather not do that, but I hear your concerns about configurations not being explicit. I like to think from the perspective of someone configuring IREE as a subproject or for their first time, and having a clear association between settings (not building the compiler -> all these options aren't relevant and thus are unavailable) helps there. Things get more complicated when building tests or cross compiling. I guess we could add some comments around IREE_HOST_BINARY_ROOT and IREE_BUILD_COMPILER, but such comments might just get buried under the rest of the CMake code...

  16. moved this from Not Started to Inbox in (Deprecated) IREEon Apr 5, 2023
  17. moved this from Inbox to Needs Scheduling in (Deprecated) IREEon Apr 11, 2023
  18. moved this from Needs Scheduling to Backlog in (Deprecated) IREEon Jun 5, 2023
  19. ScottTodd commented on Jun 27, 2024

    @ScottTodd
    MemberAuthor

    Going to close this old issue. I think the path forward for these sorts of tests is to move e2e tests into a separate project (CMake subproject, pytest suite, etc.) that purely depends on release packages (or just the compiler + runtime binary tools), similar to https://github.com/nod-ai/SHARK-TestSuite/tree/main/iree_tests. It's still convenient to work with CMake from a single build directory though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    infrastructure

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions