예제 #1
0
파일: cudnn.py 프로젝트: tjtorres/chainer
def create_uninitialized_tensor_descriptor():
    """Create uninitialized tensor descriptor.

    Create a cudnnCreateTensorDescriptor_t that is not yet initialized.
    This is used by the batch normalization functions.
    """
    desc = Descriptor(cudnn.createTensorDescriptor(), cudnn.destroyTensorDescriptor)
    return desc
예제 #2
0
def create_uninitialized_tensor_descriptor():
    """Create uninitialized tensor descriptor.

    Create a cudnnCreateTensorDescriptor_t that is not yet initialized.
    This is used by the batch normalization functions.
    """
    desc = Descriptor(cudnn.createTensorDescriptor(),
                      cudnn.destroyTensorDescriptor)
    return desc
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #7
0
파일: cudnn.py 프로젝트: tjtorres/chainer
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
예제 #8
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