Skip to content

Commit

Permalink
Remove WebGPU native platform support. (#10646)
Browse files Browse the repository at this point in the history
This removes the [Dawn](https://dawn.googlesource.com/dawn) and
[wgpu-native](https://github.com/gfx-rs/wgpu-native) implementations of
WebGPU. I kept the `iree/hal/drivers/webgpu/platform/webgpu.h` file and
`platform/` file structure so that we can still _build_ most of the
WebGPU HAL using
[webgpu-headers](https://github.com/webgpu-native/webgpu-headers). I
also emptied out the
`hal/drivers/webgpu/registration/driver_module_native.c` implementation
to just return `IREE_STATUS_UNIMPLEMENTED`.

Dawn and wgpu-native are both very large dependencies that we would only
use for development and testing (we have direct support for Vulkan,
CUDA, etc., so we wouldn't use them as compatibility layers on native
platforms). We'll focus our efforts on the browser implementation of
WebGPU (using Emscripten, at least to start).
  • Loading branch information
ScottTodd committed May 25, 2023
1 parent f7020e5 commit 919feed
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 1,108 deletions.
37 changes: 13 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,9 @@ if(APPLE)
endif()

# WebGPU is disabled by default as it's experimental.
# TODO(benvanik): FindPackage the deps or default to on when under emscripten?
# TODO(benvanik): FindPackage the deps or default to on when under Emscripten?
# (also see iree_copts.cmake and anywhere that uses IREE_HAL_DRIVER_WEBGPU)
set(IREE_HAL_DRIVER_WEBGPU_DEFAULT OFF)
set(IREE_HAL_WEBGPU_PLATFORM_DEFAULT "dawn")
set(IREE_HAL_WEBGPU_PLATFORM "${IREE_HAL_WEBGPU_PLATFORM_DEFAULT}"
CACHE STRING "Native WebGPU implementation ('dawn' or 'wgpu-native').")

option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT})
option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
Expand Down Expand Up @@ -826,7 +824,6 @@ add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/wgpu-native EXCLUDE_FROM_ALL)

iree_set_googletest_cmake_options()
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
Expand Down Expand Up @@ -869,35 +866,27 @@ if(IREE_BUILD_PYTHON_BINDINGS)
endif()

if(IREE_TARGET_BACKEND_METAL_SPIRV)
iree_set_spirv_cross_cmake_options()
# SPIRV-Cross is needed to cross compile SPIR-V into MSL source code.
iree_set_spirv_cross_cmake_options()
add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL)
endif()

if(IREE_TARGET_BACKEND_WEBGPU OR
(IREE_HAL_DRIVER_WEBGPU AND ("${IREE_HAL_WEBGPU_PLATFORM}" STREQUAL "dawn")))
# NOTE: these all need to be synchronized with Dawn.
# set(IREE_SPIRV_TOOLS_TAG "37d2396cabe56b29d37551ea55d0d745d5748ded")
set(IREE_SPIRV_TOOLS_TAG "ff07cfd86fa229525659f6b81058b3171a67bef1") # 2021-12-10
# https://dawn.googlesource.com/dawn/+/refs/heads/main/DEPS
# https://chromium.googlesource.com/vulkan-deps/+/main/DEPS
# set(IREE_TINT_TAG "5aca651c524caca8ac85962d1dff378238671eba")
set(IREE_TINT_TAG "188b1fb8f5be52299fb7fbc6db17dbb0c07dbb7e") # 2021-12-16
set(IREE_DAWN_ABSEIL_TAG "789af048b388657987c59d4da406859034fe310f")
set(IREE_DAWN_GLFW_TAG "62e175ef9fae75335575964c845a302447c012c7")
set(IREE_DAWN_TAG "2f1b0dc47d8316f3db6e5b9a55b873cd3079cea5")

if(IREE_TARGET_BACKEND_WEBGPU)
# Tint is needed to compile SPIR-V into WGSL source code.
# Tint also requires SPIRV-Tools, which requires SPIRV-Headers.
# Dawn needs Tint (and thus SPIRV-Tools), but only at runtime.
# Order matters here, unfortunately.

