divideGPU<T> function

GPUTensor<T> divideGPU<T>(
  1. GPUTensor<T> a,
  2. GPUTensor<T> b,
  3. CommandBuffer tape, {
  4. GPUTensor<T>? outTensor,
})

Appends the commands for element wise division of two GPUTensors a through b of type T to tape. Creates and allocates a Tensor to store the results.

Implementation

GPUTensor<T> divideGPU<T>(GPUTensor<T> a, GPUTensor<T> b, CommandBuffer tape,
    {GPUTensor<T>? outTensor}) {
  // Correctly inherit shape to pre-allocate VRAM
  GPUTensor<T> out = outTensor ?? GPUTensor<T>.empty(a.shape);

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

  out.creator = GPUNode(
    <GPUTensor>[a, b],
    (CommandBuffer bTape) {
      bTape.putInt(OP_DIVIDE_BACKWARD);
      bTape.putString(a.id);
      bTape.putString(b.id);
      bTape.putString(out.gradId);
      bTape.putString(a.gradId);
      bTape.putString(b.gradId);
    },
    opName: 'divideGPU',
  );

  return out;
}