Skip to content

Commit 2eb7626

Browse files
committed
minor cleanups
1 parent 0f0543b commit 2eb7626

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

docs/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ cmake --build build --config Release
572572

573573
WebGPU allows cross-platform access to the GPU from supported browsers. We utilize [Emscripten](https://emscripten.org/) to compile ggml's WebGPU backend to WebAssembly. Emscripten does not officially support WebGPU bindings yet, but Dawn currently maintains its own WebGPU bindings called emdawnwebgpu.
574574

575-
Follow the instructions [here](https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/) to download or build the emdawnwebgpu package (Note that it might be safer to build them locally, so that they stay in sync with the version of Dawn you have installed above). When building using CMake, the path to the emdawnwebgpu port file needs to be set with the flag `EMDAWNWEBGPU_DIR`.
575+
Follow the instructions [here](https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/) to download or build the emdawnwebgpu package (Note that it might be safer to build the emdawbwebgpu package locally, so that it stays in sync with the version of Dawn you have installed above). When building using CMake, the path to the emdawnwebgpu port file needs to be set with the flag `EMDAWNWEBGPU_DIR`.
576576

577577
## Notes about GPU-accelerated backends
578578

ggml/src/ggml-webgpu/ggml-webgpu.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
/* Constants */
2020

21-
// TODO: find a better way to get the memory available
22-
#define WEBGPU_MAX_BUFFERS 32
23-
2421
#define WEBGPU_MUL_MAT_WG_SIZE 64
2522
#define WEBGPU_MUL_MAT_PARAMS_SIZE (13 * sizeof(uint32_t)) // M, N, K, batch sizes, broadcasts
2623
#define WEBGPU_CPY_PARAMS_SIZE (15 * sizeof(uint32_t)) // strides and offsets
@@ -119,7 +116,7 @@ static void ggml_webgpu_create_pipeline(wgpu::Device &device, wgpu::ComputePipel
119116
pipeline_desc.label = label;
120117
pipeline_desc.compute.module = shader_module;
121118
pipeline_desc.compute.entryPoint = "main"; // Entry point in the WGSL code
122-
pipeline_desc.layout = nullptr; // Guessing that nullptr means auto layout
119+
pipeline_desc.layout = nullptr; // nullptr means auto layout
123120
if (constants.size() > 0) {
124121
pipeline_desc.compute.constants = constants.data();
125122
pipeline_desc.compute.constantCount = constants.size();
@@ -199,7 +196,6 @@ static void ggml_backend_webgpu_buffer_memset(webgpu_context ctx, wgpu::Buffer b
199196
pass.End();
200197
wgpu::CommandBuffer commands = encoder.Finish();
201198

202-
// TODO, async, do we need to wait on this?
203199
ctx->queue.Submit(1, &commands);
204200
}
205201

@@ -489,7 +485,6 @@ static void ggml_backend_webgpu_buffer_set_tensor(ggml_backend_buffer_t buffer,
489485

490486
size_t total_offset = webgpu_tensor_offset(tensor) + tensor->view_offs + offset;
491487

492-
// TODO: wait on this?
493488
webgpu_ctx->queue.WriteBuffer(buf_ctx->buffer, total_offset, data, (size/4)*4);
494489

495490
if (size % 4 != 0) {
@@ -617,9 +612,9 @@ static const char * ggml_backend_webgpu_device_get_description(ggml_backend_dev_
617612

618613
static void ggml_backend_webgpu_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
619614
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(dev->context);
620-
// TODO: what do we actually want to return here?
621-
*free = ctx->webgpu_ctx->limits.maxBufferSize * WEBGPU_MAX_BUFFERS;
622-
*total = ctx->webgpu_ctx->limits.maxBufferSize * WEBGPU_MAX_BUFFERS;
615+
// TODO: what do we actually want to return here? maxBufferSize might not be the full available memory.
616+
*free = ctx->webgpu_ctx->limits.maxBufferSize;
617+
*total = ctx->webgpu_ctx->limits.maxBufferSize;
623618
}
624619

625620
static enum ggml_backend_dev_type ggml_backend_webgpu_device_get_type(ggml_backend_dev_t dev) {

ggml/src/ggml-webgpu/wgsl-shaders/cpy.wgsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ var<storage, read_write> dst: array<f16>;
88

99
struct Params {
1010
ne: u32, // total number of elements
11-
src_offset: u32, // in bytes
12-
dst_offset: u32, // in bytes
11+
offset_src: u32, // in bytes
12+
offset_dst: u32, // in bytes
1313

1414
// Strides (in elements) — may be permuted
1515
stride_src0: u32,
@@ -56,5 +56,5 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
5656
let dst_idx = i0 * params.stride_dst0 + i1 * params.stride_dst1 +
5757
i2 * params.stride_dst2 + i3 * params.stride_dst3;
5858

59-
dst[params.dst_offset / 2 + dst_idx] = f16(src[params.src_offset / 4 + src_idx]);
59+
dst[params.offset_dst / 2 + dst_idx] = f16(src[params.offset_src / 4 + src_idx]);
6060
}

0 commit comments

Comments
 (0)