geluGPU function
GPUTensor<Vector>
geluGPU(
- GPUTensor<
Vector> v, - CommandBuffer tape, {
- GPUTensor<
Vector> ? outTensor,
Appends commands for applying the gelu activation function on every element of vector v to tape.
Implementation
GPUTensor<Vector> geluGPU(GPUTensor<Vector> v, CommandBuffer tape,
{GPUTensor<Vector>? outTensor}) {
int n = v.shape[0];
List<double> zeros = <double>[];
for (int i = 0; i < n; i = i + 1) {
zeros.add(0.0);
}
GPUTensor<Vector> out = outTensor ?? GPUTensor<Vector>(zeros);
tape.putInt(OP_GELU_FORWARD);
tape.putString(v.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[v],
(CommandBuffer bTape) {
bTape.putInt(OP_GELU_BACKWARD);
bTape.putString(v.id);
bTape.putString(out.gradId);
bTape.putString(v.gradId);
},
opName: 'geluGPU',
cost: n,
);
return out;
}