paleo/third_party/libcudnn.py
def cudnnTransformTensor(handle, alpha, srcDesc, srcData, beta, destDesc,
                         destData):
    """"
    Tensor layout conversion helper (dest = alpha * src + beta * dest).

    This function copies the scaled data from one tensor to another tensor with a different
    layout. Those descriptors need to have the same dimensions but not necessarily the
    same strides. The input and output tensors must not overlap in any way (i.e., tensors
    cannot be transformed in place). This function can be used to convert a tensor with an
    unsupported format to a supported one.

    Parameters
    ----------
    handle : cudnnHandle
        cuDNN context.
    alpha : float
        Scalar factor to be applied to every element of the input tensor before it is added
        to the output tensor.
    srcDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    srcData : void_p
        Pointer to data of the tensor described by srcDesc descriptor.
    beta: float
        Scaling factor which is applied on every element of the output tensor prior to adding
        the result of the operation. Note that if beta is zero, the output is not read and can
        contain any uninitialized data (including Nan numbers).
    destDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    destData : void_p
        Pointer to data of the tensor described by destDesc descriptor.
    """

    dataType, _, _, _, _, _, _, _, _ = cudnnGetTensor4dDescriptor(destDesc)
    if dataType == cudnnDataType['CUDNN_DATA_DOUBLE']:
        alphaRef = ctypes.byref(ctypes.c_double(alpha))
        betaRef = ctypes.byref(ctypes.c_double(beta))
    else:
        alphaRef = ctypes.byref(ctypes.c_float(alpha))
        betaRef = ctypes.byref(ctypes.c_float(beta))

    status = _libcudnn.cudnnTransformTensor(handle, alphaRef, srcDesc, srcData,
                                            betaRef, destDesc, destData)
    cudnnCheckStatus(status)

    Tensor layout conversion helper (dest = alpha * src + beta * dest).

    This function copies the scaled data from one tensor to another tensor with a different
    layout. Those descriptors need to have the same dimensions but not necessarily the
    same strides. The input and output tensors must not overlap in any way (i.e., tensors
    cannot be transformed in place). This function can be used to convert a tensor with an
    unsupported format to a supported one.

    Parameters
    ----------
    handle : cudnnHandle
        cuDNN context.
    alpha : float
        Scalar factor to be applied to every element of the input tensor before it is added
        to the output tensor.
    srcDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    srcData : void_p
        Pointer to data of the tensor described by srcDesc descriptor.
    beta: float
        Scaling factor which is applied on every element of the output tensor prior to adding
        the result of the operation. Note that if beta is zero, the output is not read and can
        contain any uninitialized data (including Nan numbers).
    destDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    destData : void_p
        Pointer to data of the tensor described by destDesc descriptor.
    
Tensor layout conversion helper (dest = alpha * src + beta * dest).
This function copies the scaled data from one tensor to another tensor with a different
layout. Those descriptors need to have the same dimensions but not necessarily the
same strides. The input and output tensors must not overlap in any way . This function can be used to convert a tensor with an
unsupported format to a supported one.

Parameters

handle : cudnnHandle
cuDNN context.
alpha : float
Scalar factor to be applied to every element of the input tensor before it is added
to the output tensor.
srcDesc : cudnnTensorDescriptor
Handle to a previously initialized tensor descriptor.
srcData : void_p
Pointer to data of the tensor described by srcDesc descriptor.
beta: float
Scaling factor which is applied on every element of the output tensor prior to adding
the result of the operation. Note that if beta is zero, the output is not read and can
contain any uninitialized data (including Nan numbers).
destDesc : cudnnTensorDescriptor
Handle to a previously initialized tensor descriptor.
destData : void_p
Pointer to data of the tensor described by destDesc descriptor.
Tensor layout conversion helper ( dest = alpha * src + beta * dest ) . This function copies the scaled data from one tensor to another tensor with a different layout . Those descriptors need to have the same dimensions but not necessarily the same strides . The input and output tensors must not overlap in any way . This function can be used to convert a tensor with an unsupported format to a supported one . Parameters handle : cudnnHandle cuDNN context . alpha : float Scalar factor to be applied to every element of the input tensor before it is added to the output tensor . srcDesc : cudnnTensorDescriptor Handle to a previously initialized tensor descriptor . srcData : void_p Pointer to data of the tensor described by srcDesc descriptor . beta : float Scaling factor which is applied on every element of the output tensor prior to adding the result of the operation . Note that if beta is zero the output is not read and can contain any uninitialized data ( including Nan numbers ) . destDesc : cudnnTensorDescriptor Handle to a previously initialized tensor descriptor . destData : void_p Pointer to data of the tensor described by destDesc descriptor .
def cudnnTransformTensor(handle, alpha, srcDesc, srcData, beta, destDesc,
                         destData):
    dataType, _, _, _, _, _, _, _, _ = cudnnGetTensor4dDescriptor(destDesc)
    if dataType == cudnnDataType['CUDNN_DATA_DOUBLE']:
        alphaRef = ctypes.byref(ctypes.c_double(alpha))
        betaRef = ctypes.byref(ctypes.c_double(beta))
    else:
        alphaRef = ctypes.byref(ctypes.c_float(alpha))
        betaRef = ctypes.byref(ctypes.c_float(beta))
    status = _libcudnn.cudnnTransformTensor(handle, alphaRef, srcDesc, srcData,
                                            betaRef, destDesc, destData)
    cudnnCheckStatus(status)
def cudnnTransformTensor ( handle , alpha , srcDesc , srcData , beta , destDesc , destData ) : dataType , _ , _ , _ , _ , _ , _ , _ , _ = cudnnGetTensor4dDescriptor ( destDesc ) if dataType == cudnnDataType [ 'CUDNN_DATA_DOUBLE' ] : alphaRef = ctypes . byref ( ctypes . c_double ( alpha ) ) betaRef = ctypes . byref ( ctypes . c_double ( beta ) ) else : alphaRef = ctypes . byref ( ctypes . c_float ( alpha ) ) betaRef = ctypes . byref ( ctypes . c_float ( beta ) ) status = _libcudnn . cudnnTransformTensor ( handle , alphaRef , srcDesc , srcData , betaRef , destDesc , destData ) cudnnCheckStatus ( status )
Tensor layout conversion helper (dest = alpha * src + beta * dest).
Tensor layout conversion helper ( dest = alpha * src + beta * dest ) .
""""
    Tensor layout conversion helper (dest = alpha * src + beta * dest).

    This function copies the scaled data from one tensor to another tensor with a different
    layout. Those descriptors need to have the same dimensions but not necessarily the
    same strides. The input and output tensors must not overlap in any way (i.e., tensors
    cannot be transformed in place). This function can be used to convert a tensor with an
    unsupported format to a supported one.

    Parameters
    ----------
    handle : cudnnHandle
        cuDNN context.
    alpha : float
        Scalar factor to be applied to every element of the input tensor before it is added
        to the output tensor.
    srcDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    srcData : void_p
        Pointer to data of the tensor described by srcDesc descriptor.
    beta: float
        Scaling factor which is applied on every element of the output tensor prior to adding
        the result of the operation. Note that if beta is zero, the output is not read and can
        contain any uninitialized data (including Nan numbers).
    destDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    destData : void_p
        Pointer to data of the tensor described by destDesc descriptor.
    """
handle
alpha
srcDesc
srcData
beta
destDesc
destData