cuda_cffi/cusparse.py
def dense2csc(A, handle=None, descrA=None, lda=None, check_inputs=True):
    """ Convert dense matrix to CSC. """
    if not isinstance(A, pycuda.gpuarray.GPUArray):
        # try moving list or numpy array to GPU
        A = np.asfortranarray(np.atleast_2d(A))
        A = gpuarray.to_gpu(A)
    if check_inputs:
        if not isinstance(A, pycuda.gpuarray.GPUArray):
            raise ValueError("A must be a pyCUDA gpuarray")
        if len(A.shape) != 2:
            raise ValueError("A must be 2D")
        if descrA is not None:
            if cusparseGetMatType(descrA) != CUSPARSE_MATRIX_TYPE_GENERAL:
                raise ValueError("Only general matrix type supported")
        if not A.flags.f_contiguous:
            raise ValueError("Dense matrix A must be in column-major order")

    if lda is None:
        lda = A.shape[0]
    m, n = A.shape
    assert lda >= m
    dtype = A.dtype

    if handle is None:
        handle = misc._global_cusparse_handle

    if descrA is None:
        descrA = cusparseCreateMatDescr()
        cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL)
        cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO)

    nnzPerCol, nnz = dense_nnz(
        descrA, A, handle=handle, dirA=CUSPARSE_DIRECTION_COLUMN, lda=lda)

    alloc = misc._global_cusparse_allocator
    cscColPtrA = gpuarray.zeros((n+1, ), dtype=np.int32, allocator=alloc)
    cscRowIndA = gpuarray.zeros((nnz, ), dtype=np.int32, allocator=alloc)
    cscValA = gpuarray.zeros((nnz, ), dtype=dtype, allocator=alloc)
    if dtype == np.float32:
        fn = cusparseSdense2csc
    elif dtype == np.float64:
        fn = cusparseDdense2csc
    elif dtype == np.complex64:
        fn = cusparseCdense2csc
    elif dtype == np.complex128:
        fn = cusparseZdense2csc
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)

    fn(handle, m, n, descrA, A, lda, nnzPerCol, cscValA, cscRowIndA,
       cscColPtrA)
    return (descrA, cscValA, cscColPtrA, cscRowIndA)
 Convert dense matrix to CSC. 
Convert dense matrix to CSC.
Convert dense matrix to CSC .
def dense2csc(A, handle=None, descrA=None, lda=None, check_inputs=True):
    if not isinstance(A, pycuda.gpuarray.GPUArray):
        A = np.asfortranarray(np.atleast_2d(A))
        A = gpuarray.to_gpu(A)
    if check_inputs:
        if not isinstance(A, pycuda.gpuarray.GPUArray):
            raise ValueError("A must be a pyCUDA gpuarray")
        if len(A.shape) != 2:
            raise ValueError("A must be 2D")
        if descrA is not None:
            if cusparseGetMatType(descrA) != CUSPARSE_MATRIX_TYPE_GENERAL:
                raise ValueError("Only general matrix type supported")
        if not A.flags.f_contiguous:
            raise ValueError("Dense matrix A must be in column-major order")
    if lda is None:
        lda = A.shape[0]
    m, n = A.shape
    assert lda >= m
    dtype = A.dtype
    if handle is None:
        handle = misc._global_cusparse_handle
    if descrA is None:
        descrA = cusparseCreateMatDescr()
        cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL)
        cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO)
    nnzPerCol, nnz = dense_nnz(
        descrA, A, handle=handle, dirA=CUSPARSE_DIRECTION_COLUMN, lda=lda)
    alloc = misc._global_cusparse_allocator
    cscColPtrA = gpuarray.zeros((n+1, ), dtype=np.int32, allocator=alloc)
    cscRowIndA = gpuarray.zeros((nnz, ), dtype=np.int32, allocator=alloc)
    cscValA = gpuarray.zeros((nnz, ), dtype=dtype, allocator=alloc)
    if dtype == np.float32:
        fn = cusparseSdense2csc
    elif dtype == np.float64:
        fn = cusparseDdense2csc
    elif dtype == np.complex64:
        fn = cusparseCdense2csc
    elif dtype == np.complex128:
        fn = cusparseZdense2csc
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)
    fn(handle, m, n, descrA, A, lda, nnzPerCol, cscValA, cscRowIndA,
       cscColPtrA)
    return (descrA, cscValA, cscColPtrA, cscRowIndA)
def dense2csc ( A , handle = None , descrA = None , lda = None , check_inputs = True ) : if not isinstance ( A , pycuda . gpuarray . GPUArray ) : A = np . asfortranarray ( np . atleast_2d ( A ) ) A = gpuarray . to_gpu ( A ) if check_inputs : if not isinstance ( A , pycuda . gpuarray . GPUArray ) : raise ValueError ( "A must be a pyCUDA gpuarray" ) if len ( A . shape ) != 2 : raise ValueError ( "A must be 2D" ) if descrA is not None : if cusparseGetMatType ( descrA ) != CUSPARSE_MATRIX_TYPE_GENERAL : raise ValueError ( "Only general matrix type supported" ) if not A . flags . f_contiguous : raise ValueError ( "Dense matrix A must be in column-major order" ) if lda is None : lda = A . shape [ 0 ] m , n = A . shape assert lda >= m dtype = A . dtype if handle is None : handle = misc . _global_cusparse_handle if descrA is None : descrA = cusparseCreateMatDescr ( ) cusparseSetMatType ( descrA , CUSPARSE_MATRIX_TYPE_GENERAL ) cusparseSetMatIndexBase ( descrA , CUSPARSE_INDEX_BASE_ZERO ) nnzPerCol , nnz = dense_nnz ( descrA , A , handle = handle , dirA = CUSPARSE_DIRECTION_COLUMN , lda = lda ) alloc = misc . _global_cusparse_allocator cscColPtrA = gpuarray . zeros ( ( n + 1 , ) , dtype = np . int32 , allocator = alloc ) cscRowIndA = gpuarray . zeros ( ( nnz , ) , dtype = np . int32 , allocator = alloc ) cscValA = gpuarray . zeros ( ( nnz , ) , dtype = dtype , allocator = alloc ) if dtype == np . float32 : fn = cusparseSdense2csc elif dtype == np . float64 : fn = cusparseDdense2csc elif dtype == np . complex64 : fn = cusparseCdense2csc elif dtype == np . complex128 : fn = cusparseZdense2csc else : raise ValueError ( "unsupported sparse matrix dtype: %s" % dtype ) fn ( handle , m , n , descrA , A , lda , nnzPerCol , cscValA , cscRowIndA , cscColPtrA ) return ( descrA , cscValA , cscColPtrA , cscRowIndA )
Convert dense matrix to CSC.
Convert dense matrix to CSC .
""" Convert dense matrix to CSC. """ # try moving list or numpy array to GPU
A
handle
descrA
lda
check_inputs