<s> """<STR_LIT>""" <EOL> import ctypes as ct <EOL> from quagga . cuda import cudart <EOL> _libcusparse = ct . cdll . LoadLibrary ( '<STR_LIT>' ) <EOL> ct_cusparse_handle = ct . c_void_p <EOL> ct_cusparse_status = ct . c_int <EOL> cusparse_statuses = { <EOL> <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' , <EOL> <NUM_LIT:3> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT>' , <EOL> <NUM_LIT:5> : '<STR_LIT>' , <EOL> <NUM_LIT:6> : '<STR_LIT>' , <EOL> <NUM_LIT:7> : '<STR_LIT>' , <EOL> <NUM_LIT:8> : '<STR_LIT>' , <EOL> <NUM_LIT:9> : '<STR_LIT>' <EOL> } <EOL> class CublasError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> exceptions = { } <EOL> for error_code , status_name in cusparse_statuses . iteritems ( ) : <EOL> class_name = status_name . replace ( '<STR_LIT>' , '<STR_LIT:_>' ) <EOL> class_name = '<STR_LIT>' . join ( each . capitalize ( ) for each in class_name . split ( '<STR_LIT:_>' ) ) <EOL> klass = type ( class_name , ( CublasError , ) , { '<STR_LIT>' : status_name } ) <EOL> exceptions [ error_code ] = klass <EOL> def check_status ( status ) : <EOL> if status != <NUM_LIT:0> : <EOL> try : <EOL> raise exceptions [ status ] <EOL> except KeyError : <EOL> raise CublasError ( '<STR_LIT>' . format ( status ) ) <EOL> _libcusparse . cusparseCreate . restype = ct_cusparse_status <EOL> _libcusparse . cusparseCreate . argtypes = [ ct . POINTER ( ct_cusparse_handle ) ] <EOL> def create ( handle ) : <EOL> status = _libcusparse . cusparseCreate ( ct . byref ( handle ) ) <EOL> check_status ( status ) <EOL> _libcusparse . cusparseDestroy . restype = ct_cusparse_status <EOL> _libcusparse . cusparseDestroy . argtypes = [ ct_cusparse_handle ] <EOL> def destroy ( handle ) : <EOL> status = _libcusparse . cusparseDestroy ( handle ) <EOL> check_status ( status ) <EOL> _libcusparse . cusparseGetVersion . restype = ct_cusparse_status <EOL> _libcusparse . cusparseGetVersion . argtypes = [ ct_cusparse_handle , ct . c_void_p ] <EOL> def get_version ( handle ) : <EOL> version = ct . c_int ( ) <EOL> status = _libcusparse . cusparseGetVersion ( handle , ct . byref ( version ) ) <EOL> check_status ( status ) <EOL> return version . value <EOL> _libcusparse . cusparseSetStream . restype = ct_cusparse_status <EOL> _libcusparse . cusparseSetStream . argtypes = [ ct_cusparse_handle , <EOL> cudart . ct_cuda_stream ] <EOL> def set_stream ( handle , stream ) : <EOL> status = _libcusparse . cusparseSetStream ( handle , stream ) <EOL> check_status ( status ) </s>
