geluMatrixGPU function

GPUTensor<Matrix> geluMatrixGPU(
  1. GPUTensor<Matrix> m,
  2. CommandBuffer tape
)

Implementation

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

  List<List<double>> zeros = <List<double>>[];
  for (int i = 0; i < numRows; i = i + 1) {
    List<double> row = <double>[];
    for (int j = 0; j < numCols; j = j + 1) {
      row.add(0.0);
    }
    zeros.add(row);
  }

  GPUTensor<Matrix> out = GPUTensor<Matrix>(zeros);

  tape.putInt(OP_GELU_FORWARD);
  tape.putString(m.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    <GPUTensor>[m],
        (CommandBuffer bTape) {
      bTape.putInt(OP_GELU_BACKWARD);
      bTape.putString(m.id);
      bTape.putString('${out.id}_grad');
      bTape.putString('${m.id}_grad');
    },
    opName: 'gelu_matrixGPU',
    cost: numRows * numCols,
  );

  return out;
}