subtractMatrixGPU function

GPUTensor<Matrix> subtractMatrixGPU(
  1. GPUTensor<Matrix> a,
  2. GPUTensor<Matrix> b,
  3. CommandBuffer tape
)

Implementation

GPUTensor<Matrix> subtractMatrixGPU(GPUTensor<Matrix> a, GPUTensor<Matrix> b, CommandBuffer tape) {
  int numRows = a.shape[0];
  int numCols = a.shape[1];
  List<int> shape = <int>[numRows, numCols];
  GPUTensor<Matrix> out = GPUTensor<Matrix>.empty(shape);

  tape.putInt(OP_SUBTRACT);
  tape.putString(a.id);
  tape.putString(b.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    <GPUTensor>[a, b],
        (CommandBuffer bTape) {
      bTape.putInt(OP_ADD_INTO);
      bTape.putString('${out.id}_grad');
      bTape.putString('${a.id}_grad');

      bTape.putInt(OP_SUBTRACT_INTO);
      bTape.putString('${out.id}_grad');
      bTape.putString('${b.id}_grad');
    },
    opName: 'subtractMatrixGPU',
    cost: numRows * numCols,
  );

  return out;
}