sigmoid3DGPU function
GPUTensor<Tensor3D>
sigmoid3DGPU(
- GPUTensor<
Tensor3D> t, - CommandBuffer tape, {
- GPUTensor<
Tensor3D> ? outTensor,
Appends commands for applying the sigmoid function on every element of Tensor3D t to tape.
Implementation
GPUTensor<Tensor3D> sigmoid3DGPU(GPUTensor<Tensor3D> t, CommandBuffer tape,
{GPUTensor<Tensor3D>? outTensor}) {
int depth = t.shape[0];
int height = t.shape[1];
int width = t.shape[2];
List<List<List<double>>> zeros = <List<List<double>>>[];
for (int c = 0; c < depth; c = c + 1) {
List<List<double>> channel = <List<double>>[];
for (int h = 0; h < height; h = h + 1) {
List<double> row = <double>[];
for (int w = 0; w < width; w = w + 1) {
row.add(0.0);
}
channel.add(row);
}
zeros.add(channel);
}
GPUTensor<Tensor3D> out = outTensor ?? GPUTensor<Tensor3D>(zeros);
tape.putInt(OP_SIGMOID);
tape.putString(t.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[t],
(CommandBuffer bTape) {
bTape.putInt(OP_SIGMOID_BACKWARD);
bTape.putString(out.id);
bTape.putString(out.gradId);
bTape.putString(t.gradId);
},
opName: 'sigmoid_3dGPU',
cost: depth * height * width,
);
return out;
}