Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7128414
[ExecuTorch][WebGPU] Port flip
JCNTH Jul 24, 2026
6094958
[ExecuTorch][WebGPU] Op-tests for flip
JCNTH Jul 24, 2026
97de6f4
[ExecuTorch][WebGPU] Port repeat
JCNTH Jul 24, 2026
a1e6920
[ExecuTorch][WebGPU] Op-tests for repeat
JCNTH Jul 24, 2026
eabb9c6
[ExecuTorch][WebGPU] Op-test framework: multi-output goldens
JCNTH Jul 24, 2026
6783f65
[ExecuTorch][WebGPU] Port index_select
JCNTH Jul 24, 2026
c09adb9
[ExecuTorch][WebGPU] Op-tests for index_select
JCNTH Jul 24, 2026
7c59a92
[ExecuTorch][WebGPU] Port native_group_norm
JCNTH Jul 24, 2026
c78474d
[ExecuTorch][WebGPU] Op-tests for native_group_norm
JCNTH Jul 24, 2026
ca380c7
[ExecuTorch][WebGPU] Port avg_pool2d
JCNTH Jul 24, 2026
032d9f7
[ExecuTorch][WebGPU] Op-tests for avg_pool2d
JCNTH Jul 24, 2026
bc07065
[ExecuTorch][WebGPU] Port pixel_shuffle
JCNTH Jul 24, 2026
7811f5c
[ExecuTorch][WebGPU] Op-tests for pixel_shuffle
JCNTH Jul 24, 2026
04bfe86
[ExecuTorch][WebGPU] Port grid_sampler_2d
JCNTH Jul 24, 2026
65c0ca1
[ExecuTorch][WebGPU] Op-tests for grid_sampler_2d
JCNTH Jul 24, 2026
f80e1ab
[ExecuTorch][WebGPU] Port aten.convolution (depthwise conv1d)
JCNTH Jul 24, 2026
6ca4a32
[ExecuTorch][WebGPU] Op-tests for conv1d_dw (depthwise conv1d)
JCNTH Jul 24, 2026
8554649
[ExecuTorch][WebGPU] Port conv1d pointwise (aten.convolution)
JCNTH Jul 24, 2026
c23f986
[ExecuTorch][WebGPU] Op-tests for conv1d pointwise
JCNTH Jul 24, 2026
90da37a
[ExecuTorch][WebGPU] Add apply_rotary_emb_interleaved op
JCNTH Jul 24, 2026
3ff3ad2
[ExecuTorch][WebGPU] Test apply_rotary_emb_interleaved
JCNTH Jul 24, 2026
b015425
[ExecuTorch][WebGPU] Add quantize_per_tensor op (int8 buffer path)
JCNTH Jul 24, 2026
0bed7d8
[ExecuTorch][WebGPU] Add dequantize_per_tensor op (int8 buffer path)
JCNTH Jul 24, 2026
7d5dabf
[ExecuTorch][WebGPU] Op-test harness: int8-output golden support
JCNTH Jul 24, 2026
2934be5
[ExecuTorch][WebGPU] Op-tests for quantize/dequantize_per_tensor
JCNTH Jul 24, 2026
8486963
[ExecuTorch][WebGPU] Add q8ta_add op (int8 elementwise add)
JCNTH Jul 24, 2026
7d9d780
[ExecuTorch][WebGPU] Op-tests for q8ta_add
JCNTH Jul 24, 2026
11846f8
[ExecuTorch][WebGPU] Add q8ta_relu op (int8 relu)
JCNTH Jul 24, 2026
787d484
[ExecuTorch][WebGPU] Op-tests for q8ta_relu
JCNTH Jul 24, 2026
31742cf
[ExecuTorch][WebGPU] Add q8ta_pixel_shuffle op (int8 pixel_shuffle)
JCNTH Jul 24, 2026
750d6a1
[ExecuTorch][WebGPU] Op-tests for q8ta_pixel_shuffle
JCNTH Jul 24, 2026
dd8fef5
[ExecuTorch][WebGPU] Add q8ta_linear op (int8 quantized linear)
JCNTH Jul 24, 2026
0f4b048
[ExecuTorch][WebGPU] Op-tests for q8ta_linear
JCNTH Jul 24, 2026
e4895f8
[ExecuTorch][WebGPU] Add q8ta_conv2d_pw op (int8 pointwise conv)
JCNTH Jul 24, 2026
cd4607b
[ExecuTorch][WebGPU] Op-tests for q8ta_conv2d_pw
JCNTH Jul 24, 2026
dbb259c
[ExecuTorch][WebGPU] Add q8ta_conv2d_dw op (int8 depthwise conv)
JCNTH Jul 24, 2026
9538365
[ExecuTorch][WebGPU] Op-tests for q8ta_conv2d_dw
JCNTH Jul 24, 2026
a210954
[ExecuTorch][WebGPU] Add q8ta_conv2d op (int8 general conv)
JCNTH Jul 24, 2026
87fba89
[ExecuTorch][WebGPU] Op-tests for q8ta_conv2d
JCNTH Jul 24, 2026
30edbde
[ExecuTorch][WebGPU] Add q8ta_conv2d_transposed op (int8 transposed c…
JCNTH Jul 24, 2026
ce362fd
[ExecuTorch][WebGPU] Op-tests for q8ta_conv2d_transposed
JCNTH Jul 24, 2026
ef2d46b
[ExecuTorch][WebGPU] Add floor_divide op (aten.div.Tensor_mode)
JCNTH Jul 24, 2026
2e3a703
[ExecuTorch][WebGPU] Op-tests for floor_divide
JCNTH Jul 24, 2026
7bd76c5
[ExecuTorch][WebGPU] Add argmax/argmin ops + int64-output path
JCNTH Jul 24, 2026
c19627b
[ExecuTorch][WebGPU] Op-tests for argmax/argmin + int64-golden harness
JCNTH Jul 24, 2026
8affea4
[ExecuTorch][WebGPU] Add linear_qcs4w op (et_vk.linear_qcs4w)
JCNTH Jul 24, 2026
6a3f050
[ExecuTorch][WebGPU] Op-tests for linear_qcs4w
JCNTH Jul 24, 2026
f5c4b9e
[ExecuTorch][WebGPU] Add linear_q8ta_q8csw op (et_vk.linear_q8ta_q8csw)
JCNTH Jul 24, 2026
df5d173
[ExecuTorch][WebGPU] Op-tests for linear_q8ta_q8csw
JCNTH Jul 24, 2026
a6afd1c
[ExecuTorch][WebGPU] Add grid_priors op (et_vk.grid_priors)
JCNTH Jul 24, 2026
a335e38
[ExecuTorch][WebGPU] Op-tests for grid_priors
JCNTH Jul 24, 2026
138cd0f
[ExecuTorch][WebGPU] Add conv_with_clamp op (et_vk.conv_with_clamp)
JCNTH Jul 24, 2026
9bdaf03
[ExecuTorch][WebGPU] Op-tests for conv_with_clamp
JCNTH Jul 24, 2026
c597684
[ExecuTorch][WebGPU] Add comparison ops (aten.eq/lt/le/gt/ge.Tensor -…
JCNTH Jul 24, 2026
a81aa91
[ExecuTorch][WebGPU] Op-tests for comparisons + bool-output golden ha…
JCNTH Jul 24, 2026
713a322
[ExecuTorch][WebGPU] Add logical_and op (aten.logical_and.default)
JCNTH Jul 24, 2026
8fe1f9a
[ExecuTorch][WebGPU] Op-tests for logical_and
JCNTH Jul 24, 2026
64c3a31
[ExecuTorch][WebGPU] Add bitwise_and + bitwise_not ops (bool)
JCNTH Jul 24, 2026
adda2b5
[ExecuTorch][WebGPU] Op-tests for bitwise_and + bitwise_not
JCNTH Jul 24, 2026
081eba9
[ExecuTorch][WebGPU] Optimize reduction-family kernels to cooperative…
JCNTH Jul 24, 2026
7a04217
[ExecuTorch][WebGPU] Add creation/cast ops (full family, scalar_tenso…
JCNTH Jul 24, 2026
518bf87
[ExecuTorch][WebGPU] Enable + golden granular ops (elementwise/bool, …
JCNTH Jul 24, 2026
fb7ae1c
[ExecuTorch][WebGPU] Enable + golden int8 quantized ops (q8ta family …
JCNTH Jul 24, 2026
7c77138
[ExecuTorch][WebGPU] Add linear_dq8ca_q4gsw + choose_qparams_affine (…
JCNTH Jul 24, 2026
30ca7e5
[ExecuTorch][WebGPU] Add bitwise_or + logical_or ops (bool)
JCNTH Jul 24, 2026
6f0bd72
[ExecuTorch][WebGPU] Raise TensorMeta rank cap 4->8 to fix rank>4 ops…
JCNTH Jul 24, 2026
e9d5296
[ExecuTorch][WebGPU] Add dynamic-shape resize hook to cat (output mis…
JCNTH Jul 24, 2026
8b15372
[ExecuTorch][WebGPU] Broadcast add.Tensor (mirror mul) + un-skip 6 mo…
JCNTH Jul 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions backends/test/suite/flows/webgpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@ def _create_webgpu_flow() -> TestFlow:
skip_patterns=[
"float16",
"float64", # Not supported in swiftshader
# WebGPU add is elementwise-only; broadcasting add.Tensor unsupported.
"bcast_first",
"bcast_second",
"hardswish",
"lstm_batch_sizes",
"upsample_nearest2d",
# torchvision models with broadcasting adds; resnet50 covers wide.
"mobilenet_v3_small",
"shufflenet_v2_x1_0",
"resnet50",
"vit_b_16",
"swin_v2_t",
"convnext_small",
],
)

Expand Down
26 changes: 15 additions & 11 deletions backends/webgpu/runtime/WebGPUBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,22 @@ Error WebGPUBackend::execute(
return Error::Internal;
}

// Execute the compute graph
graph->execute();

// Copy outputs from GPU staging buffers to EValue tensor data pointers
std::vector<std::pair<void*, size_t>> outputs;
outputs.reserve(num_outputs);
for (size_t i = 0; i < num_outputs; i++) {
const size_t arg_idx = num_inputs + i;
auto& tensor = args[arg_idx]->toTensor();
outputs.emplace_back(tensor.mutable_data_ptr(), tensor.nbytes());
// Execute + read back; fail loud as a runtime Error so a throw never crosses
// the backend boundary.
try {
graph->execute();
std::vector<std::pair<void*, size_t>> outputs;
outputs.reserve(num_outputs);
for (size_t i = 0; i < num_outputs; i++) {
const size_t arg_idx = num_inputs + i;
auto& tensor = args[arg_idx]->toTensor();
outputs.emplace_back(tensor.mutable_data_ptr(), tensor.nbytes());
}
graph->copy_outputs(outputs);
} catch (const std::exception& e) {
ET_LOG(Error, "WebGPU execute / output copy failed: %s", e.what());
return Error::Internal;
}
graph->copy_outputs(outputs);

return Error::Ok;
}
Expand Down
69 changes: 53 additions & 16 deletions backends/webgpu/runtime/WebGPUGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ void WebGPUGraph::build(
}
tensor.elem_size = vk_datatype_size(vk_tensor->datatype());
tensor.is_int = vk_datatype_is_int(vk_tensor->datatype());
tensor.is_int8 = vk_tensor->datatype() == vkgraph::VkDataType::INT8;
tensor.nbytes = numel * tensor.elem_size;
// Live dims start == max (serialized upper bound); resize_input shrinks
// them per call. Static graphs keep cur == max forever.
Expand Down Expand Up @@ -1902,9 +1903,12 @@ void WebGPUGraph::copy_outputs(std::vector<std::pair<void*, size_t>>& outputs) {

std::vector<MapCallbackData> cb_data(count);
std::vector<WGPUFuture> map_futures(count, WGPUFuture{});
// Map each output's LIVE staging size (an int64 output is int32-backed).
std::vector<size_t> map_nbytes(count, 0);

for (size_t i = 0; i < count; i++) {
if (outputs[i].second == 0) {
map_nbytes[i] = tensors_[output_ids_[i]].cur_nbytes;
if (map_nbytes[i] == 0) {
cb_data[i].status = WGPUMapAsyncStatus_Success;
continue;
}
Expand All @@ -1916,29 +1920,62 @@ void WebGPUGraph::copy_outputs(std::vector<std::pair<void*, size_t>>& outputs) {
output_staging_buffers_[i],
WGPUMapMode_Read,
0,
outputs[i].second,
map_nbytes[i],
cb_info);
}

for (size_t i = 0; i < count; i++) {
if (outputs[i].second != 0 &&
webgpu_wait(instance_, map_futures[i]) != WGPUWaitStatus_Success) {
throw std::runtime_error("WebGPU: WaitAny failed for output map");
}
}
// Tracks which output buffers are currently mapped so a mid-loop throw can
// release them before propagating (no dangling mapped buffers).
std::vector<bool> is_mapped(count, false);

for (size_t i = 0; i < count; i++) {
if (outputs[i].second == 0) {
continue;
try {
for (size_t i = 0; i < count; i++) {
if (map_nbytes[i] == 0) {
continue;
}
if (webgpu_wait(instance_, map_futures[i]) != WGPUWaitStatus_Success) {
throw std::runtime_error("WebGPU: WaitAny failed for output map");
}
if (cb_data[i].status == WGPUMapAsyncStatus_Success) {
is_mapped[i] = true;
}
}
if (cb_data[i].status == WGPUMapAsyncStatus_Success) {

for (size_t i = 0; i < count; i++) {
if (map_nbytes[i] == 0) {
continue;
}
if (cb_data[i].status != WGPUMapAsyncStatus_Success) {
throw std::runtime_error("WebGPU buffer map failed for output");
}
const void* mapped = wgpuBufferGetConstMappedRange(
output_staging_buffers_[i], 0, outputs[i].second);
std::memcpy(outputs[i].first, mapped, outputs[i].second);
output_staging_buffers_[i], 0, map_nbytes[i]);
const size_t dst_nbytes = outputs[i].second;
if (dst_nbytes == map_nbytes[i]) {
std::memcpy(outputs[i].first, mapped, map_nbytes[i]);
} else if (
dst_nbytes == 2 * map_nbytes[i] && tensors_[output_ids_[i]].is_int &&
tensors_[output_ids_[i]].elem_size == 4) {
// int64 host output backed by an int32 GPU buffer: widen (sign-extend).
const int32_t* src = static_cast<const int32_t*>(mapped);
int64_t* dst = static_cast<int64_t*>(outputs[i].first);
const size_t n = map_nbytes[i] / sizeof(int32_t);
for (size_t k = 0; k < n; k++) {
dst[k] = static_cast<int64_t>(src[k]);
}
} else {
throw std::runtime_error("WebGPU: output buffer size mismatch");
}
wgpuBufferUnmap(output_staging_buffers_[i]);
} else {
throw std::runtime_error("WebGPU buffer map failed for output");
is_mapped[i] = false;
}
} catch (...) {
for (size_t j = 0; j < count; j++) {
if (is_mapped[j]) {
wgpuBufferUnmap(output_staging_buffers_[j]);
}
}
throw;
}
}

Expand Down
2 changes: 2 additions & 0 deletions backends/webgpu/runtime/WebGPUGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct WebGPUTensor {
// Serialized (GPU-side) element type, used to narrow wider host inputs.
size_t elem_size = 0;
bool is_int = false;
// Exactly int8 (not uint8/bool), so int8-only ops can guard their dtype.
bool is_int8 = false;
};

// Host-side view of one graph input, passed to copy_inputs.
Expand Down
57 changes: 57 additions & 0 deletions backends/webgpu/runtime/WebGPUUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,63 @@ inline ComputePipelineBundle make_compute_pipeline(
return bundle;
}

// Builds another pipeline + bind group from resources owned by an earlier
// bundle. The binding indices and types must match the shared bind-group
// layout. This preserves shared-shader/layout multi-pipeline construction
// without transferring ownership of those resources to the returned bundle.
inline ComputePipelineBundle make_compute_pipeline(
WGPUDevice device,
const ComputePipelineBundle& shared_resources,
const std::vector<BindingSpec>& bindings,
const WGPUConstantEntry* constants = nullptr,
size_t constant_count = 0,
const char* entry_point = "main") {
if (shared_resources.shader == nullptr ||
shared_resources.bind_group_layout == nullptr ||
shared_resources.pipeline_layout == nullptr) {
throw std::runtime_error(
"make_compute_pipeline: shared resources are not available");
}

ComputePipelineBundle bundle;

std::vector<WGPUBindGroupEntry> bind_entries(bindings.size());
for (size_t i = 0; i < bindings.size(); i++) {
bind_entries[i] = {};
bind_entries[i].binding = bindings[i].binding;
bind_entries[i].buffer = bindings[i].buffer;
bind_entries[i].size = bindings[i].size;
}

WGPUComputePipelineDescriptor pipeline_desc = {};
pipeline_desc.layout = shared_resources.pipeline_layout;
pipeline_desc.compute.module = shared_resources.shader;
pipeline_desc.compute.entryPoint = {entry_point, WGPU_STRLEN};
pipeline_desc.compute.constantCount = constant_count;
pipeline_desc.compute.constants = constants;
WGPUComputePipeline pipeline =
wgpuDeviceCreateComputePipeline(device, &pipeline_desc);
if (pipeline == nullptr) {
throw std::runtime_error(
"make_compute_pipeline: compute pipeline creation failed");
}

WGPUBindGroupDescriptor bg_desc = {};
bg_desc.layout = shared_resources.bind_group_layout;
bg_desc.entryCount = bind_entries.size();
bg_desc.entries = bind_entries.data();
WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup(device, &bg_desc);
if (bind_group == nullptr) {
wgpuComputePipelineRelease(pipeline);
throw std::runtime_error(
"make_compute_pipeline: bind group creation failed");
}

bundle.pipeline = pipeline;
bundle.bind_group = bind_group;
return bundle;
}

// The {wg_size, stride_x} override-constant pair every 2D-spill dispatch
// builds from its DispatchGrid; was hand-rolled identically at 7 call sites.
inline std::array<WGPUConstantEntry, 2> make_grid_constants(
Expand Down
14 changes: 7 additions & 7 deletions backends/webgpu/runtime/ops/TensorMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

namespace executorch::backends::webgpu {

constexpr uint32_t kTensorMetaMaxNdim = 4;
constexpr uint32_t kTensorMetaMaxNdim = 8;

// Per-tensor metadata UBO; mirrors Vulkan BufferMetadata (4-dim NCHW, std140).
// Per-tensor metadata UBO; mirrors Vulkan BufferMetadata (8-dim NCHW, std140).
struct TensorMeta {
uint32_t ndim;
uint32_t numel;
Expand All @@ -28,19 +28,19 @@ struct TensorMeta {
};

static_assert(
sizeof(TensorMeta) == 48,
"TensorMeta std140 layout must be 48 bytes to match the WGSL uniform");
sizeof(TensorMeta) == 80,
"TensorMeta std140 layout must be 80 bytes to match the WGSL uniform");
// Lock the std140 field offsets the WGSL uniform reads, not just total size.
static_assert(offsetof(TensorMeta, ndim) == 0);
static_assert(offsetof(TensorMeta, numel) == 4);
static_assert(offsetof(TensorMeta, sizes) == 16);
static_assert(offsetof(TensorMeta, strides) == 32);
static_assert(offsetof(TensorMeta, strides) == 48);

// Fill TensorMeta from NCHW dims: contiguous strides, padded trailing slots.
inline void fill_tensor_meta(const WebGPUTensor& t, TensorMeta* m) {
const uint32_t ndim = static_cast<uint32_t>(t.dims.size());
if (ndim > kTensorMetaMaxNdim) {
throw std::runtime_error("TensorMeta: tensor rank exceeds 4 (MAX_NDIM)");
throw std::runtime_error("TensorMeta: tensor rank exceeds 8 (MAX_NDIM)");
}
*m = {};
for (uint32_t d = 0; d < kTensorMetaMaxNdim; d++) {
Expand All @@ -67,7 +67,7 @@ inline void fill_tensor_meta_broadcast(
TensorMeta* m) {
const uint32_t rank = static_cast<uint32_t>(t.dims.size());
if (out_ndim > kTensorMetaMaxNdim) {
throw std::runtime_error("TensorMeta: out_ndim exceeds 4 (MAX_NDIM)");
throw std::runtime_error("TensorMeta: out_ndim exceeds 8 (MAX_NDIM)");
}
if (rank > out_ndim) {
throw std::runtime_error("TensorMeta: operand rank exceeds out_ndim");
Expand Down
84 changes: 16 additions & 68 deletions backends/webgpu/runtime/ops/adamw/AdamwStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,78 +97,26 @@ void adamw_step_impl(WebGPUGraph& graph, const std::vector<int>& args) {
utils::make_uniform(device, &params, sizeof(params));
graph.add_uniform_buffer_bytes(sizeof(params));

WGPUShaderSourceWGSL wgsl_desc = {};
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
wgsl_desc.code = {kAdamwStepWGSL, WGPU_STRLEN};
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = &wgsl_desc.chain;
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &shader_desc);

WGPUBindGroupLayoutEntry entries[5] = {};
for (uint32_t i = 0; i <= 2; i++) {
entries[i].binding = i;
entries[i].visibility = WGPUShaderStage_Compute;
entries[i].buffer.type = WGPUBufferBindingType_Storage;
}
entries[3].binding = 3;
entries[3].visibility = WGPUShaderStage_Compute;
entries[3].buffer.type = WGPUBufferBindingType_ReadOnlyStorage;
entries[4].binding = 4;
entries[4].visibility = WGPUShaderStage_Compute;
entries[4].buffer.type = WGPUBufferBindingType_Uniform;

WGPUBindGroupLayoutDescriptor bgl_desc = {};
bgl_desc.entryCount = 5;
bgl_desc.entries = entries;
WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bgl_desc);

WGPUPipelineLayoutDescriptor pl_desc = {};
pl_desc.bindGroupLayoutCount = 1;
pl_desc.bindGroupLayouts = &bgl;
WGPUPipelineLayout pipeline_layout =
wgpuDeviceCreatePipelineLayout(device, &pl_desc);

WGPUConstantEntry wg_size_constant = {};
wg_size_constant.key = {"wg_size", WGPU_STRLEN};
wg_size_constant.value = static_cast<double>(wg_size);

WGPUComputePipelineDescriptor pipeline_desc = {};
pipeline_desc.layout = pipeline_layout;
pipeline_desc.compute.module = shader;
pipeline_desc.compute.entryPoint = {"main", WGPU_STRLEN};
pipeline_desc.compute.constantCount = 1;
pipeline_desc.compute.constants = &wg_size_constant;
WGPUComputePipeline pipeline =
wgpuDeviceCreateComputePipeline(device, &pipeline_desc);

WGPUBindGroupEntry bg_entries[5] = {};
bg_entries[0].binding = 0;
bg_entries[0].buffer = param.buffer;
bg_entries[0].size = param.nbytes;
bg_entries[1].binding = 1;
bg_entries[1].buffer = m.buffer;
bg_entries[1].size = m.nbytes;
bg_entries[2].binding = 2;
bg_entries[2].buffer = v.buffer;
bg_entries[2].size = v.nbytes;
bg_entries[3].binding = 3;
bg_entries[3].buffer = grad.buffer;
bg_entries[3].size = grad.nbytes;
bg_entries[4].binding = 4;
bg_entries[4].buffer = uniform_buffer;
bg_entries[4].size = sizeof(params);

WGPUBindGroupDescriptor bg_desc = {};
bg_desc.layout = bgl;
bg_desc.entryCount = 5;
bg_desc.entries = bg_entries;
WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup(device, &bg_desc);

graph.add_dispatch({pipeline, bind_group, workgroup_count, "adamw_step"});

wgpuShaderModuleRelease(shader);
wgpuBindGroupLayoutRelease(bgl);
wgpuPipelineLayoutRelease(pipeline_layout);
utils::ComputePipelineBundle bundle = utils::make_compute_pipeline(
device,
kAdamwStepWGSL,
{
{0, WGPUBufferBindingType_Storage, param.buffer, param.nbytes},
{1, WGPUBufferBindingType_Storage, m.buffer, m.nbytes},
{2, WGPUBufferBindingType_Storage, v.buffer, v.nbytes},
{3, WGPUBufferBindingType_ReadOnlyStorage, grad.buffer, grad.nbytes},
{4, WGPUBufferBindingType_Uniform, uniform_buffer, sizeof(params)},
},
&wg_size_constant,
1);

graph.add_dispatch(
{bundle.pipeline, bundle.bind_group, workgroup_count, "adamw_step"});

graph.own_uniform_buffer(uniform_buffer);
}

Expand Down
Loading
Loading