cuda_cffi/cusparse.py
def _csrgemmNnz(m, n, k, descrA, csrRowPtrA, csrColIndA, descrB, csrRowPtrB,
                csrColIndB, handle=None, descrC=None, csrRowPtrC=None,
                nnzA=None, nnzB=None, transA=CUSPARSE_OPERATION_NON_TRANSPOSE,
                transB=CUSPARSE_OPERATION_NON_TRANSPOSE, check_inputs=True):
    """ support routine for csrgemm.

    higher level wrapper to cusparseXcsrgemmNnz.
    """
    if check_inputs:
        for array in [csrRowPtrA, csrColIndA, csrRowPtrB, csrColIndB]:
            if not isinstance(array, pycuda.gpuarray.GPUArray):
                raise ValueError("all csr* inputs must be a pyCUDA gpuarray")
        if cusparseGetMatType(descrA) != CUSPARSE_MATRIX_TYPE_GENERAL:
            raise ValueError("Only general matrix type supported")
        if cusparseGetMatType(descrB) != CUSPARSE_MATRIX_TYPE_GENERAL:
            raise ValueError("Only general matrix type supported")
        if descrC is not None:
            if not isinstance(csrRowPtrC, pycuda.gpuarray.GPUArray):
                raise ValueError("csrRowPtrC must be a gpuarray or None")
            if cusparseGetMatType(descrC) != CUSPARSE_MATRIX_TYPE_GENERAL:
                raise ValueError("Only general matrix type supported")
    if handle is None:
        handle = misc._global_cusparse_handle
    if nnzA is None:
        nnzA = csrColIndA.size
    if nnzB is None:
        nnzB = csrColIndB.size
    if descrC is None:
        return_descrC = True
        descrC = cusparseCreateMatDescr()
        cusparseSetMatType(descrC, CUSPARSE_MATRIX_TYPE_GENERAL)
    else:
        return_descrC = False
    if csrRowPtrC is None:
        alloc = misc._global_cusparse_allocator
        csrRowPtrC = gpuarray.zeros((m+1, ), dtype=np.int32,
                                    allocator=alloc)
    nnzTotalDevHostPtr = ffi.new('int *', 0)

    # perform some basic sanity checks
    if check_inputs:
        if csrColIndA.size != nnzA:
            raise ValueError("length of csrValA array must match nnzA")
        if csrColIndB.size != nnzB:
            raise ValueError("length of csrValB array must match nnzB")
        if transA == CUSPARSE_OPERATION_NON_TRANSPOSE:
            ptrA_size = m + 1
        else:
            ptrA_size = k + 1
        if transB == CUSPARSE_OPERATION_NON_TRANSPOSE:
            ptrB_size = k + 1
        else:
            ptrB_size = n + 1
        if csrRowPtrA.size != ptrA_size:
            raise ValueError("length of csrRowPtrA array must be m+1")
        if csrRowPtrB.size != ptrB_size:
            raise ValueError("length of csrRowPtrB array must be n+1")

    cusparseXcsrgemmNnz(handle, transA, transB, m, n, k, descrA, nnzA,
                        csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB,
                        csrColIndB, descrC, csrRowPtrC, nnzTotalDevHostPtr)
    nnzC = nnzTotalDevHostPtr[0]
    if return_descrC:
        return descrC, csrRowPtrC, nnzC
    else:
        return nnzC
 support routine for csrgemm.

    higher level wrapper to cusparseXcsrgemmNnz.
    
support routine for csrgemm.
higher level wrapper to cusparseXcsrgemmNnz.
support routine for csrgemm . higher level wrapper to cusparseXcsrgemmNnz .
def _csrgemmNnz(m, n, k, descrA, csrRowPtrA, csrColIndA, descrB, csrRowPtrB,
                csrColIndB, handle=None, descrC=None, csrRowPtrC=None,
                nnzA=None, nnzB=None, transA=CUSPARSE_OPERATION_NON_TRANSPOSE,
                transB=CUSPARSE_OPERATION_NON_TRANSPOSE, check_inputs=True):
    if check_inputs:
        for array in [csrRowPtrA, csrColIndA, csrRowPtrB, csrColIndB]:
            if not isinstance(array, pycuda.gpuarray.GPUArray):
                raise ValueError("all csr* inputs must be a pyCUDA gpuarray")
        if cusparseGetMatType(descrA) != CUSPARSE_MATRIX_TYPE_GENERAL:
            raise ValueError("Only general matrix type supported")
        if cusparseGetMatType(descrB) != CUSPARSE_MATRIX_TYPE_GENERAL:
            raise ValueError("Only general matrix type supported")
        if descrC is not None:
            if not isinstance(csrRowPtrC, pycuda.gpuarray.GPUArray):
                raise ValueError("csrRowPtrC must be a gpuarray or None")
            if cusparseGetMatType(descrC) != CUSPARSE_MATRIX_TYPE_GENERAL:
                raise ValueError("Only general matrix type supported")
    if handle is None:
        handle = misc._global_cusparse_handle
    if nnzA is None:
        nnzA = csrColIndA.size
    if nnzB is None:
        nnzB = csrColIndB.size
    if descrC is None:
        return_descrC = True
        descrC = cusparseCreateMatDescr()
        cusparseSetMatType(descrC, CUSPARSE_MATRIX_TYPE_GENERAL)
    else:
        return_descrC = False
    if csrRowPtrC is None:
        alloc = misc._global_cusparse_allocator
        csrRowPtrC = gpuarray.zeros((m+1, ), dtype=np.int32,
                                    allocator=alloc)
    nnzTotalDevHostPtr = ffi.new('int *', 0)
    if check_inputs:
        if csrColIndA.size != nnzA:
            raise ValueError("length of csrValA array must match nnzA")
        if csrColIndB.size != nnzB:
            raise ValueError("length of csrValB array must match nnzB")
        if transA == CUSPARSE_OPERATION_NON_TRANSPOSE:
            ptrA_size = m + 1
        else:
            ptrA_size = k + 1
        if transB == CUSPARSE_OPERATION_NON_TRANSPOSE:
            ptrB_size = k + 1
        else:
            ptrB_size = n + 1
        if csrRowPtrA.size != ptrA_size:
            raise ValueError("length of csrRowPtrA array must be m+1")
        if csrRowPtrB.size != ptrB_size:
            raise ValueError("length of csrRowPtrB array must be n+1")
    cusparseXcsrgemmNnz(handle, transA, transB, m, n, k, descrA, nnzA,
                        csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB,
                        csrColIndB, descrC, csrRowPtrC, nnzTotalDevHostPtr)
    nnzC = nnzTotalDevHostPtr[0]
    if return_descrC:
        return descrC, csrRowPtrC, nnzC
    else:
        return nnzC
