@@ -199,6 +199,39 @@ static void ggml_backend_webgpu_free(ggml_backend_t backend) {
199
199
// TODO: cleanup
200
200
}
201
201
202
+ // Returns true if node has enqueued work into the queue, false otherwise
203
+ static bool ggml_webgpu_encode_node (webgpu_context ctx, ggml_tensor * node){
204
+ if (ggml_is_empty (node)) {
205
+ return false ;
206
+ }
207
+
208
+ WEBGPU_LOG_DEBUG (" ggml_webgpu_encode_node(" << node << " , " << ggml_op_name (node->op ) << " )" );
209
+
210
+ switch (node->op ) {
211
+ // no-op
212
+ case GGML_OP_NONE:
213
+ // these next four ops modify the logical view of the tensor, but do not change its data
214
+ case GGML_OP_RESHAPE:
215
+ case GGML_OP_VIEW:
216
+ case GGML_OP_PERMUTE:
217
+ case GGML_OP_TRANSPOSE:
218
+ return false ;
219
+ default :
220
+ return false ;
221
+ }
222
+ }
223
+
224
+ static ggml_status ggml_backend_webgpu_graph_compute (ggml_backend_t backend, struct ggml_cgraph * cgraph) {
225
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_graph_compute(" << cgraph->n_nodes << " nodes)" );
226
+
227
+ ggml_backend_webgpu_context * backend_ctx = static_cast <ggml_backend_webgpu_context *>(backend->context );
228
+ webgpu_context ctx = backend_ctx->webgpu_ctx ;
229
+
230
+ for (int i = 0 ; i < cgraph->n_nodes ; i++) {
231
+ ggml_webgpu_encode_node (ctx, cgraph->nodes [i]);
232
+ }
233
+ }
234
+
202
235
static ggml_backend_i ggml_backend_webgpu_i = {
203
236
/* .get_name = */ ggml_backend_webgpu_name,
204
237
/* .free = */ ggml_backend_webgpu_free,
@@ -209,8 +242,8 @@ static ggml_backend_i ggml_backend_webgpu_i = {
209
242
/* .graph_plan_create = */ NULL ,
210
243
/* .graph_plan_free = */ NULL ,
211
244
/* .graph_plan_update = */ NULL ,
212
- /* .graph_plan_compute = */ NULL , // TODO
213
- /* .graph_compute = */ NULL ,
245
+ /* .graph_plan_compute = */ NULL ,
246
+ /* .graph_compute = */ ggml_backend_webgpu_graph_compute ,
214
247
/* .event_record = */ NULL ,
215
248
/* .event_wait = */ NULL ,
216
249
};
@@ -228,7 +261,6 @@ static void ggml_backend_webgpu_buffer_free_buffer(ggml_backend_buffer_t buffer)
228
261
229
262
// Returns the "fake" base pointer.
230
263
static void * ggml_backend_webgpu_buffer_get_base (ggml_backend_buffer_t buffer) {
231
- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_get_base()" );
232
264
GGML_UNUSED (buffer);
233
265
return webgpu_ptr_base;
234
266
}
@@ -354,13 +386,11 @@ static size_t ggml_backend_webgpu_buffer_type_get_max_size(ggml_backend_buffer_t
354
386
/* GGML Backend Device Interface */
355
387
356
388
static const char * ggml_backend_webgpu_device_get_name (ggml_backend_dev_t dev) {
357
- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_name()" );
358
389
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
359
390
return ctx->device_name .c_str ();
360
391
}
361
392
362
393
static const char * ggml_backend_webgpu_device_get_description (ggml_backend_dev_t dev) {
363
- WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_description()" );
364
394
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
365
395
return ctx->device_desc .c_str ();
366
396
}
@@ -499,6 +529,13 @@ static bool ggml_backend_webgpu_device_supports_op(ggml_backend_dev_t dev, const
499
529
500
530
// what should we support first?
501
531
switch (op->op ) {
532
+ case GGML_OP_NONE:
533
+ case GGML_OP_RESHAPE:
534
+ case GGML_OP_VIEW:
535
+ case GGML_OP_PERMUTE:
536
+ case GGML_OP_TRANSPOSE:
537
+ return true ;
538
+
502
539
default :
503
540
return false ;
504
541
}
0 commit comments