elementWiseMultiplyGPU function
Appends the commands for element wise multiplication of two vectors a and b to tape.
Creates and allocates a Tensor to store the results.
Implementation
GPUTensor<Vector> elementWiseMultiplyGPU(
GPUTensor<Vector> a, GPUTensor<Vector> b, CommandBuffer tape,
{GPUTensor<Vector>? outTensor}) {
GPUTensor<Vector> out =
outTensor ?? GPUTensor<Vector>(List<double>.filled(a.shape[0], 0.0));
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: 'elementWiseMultiplyGPU',
cost: 1,
);
return out;
}