sumReduceColumnsGPU function
GPUTensor<Vector>
sumReduceColumnsGPU(
- GPUTensor<
Matrix> m, - CommandBuffer tape, {
- GPUTensor<
Vector> ? outTensor,
Sums all matrix elements of m via their column order returning the sum of each column as a vector.
The operation is appended to tape for execution.
Implementation
GPUTensor<Vector> sumReduceColumnsGPU(GPUTensor<Matrix> m, CommandBuffer tape,
{GPUTensor<Vector>? outTensor}) {
int cols = m.shape[1];
List<int> outShape = <int>[cols];
GPUTensor<Vector> out = outTensor ?? GPUTensor<Vector>.empty(outShape);
tape.putInt(OP_SUM_REDUCE_COLUMNS);
tape.putString(m.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[m],
(CommandBuffer bTape) {
// The backward pass of reducing columns is broadcasting the gradient back
bTape.putInt(OP_BROADCAST_ADD);
bTape.putString(m.gradId);
bTape.putString(out.gradId);
bTape.putString(m.gradId);
},
opName: 'sumReduceColumnsGPU',
);
return out;
}