| 767 | } |
| 768 | |
| 769 | static webgpu_encoded_op ggml_webgpu_set(webgpu_context & ctx, |
| 770 | ggml_tensor * src0, |
| 771 | ggml_tensor * src1, |
| 772 | ggml_tensor * dst) { |
| 773 | const bool inplace = ggml_webgpu_tensor_equal(src0, dst); |
| 774 | |
| 775 | ggml_webgpu_shader_lib_context shader_lib_ctx = {}; |
| 776 | shader_lib_ctx.src0 = src0; |
| 777 | shader_lib_ctx.src1 = src1; |
| 778 | shader_lib_ctx.dst = dst; |
| 779 | shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup; |
| 780 | shader_lib_ctx.inplace = inplace; |
| 781 | |
| 782 | webgpu_pipeline pipeline = ctx->shader_lib->get_set_pipeline(shader_lib_ctx); |
| 783 | |
| 784 | auto * decisions = static_cast<ggml_webgpu_generic_shader_decisions *>(pipeline.context.get()); |
| 785 | |
| 786 | const uint32_t ne = inplace ? (uint32_t) ggml_nelements(src1) : (uint32_t) ggml_nelements(dst); |
| 787 | const uint32_t dst_type_size = (uint32_t) ggml_type_size(dst->type); |
| 788 | |
| 789 | std::vector<uint32_t> params = { |
| 790 | ne, |
| 791 | (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src0) / ggml_type_size(src0->type)), |
| 792 | (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, src1) / ggml_type_size(src1->type)), |
| 793 | (uint32_t) (((const int32_t *) dst->op_params)[3] / dst_type_size), |
| 794 | |
| 795 | (uint32_t) (src1->nb[0] / ggml_type_size(src1->type)), |
| 796 | (uint32_t) (src1->nb[1] / ggml_type_size(src1->type)), |
| 797 | (uint32_t) (src1->nb[2] / ggml_type_size(src1->type)), |
| 798 | (uint32_t) (src1->nb[3] / ggml_type_size(src1->type)), |
| 799 | |
| 800 | 1u, |
| 801 | (uint32_t) (((const int32_t *) dst->op_params)[0] / dst_type_size), |
| 802 | (uint32_t) (((const int32_t *) dst->op_params)[1] / dst_type_size), |
| 803 | (uint32_t) (((const int32_t *) dst->op_params)[2] / dst_type_size), |
| 804 | |
| 805 | (uint32_t) src1->ne[0], |
| 806 | (uint32_t) src1->ne[1], |
| 807 | (uint32_t) src1->ne[2], |
| 808 | (uint32_t) src1->ne[3], |
| 809 | }; |
| 810 | |
| 811 | std::vector<wgpu::BindGroupEntry> entries; |
| 812 | uint32_t binding_index = 0; |
| 813 | if (!inplace) { |
| 814 | entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src0)); |
| 815 | binding_index++; |
| 816 | } |
| 817 | entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding_index, src1)); |
| 818 | entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding_index + 1, dst)); |
| 819 | |
| 820 | uint32_t wg_x = CEIL_DIV(ne, decisions->wg_size); |
| 821 | return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x); |
| 822 | } |
| 823 | |
| 824 | static webgpu_encoded_op ggml_webgpu_pad(webgpu_context & ctx, ggml_tensor * src, ggml_tensor * dst) { |
| 825 | ggml_webgpu_shader_lib_context shader_lib_ctx = {}; |
no test coverage detected