addScalar3DGPU function

GPUTensor<Tensor3D> addScalar3DGPU(
  1. GPUTensor<Tensor3D> t,
  2. double scalar,
  3. CommandBuffer tape, {
  4. GPUTensor<Tensor3D>? outTensor,
})

Appends a command for adding a scalar scalar to every element of a Tensor3D v to tape.

Implementation

GPUTensor<Tensor3D> addScalar3DGPU(
    GPUTensor<Tensor3D> t, double scalar, CommandBuffer tape,
    {GPUTensor<Tensor3D>? outTensor}) {
  int depth = t.shape[0];
  int height = t.shape[1];
  int width = t.shape[2];
  GPUTensor<Tensor3D> out =
      outTensor ?? GPUTensor<Tensor3D>.empty(<int>[depth, height, width]);

  tape.putInt(OP_ADD_SCALAR);
  tape.putString(t.id);
  tape.putString(out.id);
  tape.putFloat(scalar);

  out.creator = GPUNode(
    <GPUTensor>[t],
    (CommandBuffer bTape) {
      bTape.putInt(OP_ADD_INTO);
      bTape.putString(out.gradId);
      bTape.putString(t.gradId);
    },
    opName: 'addScalar3DGPU',
    cost: depth * height * width,
  );

  return out;
}