broadcastAddVectorToMatrixGPU function
Appends commands for addition of a 1D bias vector b to a 2D matrix m via broadcasting over the matrix to the tape.
This command is inference only! No gradient path is calculated.
Implementation
GPUTensor<Matrix> broadcastAddVectorToMatrixGPU(
GPUTensor<Matrix> m, GPUTensor<Vector> v, CommandBuffer tape,
{GPUTensor<Matrix>? outTensor}) {
GPUTensor<Matrix> out = outTensor ?? GPUTensor<Matrix>.empty(m.shape);
tape.putInt(OP_BROADCAST_ADD);
tape.putString(m.id);
tape.putString(v.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[m, v],
(CommandBuffer bTape) {
// Backward pass logic (stubbed for inference)
},
opName: 'broadcastAddVectorToMatrixGPU',
cost: m.shape[0] * m.shape[1],
);
return out;
}