• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compiler.compile_extra函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numba.compiler.compile_extra函数的典型用法代码示例。如果您正苦于以下问题:Python compile_extra函数的具体用法?Python compile_extra怎么用?Python compile_extra使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了compile_extra函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_use_car_move

    def test_use_car_move(self):
        tyctx = typing.Context()
        tyctx.insert_class(Car, self.carattrs)

        cgctx = CPUContext(tyctx)
        cgctx.insert_class(Car, self.carattrs)

        car_object = types.Object(Car)
        argtys = (car_object, types.int32)

        flags = compiler.Flags()
        cr = compiler.compile_extra(tyctx, cgctx, use_car_move, args=argtys,
                                    return_type=None, flags=flags, locals={})
        func = cr.entry_point

        if cr.typing_error:
            raise cr.typing_error

        car1 = Car(value=123)
        car2 = Car(value=123)
        self.assertEqual(use_car_move(car1, 321), func(car2, 321))

        def bm_python():
            use_car_move(car1, 321)

        def bm_numba():
            func(car2, 321)

        python = utils.benchmark(bm_python, maxsec=.1)
        numba = utils.benchmark(bm_numba, maxsec=.1)

        print(python)
        print(numba)
开发者ID:ASPP,项目名称:numba,代码行数:33,代码来源:test_jitclasses.py


示例2: compile

    def compile(self, sig, locals={}, **targetoptions):
        locs = self.locals.copy()
        locs.update(locals)

        topt = self.targetoptions.copy()
        topt.update(targetoptions)

        flags = compiler.Flags()
        self.targetdescr.options.parse_as_flags(flags, topt)
        flags.set("no_compile")
        flags.set("no_cpython_wrapper")
        flags.set("error_model", "numpy")
        # Disable loop lifting
        # The feature requires a real python function
        flags.unset("enable_looplift")

        typingctx = self.targetdescr.typing_context
        targetctx = self.targetdescr.target_context

        args, return_type = sigutils.normalize_signature(sig)

        cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
                                      args=args, return_type=return_type,
                                      flags=flags, locals=locals)

        self.overloads[cres.signature] = cres
        return cres
开发者ID:Alexhuszagh,项目名称:numba,代码行数:27,代码来源:ufuncbuilder.py


示例3: compile

    def compile(self, sig):
        with self._compile_lock:
            args, return_type = sigutils.normalize_signature(sig)
            # Don't recompile if signature already exists
            # (e.g. if another thread compiled it before we got the lock)
            existing = self.overloads.get(tuple(args))
            if existing is not None:
                return existing

            flags = compiler.Flags()
            self.targetdescr.options.parse_as_flags(flags, self.targetoptions)

            cres = compiler.compile_extra(
                self.typingctx,
                self.targetctx,
                self.py_func,
                args=args,
                return_type=return_type,
                flags=flags,
                locals=self.locals,
            )

            # Check typing error if object mode is used
            if cres.typing_error is not None and not flags.enable_pyobject:
                raise cres.typing_error

            self.add_overload(cres)
            return cres.entry_point
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:28,代码来源:dispatcher.py


示例4: compile_cuda

def compile_cuda(pyfunc, return_type, args, debug, inline):
    # First compilation will trigger the initialization of the CUDA backend.
    from .descriptor import CUDATargetDesc

    typingctx = CUDATargetDesc.typingctx
    targetctx = CUDATargetDesc.targetctx
    # TODO handle debug flag
    flags = compiler.Flags()
    # Do not compile (generate native code), just lower (to LLVM)
    flags.set('no_compile')
    flags.set('no_cpython_wrapper')
    if debug:
        flags.set('boundcheck')
    if inline:
        flags.set('forceinline')
    # Run compilation pipeline
    cres = compiler.compile_extra(typingctx=typingctx,
                                  targetctx=targetctx,
                                  func=pyfunc,
                                  args=args,
                                  return_type=return_type,
                                  flags=flags,
                                  locals={})

    library = cres.library
    library.finalize()

    return cres
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:28,代码来源:compiler.py


示例5: compile_cuda

def compile_cuda(pyfunc, return_type, args, debug):
    # First compilation will trigger the initialization of the CUDA backend.
    from .descriptor import CUDATargetDesc

    typingctx = CUDATargetDesc.typingctx
    targetctx = CUDATargetDesc.targetctx
    # TODO handle debug flag
    flags = compiler.Flags()
    # Do not compile (generate native code), just lower (to LLVM)
    flags.set('no_compile')
    # Run compilation pipeline
    cres = compiler.compile_extra(typingctx=typingctx,
                                  targetctx=targetctx,
                                  func=pyfunc,
                                  args=args,
                                  return_type=return_type,
                                  flags=flags,
                                  locals={})

    # Linking depending libraries
    targetctx.link_dependencies(cres.llvm_module, cres.target_context.linking)

    # Fix global naming
    for gv in cres.llvm_module.global_variables:
        if '.' in gv.name:
            gv.name = gv.name.replace('.', '_')

    return cres
