Repository: chainer/chainer

Issue:
CUDNN_STATUS_BAD_PARAM raised when number of channels in data is invalid in Convolution2D
I'm trying to build a CNN on Chainer.
It seems that Cudnn is not installed correctly, but I can run Tensorflow, Keras and Pytorch successfully on my PC, while failing to run Chainer with Cupy.
I tried all kinds of way from  [Cupy Installation Guide](https://docs-cupy.chainer.org/en/stable/install.html?highlight=cudnn#installation-guide), but failed with same mistake.
Can anybody solve this issue? Thanks!
- Conditions
Chainer version 4.5.0
CuPy version 4.5.0
OS/Platform Ubantu 16.04
CUDA/cuDNN version 8.0.61/5.1.10

Code
```
class MODEL(chainer.Chain):

    def __init__(self):
        super(MODEL, self).__init__()
        with self.init_scope():
            self.first=chainer.links.Convolution2D(5, 64, ksize=5, stride=1, pad=2)

    def __call__(self, x: chainer.Variable, test=False):
        x0 = self.first(x)
        return x0
```
Error Log
```
Traceback (most recent call last):
  File "main.py", line 207, in <module>
    train()
  File "main.py", line 140, in train
    sr = generator(lr)
  File "main.py", line 86, in __call__
    x0 = self.first(x)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/links/connection/convolution_2d.py", line 175, in __call__
    groups=self.groups)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/functions/connection/convolution_2d.py", line 582, in convolution_2d
    y, = fnode.apply(args)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/function_node.py", line 258, in apply
    outputs = self.forward(in_data)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/function_node.py", line 367, in forward
    return self.forward_gpu(inputs)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/functions/connection/convolution_2d.py", line 161, in forward_gpu
    return self._forward_cudnn(x, W, b, y)
  File "/root/anaconda3/envs/tf/lib/python3.6/site-packages/chainer/functions/connection/convolution_2d.py", line 234, in _forward_cudnn
    auto_tune=auto_tune, tensor_core=tensor_core)
  File "cupy/cudnn.pyx", line 820, in cupy.cudnn.convolution_forward
  File "cupy/cudnn.pyx", line 590, in cupy.cudnn._get_algorithm_fwd
  File "cupy/cuda/cudnn.pyx", line 807, in cupy.cuda.cudnn.getConvolutionForwardAlgorithm_v6
  File "cupy/cuda/cudnn.pyx", line 514, in cupy.cuda.cudnn.check_status
cupy.cuda.cudnn.CuDNNError: CUDNN_STATUS_BAD_PARAM
```


Discussion:
@psychopa4 Could you provide the code giving an actual input to your `MODEL` object? We need more information. And could you put the result of this following command?
```
$ !python -c "import chainer; chainer.print_runtime_info()"
```
Also discussing on https://github.com/cupy/cupy/issues/1691
> @psychopa4 Could you provide the code giving an actual input to your `MODEL` object? We need more information. And could you put the result of this following command?
> 
> ```
> $ !python -c "import chainer; chainer.print_runtime_info()"
> ```
I have changed my cuda and cudnn version to 9.0 and 7.0.4, but still got same mistake.
Should I reinstall cudnn to 7.3?
```
Platform: Linux-4.15.0-30-generic-x86_64-with-debian-stretch-sid
Chainer: 4.5.0
NumPy: 1.13.1
CuPy:
  CuPy Version          : 4.5.0
  CUDA Root             : /usr/local/cuda-9.0
  CUDA Build Version    : 9000
  CUDA Driver Version   : 9010
  CUDA Runtime Version  : 9000
  cuDNN Build Version   : 7300
  cuDNN Version         : 7004
  NCCL Build Version    : 2213
```

The code to generate data is as follows:
```
class ImageDataset(dataset_mixin.DatasetMixin):
    def __init__(self, paths, in_size=32, scale=4):
        self.paths=sorted(glob.glob(join(paths,'*.png')))
        self.in_size=in_size
        self.scale=scale
        self.out_size=in_size*scale

    def __len__(self):
        return len(self.paths)

    def get_example(self, i): #-> Image:
        path = self.paths[i]
        #HR = Image.open(path)
        HR = scipy.misc.imread(path)
        HR = randomcrop(HR, size=self.out_size)

        h,w,c=HR.shape
        hr=Image.fromarray(HR)
        lr=hr.resize((h//self.scale,w//self.scale),Image.BICUBIC)

        LR=np.asarray(lr)
        LR=np.transpose(LR,(2,0,1))
        HR=np.transpose(HR,(2,0,1))
        return LR.astype(np.float32), HR.astype(np.float32)
```
In general, it returns low-resolution (LR) and corresponding high-resolution (HR) images.
During training, the input x is a tensor with shape like [batch_size, channels, height, width ] ( [16,3,32,32]  for  instance).
Thank you for your enthusiasm!

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
@@ -54,8 +54,7 @@ def check_type_forward(self, in_types):
             w_type.dtype.kind == 'f',
             x_type.ndim == 4,
             w_type.ndim == 4,
-            # Need to consider the case that group count > 1.
-            # x_type.shape[1] == w_type.shape[1],
+            x_type.shape[1] == w_type.shape[1] * self.groups,
         )
 
         if type_check.eval(n_in) == 3:


Test patch: