@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
54 lines (53 loc) • 1.74 kB
JavaScript
import { defaultAllocator } from '../../../tensor/gpu/gl';
import { getSize } from '../../../util/shape';
import { Operation } from './../operation';
export class BinaryOperation extends Operation {
constructor(tensorConstructor, dtype, allocator) {
super(tensorConstructor, dtype, allocator);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getFragmentShader(info) {
return `
float process(int[${this.maxRank}] index) {
return ${this.getOp('_A(index)', '_B(index)')};
}
${this.getDefaultMain()}
`;
}
getOutputShape(input) {
return input.outputShape;
}
getTextureNames() {
return ['A', 'B'];
}
calc(input) {
return this.compute(input.outputShape, { A: input.A, B: input.B });
}
compile(info) {
if (info.shapeA !== undefined) {
this.maxRank = info.shapeA.length;
}
if (info.shapeB !== undefined) {
this.maxRank = info.shapeB.length;
}
super.compile(info);
}
getCompilationInfo(input) {
const outputSize = defaultAllocator.getAllocationDimensions(getSize(input.outputShape), this.dtype);
return {
shapeA: input.A.shape,
widthA: input.A.memory.width,
heightA: input.A.memory.height,
shapeB: input.B.shape,
widthB: input.B.memory.width,
heightB: input.B.memory.height,
shapeOutput: input.outputShape,
widthOutput: outputSize.width,
heightOutput: outputSize.height,
};
}
getInputInfoString(input) {
return `${input.A.shape}-${input.B.shape}`;
}
}
//# sourceMappingURL=binaryOperation.js.map