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

Function transpose

tfjs-backend-webgpu/src/kernels/Transpose.ts:26–53  ·  view source on GitHub ↗
(args: {
  inputs: TransposeInputs,
  attrs: TransposeAttrs,
  backend: WebGPUBackend
})

Source from the content-addressed store, hash-verified

24import {TransposeProgram} from '../transpose_webgpu';
25
26export 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
55export const transposeConfig: KernelConfig = {
56 kernelName: Transpose,

Callers 7

reduceFunction · 0.90
argMaxFunction · 0.90
cumImplFunction · 0.90
unsortedSegmentSumFunction · 0.90
batchToSpaceNDFunction · 0.90
argMinFunction · 0.90
einsumFunction · 0.90

Calls 4

runWebGPUProgramMethod · 0.80
shouldExecuteOnCPUMethod · 0.45
getMethod · 0.45
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…