subtract3DGPU function
Appends the commands for subtraction of two Tensor3Ds a and b of type T to tape.
Creates and allocates a Tensor to store the results.
Implementation
GPUTensor<Tensor3D> subtract3DGPU(
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];
List<int> shape = <int>[depth, height, width];
GPUTensor<Tensor3D> out = outTensor ?? GPUTensor<Tensor3D>.empty(shape);
tape.putInt(OP_SUBTRACT);
tape.putString(a.id);
tape.putString(b.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[a, b],
(CommandBuffer bTape) {
bTape.putInt(OP_ADD_INTO);
bTape.putString(out.gradId);
bTape.putString(a.gradId);
bTape.putInt(OP_SUBTRACT_INTO);
bTape.putString(out.gradId);
bTape.putString(b.gradId);
},
opName: 'subtract3DGPU',
cost: depth * height * width,
);
return out;
}