addBiasToFeatureMapGPU function
Appends commands for broadcast additions of a matrix wrapped scalar b to a full matrix m.
Implementation
GPUTensor<Matrix> addBiasToFeatureMapGPU(
GPUTensor<Matrix> m, GPUTensor<Matrix> b, CommandBuffer tape,
{GPUTensor<Matrix>? outTensor}) {
int rows = m.shape[0];
int cols = m.shape[1];
List<int> shape = <int>[rows, cols];
GPUTensor<Matrix> out = outTensor ?? 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.gradId);
bTape.putString(m.gradId);
bTape.putInt(OP_SUM_REDUCE);
bTape.putString(out.gradId);
bTape.putString(b.gradId);
},
opName: 'addBiasToFeatureMapGPU',
cost: rows * cols,
);
return out;
}