MCPcopy Create free account
hub / github.com/tensorflow/tfjs / kernelFunc

Function kernelFunc

tfjs-backend-wasm/src/kernels/argminmax_kernel.ts:40–78  ·  view source on GitHub ↗
(args: {
    backend: BackendWasm,
    inputs: ArgMinInputs&ArgMaxInputs,
    attrs: ArgMinAttrs&ArgMaxAttrs,
  })

Source from the content-addressed store, hash-verified

38 }
39
40 function kernelFunc(args: {
41 backend: BackendWasm,
42 inputs: ArgMinInputs&ArgMaxInputs,
43 attrs: ArgMinAttrs&ArgMaxAttrs,
44 }): TensorInfo {
45 const {backend, inputs, attrs} = args;
46 const {axis} = attrs;
47 const {x} = inputs;
48 const xId = backend.dataIdMap.get(x.dataId).id;
49 let inputId = xId;
50 let input = x;
51
52 const {transposed, axes, inputWasTransposed} =
53 permuteAxesAndTranspose(x, axis, backend);
54
55 if (inputWasTransposed) {
56 const transposedId = backend.dataIdMap.get(transposed.dataId).id;
57 if (transposedId !== xId) {
58 // transpose was not a no-op. We will need to dispose of this
59 // once we are done.
60 input = transposed;
61 inputId = transposedId;
62 }
63 }
64
65 const outShape = input.shape.slice(0, -1);
66 const out = backend.makeOutput(outShape, 'int32');
67 const outId = backend.dataIdMap.get(out.dataId).id;
68 const outerSize = util.sizeFromShape(out.shape);
69 const innerSize = input.shape[axes[0]];
70 wasmFunc(inputId, CppDType[input.dtype], outerSize, innerSize, outId);
71
72 if (inputWasTransposed) {
73 // dispose of the transposed tensor.
74 backend.disposeData(transposed.dataId);
75 }
76
77 return out;
78 }
79
80 return {
81 kernelName,

Callers

nothing calls this directly

Calls 5

permuteAxesAndTransposeFunction · 0.90
sliceMethod · 0.65
disposeDataMethod · 0.65
getMethod · 0.45
makeOutputMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…