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

Function createBinaryKernelConfig

tfjs-backend-wasm/src/kernels/binary_kernel.ts:24–73  ·  view source on GitHub ↗
(
    kernelName: string, supportsFullBroadcast: boolean,
    dtype?: DataType)

Source from the content-addressed store, hash-verified

22import {CppDType} from './types';
23
24export function createBinaryKernelConfig(
25 kernelName: string, supportsFullBroadcast: boolean,
26 dtype?: DataType): KernelConfig {
27 let wasmFunc:
28 (aId: number, aShape: Uint8Array, aShapeLen: number, bId: number,
29 bShape: Uint8Array, bShapeLen: number, dtype: number, outId: number) =>
30 void;
31
32 function setupFunc(backend: BackendWasm): void {
33 wasmFunc = backend.wasm.cwrap(kernelName, null /* void */, [
34 'number', // a_id,
35 'array', // a_shape
36 'number', // a_shape.length
37 'number', // b_id
38 'array', // b_shape
39 'number', // b_shape.length
40 'number', // dtype
41 'number' // out_id
42 ]);
43 }
44
45 function kernelFunc(args: {backend: BackendWasm, inputs: BinaryInputs}):
46 TensorInfo {
47 const {backend, inputs} = args;
48 const {a, b} = inputs;
49 const aId = backend.dataIdMap.get(a.dataId).id;
50 const bId = backend.dataIdMap.get(b.dataId).id;
51
52 const outputType = dtype != null ? dtype : a.dtype;
53 const newShape = backend_util.assertAndGetBroadcastShape(a.shape, b.shape);
54 const out = backend.makeOutput(newShape, outputType);
55
56 // Short-circuit zero-sized tensors.
57 if (util.sizeFromShape(newShape) === 0) {
58 return out;
59 }
60
61 const aShapeBytes = new Uint8Array(new Int32Array(a.shape).buffer);
62 const bShapeBytes = new Uint8Array(new Int32Array(b.shape).buffer);
63 const outId = backend.dataIdMap.get(out.dataId).id;
64 const kernelFunc = () => wasmFunc(
65 aId, aShapeBytes, a.shape.length, bId, bShapeBytes, b.shape.length,
66 CppDType[a.dtype], outId);
67
68 kernelFunc();
69 return out;
70 }
71
72 return {kernelName, backendName: 'wasm', setupFunc, kernelFunc};
73}

Callers 15

Atan2.tsFile · 0.90
LogicalAnd.tsFile · 0.90
Greater.tsFile · 0.90
BitwiseAnd.tsFile · 0.90
LogicalXor.tsFile · 0.90
Pow.tsFile · 0.90
Less.tsFile · 0.90
Equal.tsFile · 0.90
Multiply.tsFile · 0.90
Mod.tsFile · 0.90
Maximum.tsFile · 0.90
Add.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…