(device: GPUDevice,
program: webgpu_program.WebGPUProgram)
| 70 | // Reshape dispatch, not to exceed device limits. |
| 71 | const 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 | |
| 99 | export class WebGPUBackend extends KernelBackend { |
| 100 | bufferManager: BufferManager; |
no test coverage detected
searching dependent graphs…