Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ${define_active_storage_type("buffer")}

layout(std430) buffer;

#include "dispatch.glslh"
#include "indexing.glslh"
#include "convert.glslh"
#include "reduce_op_defs.glslh"
Expand Down Expand Up @@ -59,13 +60,17 @@ $if OUTPUT_IS_INDICES:
#define OUTPUT_IS_INDICES

void main() {
const uint out_idx = gl_GlobalInvocationID.y;
// The linear dispatch may launch idle workgroups past the last row.
const uint out_idx = linear_idx_from_gid();
if (out_idx >= numel(outp)) {
return;
}
const TensorIndex out_tidx = contiguous_idx_to_tensor_idx(outp, out_idx);
const uint out_bufi = tensor_idx_to_linear_idx(outp, out_tidx);

// Local indices
const uint worker_id = gl_LocalInvocationID.x;
const uint output_id = gl_LocalInvocationID.y;
const uint worker_id = gl_LocalInvocationID.z;
const uint output_id = 0;

const uint in_bufi_base = out_idx * stride_at(inp, 1);

Expand Down
13 changes: 9 additions & 4 deletions backends/vulkan/runtime/graph/ops/impl/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,16 @@ GlobalWorkGrid reduce_per_row_gwg(
(void)shader;
(void)resize_args;

// One workgroup per output row, with 64 cooperating workers along z. The
// linear dispatch wraps into x/y when the row count exceeds a device limit.
const ValueRef out = args.at(0).refs.at(0);
return GlobalWorkGrid(
{1u, utils::safe_downcast<uint32_t>(graph->numel_of(out)), 1u},
kTiledWorkGrid,
LocalWorkGroup(64u, 1u, 1u));
const LocalWorkGroup lwg(1u, 1u, 64u);
GlobalWorkGrid gwg(
{utils::safe_downcast<uint32_t>(graph->numel_of(out)), 1u, 1u},
kLinearWorkGrid);
gwg.wrap_linear_dispatch(
graph->context()->adapter_ptr()->max_compute_workgroup_count(), lwg);
return gwg;
}

void add_reduce_per_row_node(
Expand Down
2 changes: 2 additions & 0 deletions backends/vulkan/test/op_tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,8 @@ def get_reduce_per_row_inputs():
((3, 7, 280), -1, False),
((3, 17, 77), -1, True),
((3, 17, 77), -1, False),
# More rows than the usual 65535 y-workgroup limit
((70000, 8), -1, False),
]
return inputs

Expand Down