cuda_cffi/cusparse.py
def csrgeam(m, n, descrA, csrValA, csrRowPtrA, csrColIndA, descrB, csrValB,
            csrRowPtrB, csrColIndB, handle=None, alpha=1.0, beta=0.0,
            nnzA=None, nnzB=None,  check_inputs=True):
    """ add two sparse matrices:  C = alpha*A + beta*B.
    higher level wrapper to cusparse<t>csrgemm routines.
    """
    if check_inputs:
        for array in [csrValA, csrRowPtrA, csrColIndA, csrValB, 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 handle is None:
        handle = misc._global_cusparse_handle
    if nnzA is None:
        nnzA = csrValA.size
    if nnzB is None:
        nnzB = csrValB.size
    dtype = csrValA.dtype

    # perform some basic sanity checks
    if check_inputs:
        if csrValA.size != nnzA:
            raise ValueError("length of csrValA array must match nnzA")
        if csrValB.size != nnzB:
            raise ValueError("length of csrValB array must match nnzB")
        if (dtype != csrValB.dtype):
            raise ValueError("incompatible dtypes")
        if csrRowPtrA.size != m + 1:
            raise ValueError("bad csrRowPtrA size")
        if csrRowPtrB.size != m + 1:
            raise ValueError("bad csrRowPtrB size")

    # allocate output matrix C descr and row pointers
    descrC = cusparseCreateMatDescr()
    cusparseSetMatType(descrC, CUSPARSE_MATRIX_TYPE_GENERAL)
    alloc = misc._global_cusparse_allocator
    csrRowPtrC = gpuarray.zeros((m+1, ), dtype=np.int32, allocator=alloc)

    # call csrgemmNnz to determine nnzC and fill in csrRowPtrC
    nnzC = _csrgeamNnz(m, n, descrA, csrRowPtrA, csrColIndA, descrB,
                       csrRowPtrB, csrColIndB, handle=handle, descrC=descrC,
                       csrRowPtrC=csrRowPtrC, nnzA=nnzA, nnzB=nnzB,
                       check_inputs=False)

    # allocated rest of C based on nnzC
    csrValC = gpuarray.zeros((nnzC, ), dtype=dtype, allocator=alloc)
    csrColIndC = gpuarray.zeros((nnzC, ), dtype=np.int32, allocator=alloc)
    if dtype == np.float32:
        fn = cusparseScsrgeam
    elif dtype == np.float64:
        fn = cusparseDcsrgeam
    elif dtype == np.complex64:
        fn = cusparseCcsrgeam
    elif dtype == np.complex128:
        fn = cusparseZcsrgeam
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)

    fn(handle, m, n, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA,
       beta, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC,
       csrValC, csrRowPtrC, csrColIndC)
    return (descrC, csrValC, csrRowPtrC, csrColIndC)
 add two sparse matrices:  C = alpha*A + beta*B.
    higher level wrapper to cusparse<t>csrgemm routines.
    
add two sparse matrices:  C = alpha*A + beta*B.
higher level wrapper to cusparsecsrgemm routines.
add two sparse matrices : C = alpha * A + beta * B . higher level wrapper to cusparsecsrgemm routines .
def csrgeam(m, n, descrA, csrValA, csrRowPtrA, csrColIndA, descrB, csrValB,
            csrRowPtrB, csrColIndB, handle=None, alpha=1.0, beta=0.0,
            nnzA=None, nnzB=None,  check_inputs=True):
    if check_inputs:
        for array in [csrValA, csrRowPtrA, csrColIndA, csrValB, 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 handle is None:
        handle = misc._global_cusparse_handle
    if nnzA is None:
        nnzA = csrValA.size
    if nnzB is None:
        nnzB = csrValB.size
    dtype = csrValA.dtype
    if check_inputs:
        if csrValA.size != nnzA:
            raise ValueError("length of csrValA array must match nnzA")
        if csrValB.size != nnzB:
            raise ValueError("length of csrValB array must match nnzB")
        if (dtype != csrValB.dtype):
            raise ValueError("incompatible dtypes")
        if csrRowPtrA.size != m + 1:
            raise ValueError("bad csrRowPtrA size")
        if csrRowPtrB.size != m + 1:
            raise ValueError("bad csrRowPtrB size")
    descrC = cusparseCreateMatDescr()
    cusparseSetMatType(descrC, CUSPARSE_MATRIX_TYPE_GENERAL)
    alloc = misc._global_cusparse_allocator
    csrRowPtrC = gpuarray.zeros((m+1, ), dtype=np.int32, allocator=alloc)
    nnzC = _csrgeamNnz(m, n, descrA, csrRowPtrA, csrColIndA, descrB,
                       csrRowPtrB, csrColIndB, handle=handle, descrC=descrC,
                       csrRowPtrC=csrRowPtrC, nnzA=nnzA, nnzB=nnzB,
                       check_inputs=False)
    csrValC = gpuarray.zeros((nnzC, ), dtype=dtype, allocator=alloc)
    csrColIndC = gpuarray.zeros((nnzC, ), dtype=np.int32, allocator=alloc)
    if dtype == np.float32:
        fn = cusparseScsrgeam
    elif dtype == np.float64:
        fn = cusparseDcsrgeam
    elif dtype == np.complex64:
        fn = cusparseCcsrgeam
    elif dtype == np.complex128:
        fn = cusparseZcsrgeam
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)
    fn(handle, m, n, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA,
       beta, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC,
       csrValC, csrRowPtrC, csrColIndC)
    return (descrC, csrValC, csrRowPtrC, csrColIndC)
