Spaces:
Sleeping
ggml: Add initial WebGPU backend (llama/14521)
Browse files* Minimal setup of webgpu backend with dawn. Just prints out the adapter and segfaults
* Initialize webgpu device
* Making progress on setting up the backend
* Finish more boilerplate/utility functions
* Organize file and work on alloc buffer
* Add webgpu_context to prepare for actually running some shaders
* Work on memset and add shader loading
* Work on memset polyfill
* Implement set_tensor as webgpu WriteBuffer, remove host_buffer stubs since webgpu doesn't support it
* Implement get_tensor and buffer_clear
* Finish rest of setup
* Start work on compute graph
* Basic mat mul working
* Work on emscripten build
* Basic WebGPU backend instructions
* Use EMSCRIPTEN flag
* Work on passing ci, implement 4d tensor multiplication
* Pass thread safety test
* Implement permuting for mul_mat and cpy
* minor cleanups
* Address feedback
* Remove division by type size in cpy op
* Fix formatting and add github action workflows for vulkan and metal (m-series) webgpu backends
* Fix name
* Fix macos dawn prefix path
- ggml/CMakeLists.txt +3 -0
- ggml/include/ggml-webgpu.h +19 -0
- ggml/src/CMakeLists.txt +1 -0
- ggml/src/ggml-backend-reg.cpp +7 -0
|
@@ -181,6 +181,8 @@ option(GGML_VULKAN_MEMORY_DEBUG "ggml: enable Vulkan memory debug ou
|
|
| 181 |
option(GGML_VULKAN_SHADER_DEBUG_INFO "ggml: enable Vulkan shader debug info" OFF)
|
| 182 |
option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation" OFF)
|
| 183 |
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
|
|
|
|
|
|
|
| 184 |
option(GGML_METAL "ggml: use Metal" ${GGML_METAL_DEFAULT})
|
| 185 |
option(GGML_METAL_USE_BF16 "ggml: use bfloat if available" OFF)
|
| 186 |
option(GGML_METAL_NDEBUG "ggml: disable Metal debugging" OFF)
|
|
@@ -270,6 +272,7 @@ set(GGML_PUBLIC_HEADERS
|
|
| 270 |
include/ggml-rpc.h
|
| 271 |
include/ggml-sycl.h
|
| 272 |
include/ggml-vulkan.h
|
|
|
|
| 273 |
include/gguf.h)
|
| 274 |
|
| 275 |
set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
|
|
|
|
| 181 |
option(GGML_VULKAN_SHADER_DEBUG_INFO "ggml: enable Vulkan shader debug info" OFF)
|
| 182 |
option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation" OFF)
|
| 183 |
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
|
| 184 |
+
option(GGML_WEBGPU "ggml: use WebGPU" OFF)
|
| 185 |
+
option(GGML_WEBGPU_DEBUG "ggml: enable WebGPU debug output" OFF)
|
| 186 |
option(GGML_METAL "ggml: use Metal" ${GGML_METAL_DEFAULT})
|
| 187 |
option(GGML_METAL_USE_BF16 "ggml: use bfloat if available" OFF)
|
| 188 |
option(GGML_METAL_NDEBUG "ggml: disable Metal debugging" OFF)
|
|
|
|
| 272 |
include/ggml-rpc.h
|
| 273 |
include/ggml-sycl.h
|
| 274 |
include/ggml-vulkan.h
|
| 275 |
+
include/ggml-webgpu.h
|
| 276 |
include/gguf.h)
|
| 277 |
|
| 278 |
set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
|
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include "ggml.h"
|
| 4 |
+
#include "ggml-backend.h"
|
| 5 |
+
|
| 6 |
+
#ifdef __cplusplus
|
| 7 |
+
extern "C" {
|
| 8 |
+
#endif
|
| 9 |
+
|
| 10 |
+
#define GGML_WEBGPU_NAME "WebGPU"
|
| 11 |
+
|
| 12 |
+
// Needed for examples in ggml
|
| 13 |
+
GGML_BACKEND_API ggml_backend_t ggml_backend_webgpu_init(void);
|
| 14 |
+
|
| 15 |
+
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_webgpu_reg(void);
|
| 16 |
+
|
| 17 |
+
#ifdef __cplusplus
|
| 18 |
+
}
|
| 19 |
+
#endif
|
|
@@ -370,6 +370,7 @@ ggml_add_backend(MUSA)
|
|
| 370 |
ggml_add_backend(RPC)
|
| 371 |
ggml_add_backend(SYCL)
|
| 372 |
ggml_add_backend(Vulkan)
|
|
|
|
| 373 |
ggml_add_backend(OpenCL)
|
| 374 |
|
| 375 |
foreach (target ggml-base ggml)
|
|
|
|
| 370 |
ggml_add_backend(RPC)
|
| 371 |
ggml_add_backend(SYCL)
|
| 372 |
ggml_add_backend(Vulkan)
|
| 373 |
+
ggml_add_backend(WebGPU)
|
| 374 |
ggml_add_backend(OpenCL)
|
| 375 |
|
| 376 |
foreach (target ggml-base ggml)
|
|
@@ -45,6 +45,10 @@
|
|
| 45 |
#include "ggml-vulkan.h"
|
| 46 |
#endif
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
#ifdef GGML_USE_OPENCL
|
| 49 |
#include "ggml-opencl.h"
|
| 50 |
#endif
|
|
@@ -173,6 +177,9 @@ struct ggml_backend_registry {
|
|
| 173 |
#ifdef GGML_USE_VULKAN
|
| 174 |
register_backend(ggml_backend_vk_reg());
|
| 175 |
#endif
|
|
|
|
|
|
|
|
|
|
| 176 |
#ifdef GGML_USE_OPENCL
|
| 177 |
register_backend(ggml_backend_opencl_reg());
|
| 178 |
#endif
|
|
|
|
| 45 |
#include "ggml-vulkan.h"
|
| 46 |
#endif
|
| 47 |
|
| 48 |
+
#ifdef GGML_USE_WEBGPU
|
| 49 |
+
#include "ggml-webgpu.h"
|
| 50 |
+
#endif
|
| 51 |
+
|
| 52 |
#ifdef GGML_USE_OPENCL
|
| 53 |
#include "ggml-opencl.h"
|
| 54 |
#endif
|
|
|
|
| 177 |
#ifdef GGML_USE_VULKAN
|
| 178 |
register_backend(ggml_backend_vk_reg());
|
| 179 |
#endif
|
| 180 |
+
#ifdef GGML_USE_WEBGPU
|
| 181 |
+
register_backend(ggml_backend_webgpu_reg());
|
| 182 |
+
#endif
|
| 183 |
#ifdef GGML_USE_OPENCL
|
| 184 |
register_backend(ggml_backend_opencl_reg());
|
| 185 |
#endif
|