Skip to content

Conversation

@abhijitramesh
Copy link
Contributor

This PR incorporates the following changes for the webGPU backend:

  • Binary operators are now JIT compiled.
  • Generates shaders to handle overlapping regions of buffers to multiple bind group entries for binary operators

* Add binary.wgsl: unified shader with conditionals for all 4 ops

* Add gen_binary_shaders.cpp: build tool for using pre_wgsl preprocessor

* Remove bin_op.tmpl.wgsl and binary.wgsl (Python template)

* Update CMake to generate binary operator shaders at build time
* port binary operators from AOT to pre-wgsl JIT compilation

* add src1=dst overlap handling for binary ops

* use compile-time workgroup size defines instead of runtime overrides
* add support for inplace & overlap case in binding setup

* restructure conditional logic to handle all overlap cases

* ensure all buffer bindings are correctly assigned for edge cases
@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Feb 4, 2026
#if defined(INPLACE) && defined(OVERLAP)

fn update(dst_i: u32, src0_i: u32, src1_i: u32) {
#ifdef OP_ADD
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a way to avoid the duplication of all these ifdefs for different versions of inplace/overlap. Not sure if what I'm thinking is best macro practice though... something like one statement of

DST[dst_i] = SRC_A[src0_i] OP SRC_B[src1_i]

where DST, SRC_A, SRC_B, and OP are all defined based on the type.

Also, are all the combinations of src0/src1/dst necessary right now?

int type;
int op;
bool inplace;
bool overlap;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this name be more descriptive, since we have multiple types of overlap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants