MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / ggml_webgpu_get_rows

Function ggml_webgpu_get_rows

external/ggml/src/ggml-webgpu/ggml-webgpu.cpp:1339–1383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1337}
1338
1339static webgpu_encoded_op ggml_webgpu_get_rows(webgpu_context & ctx,
1340 ggml_tensor * src,
1341 ggml_tensor * idx,
1342 ggml_tensor * dst) {
1343 const bool float_parallel = src->type == GGML_TYPE_F32 || src->type == GGML_TYPE_F16 || src->type == GGML_TYPE_I32;
1344
1345 ggml_webgpu_shader_lib_context shader_lib_ctx = {};
1346 shader_lib_ctx.src0 = src;
1347 shader_lib_ctx.src1 = nullptr;
1348 shader_lib_ctx.dst = dst;
1349 shader_lib_ctx.max_wg_size = WEBGPU_MAX_WG_SIZE;
1350
1351 webgpu_pipeline pipeline = ctx->shader_lib->get_get_rows_pipeline(shader_lib_ctx);
1352 auto * decisions = static_cast<ggml_webgpu_generic_shader_decisions *>(pipeline.context.get());
1353
1354 std::vector<uint32_t> params = { (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src) / ggml_type_size(src->type)),
1355 (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, idx) / ggml_type_size(idx->type)),
1356 (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, dst) / ggml_type_size(dst->type)),
1357 (uint32_t) (src->nb[1] / ggml_type_size(src->type)),
1358 (uint32_t) (src->nb[2] / ggml_type_size(src->type)),
1359 (uint32_t) (src->nb[3] / ggml_type_size(src->type)),
1360 (uint32_t) (idx->nb[0] / ggml_type_size(idx->type)),
1361 (uint32_t) (idx->nb[1] / ggml_type_size(idx->type)),
1362 (uint32_t) (idx->nb[2] / ggml_type_size(idx->type)),
1363 (uint32_t) (dst->nb[1] / ggml_type_size(dst->type)),
1364 (uint32_t) (dst->nb[2] / ggml_type_size(dst->type)),
1365 (uint32_t) (dst->nb[3] / ggml_type_size(dst->type)),
1366 (uint32_t) dst->ne[0],
1367 (uint32_t) dst->ne[1],
1368 (uint32_t) dst->ne[2],
1369 (uint32_t) dst->ne[3],
1370 (uint32_t) (idx->ne[1]),
1371 (uint32_t) (idx->ne[2]) };
1372
1373 std::vector<wgpu::BindGroupEntry> entries = { ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src),
1374 ggml_webgpu_make_tensor_bind_group_entry(ctx, 1, idx),
1375 ggml_webgpu_make_tensor_bind_group_entry(ctx, 2, dst) };
1376
1377 uint32_t blocks_per_row = (uint32_t) (dst->ne[0] / (src->type == GGML_TYPE_F32 && dst->ne[0] % 4 == 0 ? 4 : 1));
1378 uint32_t total_rows = (uint32_t) (dst->ne[1] * dst->ne[2] * dst->ne[3]);
1379 uint32_t total_threads = float_parallel ? blocks_per_row * total_rows : total_rows;
1380 uint32_t wg_x = CEIL_DIV(total_threads, decisions->wg_size);
1381
1382 return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x);
1383}
1384
1385static webgpu_encoded_op ggml_webgpu_mul_mat(webgpu_context & ctx,
1386 ggml_tensor * src0,

Callers 1

ggml_webgpu_encodeFunction · 0.85

Calls 6

ggml_type_sizeFunction · 0.85
get_get_rows_pipelineMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected