The pooling layer has two features. First, its output size is different compared to the convolution layer and cuDNN provides the corresponding API for this. Second, it does not have any internal weights.
To specify the pooling operation, we can use cuDNN's cudnnPoolingDescriptor_t function and create and specify the cuDNN's pooling descriptor in the class constructor, as follows:
cudnnCreatePoolingDescriptor(&pool_desc_);
cudnnSetPooling2dDescriptor(pool_desc_, mode_, CUDNN_PROPAGATE_NAN,
kernel_size_, kernel_size_, padding_, padding_, stride_, stride_);
Now, let's implement the forward and backward operation of the pooling layer.