开发者ID:MJJoyce,项目名称:numba,代码行数:28,代码来源:compiler.py


示例6: __init__

    def __init__(self, pyfunc, signature):
        self.py_func = pyfunc
        self.signature = signature
        self.name = pyfunc.__name__

        # recreate for each UDF, as linking is destructive to the
        # precompiled module
        impala_typing = impala_typing_context()
        impala_targets = ImpalaTargetContext(impala_typing)

        args, return_type = sigutils.normalize_signature(signature)
        flags = Flags()
        flags.set('no_compile')
        self._cres = compile_extra(typingctx=impala_typing,
                                   targetctx=impala_targets, func=pyfunc,
                                   args=args, return_type=return_type,
                                   flags=flags, locals={})
        llvm_func = impala_targets.finalize(self._cres.llvm_func, return_type,
                                            args)
        self.llvm_func = llvm_func
        # numba_module = llvm_func.module
        self.llvm_module = llvm_func.module
        # link in the precompiled module
        # bc it's destructive, load a fresh version
        precompiled = lc.Module.from_bitcode(
            pkgutil.get_data("impala.udf", "precompiled/impyla.bc"))
        self.llvm_module.link_in(precompiled)
开发者ID:awleblang,项目名称:impyla,代码行数:27,代码来源:__init__.py


示例7: compile

    def compile(self, sig, locals={}, **targetoptions):
        with self._compile_lock():
            locs = self.locals.copy()
            locs.update(locals)

            topt = self.targetoptions.copy()
            topt.update(targetoptions)

            flags = compiler.Flags()
            self.targetdescr.options.parse_as_flags(flags, topt)

            glctx = self.targetdescr
            typingctx = glctx.typing_context
            targetctx = glctx.target_context

            args, return_type = sigutils.normalize_signature(sig)

            # Don't recompile if signature already exist.
            existing = self.overloads.get(tuple(args))
            if existing is not None:
                return existing.entry_point

            cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
                                          args=args, return_type=return_type,
                                          flags=flags, locals=locs)

            # Check typing error if object mode is used
            if cres.typing_error is not None and not flags.enable_pyobject:
                raise cres.typing_error

            self.add_overload(cres)
            return cres.entry_point
开发者ID:jiaxu825,项目名称:numba,代码行数:32,代码来源:dispatcher.py


示例8: compile

    def compile(self, sig, locals={}, **targetoptions):
        locs = self.locals.copy()
        locs.update(locals)

        topt = self.targetoptions.copy()
        topt.update(targetoptions)

        if topt.get('nopython', True) == False:
            raise TypeError("nopython option must be False")
        topt['nopython'] = True

        flags = compiler.Flags()
        flags.set("no_compile")
        self.targetdescr.options.parse_as_flags(flags, topt)

        typingctx = self.targetdescr.typing_context
        targetctx = self.targetdescr.target_context

        args, return_type = sigutils.normalize_signature(sig)

        cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
                                      args=args, return_type=return_type,
                                      flags=flags, locals=locals)

        self.overloads[cres.signature] = cres
        return cres
开发者ID:B-Rich,项目名称:numba,代码行数:26,代码来源:ufuncbuilder.py


示例9: compile

    def compile(self, sig):
        with self._compile_lock:
            args, return_type = sigutils.normalize_signature(sig)
            # Don't recompile if signature already exists
            existing = self.overloads.get(tuple(args))
            if existing is not None:
                return existing

            # Try to load from disk cache
            cres = self._cache.load_overload(sig, self.targetctx)
            if cres is not None:
                # XXX fold this in add_overload()? (also see compiler.py)
                if not cres.objectmode and not cres.interpmode:
                    self.targetctx.insert_user_function(cres.entry_point,
                                                   cres.fndesc, [cres.library])
                self.add_overload(cres)
                return cres.entry_point

            flags = compiler.Flags()
            self.targetdescr.options.parse_as_flags(flags, self.targetoptions)

            cres = compiler.compile_extra(self.typingctx, self.targetctx,
                                          self.py_func,
                                          args=args, return_type=return_type,
                                          flags=flags, locals=self.locals)

            # Check typing error if object mode is used
            if cres.typing_error is not None and not flags.enable_pyobject:
                raise cres.typing_error

            self.add_overload(cres)
            self._cache.save_overload(sig, cres)
            return cres.entry_point
