예제 #1
0
파일: cudnn.py 프로젝트: nicedi/chainer
def create_tensor_descriptor(arr, format=cudnn.CUDNN_TENSOR_NCHW):
    desc = Descriptor(cudnn.createTensorDescriptor(), cudnn.destroyTensorDescriptor)
    if arr.ndim != 4:
        raise ValueError("cupy.cudnn supports 4-dimensional arrays only")
    if not arr.flags.c_contiguous:
        raise ValueError("cupy.cudnn supports c-contiguous arrays only")
    data_type = get_data_type(arr.dtype)
    cudnn.setTensor4dDescriptor(desc.value, format, data_type, *arr.shape)

    return desc
예제 #2
0
def create_tensor_descriptor(arr, format=cudnn.CUDNN_TENSOR_NCHW):
    desc = Descriptor(cudnn.createTensorDescriptor(),
                      cudnn.destroyTensorDescriptor)
    if arr.ndim != 4:
        raise ValueError('cupy.cudnn supports 4-dimensional arrays only')
    if not arr.flags.c_contiguous:
        raise ValueError('cupy.cudnn supports c-contiguous arrays only')
    data_type = get_data_type(arr.dtype)
    cudnn.setTensor4dDescriptor(desc.value, format, data_type, *arr.shape)

    return desc
예제 #3
0
파일: cudnn.py 프로젝트: tjtorres/chainer
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
예제 #4
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