Search code examples
c++cudaconvolutioncudnn

How to compute a 'full' convolution with NVIDIA cuDNN?


I'm testing the NVIDIA cuDNN library on simple problems. I'm trying to achieve something that I thought would be simple, doing a 'full' convolution. I have been able to compute a 'valid' convolution with the forward algorithm without too much problems, but I'm unable to do the same with the backward algorithm for the 'full' convolution.

I've prepared the tensors for my input, kernel and convolution and tried:

cudnnConvolutionBackwardData(handle.get(),
    alpha, //Set to 1.0
    filter, //Filter descriptor
    kernel_gpu_memory,
    input_tensor, //The input tensor descriptor
    input_gpu_memory,
    convolution, //The convolution descriptor
    conv_algo, //Obtained with getConvolutionBackwardDataAlgorithm
    workspace_cpu_memory, 
    workspace_size, //Obtained with getConvolutionBackwardDataWorkspaceSize
    beta, //Set to 0.0
    output_tensor, //The output tensor descriptor
    conv_gpu_memory);

I have checked the return of all CUDA calls and I have no errors, but the result are not the results of the correct 'full' convolution. I'm comparing the obtained results with the 'full' convolution of matlab.

I guess that this does not do what I'm expecting. Should I try the convolutionBackwardFilter algorithm ?

How can I perform a 'full' convolution with cudnn ?


Solution

  • I got it. By default, they consider that the weights have been flipped before the operation. Therefore, it must be configured as a CUDNN_CROSS_CORRELATION instead of a CUDNN_CONVOLUTION.