开发者ID:GaZ3ll3,项目名称:numba,代码行数:33,代码来源:dispatcher.py


示例10: compile_hsa

def compile_hsa(pyfunc, return_type, args, debug):
    # First compilation will trigger the initialization of the HSA backend.
    from .descriptor import HSATargetDesc

    typingctx = HSATargetDesc.typingctx
    targetctx = HSATargetDesc.targetctx
    # TODO handle debug flag
    flags = compiler.Flags()
    # Do not compile (generate native code), just lower (to LLVM)
    flags.set('no_compile')
    flags.set('no_cpython_wrapper')
    flags.unset('nrt')
    # Run compilation pipeline
    cres = compiler.compile_extra(typingctx=typingctx,
                                  targetctx=targetctx,
                                  func=pyfunc,
                                  args=args,
                                  return_type=return_type,
                                  flags=flags,
                                  locals={})

    # Linking depending libraries
    # targetctx.link_dependencies(cres.llvm_module, cres.target_context.linking)
    library = cres.library
    library.finalize()

    return cres
开发者ID:Alexhuszagh,项目名称:numba,代码行数:27,代码来源:compiler.py


示例11: _cull_exports

    def _cull_exports(self):
        """Read all the exported functions/modules in the translator
        environment, and join them into a single LLVM module.
        """
        self.exported_function_types = {}
        self.function_environments = {}
        self.environment_gvs = {}

        codegen = self.context.codegen()
        library = codegen.create_library(self.module_name)

        # Generate IR for all exported functions
        flags = Flags()
        flags.set("no_compile")
        if not self.export_python_wrap:
            flags.set("no_cpython_wrapper")
        if self.use_nrt:
            flags.set("nrt")
            # Compile NRT helpers
            nrt_module, _ = nrtdynmod.create_nrt_module(self.context)
            library.add_ir_module(nrt_module)

        for entry in self.export_entries:
            cres = compile_extra(self.typing_context, self.context,
                                 entry.function,
                                 entry.signature.args,
                                 entry.signature.return_type, flags,
                                 locals={}, library=library)

            func_name = cres.fndesc.llvm_func_name
            llvm_func = cres.library.get_function(func_name)

            if self.export_python_wrap:
                llvm_func.linkage = lc.LINKAGE_INTERNAL
                wrappername = cres.fndesc.llvm_cpython_wrapper_name
                wrapper = cres.library.get_function(wrappername)
                wrapper.name = self._mangle_method_symbol(entry.symbol)
                wrapper.linkage = lc.LINKAGE_EXTERNAL
                fnty = cres.target_context.call_conv.get_function_type(
                    cres.fndesc.restype, cres.fndesc.argtypes)
                self.exported_function_types[entry] = fnty
                self.function_environments[entry] = cres.environment
                self.environment_gvs[entry] = cres.fndesc.env_name
            else:
                llvm_func.name = entry.symbol
                self.dll_exports.append(entry.symbol)

        if self.export_python_wrap:
            wrapper_module = library.create_ir_module("wrapper")
            self._emit_python_wrapper(wrapper_module)
            library.add_ir_module(wrapper_module)

        # Hide all functions in the DLL except those explicitly exported
        library.finalize()
        for fn in library.get_defined_functions():
            if fn.name not in self.dll_exports:
                fn.visibility = "hidden"

        return library
开发者ID:cpcloud,项目名称:numba,代码行数:59,代码来源:compiler.py


示例12: test_scalar

    def test_scalar(self):
        flags = Flags()

        # Compile the inner function
        global cnd_jitted
        cr1 = compile_isolated(cnd, (types.float64,))
        cnd_jitted = cr1.entry_point
        # Manually type the compiled function for calling into
        tyctx = cr1.typing_context
        ctx = cr1.target_context
        signature = typing.make_concrete_template("cnd_jitted", cnd_jitted,
                                                  [cr1.signature])
        tyctx.insert_user_function(cnd_jitted, signature)

        # Compile the outer function
        array = types.Array(types.float64, 1, 'C')
        argtys = (array,) * 5 + (types.float64, types.float64)
        cr2 = compile_extra(tyctx, ctx, blackscholes_scalar_jitted,
                            args=argtys, return_type=None, flags=flags,
                            locals={})
        jitted_bs = cr2.entry_point

        OPT_N = 400
        iterations = 10

        callResultGold = np.zeros(OPT_N)
        putResultGold = np.zeros(OPT_N)

        callResultNumba = np.zeros(OPT_N)
        putResultNumba = np.zeros(OPT_N)

        stockPrice = randfloat(self.random.random_sample(OPT_N), 5.0, 30.0)
        optionStrike = randfloat(self.random.random_sample(OPT_N), 1.0, 100.0)
        optionYears = randfloat(self.random.random_sample(OPT_N), 0.25, 10.0)

        args = stockPrice, optionStrike, optionYears, RISKFREE, VOLATILITY

        ts = timer()
        for i in range(iterations):
             blackscholes_scalar(callResultGold, putResultGold, *args)
        te = timer()
        pytime = te - ts

        ts = timer()
        for i in range(iterations):
            jitted_bs(callResultNumba, putResultNumba, *args)
        te = timer()
        jittime = te - ts

        print("Python", pytime)
        print("Numba", jittime)
        print("Speedup: %s" % (pytime / jittime))

        delta = np.abs(callResultGold - callResultNumba)
        L1norm = delta.sum() / np.abs(callResultGold).sum()
        print("L1 norm: %E" % L1norm)
        print("Max absolute error: %E" % delta.max())
        self.assertAlmostEqual(delta.max(), 0)
开发者ID:Alexhuszagh,项目名称:numba,代码行数:58,代码来源:test_blackscholes.py


示例13: compile

 def compile(self, py_func, sig, library=None):
     if library is None:
         library = self.library
     args, return_type = sigutils.normalize_signature(sig)
     return compiler.compile_extra(self.typingctx, self.targetctx,
                                   py_func, args=args,
                                   return_type=return_type,
                                   flags=self.flags, locals=self.locals,
                                   library=library)
开发者ID:jriehl,项目名称:sandbox,代码行数:9,代码来源:despatcher.py


示例14: _cull_exports

    def _cull_exports(self):
        """Read all the exported functions/modules in the translator
        environment, and join them into a single LLVM module.

        Resets the export environment afterwards.
        """
        self.exported_signatures = export_registry

        # Create new module containing everything
        llvm_module = lc.Module.new(self.module_name)

        # Compile all exported functions
        typing_ctx = CPUTarget.typing_context
        # TODO Use non JIT-ing target
        target_ctx = CPUTarget.target_context
        modules = []
        flags = Flags()
        if not self.export_python_wrap:
            flags.set("no_compile")

        for entry in self.exported_signatures:
            cres = compile_extra(typing_ctx, target_ctx, entry.function,
                                 entry.signature.args,
                                 entry.signature.return_type, flags,
                                 locals={})

            if self.export_python_wrap:
                module = cres.llvm_func.module
                cres.llvm_func.linkage = lc.LINKAGE_INTERNAL
                wrappername = "wrapper." + cres.llvm_func.name
                wrapper = module.get_function_named(wrappername)
                wrapper.name = entry.symbol
            else:
                cres.llvm_func.name = entry.symbol

            modules.append(cres.llvm_module)

        # Link all exported functions
        for mod in modules:
            llvm_module.link_in(mod, preserve=self.export_python_wrap)

        # Optimize
        tm = le.TargetMachine.new(opt=3)
        pms = lp.build_pass_managers(tm=tm, opt=3, loop_vectorize=True,
                                     fpm=False)
        pms.pm.run(llvm_module)

        if self.export_python_wrap:
            self._emit_python_wrapper(llvm_module)

        #del self.exported_signatures[:]
        print(llvm_module)
        return llvm_module
开发者ID:ewiger,项目名称:numba,代码行数:53,代码来源:compiler.py


示例15: compile

 def compile(self, func, args, return_type=None, flags=DEFAULT_FLAGS):
     """
     Compile the function or retrieve an already compiled result
     from the cache.
     """
     cache_key = (func, args, return_type, flags)
     try:
         cr = self.cr_cache[cache_key]
     except KeyError:
         cr = compile_extra(self.typingctx, self.targetctx, func,
                            args, return_type, flags, locals={})
         self.cr_cache[cache_key] = cr
     return cr
开发者ID:dboyliao,项目名称:numba,代码行数:13,代码来源:support.py


示例16: compile

    def compile(self, args, return_type):
        flags = compiler.Flags()
        self.targetdescr.options.parse_as_flags(flags, self.targetoptions)

        impl = self._get_implementation(args, {})
        cres = compiler.compile_extra(self.targetdescr.typing_context,
                                      self.targetdescr.target_context,
                                      impl,
                                      args=args, return_type=return_type,
                                      flags=flags, locals=self.locals)
        # Check typing error if object mode is used
        if cres.typing_error is not None and not flags.enable_pyobject:
            raise cres.typing_error
        return cres
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:14,代码来源:dispatcher.py


