Skip to content

Replace CMake IREE_HOST_BINARY_ROOT var with IREE_HOST_BIN_DIR. - #11812

Merged
ScottTodd merged 5 commits into
iree-org:mainfrom
ScottTodd:cmake-host-bin
Jan 13, 2023
Merged

ScottTodd merged 5 commits into
iree-org:mainfrom
ScottTodd:cmake-host-bin

Conversation

@ScottTodd

Copy link
Copy Markdown
Member

The new variable is documented in the root CMakeLists.txt and is initialized from the (new deprecated) old variable.

iree-build/      # CMake build directory
  install/       # Set by -DCMAKE_INSTALL_PREFIX, IREE_HOST_BINARY_ROOT pointed here
    bin/         # IREE_HOST_BIN_DIR should point here
    lib/
    src/
    tests/

Now we can also point to other binary distributions that don't have CMake's build/install structure.


Closes #11441. Fixes #4662. This new variable approach was discussed on #11764 (comment).

The new variable is documented in the root CMakeLists.txt and is initialized from the (new deprecated) old variable.


```
iree-build/      # CMake build directory
  install/       # Set by -DCMAKE_INSTALL_PREFIX, IREE_HOST_BINARY_ROOT pointed here
    bin/         # IREE_HOST_BIN_DIR should point here
    lib/
    src/
    tests/
```

Now we can also point to other binary distributions that don't have CMake's build/install structure.
@ScottTodd
ScottTodd marked this pull request as ready for review January 12, 2023 18:31

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat tangential musing: For compiler configuration detection without silent failures should we make the IREE_TARGET_BACKEND_* options available (maybe hidden) even if IREE_BUILD_COMPILER is OFF? We could do a single configure step to set them by calling iree-compile --iree-list-target-backends, but explicit setting would take precedence. Then users can get nice behavior of just "run all the supported things" and in CI we can set everything explicitly

@ScottTodd

Copy link
Copy Markdown
Member Author

Somewhat tangential musing: For compiler configuration detection without silent failures should we make the IREE_TARGET_BACKEND_* options available (maybe hidden) even if IREE_BUILD_COMPILER is OFF? We could do a single configure step to set them by calling iree-compile --iree-list-target-backends, but explicit setting would take precedence. Then users can get nice behavior of just "run all the supported things" and in CI we can set everything explicitly

Maybe something like this?

if(IREE_HOST_BIN_DIR)
  if(IREE_BUILD_COMPILER)
    # Disallow because it would be ambiguous whether to use the prebuilt tools or build from source.
    message(FATAL_ERROR "IREE_HOST_BIN_DIR and IREE_BUILD_COMPILER cannot be set together")
  endif()

  get_target_property(_IREE_COMPILE_LOCATION iree-compile IMPORTED_LOCATION)
  execute_process(
      COMMAND ${_IREE_COMPILE_LOCATION} --iree-hal-list-target-backends
      OUTPUT_VARIABLE _TARGET_BACKENDS_OUTPUT
  )

  if(_TARGET_BACKENDS_OUTPUT MATCHES "cuda")
    set(IREE_TARGET_BACKEND_CUDA ON)
  elseif(IREE_TARGET_BACKEND_CUDA)
    message(FATAL_ERROR "IREE_TARGET_BACKEND_CUDA is set, but the imported iree-compile does not support CUDA")
  endif()
  # ... handle other target backends (maybe with a macro to save typing?)
endif()

@GMNGeoffrey

GMNGeoffrey commented Jan 12, 2023 •

Copy link
Copy Markdown
Member

Maybe something like this?

I think explicit "OFF" should probably be allowed also, but I'm not quite sure how to do that. I don't think you can differentiate between options being set and unset.

Also should probably make the matching logic a bit more robust.

Maybe this works?

set(_IREE_TARGET_BACKEND_VMVX_DEFAULT ON)
set(_IREE_TARGET_BACKEND_CUDA_DEFAULT OFF)