def _csrgemmNnz ( m , n , k , descrA , csrRowPtrA , csrColIndA , descrB , csrRowPtrB , csrColIndB , handle = None , descrC = None , csrRowPtrC = None , nnzA = None , nnzB = None , transA = CUSPARSE_OPERATION_NON_TRANSPOSE , transB = CUSPARSE_OPERATION_NON_TRANSPOSE , check_inputs = True ) : if check_inputs : for array in [ csrRowPtrA , csrColIndA , csrRowPtrB , csrColIndB ] : if not isinstance ( array , pycuda . gpuarray . GPUArray ) : raise ValueError ( "all csr* inputs must be a pyCUDA gpuarray" ) if cusparseGetMatType ( descrA ) != CUSPARSE_MATRIX_TYPE_GENERAL : raise ValueError ( "Only general matrix type supported" ) if cusparseGetMatType ( descrB ) != CUSPARSE_MATRIX_TYPE_GENERAL : raise ValueError ( "Only general matrix type supported" ) if descrC is not None : if not isinstance ( csrRowPtrC , pycuda . gpuarray . GPUArray ) : raise ValueError ( "csrRowPtrC must be a gpuarray or None" ) if cusparseGetMatType ( descrC ) != CUSPARSE_MATRIX_TYPE_GENERAL : raise ValueError ( "Only general matrix type supported" ) if handle is None : handle = misc . _global_cusparse_handle if nnzA is None : nnzA = csrColIndA . size if nnzB is None : nnzB = csrColIndB . size if descrC is None : return_descrC = True descrC = cusparseCreateMatDescr ( ) cusparseSetMatType ( descrC , CUSPARSE_MATRIX_TYPE_GENERAL ) else : return_descrC = False if csrRowPtrC is None : alloc = misc . _global_cusparse_allocator csrRowPtrC = gpuarray . zeros ( ( m + 1 , ) , dtype = np . int32 , allocator = alloc ) nnzTotalDevHostPtr = ffi . new ( 'int *' , 0 ) if check_inputs : if csrColIndA . size != nnzA : raise ValueError ( "length of csrValA array must match nnzA" ) if csrColIndB . size != nnzB : raise ValueError ( "length of csrValB array must match nnzB" ) if transA == CUSPARSE_OPERATION_NON_TRANSPOSE : ptrA_size = m + 1 else : ptrA_size = k + 1 if transB == CUSPARSE_OPERATION_NON_TRANSPOSE : ptrB_size = k + 1 else : ptrB_size = n + 1 if csrRowPtrA . size != ptrA_size : raise ValueError ( "length of csrRowPtrA array must be m+1" ) if csrRowPtrB . size != ptrB_size : raise ValueError ( "length of csrRowPtrB array must be n+1" ) cusparseXcsrgemmNnz ( handle , transA , transB , m , n , k , descrA , nnzA , csrRowPtrA , csrColIndA , descrB , nnzB , csrRowPtrB , csrColIndB , descrC , csrRowPtrC , nnzTotalDevHostPtr ) nnzC = nnzTotalDevHostPtr [ 0 ] if return_descrC : return descrC , csrRowPtrC , nnzC else : return nnzC
support routine for csrgemm.
support routine for csrgemm .
""" support routine for csrgemm.

    higher level wrapper to cusparseXcsrgemmNnz.
    """ # perform some basic sanity checks
m
n
k
descrA
csrRowPtrA
csrColIndA
descrB
csrRowPtrB
csrColIndB
handle
descrC
csrRowPtrC
nnzA
nnzB
transA
transB
check_inputs