addMatrixAndVectorGPU function

GPUTensor<Matrix> addMatrixAndVectorGPU(
  1. GPUTensor<Matrix> m,
  2. GPUTensor<Vector> v,
  3. CommandBuffer tape
)

Implementation

GPUTensor<Matrix> addMatrixAndVectorGPU(GPUTensor<Matrix> m, GPUTensor<Vector> v, CommandBuffer tape) {
  int numRows = m.shape[0];
  int numCols = m.shape[1];

  GPUTensor<Matrix> out = GPUTensor<Matrix>.empty(<int>[numRows, numCols]);

  tape.putInt(OP_BROADCAST_ADD);
  tape.putString(m.id);
  tape.putString(v.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    [m, v],
        (CommandBuffer bTape) {
      bTape.putInt(OP_ADD_INTO);
      bTape.putString('${out.id}_grad');
      bTape.putString('${m.id}_grad');

      bTape.putInt(OP_SUM_REDUCE_COLUMNS);
      bTape.putString('${out.id}_grad');
      bTape.putString('${v.id}_grad');
    },
    opName: 'addMatrixAndVectorGPU',
    cost: numRows * numCols,
  );

  return out;
}