Example #1
0
def create_tensor_descriptor(arr, format=cudnn.CUDNN_TENSOR_NCHW):
    desc = Descriptor(cudnn.createTensorDescriptor(), cudnn.destroyTensorDescriptor)
    if not arr.flags.c_contiguous:
        raise ValueError("cupy.cudnn supports c-contiguous arrays only")
    data_type = get_data_type(arr.dtype)
    if arr.ndim == 4:
        cudnn.setTensor4dDescriptor(desc.value, format, data_type, *arr.shape)
    else:
        c_shape = _to_ctypes_array(arr.shape)
        c_strides = _to_ctypes_array(_compute_strides(arr.shape))
        cudnn.setTensorNdDescriptor(desc.value, data_type, arr.ndim, c_shape.data, c_strides.data)
    return desc
Example #2
0
def create_tensor_descriptor(arr, format=cudnn.CUDNN_TENSOR_NCHW):
    desc = Descriptor(cudnn.createTensorDescriptor(),
                      cudnn.destroyTensorDescriptor)
    if not arr.flags.c_contiguous:
        raise ValueError('cupy.cudnn supports c-contiguous arrays only')
    data_type = get_data_type(arr.dtype)
    if arr.ndim == 4:
        cudnn.setTensor4dDescriptor(desc.value, format, data_type, *arr.shape)
    else:
        c_shape = _to_ctypes_array(arr.shape)
        c_strides = _to_ctypes_array(_compute_strides(arr.shape))
        cudnn.setTensorNdDescriptor(desc.value, data_type, arr.ndim,
                                    c_shape.data, c_strides.data)
    return desc
Example #3
0
def create_tensor_nd_descriptor(arr):
    desc = Descriptor(cudnn.createTensorDescriptor(), cudnn.destroyTensorDescriptor)
    if not arr.flags.c_contiguous:
        raise ValueError("cupy.cudnn supports c-contiguous arrays only")
    data_type = get_data_type(arr.dtype)
    shape = arr.shape
    # numpy's stride is defined in bytes, but cudnn's stride is defined in
    # size of element
    strides = [s // arr.itemsize for s in arr.strides]

    c_shape = _to_ctypes_array(shape)
    c_strides = _to_ctypes_array(strides)
    cudnn.setTensorNdDescriptor(desc.value, data_type, arr.ndim, c_shape.data, c_strides.data)

    return desc
Example #4
0
def create_tensor_nd_descriptor(arr):
    desc = Descriptor(cudnn.createTensorDescriptor(),
                      cudnn.destroyTensorDescriptor)
    if not arr.flags.c_contiguous:
        raise ValueError('cupy.cudnn supports c-contiguous arrays only')
    data_type = get_data_type(arr.dtype)
    shape = arr.shape
    # numpy's stride is defined in bytes, but cudnn's stride is defined in
    # size of element
    strides = [s // arr.itemsize for s in arr.strides]

    c_shape = _to_ctypes_array(shape)
    c_strides = _to_ctypes_array(strides)
    cudnn.setTensorNdDescriptor(desc.value, data_type,
                                arr.ndim, c_shape.data, c_strides.data)

    return desc