globalAveragePoolingGPU function
GPUTensor<Vector>
globalAveragePoolingGPU(
- GPUTensor<
Matrix> input, - CommandBuffer tape, {
- GPUTensor<
Vector> ? outTensor,
Collapses a matrix input to a vector of their average values of their feature columns.
The operations are appended to tape for execution.
Implementation
GPUTensor<Vector> globalAveragePoolingGPU(
GPUTensor<Matrix> input, CommandBuffer tape,
{GPUTensor<Vector>? outTensor}) {
//int sequenceLength = input.shape[0];
int dModel = input.shape[1];
List<int> outShape = <int>[dModel];
GPUTensor<Vector> out = outTensor ?? GPUTensor<Vector>.empty(outShape);
tape.putInt(OP_GLOBAL_AVG_POOL_FORWARD);
tape.putString(input.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[input],
(CommandBuffer backwardTape) {
backwardTape.putInt(OP_GLOBAL_AVG_POOL_BACKWARD);
backwardTape.putString(out.gradId);
backwardTape.putString(input.gradId);
},
opName: 'global_avg_pool_gpu',
);
return out;
}