@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
54 lines (53 loc) • 1.65 kB
JavaScript
import { defaultAllocator } from '../../../tensor/gpu/gl';
import { getSize } from '../../../util/shape';
import { Operation } from '../operation';
export class CopyOperation extends Operation {
constructor(tensorConstructor, dtype, allocator) {
super(tensorConstructor, dtype, allocator);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getFragmentShader(info) {
return `
void main() {
initVars();
gl_FragColor = texture2D(X, uv);
}
`;
}
getTextureNames() {
return ['X'];
}
calc(input) {
const shape = this.getOutputShape(input);
return this.compute(shape, { X: input.input });
}
getOutputShape(input) {
let shape = input.outputShape;
if (shape === undefined) {
shape = input.input.shape;
}
return shape;
}
compile(info) {
if (info.shapeX !== undefined) {
this.maxRank = info.shapeX.length;
}
super.compile(info);
}
getCompilationInfo(input) {
const outputShape = this.getOutputShape(input);
const outputSize = defaultAllocator.getAllocationDimensions(getSize(outputShape), this.dtype);
return {
shapeX: input.input.shape,
widthX: input.input.memory.width,
heightX: input.input.memory.height,
shapeOutput: outputShape,
widthOutput: outputSize.width,
heightOutput: outputSize.height,
};
}
getInputInfoString(input) {
return `${input.input}-${this.getOutputShape(input)}`;
}
}
//# sourceMappingURL=copy.js.map