# NOTE: these can be synced by referencing one of these repositories:
# * https://dawn.googlesource.com/dawn/
# * https://dawn.googlesource.com/tint/
# * https://chromium.googlesource.com/vulkan-deps/+/refs/heads/main/DEPS
# or they can be updated independently
set(IREE_TINT_TAG "200492e32b94f042d9942154fb4fa7f93bb8289a") # 2022-08-17
set(IREE_SPIRV_TOOLS_TAG "ff07cfd86fa229525659f6b81058b3171a67bef1") # 2021-12-10

iree_set_spirv_headers_cmake_options()
add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL)
if(IREE_HAL_DRIVER_WEBGPU AND ("${IREE_HAL_WEBGPU_PLATFORM}" STREQUAL "dawn"))
add_subdirectory(build_tools/third_party/dawn EXCLUDE_FROM_ALL)
endif()
endif()

#-------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions build_tools/bazel/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,10 @@ def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"):
build_file = iree_repo_alias + "//:build_tools/third_party/nccl/BUILD.overlay",
path = paths.join(iree_path, "third_party/nccl"),
)

maybe(
native.new_local_repository,
name = "webgpu_headers",
build_file = iree_repo_alias + "//:build_tools/third_party/webgpu-headers/BUILD.overlay",
path = paths.join(iree_path, "third_party/webgpu-headers"),
)
1 change: 0 additions & 1 deletion build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def __init__(self, repo_map: Dict[str, str]):
"vulkan_memory_allocator"
],
"@webgpu_headers": [],
"@wgpu-native//:static": ["wgpu-native-static"],
})

self._initialize()
Expand Down
1 change: 1 addition & 0 deletions build_tools/cmake/iree_copts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ endif()
if(EMSCRIPTEN AND IREE_HAL_DRIVER_WEBGPU)
iree_select_compiler_opts(IREE_DEFAULT_LINKOPTS
ALL
# TODO(scotttodd): Only add when using WebGPU in a library/binary?
"-sUSE_WEBGPU"
# Hack: Used to create sync versions of requestAdapter and requestDevice
# TODO(scotttodd): Only set for test binaries, avoid sync code in apps
Expand Down
58 changes: 0 additions & 58 deletions build_tools/third_party/dawn/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion build_tools/third_party/dawn/dummy.c

This file was deleted.

14 changes: 6 additions & 8 deletions build_tools/third_party/tint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ set(TINT_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_TESTS OFF CACHE BOOL "" FORCE)

# Our usage at compile time primarily needs the SPIR-V reader and WGSL writer,
# but usage at runtime through Dawn needs a broader set. WebGPU on native is
# not a supported production use case and is only for development/testing and
# as such we don't get too particular about minimizing its size here.
# Our usage at compile time primarily needs the SPIR-V reader and WGSL writer.
# Other readers and writers could be enabled, but we want to keep this small.

set(TINT_BUILD_SPV_READER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_READER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_READER OFF CACHE BOOL "" FORCE)

set(TINT_BUILD_GLSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_HLSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_MSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_SPV_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(tint)
Expand Down
13 changes: 13 additions & 0 deletions build_tools/third_party/webgpu-headers/BUILD.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

package(default_visibility = ["//visibility:public"])

cc_library(
name = "webgpu_headers",
hdrs = ["webgpu.h"],
include_prefix = "third_party/webgpu-headers",
)
64 changes: 0 additions & 64 deletions build_tools/third_party/wgpu-native/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion experimental/web/sample_webgpu/build_sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ emcmake "${CMAKE_BIN?}" -G Ninja .. \
-DIREE_HAL_DRIVER_LOCAL_SYNC=OFF \
-DIREE_HAL_DRIVER_LOCAL_TASK=OFF \
-DIREE_HAL_DRIVER_WEBGPU=ON \
-DIREE_HAL_WEBGPU_PLATFORM=emscripten \
-DIREE_BUILD_COMPILER=OFF \
-DIREE_BUILD_TESTS=OFF

Expand Down
1 change: 0 additions & 1 deletion experimental/web/testing/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ emcmake "${CMAKE_BIN?}" -G Ninja .. \
-DIREE_BUILD_COMPILER=OFF \
-DIREE_HAL_DRIVER_DEFAULTS=OFF \
-DIREE_HAL_DRIVER_WEBGPU=ON \
-DIREE_HAL_WEBGPU_PLATFORM=emscripten \
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
-DIREE_HAL_DRIVER_LOCAL_TASK=ON \
-DIREE_HAL_EXECUTABLE_LOADER_DEFAULTS=OFF \
Expand Down
1 change: 0 additions & 1 deletion runtime/src/iree/hal/allocator_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ IREE_API_EXPORT iree_status_t iree_hal_allocator_create_heap(
IREE_ASSERT_ARGUMENT(out_allocator);
*out_allocator = NULL;
IREE_TRACE_ZONE_BEGIN(z0);
*out_allocator = NULL;

iree_hal_heap_allocator_t* allocator = NULL;
iree_host_size_t total_size =
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/iree/hal/drivers/webgpu/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//iree:build_defs.oss.bzl", "iree_runtime_cc_library")
load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library")

package(
default_visibility = ["//visibility:public"],
Expand Down
19 changes: 13 additions & 6 deletions runtime/src/iree/hal/drivers/webgpu/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ static iree_status_t iree_hal_webgpu_builtins_initialize_fill_buffer(
"failed to create fill_buffer builtin pipeline layout");
}

const char* code = iree_hal_webgpu_builtins_find_code("fill_buffer.wgsl");
const WGPUShaderModuleWGSLDescriptor wgsl_descriptor = {
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
.source = iree_hal_webgpu_builtins_find_code("fill_buffer.wgsl"),
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
#if defined(__EMSCRIPTEN__)
// Emscripten uses this older name.
.source = code,
#else
// Spec uses this name: https://www.w3.org/TR/webgpu/#shader-module-creation
.code = code,
#endif
};
const WGPUShaderModuleDescriptor module_descriptor = {
.nextInChain = &wgsl_descriptor.chain,
Expand Down
18 changes: 12 additions & 6 deletions runtime/src/iree/hal/drivers/webgpu/executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ static iree_status_t iree_hal_webgpu_create_wgsl_shader_module(
const char* code = iree_WGSLShaderModuleDef_code_get(shader_module_def);

const WGPUShaderModuleWGSLDescriptor descriptor = {
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
.source = code,
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
#if defined(__EMSCRIPTEN__)
// Emscripten uses this older name.
.source = code,
#else
// Spec uses this name: https://www.w3.org/TR/webgpu/#shader-module-creation
.code = code,
#endif
};
const WGPUShaderModuleDescriptor module_descriptor = {
.nextInChain = &descriptor.chain,
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/iree/hal/drivers/webgpu/platform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library")

package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
licenses = ["notice"], # Apache 2.0
)

cc_library(
iree_runtime_cc_library(
name = "platform",
hdrs = [
"webgpu.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ IREEWGPUBufferMapSyncStatus iree_wgpuBufferMapSync(WGPUDevice device,
WGPUBuffer buffer,
WGPUMapModeFlags mode,
size_t offset, size_t size) {
IREEWGPUBufferMapSyncStatus status = IREEWGPUBufferMapSyncStatus_Unknown;
wgpuBufferMapAsync(buffer, mode, offset, size,
iree_hal_webgpu_buffer_map_sync_callback, &status);
// TODO(scotttodd): poll / wait somehow, or implement sync mapping differently
// wgpuDevicePoll(device, /*force_wait=*/true);
return status;
// WebGPU (browser/Emscripten) does not support synchronous buffer mapping.
return IREEWGPUBufferMapSyncStatus_Error;
}
Loading

0 comments on commit 919feed

Please sign in to comment.