Fix by review
@@ -10,6 +10,7 @@ from cupy.core import internal
from cupy import cuda
from cupy.cuda import cudnn
from cupy.cuda import device
+from cupy.cuda import memory
_cudnn_version = cudnn.getVersion()
@@ -345,16 +346,16 @@ class DropoutStates(object):
def __init__(self, handle, seed):
state_size = cudnn.dropoutGetStatesSize(handle)
- self.states = cupy.empty((state_size,), dtype='b')
- self.desc = create_dropout_descriptor(
- handle, 0., self.states.data.ptr,
- self.states.size, seed)
+ self._states = memory.alloc(state_size)
+ self._desc = create_dropout_descriptor(
+ handle, 0., self._states.ptr,
+ state_size, seed)
def forward(self, handle, x, dropout_ratio):
if not isinstance(x, cupy.ndarray):
raise TypeError('argument x must be an cupy.ndarray')
- set_dropout_descriptor(self.desc, handle, dropout_ratio)
+ set_dropout_descriptor(self._desc, handle, dropout_ratio)
x = cupy.ascontiguousarray(x)
y = cupy.empty_like(x)
@@ -363,9 +364,9 @@ class DropoutStates(object):
x_desc = create_tensor_descriptor(x_mat)
reserve_size = cudnn.getDropoutReserveSpaceSize(x_desc.value)
- reserve_space = cupy.empty((reserve_size,))
+ reserve_space = cupy.empty((reserve_size,), dtype='b')
- cudnn.dropoutForward(handle, self.desc.value,
+ cudnn.dropoutForward(handle, self._desc.value,
x_desc.value, x_mat.data.ptr,
x_desc.value, y.data.ptr,
reserve_space.data.ptr, reserve_size)
@@ -375,7 +376,7 @@ class DropoutStates(object):
if not isinstance(dy, cupy.ndarray):
raise TypeError('argument dy must be an cupy.ndarray')
- set_dropout_descriptor(self.desc, handle, dropout_ratio)
+ set_dropout_descriptor(self._desc, handle, dropout_ratio)
dy = cupy.ascontiguousarray(dy)
dx = cupy.empty_like(dy)
@@ -383,7 +384,7 @@ class DropoutStates(object):
dy_mat = _as4darray(dy)
dy_desc = create_tensor_descriptor(dy_mat)
- cudnn.dropoutBackward(handle, self.desc.value,
+ cudnn.dropoutBackward(handle, self._desc.value,
dy_desc.value, dy_mat.data.ptr,
dy_desc.value, dx.data.ptr,
reserve_space.data.ptr,
