addScalarMatrixGPU function
GPUTensor<Matrix>
addScalarMatrixGPU(
- GPUTensor<
Matrix> m, - GPUTensor<
Scalar> b, - CommandBuffer tape
Implementation
GPUTensor<Matrix> addScalarMatrixGPU(GPUTensor<Matrix> m, GPUTensor<Scalar> b, CommandBuffer tape) {
int rows = m.shape[0];
int cols = m.shape[1];
List<int> shape = <int>[rows, cols];
GPUTensor<Matrix> out = GPUTensor<Matrix>.empty(shape);
tape.putInt(OP_BROADCAST_ADD);
tape.putString(m.id);
tape.putString(b.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[m, b],
(CommandBuffer bTape) {
bTape.putInt(OP_ADD_INTO);
bTape.putString('${out.id}_grad');
bTape.putString('${m.id}_grad');
bTape.putInt(OP_SUM_REDUCE);
bTape.putString('${out.id}_grad');
bTape.putString('${b.id}_grad');
},
opName: 'addScalarToMatrixGPU',
cost: rows * cols,
);
return out;
}