@@ -309,10 +309,12 @@ struct ggml_backend_webgpu_context {
309309struct ggml_backend_webgpu_buffer_context {
310310 webgpu_context webgpu_ctx;
311311 wgpu::Buffer buffer;
312+ std::string label;
312313
313- ggml_backend_webgpu_buffer_context (webgpu_context ctx, wgpu::Buffer buf) :
314+ ggml_backend_webgpu_buffer_context (webgpu_context ctx, wgpu::Buffer buf, std::string lbl ) :
314315 webgpu_ctx (std::move(ctx)),
315- buffer (std::move(buf)) {}
316+ buffer (std::move(buf)),
317+ label (std::move(lbl)) {}
316318};
317319
318320/* End struct definitions */
@@ -1336,11 +1338,11 @@ static void ggml_backend_webgpu_buffer_memset_tensor(ggml_backend_buffer_t buffe
13361338
13371339 WEBGPU_CPU_PROFILE_TOTAL_START (memset_tensor);
13381340
1339- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_memset_tensor(" << buffer << " , " << tensor << " , " << value << " , "
1340- << offset << " , " << size << " )" );
1341-
13421341 ggml_backend_webgpu_buffer_context * buf_ctx = (ggml_backend_webgpu_buffer_context *) buffer->context ;
13431342
1343+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_memset_tensor(" << buf_ctx->label << " , " << tensor << " , " << value
1344+ << " , " << offset << " , " << size << " )" );
1345+
13441346 size_t total_offset = webgpu_tensor_offset (tensor) + tensor->view_offs + offset;
13451347
13461348 // This is a trick to set all bytes of a u32 to the same 1 byte value.
@@ -1354,12 +1356,13 @@ static void ggml_backend_webgpu_buffer_set_tensor(ggml_backend_buffer_t buffer,
13541356 const void * data,
13551357 size_t offset,
13561358 size_t size) {
1357- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_set_tensor(" << buffer << " , " << tensor << " , " << data << " , "
1358- << offset << " , " << size << " )" );
13591359 WEBGPU_CPU_PROFILE_TOTAL_START (set_tensor);
13601360 ggml_backend_webgpu_buffer_context * buf_ctx = (ggml_backend_webgpu_buffer_context *) buffer->context ;
13611361 webgpu_context webgpu_ctx = buf_ctx->webgpu_ctx ;
13621362
1363+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_set_tensor(" << buf_ctx->label << " , " << tensor << " , " << data
1364+ << " , " << offset << " , " << size << " )" );
1365+
13631366 size_t total_offset = webgpu_tensor_offset (tensor) + tensor->view_offs + offset;
13641367
13651368 webgpu_ctx->queue .WriteBuffer (buf_ctx->buffer , total_offset, data, (size / 4 ) * 4 );
@@ -1397,12 +1400,12 @@ static void ggml_backend_webgpu_buffer_get_tensor(ggml_backend_buffer_t buffer,
13971400 void * data,
13981401 size_t offset,
13991402 size_t size) {
1400- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_get_tensor(" << buffer << " , " << tensor << " , " << data << " , "
1401- << offset << " , " << size << " )" );
14021403 WEBGPU_CPU_PROFILE_TOTAL_START (get_tensor);
1403- ggml_backend_webgpu_buffer_context * buf_ctx = (ggml_backend_webgpu_buffer_context *) buffer->context ;
1404- webgpu_context webgpu_ctx = buf_ctx->webgpu_ctx ;
1405- wgpu::Device device = webgpu_ctx->device ;
1404+ ggml_backend_webgpu_buffer_context * buf_ctx = (ggml_backend_webgpu_buffer_context *) buffer->context ;
1405+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_get_tensor(" << buf_ctx->label << " , " << tensor << " , " << data
1406+ << " , " << offset << " , " << size << " )" );
1407+ webgpu_context webgpu_ctx = buf_ctx->webgpu_ctx ;
1408+ wgpu::Device device = webgpu_ctx->device ;
14061409
14071410 size_t total_offset = webgpu_tensor_offset (tensor) + tensor->view_offs + offset;
14081411
@@ -1473,16 +1476,20 @@ static const char * ggml_backend_webgpu_buffer_type_get_name(ggml_backend_buffer
14731476
14741477static ggml_backend_buffer_t ggml_backend_webgpu_buffer_type_alloc_buffer (ggml_backend_buffer_type_t buft,
14751478 size_t size) {
1476- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_type_alloc_buffer(" << size << " )" );
1479+ static std::atomic<int > buffer_count;
1480+ int buffer_id = buffer_count++;
1481+ std::string buf_name = " tensor_buf" + std::to_string (buffer_id);
1482+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_type_alloc_buffer_" << buffer_id << " : " << size << " bytes" );
14771483 ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(buft->device ->context );
14781484
14791485 wgpu::Buffer buf;
14801486 ggml_webgpu_create_buffer (ctx->webgpu_ctx ->device , buf,
14811487 (size + WEBGPU_STORAGE_BUF_BINDING_MULT - 1 ) & ~(WEBGPU_STORAGE_BUF_BINDING_MULT - 1 ),
14821488 wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
1483- " allocated_buffer " );
1489+ buf_name. c_str () );
14841490
1485- ggml_backend_webgpu_buffer_context * buf_ctx = new ggml_backend_webgpu_buffer_context (ctx->webgpu_ctx , buf);
1491+ ggml_backend_webgpu_buffer_context * buf_ctx =
1492+ new ggml_backend_webgpu_buffer_context (ctx->webgpu_ctx , buf, buf_name);
14861493
14871494 return ggml_backend_buffer_init (buft, ggml_backend_webgpu_buffer_interface, buf_ctx, size);
14881495}
@@ -2129,6 +2136,15 @@ static ggml_backend_dev_t ggml_backend_webgpu_reg_get_device(ggml_backend_reg_t
21292136 required_features.push_back (wgpu::FeatureName::TimestampQuery);
21302137#endif
21312138
2139+ const char * const deviceEnabledToggles[] = { " skip_validation" , " disable_robustness" , " disable_workgroup_init" ,
2140+ " disable_polyfills_on_integer_div_and_mod" };
2141+ const char * const deviceDisabledToggles[] = { " timestamp_quantization" };
2142+ wgpu::DawnTogglesDescriptor deviceTogglesDesc;
2143+ deviceTogglesDesc.enabledToggles = deviceEnabledToggles;
2144+ deviceTogglesDesc.enabledToggleCount = 4 ;
2145+ deviceTogglesDesc.disabledToggles = deviceDisabledToggles;
2146+ deviceTogglesDesc.disabledToggleCount = 1 ;
2147+
21322148 wgpu::DeviceDescriptor dev_desc;
21332149 dev_desc.requiredLimits = &ctx->limits ;
21342150 dev_desc.requiredFeatures = required_features.data ();
@@ -2146,6 +2162,7 @@ static ggml_backend_dev_t ggml_backend_webgpu_reg_get_device(ggml_backend_reg_t
21462162 GGML_ABORT (" ggml_webgpu: Device error! Reason: %d, Message: %s\n " , static_cast <int >(reason),
21472163 std::string (message).c_str ());
21482164 });
2165+ dev_desc.nextInChain = &deviceTogglesDesc;
21492166 ctx->instance .WaitAny (ctx->adapter .RequestDevice (
21502167 &dev_desc, wgpu::CallbackMode::AllowSpontaneous,
21512168 [ctx](wgpu::RequestDeviceStatus status, wgpu::Device device, wgpu::StringView message) {
@@ -2243,11 +2260,18 @@ ggml_backend_reg_t ggml_backend_webgpu_reg() {
22432260 ctx.name = GGML_WEBGPU_NAME;
22442261 ctx.device_count = 1 ;
22452262
2263+ const char * const instanceEnabledToggles[] = { " allow_unsafe_apis" };
2264+
2265+ wgpu::DawnTogglesDescriptor instanceTogglesDesc;
2266+ instanceTogglesDesc.enabledToggles = instanceEnabledToggles;
2267+ instanceTogglesDesc.enabledToggleCount = 1 ;
22462268 wgpu::InstanceDescriptor instance_descriptor{};
22472269 std::vector<wgpu::InstanceFeatureName> instance_features = { wgpu::InstanceFeatureName::TimedWaitAny };
22482270 instance_descriptor.requiredFeatures = instance_features.data ();
22492271 instance_descriptor.requiredFeatureCount = instance_features.size ();
2250- webgpu_ctx->instance = wgpu::CreateInstance (&instance_descriptor);
2272+ instance_descriptor.nextInChain = &instanceTogglesDesc;
2273+
2274+ webgpu_ctx->instance = wgpu::CreateInstance (&instance_descriptor);
22512275 GGML_ASSERT (webgpu_ctx->instance != nullptr );
22522276
22532277 static ggml_backend_reg reg = {
0 commit comments