elementWiseMultiply3DGPU function

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

Appends the commands for element wise multiplication of two Tensor3Ds a and b to tape. Creates and allocates a Tensor to store the results.

Implementation

GPUTensor<Tensor3D> elementWiseMultiply3DGPU(
    GPUTensor<Tensor3D> a, GPUTensor<Tensor3D> b, CommandBuffer tape,
    {GPUTensor<Tensor3D>? outTensor}) {
  int depth = a.shape[0];
  int height = a.shape[1];
  int width = a.shape[2];

  GPUTensor<Tensor3D> out =
      outTensor ?? GPUTensor<Tensor3D>.empty([depth, height, width]);

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

  out.creator = GPUNode(
    [a, b],
    (CommandBuffer bTape) {
      bTape.putInt(OP_MULTIPLY_BACKWARD);
      bTape.putString(out.gradId);
      bTape.putString(b.id);
      bTape.putString(a.gradId);

      bTape.putInt(OP_MULTIPLY_BACKWARD);
      bTape.putString(out.gradId);
      bTape.putString(a.id);
      bTape.putString(b.gradId);
    },
    opName: 'multiply_3dGPU',
    cost: depth * height * width,
  );

  return out;
}