if(IREE_HOST_BIN_DIR)
  if(IREE_BUILD_COMPILER)
    # Disallow because it would be ambiguous whether to use the prebuilt tools or build from source.
    message(FATAL_ERROR "IREE_HOST_BIN_DIR and IREE_BUILD_COMPILER cannot be set together")
  endif()

  get_target_property(_IREE_COMPILE_LOCATION iree-compile IMPORTED_LOCATION)
  execute_process(
      COMMAND ${_IREE_COMPILE_LOCATION} --iree-hal-list-target-backends
      OUTPUT_VARIABLE _TARGET_BACKENDS_OUTPUT
  )

  if(_TARGET_BACKENDS_OUTPUT MATCHES "cuda")
    # These variables will always have the same value, but named separately because they're
    # conceptually different.
    set(_IREE_TARGET_BACKEND_CUDA_DETECTED ON)
    set(_IREE_TARGET_BACKEND_CUDA_DEFAULT ON)
  endif()

  if(_TARGET_BACKENDS_OUTPUT MATCHES "vmvx")
    set(_IREE_TARGET_BACKEND_VMVX_DETECTED ON)
    set(_IREE_TARGET_BACKEND_VMVX_DEFAULT ON)
  endif()
endif()

option(IREE_TARGET_BACKEND_VMVX "Turns on VMVX" "${_IREE_TARGET_BACKEND_VMVX_DEFAULT}")
option(IREE_TARGET_BACKEND_CUDA "Turns on Cuda" "${_IREE_TARGET_BACKEND_CUDA_DEFAULT}")

if(IREE_HOST_BIN_DIR)
  if(IREE_TARGET_BACKEND_CUDA AND NOT _IREE_TARGET_BACKEND_CUDA_DETECTED)
    message(FATAL_ERROR "IREE_TARGET_BACKEND_CUDA is set, but the imported iree-compile does not support CUDA")
  endif()
  if(IREE_TARGET_BACKEND_VMVX AND NOT _IREE_TARGET_BACKEND_VMVX_DETECTED)
    message(FATAL_ERROR "IREE_TARGET_BACKEND_VMVX is set, but the imported iree-compile does not support VMVX")
  endif()
endif()

I think that works, but it's pretty convoluted. Not sure of another way...

@ScottTodd
ScottTodd enabled auto-merge (squash) January 13, 2023 00:00
@ScottTodd
ScottTodd disabled auto-merge January 13, 2023 00:38
@ScottTodd
ScottTodd merged commit de426de into iree-org:main Jan 13, 2023
@ScottTodd
ScottTodd deleted the cmake-host-bin branch January 13, 2023 16:26
ScottTodd added a commit that referenced this pull request Jan 13, 2023
Follow-up to #11812.

`IREE_HOST_BIN_DIR` will still be populated from the deprecated
`IREE_HOST_BINARY_ROOT` to give downstream users time to update to the
new variable.
jpienaar pushed a commit that referenced this pull request May 1, 2023
…11812)

The new variable is documented in the root CMakeLists.txt and is
initialized from the (new deprecated) old variable.


```
iree-build/      # CMake build directory
  install/       # Set by -DCMAKE_INSTALL_PREFIX, IREE_HOST_BINARY_ROOT pointed here
    bin/         # IREE_HOST_BIN_DIR should point here
    lib/
    src/
    tests/
```

Now we can also point to other binary distributions that don't have
CMake's build/install structure.

---

Closes #11441. Fixes
#4662. This new variable approach
was discussed on
#11764 (comment).

Co-authored-by: Geoffrey Martin-Noble <[email protected]>
jpienaar pushed a commit that referenced this pull request May 1, 2023
Follow-up to #11812.

`IREE_HOST_BIN_DIR` will still be populated from the deprecated
`IREE_HOST_BINARY_ROOT` to give downstream users time to update to the
new variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add flexible configuration options to CMake for building/reusing tools

3 participants