<s> from __future__ import absolute_import , print_function <EOL> import copy <EOL> import sys <EOL> import warnings <EOL> import operator <EOL> from functools import reduce , wraps <EOL> import threading <EOL> from numba import ctypes_support as ctypes <EOL> from numba . typing . templates import AbstractTemplate <EOL> from numba import config , compiler , types <EOL> from numba . typing . templates import ConcreteTemplate <EOL> from numba import funcdesc , typing , utils , serialize <EOL> from . cudadrv . autotune import AutoTuner <EOL> from . cudadrv . devices import get_context <EOL> from . cudadrv import nvvm , devicearray , driver <EOL> from . errors import KernelRuntimeError <EOL> from . api import get_current_device <EOL> _cuda_compiler_lock = threading . RLock ( ) <EOL> def nonthreadsafe ( fn ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( fn ) <EOL> def core ( * args , ** kwargs ) : <EOL> with _cuda_compiler_lock : <EOL> return fn ( * args , ** kwargs ) <EOL> return core <EOL> @ nonthreadsafe <EOL> def compile_cuda ( pyfunc , return_type , args , debug , inline ) : <EOL> from . descriptor import CUDATargetDesc <EOL> typingctx = CUDATargetDesc . typingctx <EOL> targetctx = CUDATargetDesc . targetctx <EOL> flags = compiler . Flags ( ) <EOL> flags . set ( '<STR_LIT>' ) <EOL> flags . set ( '<STR_LIT>' ) <EOL> if debug : <EOL> flags . set ( '<STR_LIT>' ) <EOL> if inline : <EOL> flags . set ( '<STR_LIT>' ) <EOL> cres = compiler . compile_extra ( typingctx = typingctx , <EOL> targetctx = targetctx , <EOL> func = pyfunc , <EOL> args = args , <EOL> return_type = return_type , <EOL> flags = flags , <EOL> locals = { } ) <EOL> library = cres . library <EOL> library . finalize ( ) <EOL> return cres <EOL> @ nonthreadsafe <EOL> def compile_kernel ( pyfunc , args , link , debug = False , inline = False , <EOL> fastmath = False ) : <EOL> cres = compile_cuda ( pyfunc , types . void , args , debug = debug , inline = inline ) <EOL> fname = cres . fndesc . llvm_func_name <EOL> lib , kernel = cres . target_context . prepare_cuda_kernel ( cres . library , fname , <EOL> cres . signature . args ) <EOL> cukern = CUDAKernel ( llvm_module = lib . _final_module , <EOL> name = kernel . name , <EOL> pretty_name = cres . fndesc . qualname , <EOL> argtypes = cres . signature . args , <EOL> type_annotation = cres . type_annotation , <EOL> link = link , <EOL> debug = debug , <EOL> call_helper = cres . call_helper , <EOL> fastmath = fastmath ) <EOL> return cukern <EOL> class DeviceFunctionTemplate ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pyfunc , debug , inline ) : <EOL> self . py_func = pyfunc <EOL> self . debug = debug <EOL> self . inline = inline <EOL> self . _compileinfos = { } <EOL> def __reduce__ ( self ) : <EOL> glbls = serialize . _get_function_globals_for_reduction ( self . py_func ) <EOL> func_reduced = serialize . _reduce_function ( self . py_func , glbls ) <EOL> args = ( self . __class__ , func_reduced , self . debug , self . inline ) <EOL> return ( serialize . _rebuild_reduction , args ) <EOL> @ classmethod <EOL> def _rebuild ( cls , func_reduced , debug , inline ) : <EOL> func = serialize . _rebuild_function ( * func_reduced ) <EOL> return compile_device_template ( func , debug = debug , inline = inline ) <EOL> def compile ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if args not in self . _compileinfos : <EOL> cres = compile_cuda ( self . py_func , None , args , debug = self . debug , <EOL> inline = self . inline ) <EOL> first_definition = not self . _compileinfos <EOL> self . _compileinfos [ args ] = cres <EOL> libs = [ cres . library ] <EOL> if first_definition : <EOL> cres . target_context . insert_user_function ( self , cres . fndesc , <EOL> libs ) <EOL> else : <EOL> cres . target_context . add_user_function ( self , cres . fndesc , libs ) <EOL> else : <EOL> cres = self . _compileinfos [ args ] <EOL> return cres . signature <EOL> def compile_device_template ( pyfunc , debug = False , inline = False ) : <EOL> """<STR_LIT>""" <EOL> from . descriptor import CUDATargetDesc <EOL> dft = DeviceFunctionTemplate ( pyfunc , debug = debug , inline = inline ) <EOL> class device_function_template ( AbstractTemplate ) : <EOL> key = dft <EOL> def generic ( self , args , kws ) : <EOL> assert not kws <EOL> return dft . compile ( args ) <EOL> typingctx = CUDATargetDesc . typingctx <EOL> typingctx . insert_user_function ( dft , device_function_template ) <EOL> return dft <EOL> def compile_device ( pyfunc , return_type , args , inline = True , debug = False ) : <EOL> return DeviceFunction ( pyfunc , return_type , args , inline = True , debug = False ) <EOL> def declare_device_function ( name , restype , argtypes ) : <EOL> from . descriptor import CUDATargetDesc <EOL> typingctx = CUDATargetDesc . typingctx <EOL> targetctx = CUDATargetDesc . targetctx <EOL> sig = typing . signature ( restype , * argtypes ) <EOL> extfn = ExternFunction ( name , sig ) <EOL> class device_function_template ( ConcreteTemplate ) : <EOL> key = extfn <EOL> cases = [ sig ] <EOL> fndesc = funcdesc . ExternalFunctionDescriptor ( <EOL> name = name , restype = restype , argtypes = argtypes ) <EOL> typingctx . insert_user_function ( extfn , device_function_template ) <EOL> targetctx . insert_user_function ( extfn , fndesc ) <EOL> return extfn <EOL> class DeviceFunction ( object ) : <EOL> def __init__ ( self , pyfunc , return_type , args , inline , debug ) : <EOL> self . py_func = pyfunc <EOL> self . return_type = return_type <EOL> self . args = args <EOL> self . inline = True <EOL> self . debug = False <EOL> cres = compile_cuda ( self . py_func , self . return_type , self . args , <EOL> debug = self . debug , inline = self . inline ) <EOL> self . cres = cres <EOL> class device_function_template ( ConcreteTemplate ) : <EOL> key = self <EOL> cases = [ cres . signature ] <EOL> cres . typing_context . insert_user_function ( <EOL> self , device_function_template ) <EOL> cres . target_context . insert_user_function ( self , cres . fndesc , <EOL> [ cres . library ] ) <EOL> def __reduce__ ( self ) : <EOL> globs = serialize . _get_function_globals_for_reduction ( self . py_func ) <EOL> func_reduced = serialize . _reduce_function ( self . py_func , globs ) <EOL> args = ( self . __class__ , func_reduced , self . return_type , self . args , <EOL> self . inline , self . debug ) <EOL> return ( serialize . _rebuild_reduction , args ) <EOL> @ classmethod <EOL> def _rebuild ( cls , func_reduced , return_type , args , inline , debug ) : <EOL> return cls ( serialize . _rebuild_function ( * func_reduced ) , return_type , <EOL> args , inline , debug ) <EOL> def __repr__ ( self ) : <EOL> fmt = "<STR_LIT>" <EOL> return fmt . format ( self . py_func , self . cres . signature ) <EOL> class ExternFunction ( object ) : <EOL> def __init__ ( self , name , sig ) : <EOL> self . name = name <EOL> self . sig = sig <EOL> def _compute_thread_per_block ( kernel , tpb ) : <EOL> if tpb != <NUM_LIT:0> : <EOL> return tpb <EOL> else : <EOL> try : <EOL> tpb = kernel . autotune . best ( ) <EOL> except ValueError : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> tpb = <NUM_LIT> <EOL> return tpb <EOL> class ForAll ( object ) : <EOL> def __init__ ( self , kernel , ntasks , tpb , stream , sharedmem ) : <EOL> self . kernel = kernel <EOL> self . ntasks = ntasks <EOL> self . thread_per_block = tpb <EOL> self . stream = stream <EOL> self . sharedmem = sharedmem <EOL> def __call__ ( self , * args ) : <EOL> if isinstance ( self . kernel , AutoJitCUDAKernel ) : <EOL> kernel = self . kernel . specialize ( * args ) <EOL> else : <EOL> kernel = self . kernel <EOL> tpb = _compute_thread_per_block ( kernel , self . thread_per_block ) <EOL> tpbm1 = tpb - <NUM_LIT:1> <EOL> blkct = ( self . ntasks + tpbm1 ) // tpb <EOL> return kernel . configure ( blkct , tpb , stream = self . stream , <EOL> sharedmem = self . sharedmem ) ( * args ) <EOL> class CUDAKernelBase ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . griddim = ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . blockdim = ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . sharedmem = <NUM_LIT:0> <EOL> self . stream = <NUM_LIT:0> <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> cls = self . __class__ <EOL> new = cls . __new__ ( cls ) <EOL> new . __dict__ . update ( self . __dict__ ) <EOL> return new <EOL> def configure ( self , griddim , blockdim , stream = <NUM_LIT:0> , sharedmem = <NUM_LIT:0> ) : <EOL> if not isinstance ( griddim , ( tuple , list ) ) : <EOL> griddim = [ griddim ] <EOL> else : <EOL> griddim = list ( griddim ) <EOL> if len ( griddim ) > <NUM_LIT:3> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> while len ( griddim ) < <NUM_LIT:3> : <EOL> griddim . append ( <NUM_LIT:1> ) <EOL> if not isinstance ( blockdim , ( tuple , list ) ) : <EOL> blockdim = [ blockdim ] <EOL> else : <EOL> blockdim = list ( blockdim ) <EOL> if len ( blockdim ) > <NUM_LIT:3> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> while len ( blockdim ) < <NUM_LIT:3> : <EOL> blockdim . append ( <NUM_LIT:1> ) <EOL> clone = self . copy ( ) <EOL> clone . griddim = tuple ( griddim ) <EOL> clone . blockdim = tuple ( blockdim ) <EOL> clone . stream = stream <EOL> clone . sharedmem = sharedmem <EOL> return clone <EOL> def __getitem__ ( self , args ) : <EOL> if len ( args ) not in [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return self . configure ( * args ) <EOL> def forall ( self , ntasks , tpb = <NUM_LIT:0> , stream = <NUM_LIT:0> , sharedmem = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return ForAll ( self , ntasks , tpb = tpb , stream = stream , sharedmem = sharedmem ) <EOL> def _serialize_config ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . griddim , self . blockdim , self . sharedmem <EOL> def _deserialize_config ( self , config ) : <EOL> """<STR_LIT>""" <EOL> self . griddim , self . blockdim , self . sharedmem = config <EOL> class CachedPTX ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , llvmir , options ) : <EOL> self . name = name <EOL> self . llvmir = llvmir <EOL> self . cache = { } <EOL> self . _extra_options = options . copy ( ) <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> cuctx = get_context ( ) <EOL> device = cuctx . device <EOL> cc = device . compute_capability <EOL> ptx = self . cache . get ( cc ) <EOL> if ptx is None : <EOL> arch = nvvm . get_arch_option ( * cc ) <EOL> ptx = nvvm . llvm_to_ptx ( self . llvmir , opt = <NUM_LIT:3> , arch = arch , <EOL> ** self . _extra_options ) <EOL> self . cache [ cc ] = ptx <EOL> if config . DUMP_ASSEMBLY : <EOL> print ( ( "<STR_LIT>" % self . name ) . center ( <NUM_LIT> , '<STR_LIT:->' ) ) <EOL> print ( ptx . decode ( '<STR_LIT:utf-8>' ) ) <EOL> print ( '<STR_LIT:=>' * <NUM_LIT> ) <EOL> return ptx <EOL> class CachedCUFunction ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , entry_name , ptx , linking ) : <EOL> self . entry_name = entry_name <EOL> self . ptx = ptx <EOL> self . linking = linking <EOL> self . cache = { } <EOL> self . ccinfos = { } <EOL> def get ( self ) : <EOL> cuctx = get_context ( ) <EOL> device = cuctx . device <EOL> cufunc = self . cache . get ( device . id ) <EOL> if cufunc is None : <EOL> ptx = self . ptx . get ( ) <EOL> linker = driver . Linker ( ) <EOL> linker . add_ptx ( ptx ) <EOL> for path in self . linking : <EOL> linker . add_file_guess_ext ( path ) <EOL> cubin , _size = linker . complete ( ) <EOL> compile_info = linker . info_log <EOL> module = cuctx . create_module_image ( cubin ) <EOL> cufunc = module . get_function ( self . entry_name ) <EOL> self . cache [ device . id ] = cufunc <EOL> self . ccinfos [ device . id ] = compile_info <EOL> return cufunc <EOL> def get_info ( self ) : <EOL> self . get ( ) <EOL> cuctx = get_context ( ) <EOL> device = cuctx . device <EOL> ci = self . ccinfos [ device . id ] <EOL> return ci <EOL> def __reduce__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . linking : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise RuntimeError ( msg ) <EOL> args = ( self . __class__ , self . entry_name , self . ptx , self . linking ) <EOL> return ( serialize . _rebuild_reduction , args ) <EOL> @ classmethod <EOL> def _rebuild ( cls , entry_name , ptx , linking ) : <EOL> """<STR_LIT>""" <EOL> return cls ( entry_name , ptx , linking ) <EOL> class CUDAKernel ( CUDAKernelBase ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , llvm_module , name , pretty_name , argtypes , call_helper , <EOL> link = ( ) , debug = False , fastmath = False , type_annotation = None ) : <EOL> super ( CUDAKernel , self ) . __init__ ( ) <EOL> options = { } <EOL> if fastmath : <EOL> options . update ( dict ( ftz = True , <EOL> prec_sqrt = False , <EOL> prec_div = False , <EOL> fma = True ) ) <EOL> ptx = CachedPTX ( pretty_name , str ( llvm_module ) , options = options ) <EOL> cufunc = CachedCUFunction ( name , ptx , link ) <EOL> self . entry_name = name <EOL> self . argument_types = tuple ( argtypes ) <EOL> self . linking = tuple ( link ) <EOL> self . _type_annotation = type_annotation <EOL> self . _func = cufunc <EOL> self . debug = debug <EOL> self . call_helper = call_helper <EOL> @ classmethod <EOL> def _rebuild ( cls , name , argtypes , cufunc , link , debug , call_helper , config ) : <EOL> """<STR_LIT>""" <EOL> instance = cls . __new__ ( cls ) <EOL> super ( cls , instance ) . __init__ ( ) <EOL> instance . entry_name = name <EOL> instance . argument_types = tuple ( argtypes ) <EOL> instance . linking = tuple ( link ) <EOL> instance . _type_annotation = None <EOL> instance . _func = cufunc <EOL> instance . debug = debug <EOL> instance . call_helper = call_helper <EOL> instance . _deserialize_config ( config ) <EOL> return instance <EOL> def __reduce__ ( self ) : <EOL> """<STR_LIT>""" <EOL> config = self . _serialize_config ( ) <EOL> args = ( self . __class__ , self . entry_name , self . argument_types , <EOL> self . _func , self . linking , self . debug , self . call_helper , <EOL> config ) <EOL> return ( serialize . _rebuild_reduction , args ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> assert not kwargs <EOL> self . _kernel_call ( args = args , <EOL> griddim = self . griddim , <EOL> blockdim = self . blockdim , <EOL> stream = self . stream , <EOL> sharedmem = self . sharedmem ) <EOL> def bind ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _func . get ( ) <EOL> @ property <EOL> def ptx ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _func . ptx . get ( ) . decode ( '<STR_LIT:utf8>' ) <EOL> @ property <EOL> def device ( self ) : <EOL> """<STR_LIT>""" <EOL> return get_current_device ( ) <EOL> def inspect_llvm ( self ) : <EOL> '''<STR_LIT>''' <EOL> return str ( self . _func . ptx . llvmir ) <EOL> def inspect_asm ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _func . ptx . get ( ) . decode ( '<STR_LIT:ascii>' ) <EOL> def inspect_types ( self , file = None ) : <EOL> '''<STR_LIT>''' <EOL> if self . _type_annotation is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if file is None : <EOL> file = sys . stdout <EOL> print ( "<STR_LIT>" % ( self . entry_name , self . argument_types ) , file = file ) <EOL> print ( '<STR_LIT:->' * <NUM_LIT> , file = file ) <EOL> print ( self . _type_annotation , file = file ) <EOL> print ( '<STR_LIT:=>' * <NUM_LIT> , file = file ) <EOL> def _kernel_call ( self , args , griddim , blockdim , stream = <NUM_LIT:0> , sharedmem = <NUM_LIT:0> ) : <EOL> cufunc = self . _func . get ( ) <EOL> if self . debug : <EOL> excname = cufunc . name + "<STR_LIT>" <EOL> excmem , excsz = cufunc . module . get_global_symbol ( excname ) <EOL> assert excsz == ctypes . sizeof ( ctypes . c_int ) <EOL> excval = ctypes . c_int ( ) <EOL> excmem . memset ( <NUM_LIT:0> , stream = stream ) <EOL> retr = [ ] <EOL> kernelargs = [ ] <EOL> for t , v in zip ( self . argument_types , args ) : <EOL> self . _prepare_args ( t , v , stream , retr , kernelargs ) <EOL> cu_func = cufunc . configure ( griddim , blockdim , <EOL> stream = stream , <EOL> sharedmem = sharedmem ) <EOL> cu_func ( * kernelargs ) <EOL> if self . debug : <EOL> driver . device_to_host ( ctypes . addressof ( excval ) , excmem , excsz ) <EOL> if excval . value != <NUM_LIT:0> : <EOL> def load_symbol ( name ) : <EOL> mem , sz = cufunc . module . get_global_symbol ( "<STR_LIT>" % <EOL> ( cufunc . name , <EOL> name ) ) <EOL> val = ctypes . c_int ( ) <EOL> driver . device_to_host ( ctypes . addressof ( val ) , mem , sz ) <EOL> return val . value <EOL> tid = [ load_symbol ( "<STR_LIT>" + i ) for i in '<STR_LIT>' ] <EOL> ctaid = [ load_symbol ( "<STR_LIT>" + i ) for i in '<STR_LIT>' ] <EOL> code = excval . value <EOL> exccls , exc_args = self . call_helper . get_exception ( code ) <EOL> prefix = "<STR_LIT>" % ( tid , ctaid ) <EOL> if exc_args : <EOL> exc_args = ( "<STR_LIT>" % ( prefix , exc_args [ <NUM_LIT:0> ] ) , ) + exc_args [ <NUM_LIT:1> : ] <EOL> else : <EOL> exc_args = prefix , <EOL> raise exccls ( * exc_args ) <EOL> for wb in retr : <EOL> wb ( ) <EOL> def _prepare_args ( self , ty , val , stream , retr , kernelargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( ty , types . Array ) : <EOL> if isinstance ( ty , types . SmartArrayType ) : <EOL> devary = val . gpu ( ) <EOL> retr . append ( lambda : val . gpu_changed ( ) ) <EOL> outer_parent = ctypes . c_void_p ( <NUM_LIT:0> ) <EOL> kernelargs . append ( outer_parent ) <EOL> else : <EOL> devary , conv = devicearray . auto_device ( val , stream = stream ) <EOL> if conv : <EOL> retr . append ( lambda : devary . copy_to_host ( val , stream = stream ) ) <EOL> c_intp = ctypes . c_ssize_t <EOL> meminfo = ctypes . c_void_p ( <NUM_LIT:0> ) <EOL> parent = ctypes . c_void_p ( <NUM_LIT:0> ) <EOL> nitems = c_intp ( devary . size ) <EOL> itemsize = c_intp ( devary . dtype . itemsize ) <EOL> data = ctypes . c_void_p ( driver . device_pointer ( devary ) ) <EOL> kernelargs . append ( meminfo ) <EOL> kernelargs . append ( parent ) <EOL> kernelargs . append ( nitems ) <EOL> kernelargs . append ( itemsize ) <EOL> kernelargs . append ( data ) <EOL> for ax in range ( devary . ndim ) : <EOL> kernelargs . append ( c_intp ( devary . shape [ ax ] ) ) <EOL> for ax in range ( devary . ndim ) : <EOL> kernelargs . append ( c_intp ( devary . strides [ ax ] ) ) <EOL> elif isinstance ( ty , types . Integer ) : <EOL> cval = getattr ( ctypes , "<STR_LIT>" % ty ) ( val ) <EOL> kernelargs . append ( cval ) <EOL> elif ty == types . float64 : <EOL> cval = ctypes . c_double ( val ) <EOL> kernelargs . append ( cval ) <EOL> elif ty == types . float32 : <EOL> cval = ctypes . c_float ( val ) <EOL> kernelargs . append ( cval ) <EOL> elif ty == types . boolean : <EOL> cval = ctypes . c_uint8 ( int ( val ) ) <EOL> kernelargs . append ( cval ) <EOL> elif ty == types . complex64 : <EOL> kernelargs . append ( ctypes . c_float ( val . real ) ) <EOL> kernelargs . append ( ctypes . c_float ( val . imag ) ) <EOL> elif ty == types . complex128 : <EOL> kernelargs . append ( ctypes . c_double ( val . real ) ) <EOL> kernelargs . append ( ctypes . c_double ( val . imag ) ) <EOL> elif isinstance ( ty , types . Record ) : <EOL> devrec , conv = devicearray . auto_device ( val , stream = stream ) <EOL> if conv : <EOL> retr . append ( lambda : devrec . copy_to_host ( val , stream = stream ) ) <EOL> kernelargs . append ( devrec ) <EOL> else : <EOL> raise NotImplementedError ( ty , val ) <EOL> @ property <EOL> def autotune ( self ) : <EOL> """<STR_LIT>""" <EOL> has_autotune = hasattr ( self , '<STR_LIT>' ) <EOL> if has_autotune and self . _autotune . dynsmem == self . sharedmem : <EOL> return self . _autotune <EOL> else : <EOL> cufunc = self . _func . get ( ) <EOL> at = AutoTuner ( info = cufunc . attrs , cc = cufunc . device . compute_capability ) <EOL> self . _autotune = at <EOL> return self . _autotune <EOL> @ property <EOL> def occupancy ( self ) : <EOL> """<STR_LIT>""" <EOL> thread_per_block = reduce ( operator . mul , self . blockdim , <NUM_LIT:1> ) <EOL> return self . autotune . closest ( thread_per_block ) <EOL> class AutoJitCUDAKernel ( CUDAKernelBase ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , func , bind , targetoptions ) : <EOL> super ( AutoJitCUDAKernel , self ) . __init__ ( ) <EOL> self . py_func = func <EOL> self . bind = bind <EOL> self . definitions = { } <EOL> self . targetoptions = targetoptions <EOL> from . descriptor import CUDATargetDesc <EOL> self . typingctx = CUDATargetDesc . typingctx <EOL> def __call__ ( self , * args ) : <EOL> '''<STR_LIT>''' <EOL> kernel = self . specialize ( * args ) <EOL> cfg = kernel [ self . griddim , self . blockdim , self . stream , self . sharedmem ] <EOL> cfg ( * args ) <EOL> def specialize ( self , * args ) : <EOL> '''<STR_LIT>''' <EOL> argtypes = tuple ( <EOL> [ self . typingctx . resolve_argument_type ( a ) for a in args ] ) <EOL> kernel = self . definitions . get ( argtypes ) <EOL> if kernel is None : <EOL> if '<STR_LIT>' not in self . targetoptions : <EOL> self . targetoptions [ '<STR_LIT>' ] = ( ) <EOL> kernel = compile_kernel ( self . py_func , argtypes , <EOL> ** self . targetoptions ) <EOL> self . definitions [ argtypes ] = kernel <EOL> if self . bind : <EOL> kernel . bind ( ) <EOL> return kernel <EOL> def inspect_llvm ( self , signature = None ) : <EOL> '''<STR_LIT>''' <EOL> if signature is not None : <EOL> return self . definitions [ signature ] . inspect_llvm ( ) <EOL> else : <EOL> return dict ( ( sig , defn . inspect_llvm ( ) ) <EOL> for sig , defn in self . definitions . items ( ) ) <EOL> def inspect_asm ( self , signature = None ) : <EOL> '''<STR_LIT>''' <EOL> if signature is not None : <EOL> return self . definitions [ signature ] . inspect_asm ( ) <EOL> else : <EOL> return dict ( ( sig , defn . inspect_asm ( ) ) <EOL> for sig , defn in self . definitions . items ( ) ) <EOL> def inspect_types ( self , file = None ) : <EOL> '''<STR_LIT>''' <EOL> if file is None : <EOL> file = sys . stdout <EOL> for ver , defn in utils . iteritems ( self . definitions ) : <EOL> defn . inspect_types ( file = file ) <EOL> @ classmethod <EOL> def _rebuild ( cls , func_reduced , bind , targetoptions , config ) : <EOL> """<STR_LIT>""" <EOL> func = serialize . _rebuild_function ( * func_reduced ) <EOL> instance = cls ( func , bind , targetoptions ) <EOL> instance . _deserialize_config ( config ) <EOL> return instance <EOL> def __reduce__ ( self ) : <EOL> """<STR_LIT>""" <EOL> glbls = serialize . _get_function_globals_for_reduction ( self . py_func ) <EOL> func_reduced = serialize . _reduce_function ( self . py_func , glbls ) <EOL> config = self . _serialize_config ( ) <EOL> args = ( self . __class__ , func_reduced , self . bind , self . targetoptions , <EOL> config ) <EOL> return ( serialize . _rebuild_reduction , args ) </s>
