Repository: chainer/chainer

Issue:
chainer not compatible with cudnn-7.0-linux-x64-v4.0
Running `python setup.py build` in master branch of e99cf1594c5bc70825bd156f6684a37ef6ffe0c5 results in following error, when `cudnn-7.0-linux-x64-v4.0` is in path.

The same commit successfully builds with `cudnn-6.5-linux-x64-v2` .

```
cupy/cuda/cudnn.cpp:4926:398: error: cannot convert ‘void*’ to ‘cudnnConvolutionBwdFilterAlgo_t’ for argument ‘8’ to ‘cudnnStatus_t cudnnConvolutionBackwardFilter(cudnnHandle_t, const void*, cudnnTensorDescriptor_t, const void*, cudnnTensorDescriptor_t, const void*, cudnnConvolutionDescriptor_t, cudnnConvolutionBwdFilterAlgo_t, void*, size_t, const void*, cudnnFilterDescriptor_t, void*)’

   __pyx_v_status = cudnnConvolutionBackwardFilter(((cudnnHandle_t)__pyx_v_handle), ((void *)__pyx_v_alpha), ((cudnnTensorDescriptor_t)__pyx_v_srcDesc), ((void *)__pyx_v_srcData), ((cudnnTensorDescriptor_t)__pyx_v_diffDesc), ((void *)__pyx_v_diffData), ((cudnnConvolutionDescriptor_t)__pyx_v_convDesc), ((void *)__pyx_v_beta), ((cudnnFilterDescriptor_t)__pyx_v_gradDesc), ((void *)__pyx_v_gradData));

                                                                                                                                                                                                                                                                                                                                                                                                              ^

cupy/cuda/cudnn.cpp: In function ‘PyObject* __pyx_f_4cupy_4cuda_5cudnn_convolutionBackwardData(size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, int)’:

cupy/cuda/cudnn.cpp:5145:402: error: cannot convert ‘void*’ to ‘cudnnConvolutionBwdDataAlgo_t’ for argument ‘8’ to ‘cudnnStatus_t cudnnConvolutionBackwardData(cudnnHandle_t, const void*, cudnnFilterDescriptor_t, const void*, cudnnTensorDescriptor_t, const void*, cudnnConvolutionDescriptor_t, cudnnConvolutionBwdDataAlgo_t, void*, size_t, const void*, cudnnTensorDescriptor_t, void*)’

   __pyx_v_status = cudnnConvolutionBackwardData(((cudnnHandle_t)__pyx_v_handle), ((void *)__pyx_v_alpha), ((cudnnFilterDescriptor_t)__pyx_v_filterDesc), ((void *)__pyx_v_filterData), ((cudnnTensorDescriptor_t)__pyx_v_diffDesc), ((void *)__pyx_v_diffData), ((cudnnConvolutionDescriptor_t)__pyx_v_convDesc), ((void *)__pyx_v_beta), ((cudnnTensorDescriptor_t)__pyx_v_gradDesc), ((void *)__pyx_v_gradData));

                                                                                                                                                                                                                                                                                                                                                                                                                  ^

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_ubuntu/chainer/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-KqXMta-record/install-record.txt --single-version-externally-managed --compile --user failed with error code 1 in /tmp/pip_build_ubuntu/chainer
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 235, in main
    return command.main(cmd_args)
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 42: ordinal not in range(128)
```



Discussion:

Resolving patch:
diff --git a/chainer/functions/connection/convolution_2d.py b/chainer/functions/connection/convolution_2d.py
--- a/chainer/functions/connection/convolution_2d.py
+++ b/chainer/functions/connection/convolution_2d.py
@@ -103,7 +103,7 @@ def forward_gpu(self, inputs):
 
             # TODO(beam2d): Support unshared bias
             if b is not None:
-                libcudnn.addTensor(
+                libcudnn.addTensor_v2(
                     handle, libcudnn.CUDNN_ADD_SAME_C, one.data,
                     self.bias_desc.value, b.data.ptr, one.data,
                     y_desc.value, y.data.ptr)
@@ -158,13 +158,13 @@ def backward_gpu(self, inputs, grad_outputs):
             one = numpy.array(1, dtype=dtype).ctypes
             zero = numpy.array(0, dtype=dtype).ctypes
 
-            libcudnn.convolutionBackwardFilter(
+            libcudnn.convolutionBackwardFilter_v2(
                 handle, one.data, x_desc.value, x.data.ptr,
                 gy_desc.value, gy.data.ptr, self.conv_desc.value,
                 zero.data, self.filter_desc.value, gW.data.ptr)
 
             gx = cuda.cupy.empty_like(x)
-            libcudnn.convolutionBackwardData(
+            libcudnn.convolutionBackwardData_v2(
                 handle, one.data, self.filter_desc.value, W.data.ptr,
                 gy_desc.value, gy.data.ptr, self.conv_desc.value,
                 zero.data, x_desc.value, gx.data.ptr)
diff --git a/chainer/functions/connection/deconvolution_2d.py b/chainer/functions/connection/deconvolution_2d.py
--- a/chainer/functions/connection/deconvolution_2d.py
+++ b/chainer/functions/connection/deconvolution_2d.py
@@ -110,12 +110,12 @@ def forward_gpu(self, inputs):
             one = numpy.array(1, dtype=x.dtype).ctypes
             zero = numpy.array(0, dtype=x.dtype).ctypes
 
-            libcudnn.convolutionBackwardData(
+            libcudnn.convolutionBackwardData_v2(
                 handle, one.data, self.filter_desc.value, W.data.ptr,
                 x_desc.value, x.data.ptr, self.conv_desc.value,
                 zero.data, y_desc.value, y.data.ptr)
             if len(inputs) == 3:
-                libcudnn.addTensor(
+                libcudnn.addTensor_v2(
                     handle, libcudnn.CUDNN_ADD_SAME_C,
                     one.data, self.bias_desc.value, b.data.ptr,
                     one.data, y_desc.value, y.data.ptr)
@@ -191,7 +191,7 @@ def backward_gpu(self, inputs, grad_outputs):
                     zero.data, self.bias_desc.value, gb.data.ptr)
             gW = cuda.cupy.empty_like(W)
             # filter backward
-            libcudnn.convolutionBackwardFilter(
+            libcudnn.convolutionBackwardFilter_v2(
                 handle, one.data, gy_desc.value, gy.data.ptr,
                 gx_desc.value, x.data.ptr, self.conv_desc.value,
                 zero.data, self.filter_desc.value, gW.data.ptr)
diff --git a/cupy/cudnn.py b/cupy/cudnn.py
--- a/cupy/cudnn.py
+++ b/cupy/cudnn.py
@@ -98,7 +98,7 @@ def create_convolution_descriptor(pad, stride,
         c_pad = _to_ctypes_array(pad)
         c_stride = _to_ctypes_array(stride)
         c_upscale = _to_ctypes_array((1,) * ndim)
-        cudnn.setConvolutionNdDescriptor(
+        cudnn.setConvolutionNdDescriptor_v2(
             desc.value, ndim, c_pad.data, c_stride.data, c_upscale.data, mode)
 
     return desc


Test patch: