cuda_cffi/cusparse.py
def _csrgeamNnz(m, n, descrA, csrRowPtrA, csrColIndA, descrB, csrRowPtrB,
                csrColIndB, handle=None, descrC=None, csrRowPtrC=None,
                nnzA=None, nnzB=None, check_inputs=True):
    """ support routine for csrgeam

    higher level wrapper to cusparseXcsrgeamNnz.
    """
    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 csrRowPtrA.size != m+1:
            raise ValueError("length of csrRowPtrA array must be m+1")
        if csrRowPtrB.size != m+1:
            raise ValueError("length of csrRowPtrB array must be m+1")

    cusparseXcsrgeamNnz(handle, m, n, 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 csrgeam

    higher level wrapper to cusparseXcsrgeamNnz.
    
support routine for csrgeam
higher level wrapper to cusparseXcsrgeamNnz.
support routine for csrgeam higher level wrapper to cusparseXcsrgeamNnz .
def _csrgeamNnz(m, n, descrA, csrRowPtrA, csrColIndA, descrB, csrRowPtrB,
                csrColIndB, handle=None, descrC=None, csrRowPtrC=None,
                nnzA=None, nnzB=None, 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 csrRowPtrA.size != m+1:
            raise ValueError("length of csrRowPtrA array must be m+1")
        if csrRowPtrB.size != m+1:
            raise ValueError("length of csrRowPtrB array must be m+1")
    cusparseXcsrgeamNnz(handle, m, n, 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 _csrgeamNnz ( m , n , descrA , csrRowPtrA , csrColIndA , descrB , csrRowPtrB , csrColIndB , handle = None , descrC = None , csrRowPtrC = None , nnzA = None , nnzB = None , 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 csrRowPtrA . size != m + 1 : raise ValueError ( "length of csrRowPtrA array must be m+1" ) if csrRowPtrB . size != m + 1 : raise ValueError ( "length of csrRowPtrB array must be m+1" ) cusparseXcsrgeamNnz ( handle , m , n , 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 csrgeam
higher level wrapper to cusparseXcsrgeamNnz.
support routine for csrgeam higher level wrapper to cusparseXcsrgeamNnz .
""" support routine for csrgeam

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