def csrgeam ( m , n , descrA , csrValA , csrRowPtrA , csrColIndA , descrB , csrValB , csrRowPtrB , csrColIndB , handle = None , alpha = 1.0 , beta = 0.0 , nnzA = None , nnzB = None , check_inputs = True ) : if check_inputs : for array in [ csrValA , csrRowPtrA , csrColIndA , csrValB , 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 handle is None : handle = misc . _global_cusparse_handle if nnzA is None : nnzA = csrValA . size if nnzB is None : nnzB = csrValB . size dtype = csrValA . dtype if check_inputs : if csrValA . size != nnzA : raise ValueError ( "length of csrValA array must match nnzA" ) if csrValB . size != nnzB : raise ValueError ( "length of csrValB array must match nnzB" ) if ( dtype != csrValB . dtype ) : raise ValueError ( "incompatible dtypes" ) if csrRowPtrA . size != m + 1 : raise ValueError ( "bad csrRowPtrA size" ) if csrRowPtrB . size != m + 1 : raise ValueError ( "bad csrRowPtrB size" ) descrC = cusparseCreateMatDescr ( ) cusparseSetMatType ( descrC , CUSPARSE_MATRIX_TYPE_GENERAL ) alloc = misc . _global_cusparse_allocator csrRowPtrC = gpuarray . zeros ( ( m + 1 , ) , dtype = np . int32 , allocator = alloc ) nnzC = _csrgeamNnz ( m , n , descrA , csrRowPtrA , csrColIndA , descrB , csrRowPtrB , csrColIndB , handle = handle , descrC = descrC , csrRowPtrC = csrRowPtrC , nnzA = nnzA , nnzB = nnzB , check_inputs = False ) csrValC = gpuarray . zeros ( ( nnzC , ) , dtype = dtype , allocator = alloc ) csrColIndC = gpuarray . zeros ( ( nnzC , ) , dtype = np . int32 , allocator = alloc ) if dtype == np . float32 : fn = cusparseScsrgeam elif dtype == np . float64 : fn = cusparseDcsrgeam elif dtype == np . complex64 : fn = cusparseCcsrgeam elif dtype == np . complex128 : fn = cusparseZcsrgeam else : raise ValueError ( "unsupported sparse matrix dtype: %s" % dtype ) fn ( handle , m , n , alpha , descrA , nnzA , csrValA , csrRowPtrA , csrColIndA , beta , descrB , nnzB , csrValB , csrRowPtrB , csrColIndB , descrC , csrValC , csrRowPtrC , csrColIndC ) return ( descrC , csrValC , csrRowPtrC , csrColIndC )
add two sparse matrices:  C = alpha*A + beta*B.
higher level wrapper to cusparse<t>csrgemm routines.
add two sparse matrices : C = alpha * A + beta * B . higher level wrapper to cusparse<t > csrgemm routines .
""" add two sparse matrices:  C = alpha*A + beta*B.
    higher level wrapper to cusparse<t>csrgemm routines.
    """ # perform some basic sanity checks # allocate output matrix C descr and row pointers # call csrgemmNnz to determine nnzC and fill in csrRowPtrC # allocated rest of C based on nnzC
m
n
descrA
csrValA
csrRowPtrA
csrColIndA
descrB
csrValB
csrRowPtrB
csrColIndB
handle
alpha
beta
nnzA
nnzB
check_inputs