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

Function ggml_webgpu_set

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

Source from the content-addressed store, hash-verified

741}
742
743static webgpu_encoded_op ggml_webgpu_set(webgpu_context & ctx,
744 ggml_tensor * src0,
745 ggml_tensor * src1,
746 ggml_tensor * dst) {
747 ggml_webgpu_shader_lib_context shader_lib_ctx = {};
748 shader_lib_ctx.src0 = src0;
749 shader_lib_ctx.src1 = src1;
750 shader_lib_ctx.dst = dst;
751 shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;
752
753 webgpu_pipeline pipeline = ctx->shader_lib->get_set_pipeline(shader_lib_ctx);
754
755 auto * decisions = static_cast<ggml_webgpu_generic_shader_decisions *>(pipeline.context.get());
756 const bool inplace = decisions->inplace;
757
758 const uint32_t ne = inplace ? (uint32_t) ggml_nelements(src1) : (uint32_t) ggml_nelements(dst);
759 const uint32_t dst_type_size = (uint32_t) ggml_type_size(dst->type);
760
761 std::vector<uint32_t> params = {
762 ne,
763 (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src0) / ggml_type_size(src0->type)),
764 (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src1) / ggml_type_size(src1->type)),
765 (uint32_t) (((const int32_t *) dst->op_params)[3] / dst_type_size),
766
767 (uint32_t) (src1->nb[0] / ggml_type_size(src1->type)),
768 (uint32_t) (src1->nb[1] / ggml_type_size(src1->type)),
769 (uint32_t) (src1->nb[2] / ggml_type_size(src1->type)),
770 (uint32_t) (src1->nb[3] / ggml_type_size(src1->type)),
771
772 1u,
773 (uint32_t) (((const int32_t *) dst->op_params)[0] / dst_type_size),
774 (uint32_t) (((const int32_t *) dst->op_params)[1] / dst_type_size),
775 (uint32_t) (((const int32_t *) dst->op_params)[2] / dst_type_size),
776
777 (uint32_t) src1->ne[0],
778 (uint32_t) src1->ne[1],
779 (uint32_t) src1->ne[2],
780 (uint32_t) src1->ne[3],
781 };
782
783 std::vector<wgpu::BindGroupEntry> entries;
784 uint32_t binding_index = 0;
785 if (!inplace) {
786 entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src0));
787 binding_index++;
788 }
789 entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding_index, src1));
790 entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding_index + 1, dst));
791
792 uint32_t wg_x = CEIL_DIV(ne, decisions->wg_size);
793 return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x);
794}
795
796static webgpu_encoded_op ggml_webgpu_pad(webgpu_context & ctx, ggml_tensor * src, ggml_tensor * dst) {
797 ggml_webgpu_shader_lib_context shader_lib_ctx = {};

Callers 1

ggml_webgpu_encodeFunction · 0.85

Calls 7

ggml_nelementsFunction · 0.85
ggml_type_sizeFunction · 0.85
get_set_pipelineMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected