(args: {
inputs: TransposeInputs,
attrs: TransposeAttrs,
backend: WebGPUBackend
})
| 24 | import {TransposeProgram} from '../transpose_webgpu'; |
| 25 | |
| 26 | export function transpose(args: { |
| 27 | inputs: TransposeInputs, |
| 28 | attrs: TransposeAttrs, |
| 29 | backend: WebGPUBackend |
| 30 | }) { |
| 31 | const {inputs, backend, attrs} = args; |
| 32 | const {x} = inputs; |
| 33 | const {perm} = attrs; |
| 34 | const webgpuBackend = backend; |
| 35 | |
| 36 | const xRank = x.shape.length; |
| 37 | const newShape: number[] = new Array(xRank); |
| 38 | for (let i = 0; i < newShape.length; i++) { |
| 39 | newShape[i] = x.shape[perm[i]]; |
| 40 | } |
| 41 | if (backend.shouldExecuteOnCPU([x])) { |
| 42 | const xData = webgpuBackend.tensorMap.get(x.dataId); |
| 43 | const values = xData.values as TypedArray; |
| 44 | const outValues = cpuTranspose(values, x.shape, x.dtype, perm, newShape); |
| 45 | return backend.makeTensorInfo(newShape, x.dtype, outValues); |
| 46 | } |
| 47 | if (x.shape.length === 2 && util.arraysEqual(perm, [1, 0])) { |
| 48 | const program = new TransposeSharedProgram(x.shape, perm); |
| 49 | return webgpuBackend.runWebGPUProgram(program, [x], x.dtype); |
| 50 | } |
| 51 | const program = new TransposeProgram(x.shape, perm); |
| 52 | return webgpuBackend.runWebGPUProgram(program, [x], x.dtype); |
| 53 | } |
| 54 | |
| 55 | export const transposeConfig: KernelConfig = { |
| 56 | kernelName: Transpose, |
no test coverage detected
searching dependent graphs…