maxPool1dGPU function
Slides a pool of size poolSize over vector input. The resulting vector consists of the maximum elements in each window.
The value of stride tells how big the step size of the sliding window is.
The operations are appended to tape for execution.
Implementation
GPUTensor<Vector> maxPool1dGPU(
GPUTensor<Vector> input, int poolSize, int stride, CommandBuffer tape,
{GPUTensor<Vector>? outTensor, GPUTensor<Vector>? indicesTensor}) {
int inputSize = input.shape[0];
int outputSize = (inputSize - poolSize) ~/ stride + 1;
GPUTensor<Vector> out =
outTensor ?? GPUTensor<Vector>(List<double>.filled(outputSize, 0.0));
GPUTensor<Vector> indices =
indicesTensor ?? GPUTensor<Vector>(List<double>.filled(outputSize, 0.0));
out.subMap["indices"] = indices;
tape.putInt(OP_MAX_POOL_1D_FORWARD);
tape.putString(input.id);
tape.putString(out.id);
tape.putString(indices.id);
tape.putInt(poolSize);
tape.putInt(stride);
out.creator = GPUNode(
[input],
(CommandBuffer bTape) {
bTape.putInt(OP_MAX_POOL_1D_BACKWARD);
bTape.putString(out.gradId);
bTape.putString(indices.id);
bTape.putString(input.gradId);
},
opName: 'maxPool1dGPU',
cost: inputSize,
);
return out;
}