示例17: _cull_exports

    def _cull_exports(self):
        """Read all the exported functions/modules in the translator
        environment, and join them into a single LLVM module.

        Resets the export environment afterwards.
        """
        self.exported_signatures = export_registry
        self.exported_function_types = {}

        typing_ctx = CPUTarget.typing_context
        target_ctx = CPUTarget.target_context

        codegen = target_ctx.aot_codegen(self.module_name)
        library = codegen.create_library(self.module_name)

        # Generate IR for all exported functions
        flags = Flags()
        flags.set("no_compile")

        for entry in self.exported_signatures:
            cres = compile_extra(typing_ctx, target_ctx, entry.function,
                                 entry.signature.args,
                                 entry.signature.return_type, flags,
                                 locals={}, library=library)

            func_name = cres.fndesc.llvm_func_name
            llvm_func = cres.library.get_function(func_name)

            if self.export_python_wrap:
                # XXX: unsupported (necessary?)
                llvm_func.linkage = lc.LINKAGE_INTERNAL
                wrappername = cres.fndesc.llvm_cpython_wrapper_name
                wrapper = cres.library.get_function(wrappername)
                wrapper.name = entry.symbol
                wrapper.linkage = lc.LINKAGE_EXTERNAL
                fnty = cres.target_context.call_conv.get_function_type(
                    cres.fndesc.restype, cres.fndesc.argtypes)
                self.exported_function_types[entry] = fnty
            else:
                llvm_func.linkage = lc.LINKAGE_EXTERNAL
                llvm_func.name = entry.symbol

        if self.export_python_wrap:
            wrapper_module = library.create_ir_module("wrapper")
            self._emit_python_wrapper(wrapper_module)
            library.add_ir_module(wrapper_module)

        return library
开发者ID:hargup,项目名称:numba,代码行数:48,代码来源:compiler.py


示例18: __init__

    def __init__(self, pyfunc, signature):
        self.py_func = pyfunc
        self.signature = signature
        self.name = pyfunc.__name__

        args, return_type = sigutils.normalize_signature(signature)
        flags = Flags()
        flags.set('no_compile')
        self._cres = compile_extra(typingctx=impala_typing,
                                   targetctx=impala_targets, func=pyfunc,
                                   args=args, return_type=return_type,
                                   flags=flags, locals={})
        llvm_func = impala_targets.finalize(self._cres.llvm_func, return_type,
                                            args)
        self.llvm_func = llvm_func
        self.llvm_module = llvm_func.module
开发者ID:B-Rich,项目名称:numba,代码行数:16,代码来源:impala.py


示例19: _compile_core

 def _compile_core(self, sig, flags, locals):
     """
     Trigger the compiler on the core function or load a previously
     compiled version from the cache.  Returns the CompileResult.
     """
     typingctx = self.targetdescr.typing_context
     targetctx = self.targetdescr.target_context
     cres = self.cache.load_overload(sig, targetctx)
     if cres is not None:
         # Use cached version
         return cres
     # Compile
     args, return_type = sigutils.normalize_signature(sig)
     cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
                                   args=args, return_type=return_type,
                                   flags=flags, locals=locals)
     self.cache.save_overload(sig, cres)
     return cres
开发者ID:FedericoStra,项目名称:numba,代码行数:18,代码来源:ufuncbuilder.py


示例20: compile

    def compile(self, func, args, return_type=None, flags=DEFAULT_FLAGS):
        """
        Compile the function or retrieve an already compiled result
        from the cache.
        """
        from numba.targets.registry import cpu_target

        cache_key = (func, args, return_type, flags)
        try:
            cr = self.cr_cache[cache_key]
        except KeyError:
            # Register the contexts in case for nested @jit or @overload calls
            # (same as compile_isolated())
            with cpu_target.nested_context(self.typingctx, self.targetctx):
                cr = compile_extra(self.typingctx, self.targetctx, func,
                                   args, return_type, flags, locals={})
            self.cr_cache[cache_key] = cr
        return cr
开发者ID:cpcloud,项目名称:numba,代码行数:18,代码来源:support.py



注:本文中的numba.compiler.compile_extra函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compiler.compile_isolated函数代码示例发布时间:2022-05-27
下一篇:
Python cgutils.unpack_tuple函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap