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

Function ggml_webgpu_binary_op

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

Source from the content-addressed store, hash-verified

2073}
2074
2075static webgpu_encoded_op ggml_webgpu_binary_op(webgpu_context & ctx,
2076 ggml_tensor * src0,
2077 ggml_tensor * src1,
2078 ggml_tensor * dst) {
2079 ggml_webgpu_shader_lib_context shader_lib_ctx = {};
2080 shader_lib_ctx.src0 = src0;
2081 shader_lib_ctx.src1 = src1;
2082 shader_lib_ctx.dst = dst;
2083 shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;
2084
2085 webgpu_pipeline pipeline = ctx->shader_lib->get_binary_pipeline(shader_lib_ctx);
2086 auto * decisions = static_cast<ggml_webgpu_binary_shader_decisions *>(pipeline.context.get());
2087
2088 uint32_t ne = (uint32_t) ggml_nelements(dst);
2089
2090 size_t src0_webgpu_tensor_align_offset = ggml_webgpu_tensor_align_offset(ctx, src0);
2091 size_t src1_webgpu_tensor_align_offset = ggml_webgpu_tensor_align_offset(ctx, src1);
2092
2093 uint32_t offset_src0 = (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src0) / ggml_type_size(src0->type));
2094 uint32_t offset_src1 = (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src1) / ggml_type_size(src1->type));
2095 size_t merged_offset = 0;
2096 size_t merged_size = 0;
2097 if (decisions->src_overlap) {
2098 const ggml_webgpu_merged_binding_range merged_range =
2099 ggml_webgpu_tensor_merged_binding_range(ctx, { src0, src1 });
2100 merged_offset = merged_range.offset;
2101 merged_size = merged_range.size;
2102 offset_src0 = ggml_webgpu_tensor_merged_element_offset(src0, merged_range);
2103 offset_src1 = ggml_webgpu_tensor_merged_element_offset(src1, merged_range);
2104 }
2105
2106 std::vector<uint32_t> params = {
2107 ne,
2108 offset_src0,
2109 offset_src1,
2110 (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, dst) / ggml_type_size(dst->type)),
2111 (uint32_t) (src0->nb[0] / ggml_type_size(src0->type)),
2112 (uint32_t) (src0->nb[1] / ggml_type_size(src0->type)),
2113 (uint32_t) (src0->nb[2] / ggml_type_size(src0->type)),
2114 (uint32_t) (src0->nb[3] / ggml_type_size(src0->type)),
2115 (uint32_t) (src1->nb[0] / ggml_type_size(src1->type)),
2116 (uint32_t) (src1->nb[1] / ggml_type_size(src1->type)),
2117 (uint32_t) (src1->nb[2] / ggml_type_size(src1->type)),
2118 (uint32_t) (src1->nb[3] / ggml_type_size(src1->type)),
2119 (uint32_t) src0->ne[0],
2120 (uint32_t) src0->ne[1],
2121 (uint32_t) src0->ne[2],
2122 (uint32_t) src1->ne[0],
2123 (uint32_t) src1->ne[1],
2124 (uint32_t) src1->ne[2],
2125 (uint32_t) src1->ne[3],
2126 };
2127
2128 std::vector<wgpu::BindGroupEntry> entries;
2129
2130 if (decisions->src_overlap) {
2131 entries.push_back(
2132 ggml_webgpu_make_bind_group_entry(0, ggml_webgpu_tensor_buf(src0), merged_offset, merged_size));

Callers 1

ggml_webgpu_encodeFunction · 0.85

Tested by

no test coverage detected