MCPcopy Index your code
hub / github.com/tensorflow/tfjs / reshapeDispatch

Function reshapeDispatch

tfjs-backend-webgpu/src/backend_webgpu.ts:72–97  ·  view source on GitHub ↗
(device: GPUDevice,
     program: webgpu_program.WebGPUProgram)

Source from the content-addressed store, hash-verified

70// Reshape dispatch, not to exceed device limits.
71const reshapeDispatch =
72 (device: GPUDevice,
73 program: webgpu_program.WebGPUProgram): [number, number, number] => {
74 const MAX_COMPUTE_PER_DIMENSION_DISPATCH_SIZE =
75 device.limits.maxComputeWorkgroupsPerDimension;
76 const layout = program['dispatchLayout'];
77 const dispatch = program['dispatch'];
78 if (dispatch.every((d) => d <= MAX_COMPUTE_PER_DIMENSION_DISPATCH_SIZE)) {
79 return dispatch;
80 }
81
82 util.assert(
83 dispatch[0] > MAX_COMPUTE_PER_DIMENSION_DISPATCH_SIZE &&
84 layout.y === undefined && layout.z === undefined,
85 () => 'Dispatch size exceeds WebGPU limits in Y or Z dimension.');
86
87 let dispatchAverage = Math.ceil(Math.sqrt(dispatch[0]));
88 if (dispatchAverage > MAX_COMPUTE_PER_DIMENSION_DISPATCH_SIZE) {
89 dispatchAverage = Math.ceil(Math.cbrt(dispatch[0]));
90 util.assert(
91 dispatchAverage <= MAX_COMPUTE_PER_DIMENSION_DISPATCH_SIZE,
92 () => 'Total dispatch size exceeds WebGPU maximum.');
93 return [dispatchAverage, dispatchAverage, dispatchAverage];
94 } else {
95 return [dispatchAverage, dispatchAverage, 1];
96 }
97 };
98
99export class WebGPUBackend extends KernelBackend {
100 bufferManager: BufferManager;

Callers 1

runWebGPUProgramMethod · 0.85

Calls 2

ceilMethod · 0.80
sqrtMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…