def setUp(self): ndim = self.ndim dtype = self.dtype batches = 2 in_channels_a_group = 3 out_channels_a_group = 2 in_channels = in_channels_a_group * self.groups out_channels = out_channels_a_group * self.groups ksize = 3 stride = 2 pad = ksize // stride * self.dilate self.strides = (stride,) * ndim self.pads = (pad,) * ndim self.dilations = (self.dilate,) * ndim self.x = cupy.zeros( (batches, in_channels) + (ksize,) * ndim, dtype) self.gy = cupy.zeros((batches, out_channels) + (2,) * ndim, dtype) self.gW = cupy.ones( (out_channels, in_channels_a_group) + (ksize,) * ndim, dtype) version = libcudnn.getVersion() deterministic = self.deterministic self.err = None if ((self.dilate > 1 and version < 6000) or (self.groups > 1 and version < 7000)): self.err = ValueError elif ((self.dilate > 1 and deterministic and version < 7000) or (ndim > 2 and deterministic and version < 6000) or (ndim > 2 and deterministic and self.dtype == numpy.float64)): self.err = libcudnn.CuDNNError self._workspace_size = cudnn.get_max_workspace_size() cudnn.set_max_workspace_size(self.max_workspace_size)
def setUp(self): self.layout = libcudnn.CUDNN_TENSOR_NHWC n = 16 x_c, y_c = 64, 64 x_h, x_w = 32, 32 y_h, y_w = x_h // self.stride, x_w // self.stride self.pad = (self.ksize - 1) // 2 if self.layout == libcudnn.CUDNN_TENSOR_NHWC: x_shape = (n, x_h, x_w, x_c) y_shape = (n, y_h, y_w, y_c) W_shape = (y_c, self.ksize, self.ksize, x_c) else: x_shape = (n, x_c, x_h, x_w) y_shape = (n, y_c, y_h, y_w) W_shape = (y_c, x_c, self.ksize, self.ksize) self.x = cupy.ones(x_shape, dtype=self.dtype) self.W = cupy.ones(W_shape, dtype=self.dtype) self.y = cupy.empty(y_shape, dtype=self.dtype) self.gx = cupy.empty(x_shape, dtype=self.dtype) self.gW = cupy.empty(W_shape, dtype=self.dtype) self.gy = cupy.ones(y_shape, dtype=self.dtype) _workspace_size = cudnn.get_max_workspace_size() cudnn.set_max_workspace_size(0) yield cudnn.set_max_workspace_size(_workspace_size)
def set_max_workspace_size(size): """Sets the workspace size for cuDNN. Check "cuDNN Library User Guide" for detail. Args: size: The workspace size for cuDNN. """ # To avoid error on no cuDNN environment if cudnn_enabled: cudnn.set_max_workspace_size(size)
def setUp(self): ndim = self.ndim dtype = self.dtype batches = 2 in_channels_a_group = 3 out_channels_a_group = 2 in_channels = in_channels_a_group * self.groups out_channels = out_channels_a_group * self.groups # TODO(anaruse): increase test cases. ksize = 3 stride = 2 pad = ksize // stride * self.dilate self.strides = (stride, ) * ndim self.pads = (pad, ) * ndim self.dilations = (self.dilate, ) * ndim self.W = cupy.zeros( (out_channels, in_channels_a_group) + (ksize, ) * ndim, dtype) self.gy = cupy.zeros((batches, out_channels) + (2, ) * ndim, dtype) self.b = None if self.bias: self.b = cupy.zeros((in_channels, ), dtype) self.gx = cupy.ones((batches, in_channels) + (ksize, ) * ndim, dtype) version = libcudnn.getVersion() deterministic = self.deterministic self.err = None if ((self.dilate > 1 and version < 6000) or (self.groups > 1 and version < 7000)): self.err = ValueError elif (sys.platform.startswith('win32') and version == 7605 and deterministic and self.dtype == numpy.float16 and self.ndim == 3 and self.dilate == 2 and self.groups == 2): # see https://github.com/cupy/cupy/pull/4893 self.err = RuntimeError elif deterministic and ( (self.dilate > 1 and (ndim != 2 and version < 8100 or version < 7300)) or (ndim > 2 and version < 6000) or (ndim > 2 and self.dtype == numpy.float64 and version < 8100)): self.err = libcudnn.CuDNNError elif (8000 <= version < 8100 and int(cupy.cuda.device.get_compute_capability()) < 70 and self.dilate > 1 and self.groups > 1 and ndim > 2 and self.dtype == numpy.float16): self.err = RuntimeError _workspace_size = cudnn.get_max_workspace_size() cudnn.set_max_workspace_size(self.max_workspace_size) yield cudnn.set_max_workspace_size(_workspace_size)
def setUp(self): ndim = self.ndim dtype = self.dtype batches = 2 if self.layout == libcudnn.CUDNN_TENSOR_NHWC: # channel size must be multiple of 4 in_channels_a_group = 4 out_channels_a_group = 4 else: in_channels_a_group = 3 out_channels_a_group = 2 in_channels = in_channels_a_group * self.groups out_channels = out_channels_a_group * self.groups # TODO(anaruse): increase test cases. ksize = 3 stride = 2 pad = ksize // stride * self.dilate self.strides = (stride, ) * ndim self.pads = (pad, ) * ndim self.dilations = (self.dilate, ) * ndim if self.layout == libcudnn.CUDNN_TENSOR_NHWC: self.x = cupy.zeros( (batches, ) + (ksize, ) * ndim + (in_channels, ), dtype) self.W = cupy.zeros( (out_channels, ) + (ksize, ) * ndim + (in_channels_a_group, ), dtype) self.y = cupy.ones((batches, ) + (2, ) * ndim + (out_channels, ), dtype) else: self.x = cupy.zeros((batches, in_channels) + (ksize, ) * ndim, dtype) self.W = cupy.zeros( (out_channels, in_channels_a_group) + (ksize, ) * ndim, dtype) self.y = cupy.ones((batches, out_channels) + (2, ) * ndim, dtype) self.b = None if self.bias: self.b = cupy.zeros((out_channels, ), dtype) version = libcudnn.getVersion() self.err = None if ((self.dilate > 1 and version < 6000) or (self.groups > 1 and version < 7000)): self.err = ValueError elif ndim > 2 and self.dilate > 1: self.err = libcudnn.CuDNNError _workspace_size = cudnn.get_max_workspace_size() cudnn.set_max_workspace_size(self.max_workspace_size) yield cudnn.set_max_workspace_size(_workspace_size)
def setUp(self): ndim = self.ndim dtype = self.dtype batches = 2 in_channels_a_group = 3 out_channels_a_group = 2 in_channels = in_channels_a_group * self.groups out_channels = out_channels_a_group * self.groups # TODO(anaruse): increase test cases. ksize = 3 stride = 2 pad = ksize // stride * self.dilate self.strides = (stride,) * ndim self.pads = (pad,) * ndim self.dilations = (self.dilate,) * ndim self.W = cupy.zeros( (out_channels, in_channels_a_group) + (ksize,) * ndim, dtype) self.gy = cupy.zeros((batches, out_channels) + (2,) * ndim, dtype) self.b = None if self.bias: self.b = cupy.zeros((in_channels,), dtype) self.gx = cupy.ones( (batches, in_channels) + (ksize,) * ndim, dtype) version = libcudnn.getVersion() deterministic = self.deterministic self.err = None if ((self.dilate > 1 and version < 6000) or (self.groups > 1 and version < 7000)): self.err = ValueError elif deterministic and ( (self.dilate > 1 and (ndim != 2 or version < 7300)) or (ndim > 2 and version < 6000) or (ndim > 2 and self.dtype == numpy.float64)): self.err = libcudnn.CuDNNError elif (8000 <= version and int(cupy.cuda.device.get_compute_capability()) < 70 and self.dilate > 1 and self.groups > 1 and ndim > 2 and self.dtype == numpy.float16): self.err = RuntimeError self._workspace_size = cudnn.get_max_workspace_size() cudnn.set_max_workspace_size(self.max_workspace_size)
def tearDown(self): cudnn.set_max_workspace_size(self._workspace_size)