Skip to content

Add WebGPU dependencies and refactor *_TO_BUILD CMake options.#7905

Merged
ScottTodd merged 3 commits intoiree-org:mainfrom
ScottTodd:webgpu-deps
Dec 21, 2021
Merged

Add WebGPU dependencies and refactor *_TO_BUILD CMake options.#7905
ScottTodd merged 3 commits intoiree-org:mainfrom
ScottTodd:webgpu-deps

Conversation

@ScottTodd
Copy link
Copy Markdown
Member

Part of #7840

IREE_HAL_DRIVERS_TO_BUILD and IREE_TARGET_BACKENDS_TO_BUILD now use "default" instead of "all".

The new WebGPU compiler target is included in the list of all targets but is not enabled by default, and the Metal+CUDA targets similarly disable themselves on incompatible platforms. Developers must explicitly opt in to building the WebGPU compiler target or the Metal/CUDA targets in unsupported configurations. I'm using -DIREE_TARGET_BACKENDS_TO_BUILD=CUDA;Dylib-LLVM-AOT;WASM-LLVM-AOT;Vulkan-SPIRV;VMVX;WebGPU, for example.

Thanks to being conditionally enabled, we can also use CMake's FetchContent instead of git submodules for some dependencies, which will hopefully keep the rest of IREE's CMake and git infrastructure simple for most users while only adding costs for those us of working on or using these optional components.

Comment thread iree/tools/utils/BUILD
],
)

iree_cmake_extra_content(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wish we had a better way of doing this - like a custom field on the rule that was like cmake_enable_if = "${IREE_HAL_DRIVER_VMVX}" or something - these blocks are so ugly ;(

Copy link
Copy Markdown
Member Author

@ScottTodd ScottTodd Dec 21, 2021

Choose a reason for hiding this comment

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

Yeah :P we've used this particular escape hatch in this way enough times that it would be worth promoting it to something with its own syntax.

Comment thread CMakeLists.txt
set(IREE_HAL_DRIVERS_TO_BUILD ${IREE_ALL_HAL_DRIVERS})

# For Apple platforms we need to use Metal instead of Vulkan.
# Vulkan is not natively supported on Apple platforms.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This logic always sketched me out as it obfuscates both the name of the cmake options we're setting and requires people to evaluate the cmake in their head to know what's all/default/enabled

It'd be nice to have real actual explicit cmake options (like tint has TINT_BUILD_GLSL_WRITER and such) - every time I see an if(${IREE_HAL_DRIVER_FOO}) and try to search for it I get sad when I remember we're doing dynamic variable name construction. I think it was a tradeoff for making one way of setting things (a delimited string flag on the command line) easier while making everything else way harder to reason about. We can still have the string parsing for the simplified command line but having them backed by concrete cmake options feels like it'd be much less magic. It'd also make it easier to have more of these kind of settings in the future (all, default, host, cpu, etc) that just become if(cpu) set(SOMETHING ON).

This PR is fine as it's just adding to the pile of sadness, but something to think about as we grow this - getting tint and dawn set up was pretty easy because they had nice clear options with no magic, I wouldn't want to set up iree ;P When embedding in other projects being able to set(IREE_HAL_DRIVER_FOO ON/OFF) is way more natural than a string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

SG, I can refactor all those options in a future PR.

Comment thread CMakeLists.txt
add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL)
endif()

if(IREE_TARGET_BACKEND_WEBGPU)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(future cleanup, like whenever metal uses tint) we'll likely want a dedicated option for whether to enable SPIRV_TOOLING (or w/e) - it's easier to reason about "metal, d3d12, wgsl, and vulkan need SPIRV_TOOLING" by having if(d3d12) set(SPIRV_TOOLING ON) kind of blocks that are easy to search for/tweak than to have that if statement in all those places expanded out like we do in places today.

set(LLVM_EXTERNAL_PROJECTS ${LLVM_EXTERNAL_PROJECTS} CACHE STRING "" FORCE)
endmacro()

macro(iree_set_spirv_headers_cmake_options)
Copy link
Copy Markdown
Collaborator

@benvanik benvanik Dec 17, 2021

Choose a reason for hiding this comment

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

I hate this file - it's the last place I'd look for settings despite the name - I really like having the settings near the FetchContents like we have with tint - maybe as we refactor things we can do that more. It also makes it easier to keep bazel and cmake in sync as the bzl and cmakelists live side-by-side instead of having all these things set in build_tools/cmake/. If we're able to fully exclude third_party/spirv_headers/ then maybe we switch that to FetchContent as well.

@ScottTodd ScottTodd merged commit 229dbeb into iree-org:main Dec 21, 2021
@ScottTodd ScottTodd deleted the webgpu-deps branch December 21, 2021 17:19
ScottTodd added a commit that referenced this pull request Dec 22, 2021
)

Following up on #7905 (comment), this uses regular options for these settings, which are easier to search for and set. The CMakeLists from Tint was used as a reference: https://dawn.googlesource.com/tint/+/refs/heads/main/CMakeLists.txt. The main focus is to use explicit names instead of dynamic name construction, but using [option](https://cmake.org/cmake/help/latest/command/option.html) is a nice bonus.

New `IREE_HAL_DRIVER_DEFAULTS` and `IREE_TARGET_BACKEND_DEFAULTS` options can be used to set only a specific subset (set to `OFF` by default, then enable just the features you want).
@GMNGeoffrey GMNGeoffrey added the infrastructure Relating to build systems, CI, or testing label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/webgpu Runtime WebGPU HAL backend infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants