Skip to content

Commit 3b15924

Browse files
authored
ggml WebGPU: remove userdata from request adapter callback (ggml-org#15527)
* ggml WebGPU: remove userdata from request adapter callback This commit removes the `userdata` parameter from the WebGPU request adapter callback in `ggml-webgpu.cpp`. Instead, the lambda function captures the `webgpu_context` directly. The motivation for this change is to simplify the code and improve readability. * inline the callback lambda into the RequestAdapter call This commit removes the callback lambda variable and inlines it directly into the RequestAdapter call.
1 parent 79bc429 commit 3b15924

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,17 +1154,15 @@ static ggml_backend_dev_t ggml_backend_webgpu_reg_get_device(ggml_backend_reg_t
11541154
webgpu_context ctx = reg_ctx->webgpu_ctx;
11551155

11561156
wgpu::RequestAdapterOptions options = {};
1157-
auto callback =
1158-
[](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter, const char * message, void * userdata) {
1159-
if (status != wgpu::RequestAdapterStatus::Success) {
1160-
GGML_LOG_ERROR("ggml_webgpu: Failed to get an adapter: %s\n", message);
1161-
return;
1162-
}
1163-
*static_cast<wgpu::Adapter *>(userdata) = std::move(adapter);
1164-
};
1165-
void * userdata = &ctx->adapter;
11661157
ctx->instance.WaitAny(
1167-
ctx->instance.RequestAdapter(&options, wgpu::CallbackMode::AllowSpontaneous, callback, userdata), UINT64_MAX);
1158+
ctx->instance.RequestAdapter(&options, wgpu::CallbackMode::AllowSpontaneous,
1159+
[&ctx](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter, const char * message) {
1160+
if (status != wgpu::RequestAdapterStatus::Success) {
1161+
GGML_LOG_ERROR("ggml_webgpu: Failed to get an adapter: %s\n", message);
1162+
return;
1163+
}
1164+
ctx->adapter = std::move(adapter);
1165+
}), UINT64_MAX);
11681166
GGML_ASSERT(ctx->adapter != nullptr);
11691167

11701168
ctx->adapter.GetLimits(&ctx->limits);

0 commit comments

Comments
 (0)