<s> """<STR_LIT>""" <EOL> import atexit <EOL> import ctypes . util <EOL> import platform <EOL> from string import Template <EOL> import sys <EOL> import warnings <EOL> import numpy as np <EOL> import cuda <EOL> _version_list = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> if '<STR_LIT>' in sys . platform : <EOL> _libcusparse_libname_list = [ '<STR_LIT>' ] + [ '<STR_LIT>' % v for v in _version_list ] <EOL> elif sys . platform == '<STR_LIT>' : <EOL> _libcusparse_libname_list = [ '<STR_LIT>' ] <EOL> elif sys . platform == '<STR_LIT:win32>' : <EOL> if platform . machine ( ) . endswith ( '<STR_LIT>' ) : <EOL> _libcusparse_libname_list = [ '<STR_LIT>' ] + [ '<STR_LIT>' % int ( <NUM_LIT:10> * v ) for v in _version_list ] <EOL> else : <EOL> _libcusparse_libname_list = [ '<STR_LIT>' ] + [ '<STR_LIT>' % int ( <NUM_LIT:10> * v ) for v in _version_list ] <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> _libcusparse = None <EOL> for _libcusparse_libname in _libcusparse_libname_list : <EOL> try : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> _libcusparse = ctypes . windll . LoadLibrary ( _libcusparse_libname ) <EOL> else : <EOL> _libcusparse = ctypes . cdll . LoadLibrary ( _libcusparse_libname ) <EOL> except OSError : <EOL> pass <EOL> else : <EOL> break <EOL> if _libcusparse == None : <EOL> OSError ( '<STR_LIT>' ) <EOL> class cusparseError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusNotInitialized ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusAllocFailed ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusInvalidValue ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusArchMismatch ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusMappingError ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusExecutionFailed ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusInternalError ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class cusparseStatusMatrixTypeNotSupported ( cusparseError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> cusparseExceptions = { <EOL> <NUM_LIT:1> : cusparseStatusNotInitialized , <EOL> <NUM_LIT:2> : cusparseStatusAllocFailed , <EOL> <NUM_LIT:3> : cusparseStatusInvalidValue , <EOL> <NUM_LIT:4> : cusparseStatusArchMismatch , <EOL> <NUM_LIT:5> : cusparseStatusMappingError , <EOL> <NUM_LIT:6> : cusparseStatusExecutionFailed , <EOL> <NUM_LIT:7> : cusparseStatusInternalError , <EOL> <NUM_LIT:8> : cusparseStatusMatrixTypeNotSupported , <EOL> } <EOL> CUSPARSE_MATRIX_TYPE_GENERAL = <NUM_LIT:0> <EOL> CUSPARSE_MATRIX_TYPE_SYMMETRIC = <NUM_LIT:1> <EOL> CUSPARSE_MATRIX_TYPE_HERMITIAN = <NUM_LIT:2> <EOL> CUSPARSE_MATRIX_TYPE_TRIANGULAR = <NUM_LIT:3> <EOL> CUSPARSE_FILL_MODE_LOWER = <NUM_LIT:0> <EOL> CUSPARSE_FILL_MODE_UPPER = <NUM_LIT:1> <EOL> CUSPARSE_DIAG_TYPE_NON_UNIT = <NUM_LIT:0> <EOL> CUSPARSE_DIAG_TYPE_UNIT = <NUM_LIT:1> <EOL> CUSPARSE_INDEX_BASE_ZERO = <NUM_LIT:0> <EOL> CUSPARSE_INDEX_BASE_ONE = <NUM_LIT:1> <EOL> CUSPARSE_OPERATION_NON_TRANSPOSE = <NUM_LIT:0> <EOL> CUSPARSE_OPERATION_TRANSPOSE = <NUM_LIT:1> <EOL> CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE = <NUM_LIT:2> <EOL> CUSPARSE_DIRECTION_ROW = <NUM_LIT:0> <EOL> CUSPARSE_DIRECTION_COLUMN = <NUM_LIT:1> <EOL> class cusparseMatDescr ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ctypes . c_int ) , <EOL> ( '<STR_LIT>' , ctypes . c_int ) , <EOL> ( '<STR_LIT>' , ctypes . c_int ) , <EOL> ( '<STR_LIT>' , ctypes . c_int ) <EOL> ] <EOL> def cusparseCheckStatus ( status ) : <EOL> """<STR_LIT>""" <EOL> if status != <NUM_LIT:0> : <EOL> try : <EOL> raise cusparseExceptions [ status ] <EOL> except KeyError : <EOL> raise cusparseError <EOL> _libcusparse . cusparseCreate . restype = int <EOL> _libcusparse . cusparseCreate . argtypes = [ ctypes . c_void_p ] <EOL> def cusparseCreate ( ) : <EOL> """<STR_LIT>""" <EOL> handle = ctypes . c_int ( ) <EOL> status = _libcusparse . cusparseCreate ( ctypes . byref ( handle ) ) <EOL> cusparseCheckStatus ( status ) <EOL> return handle . value <EOL> _libcusparse . cusparseDestroy . restype = int <EOL> _libcusparse . cusparseDestroy . argtypes = [ ctypes . c_int ] <EOL> def cusparseDestroy ( handle ) : <EOL> """<STR_LIT>""" <EOL> status = _libcusparse . cusparseDestroy ( handle ) <EOL> cusparseCheckStatus ( status ) <EOL> _libcusparse . cusparseGetVersion . restype = int <EOL> _libcusparse . cusparseGetVersion . argtypes = [ ctypes . c_int , <EOL> ctypes . c_void_p ] <EOL> def cusparseGetVersion ( handle ) : <EOL> """<STR_LIT>""" <EOL> version = ctypes . c_int ( ) <EOL> status = _libcusparse . cusparseGetVersion ( handle , <EOL> ctypes . byref ( version ) ) <EOL> cusparseCheckStatus ( status ) <EOL> return version . value <EOL> _libcusparse . cusparseSetStream . restype = int <EOL> _libcusparse . cusparseSetStream . argtypes = [ ctypes . c_int , <EOL> ctypes . c_int ] <EOL> def cusparseSetStream ( handle , id ) : <EOL> """<STR_LIT>""" <EOL> status = _libcusparse . cusparseSetStream ( handle , id ) <EOL> cusparseCheckStatus ( status ) <EOL> _libcusparse . cusparseCreateMatDescr . restype = int <EOL> _libcusparse . cusparseCreateMatDescr . argtypes = [ cusparseMatDescr ] <EOL> def cusparseCreateMatDescr ( ) : <EOL> """<STR_LIT>""" <EOL> desc = cusparseMatrixDesc ( ) <EOL> status = _libcusparse . cusparseCreateMatDescr ( ctypes . byref ( desc ) ) <EOL> cusparseCheckStatus ( status ) <EOL> return desc <EOL> _libcusparse . cusparseDestroyMatDescr . restype = int <EOL> _libcusparse . cusparseDestroyMatDescr . argtypes = [ ctypes . c_int ] <EOL> def cusparseDestroyMatDescr ( desc ) : <EOL> """<STR_LIT>""" <EOL> status = _libcusparse . cusparseDestroyMatDescr ( desc ) <EOL> cusparseCheckStatus ( status ) <EOL> _libcusparse . cusparseSetMatType . restype = int <EOL> _libcusparse . cusparseSetMatType . argtypes = [ cusparseMatDescr , <EOL> ctypes . c_int ] <EOL> def cusparseSetMatType ( desc , type ) : <EOL> """<STR_LIT>""" <EOL> status = _libcusparse . cusparseSetMatType ( desc , type ) <EOL> cusparseCheckStatus ( status ) <EOL> _libcusparse . cusparseGetMatType . restype = int <EOL> _libcusparse . cusparseGetMatType . argtypes = [ cusparseMatDescr ] <EOL> def cusparseGetMatType ( desc ) : <EOL> """<STR_LIT>""" <EOL> return _libcusparse . cusparseGetMatType ( desc ) <EOL> _libcusparse . cusparseSnnz . restype = int <EOL> _libcusparse . cusparseSnnz . argtypes = [ ctypes . c_int , <EOL> ctypes . c_int , <EOL> ctypes . c_int , <EOL> ctypes . c_int , <EOL> cusparseMatDescr , <EOL> ctypes . c_void_p , <EOL> ctypes . c_int , <EOL> ctypes . c_void_p , <EOL> ctypes . c_void_p ] <EOL> def cusparseSnnz ( handle , dirA , m , n , descrA , A , lda , <EOL> nnzPerRowColumn , nnzTotalDevHostPtr ) : <EOL> """<STR_LIT>""" <EOL> nnzPerRowColumn = gpuarray . empty ( ) <EOL> nnzTotalDevHostPtr = gpuarray . empty ( ) <EOL> status = _libcusparse . cusparseSnnz ( handle , dirA , m , n , <EOL> descrA , int ( A ) , lda , <EOL> int ( nnzPerRowColumn ) , int ( nnzTotalDevHostPtr ) ) <EOL> cusparseCheckStatus ( status ) <EOL> return nnzPerVector , nnzHost <EOL> _libcusparse . cusparseSdense2csr . restype = int <EOL> _libcusparse . cusparseSdense2csr . argtypes = [ ctypes . c_int , <EOL> ctypes . c_int , <EOL> ctypes . c_int , <EOL> cusparseMatDescr , <EOL> ctypes . c_void_p , <EOL> ctypes . c_int , <EOL> ctypes . c_void_p , <EOL> ctypes . c_void_p , <EOL> ctypes . c_void_p , <EOL> ctypes . c_void_p ] <EOL> def cusparseSdense2csr ( handle , m , n , descrA , A , lda , <EOL> nnzPerRow , csrValA , csrRowPtrA , csrColIndA ) : <EOL> pass </s>
