mseMatrixGPU function

GPUTensor<Scalar> mseMatrixGPU(
  1. GPUTensor<Matrix> predictions,
  2. GPUTensor<Matrix> targets,
  3. CommandBuffer tape
)

Implementation

GPUTensor<Scalar> mseMatrixGPU(GPUTensor<Matrix> predictions, GPUTensor<Matrix> targets, CommandBuffer tape) {
  int numRows = predictions.shape[0];
  int numCols = predictions.shape[1];

  GPUTensor<Scalar> out = GPUTensor<Scalar>(0.0);

  tape.putInt(OP_MSE_LOSS_FORWARD);
  tape.putString(predictions.id);
  tape.putString(targets.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    [predictions, targets],
        (CommandBuffer bTape) {
      bTape.putInt(OP_MSE_LOSS_BACKWARD);
      bTape.putString('${predictions.id}_grad');
      bTape.putString(predictions.id);
      bTape.putString(targets.id);
      bTape.putString('${out.id}_grad');
    },
    opName: 'mse_matrixGPU',
    cost: 3 * numRows * numCols,
  );

  return out;
}