Use normalized strides
@@ -14,6 +14,7 @@ from cupy.core cimport internal
from cupy.cuda cimport memory
from cupy import util
+from cupy.core._ufuncs import elementwise_copy
from cupy.cuda import cudnn as py_cudnn
@@ -234,6 +235,16 @@ cpdef _create_convolution_descriptor(
raise ValueError('groups must be one when cuDNN < 7.0')
+cpdef core.ndarray _ascontiguousarray_normalized_strides(core.ndarray a):
+ if a._c_contiguous:
+ newarray = a.view()
+ newarray._set_contiguous_strides(newarray.itemsize, True)
+ else:
+ newarray = core.ndarray(a.shape, a.dtype)
+ elementwise_copy(a, newarray)
+ return newarray
+
+
def create_tensor_descriptor(arr, format=cudnn.CUDNN_TENSOR_NCHW):
desc = Descriptor(cudnn.createTensorDescriptor(),
py_cudnn.destroyTensorDescriptor)
@@ -1052,11 +1063,11 @@ def rnn_backward_data(
cx = core._internal_ascontiguousarray(cx)
w = core._internal_ascontiguousarray(w)
xs = core._internal_ascontiguousarray(xs)
- ys = core._internal_ascontiguousarray(ys.copy())
+ ys = _ascontiguousarray_normalized_strides(ys)
dhy = core._internal_ascontiguousarray(dhy)
if dcy is not None:
dcy = core._internal_ascontiguousarray(dcy)
- dys = core._internal_ascontiguousarray(dys.copy())
+ dys = _ascontiguousarray_normalized_strides(dys)
cdef int length = len(lengths)
cdef int n_layers = _get_n_layers(direction_mode, hx)
