| 20 | import {computeDispatch, flatDispatchLayout} from './webgpu_util'; |
| 21 | |
| 22 | export class UnaryOpProgram implements WebGPUProgram { |
| 23 | outputShape: number[]; |
| 24 | shaderKey: string; |
| 25 | dispatchLayout: {x: number[]}; |
| 26 | dispatch: [number, number, number]; |
| 27 | variableNames = ['A']; |
| 28 | workgroupSize: [number, number, number]; |
| 29 | op: UnaryOpType; |
| 30 | uniforms?: string; |
| 31 | size = true; |
| 32 | |
| 33 | constructor(outputShape: number[], op: UnaryOpType, uniforms = '') { |
| 34 | // TODO(jiajia.qin@intel.com): Heuristically select a good work group size. |
| 35 | const workgroupSizeX = 128; |
| 36 | this.workgroupSize = [workgroupSizeX, 1, 1]; |
| 37 | this.outputShape = outputShape; |
| 38 | this.dispatchLayout = flatDispatchLayout(this.outputShape); |
| 39 | this.dispatch = computeDispatch( |
| 40 | this.dispatchLayout, this.outputShape, this.workgroupSize); |
| 41 | this.op = op; |
| 42 | if (uniforms !== '') { |
| 43 | this.uniforms = uniforms; |
| 44 | } |
| 45 | this.shaderKey = `unary_${op}`; |
| 46 | } |
| 47 | |
| 48 | getUserCode(): string { |
| 49 | return ` |
| 50 | fn unaryOperation(a : f32) -> f32 { |
| 51 | ${getUnaryOpString(this.op, false)} |
| 52 | } |
| 53 | ${main('index')} { |
| 54 | if (index < uniforms.size) { |
| 55 | let a = getAByOutputIndex(index); |
| 56 | setOutputAtIndex(index, unaryOperation(a)); |
| 57 | } |
| 58 | } |
| 59 | `; |
| 60 | } |
| 61 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…