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

Python cgutils.get_module函数代码示例

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

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



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

示例1: ptx_atomic_add_tuple

def ptx_atomic_add_tuple(context, builder, sig, args):
    aryty, indty, valty = sig.args
    ary, inds, val = args
    dtype = aryty.dtype

    indices = cgutils.unpack_tuple(builder, inds, count=len(indty))
    indices = [context.cast(builder, i, t, types.intp)
               for t, i in zip(indty, indices)]

    if dtype != valty:
        raise TypeError("expect %s but got %s" % (dtype, valty))

    if aryty.ndim != len(indty):
        raise TypeError("indexing %d-D array with %d-D index" %
                        (aryty.ndim, len(indty)))

    lary = context.make_array(aryty)(context, builder, ary)
    ptr = cgutils.get_item_pointer(builder, aryty, lary, indices)

    if aryty.dtype == types.float32:
        lmod = cgutils.get_module(builder)
        return builder.call(nvvmutils.declare_atomic_add_float32(lmod), (ptr, val))
    elif aryty.dtype == types.float64:
        lmod = cgutils.get_module(builder)
        return builder.call(nvvmutils.declare_atomic_add_float64(lmod), (ptr, val))
    else:
        return builder.atomic_rmw('add', ptr, val, 'monotonic')
开发者ID:PierreBizouard,项目名称:numba,代码行数:27,代码来源:cudaimpl.py


示例2: complex128_power_impl

def complex128_power_impl(context, builder, sig, args):
    [ca, cb] = args
    a = Complex128(context, builder, value=ca)
    b = Complex128(context, builder, value=cb)
    c = Complex128(context, builder)
    module = cgutils.get_module(builder)
    pa = a._getpointer()
    pb = b._getpointer()
    pc = c._getpointer()

    # Optimize for square because cpow looses a lot of precsiion
    TWO = context.get_constant(types.float64, 2)
    ZERO = context.get_constant(types.float64, 0)

    b_real_is_two = builder.fcmp(lc.FCMP_OEQ, b.real, TWO)
    b_imag_is_zero = builder.fcmp(lc.FCMP_OEQ, b.imag, ZERO)
    b_is_two = builder.and_(b_real_is_two, b_imag_is_zero)

    with cgutils.ifelse(builder, b_is_two) as (then, otherwise):
        with then:
            # Lower as multiplication
            res = complex_mul_impl(context, builder, sig, (ca, ca))
            cres = Complex128(context, builder, value=res)
            c.real = cres.real
            c.imag = cres.imag

        with otherwise:
            # Lower with call to external function
            fnty = Type.function(Type.void(), [pa.type] * 3)
            cpow = module.get_or_insert_function(fnty, name="numba.math.cpow")
            builder.call(cpow, (pa, pb, pc))

    return builder.load(pc)
开发者ID:whalen53,项目名称:numba,代码行数:33,代码来源:builtins.py


示例3: compile_internal

    def compile_internal(self, builder, impl, sig, args, locals={}):
        """Invoke compiler to implement a function for a nopython function
        """
        cache_key = (impl.__code__, sig)
        fndesc = self.cached_internal_func.get(cache_key)

        if fndesc is None:
            # Compile
            cres = numba.compiler.compile_internal(self.typing_context, self,
                                                   impl, sig.args,
                                                   sig.return_type,
                                                   locals=locals)
            llvm_func = cres.llvm_func
            # Set to linkonce one-definition-rule so that the function
            # is removed once it is linked.
            llvm_func.linkage = lc.LINKAGE_LINKONCE_ODR
            self.add_libs([cres.llvm_module])
            fndesc = cres.fndesc

            self.cached_internal_func[cache_key] = fndesc

        # Add call to the generated function
        llvm_mod = cgutils.get_module(builder)
        fn = self.declare_function(llvm_mod, fndesc)
        status, res = self.call_function(builder, fn, sig.return_type,
                                         sig.args, args)

        return res
开发者ID:meawoppl,项目名称:numba,代码行数:28,代码来源:base.py


示例4: compile_internal

    def compile_internal(self, builder, impl, sig, args, locals={}):
        """Invoke compiler to implement a function for a nopython function
        """
        cache_key = (impl.__code__, sig)
        fndesc = self.cached_internal_func.get(cache_key)

        if fndesc is None:
            # Compile
            from numba import compiler

            codegen = self.jit_codegen()
            library = codegen.create_library(impl.__name__)
            flags = compiler.Flags()
            flags.set("no_compile")
            flags.set("no_cpython_wrapper")
            cres = compiler.compile_internal(
                self.typing_context, self, library, impl, sig.args, sig.return_type, flags, locals=locals
            )

            # Allow inlining the function inside callers.
            codegen.add_linking_library(cres.library)
            fndesc = cres.fndesc
            self.cached_internal_func[cache_key] = fndesc

        # Add call to the generated function
        llvm_mod = cgutils.get_module(builder)
        fn = self.declare_function(llvm_mod, fndesc)
        status, res = self.call_function(builder, fn, sig.return_type, sig.args, args)

        return res
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:30,代码来源:base.py


示例5: _generic_array

def _generic_array(context, builder, shape, dtype, symbol_name, addrspace,
                   can_dynsized=False):
    elemcount = reduce(operator.mul, shape)
    lldtype = context.get_data_type(dtype)
    laryty = Type.array(lldtype, elemcount)

    if addrspace == nvvm.ADDRSPACE_LOCAL:
        # Special case local addrespace allocation to use alloca
        # NVVM is smart enough to only use local memory if no register is
        # available
        dataptr = builder.alloca(laryty, name=symbol_name)
    else:
        lmod = cgutils.get_module(builder)

        # Create global variable in the requested address-space
        gvmem = lmod.add_global_variable(laryty, symbol_name, addrspace)

        if elemcount <= 0:
            if can_dynsized:    # dynamic shared memory
                gvmem.linkage = lc.LINKAGE_EXTERNAL
            else:
                raise ValueError("array length <= 0")
        else:
            gvmem.linkage = lc.LINKAGE_INTERNAL
            gvmem.initializer = lc.Constant.undef(laryty)

        if dtype not in types.number_domain:
            raise TypeError("unsupported type: %s" % dtype)

        # Convert to generic address-space
        conv = nvvmutils.insert_addrspace_conv(lmod, Type.int(8), addrspace)
        addrspaceptr = gvmem.bitcast(Type.pointer(Type.int(8), addrspace))
        dataptr = builder.call(conv, [addrspaceptr])

    return _make_array(context, builder, dataptr, dtype, shape)
开发者ID:ASPP,项目名称:numba,代码行数:35,代码来源:cudaimpl.py


示例6: string_split_2

def string_split_2(context, builder, sig, args):
    module = cgutils.get_module(builder)
    precomp_func = context._get_precompiled_function("StringSplitImpl")
    func = module.get_or_insert_function(
        precomp_func.type.pointee, precomp_func.name)
    fnctx_arg = context.get_arguments(cgutils.get_function(builder))[0]
    cfnctx_arg = builder.bitcast(fnctx_arg, func.args[0].type)
    [s, sep] = args
    maxsplit = context.get_constant_struct(builder, IntVal, -1)
    cs = _conv_numba_struct_to_clang(builder, s, func.args[1].type)
    csep = _conv_numba_struct_to_clang(builder, sep, func.args[2].type)
    cmaxsplit = _conv_numba_struct_to_clang(
        builder, maxsplit, func.args[3].type)
    # result is StringVal with an array of StringVals in the buffer
    array_as_lowered_struct = builder.call(
        func, [cfnctx_arg, cs, csep, cmaxsplit])
    array_as_struct = raise_return_type(
        context, builder, StringVal, array_as_lowered_struct)
    array_as_StringVal = StringValStruct(
        context, builder, value=array_as_struct)
    array_as_numba = context.make_array(sig.return_type)(context, builder)
    data_ptr = builder.bitcast(
        array_as_StringVal.ptr, array_as_numba.data.type)
    array_as_numba.data = data_ptr
    return array_as_numba._getvalue()
开发者ID:awleblang,项目名称:impyla,代码行数:25,代码来源:stringimpl.py


示例7: imp

 def imp(context, builder, sig, args):
     func = context.declare_function(cgutils.get_module(builder), fndesc)
     status, retval = context.call_function(builder, func, fndesc.restype,
                                            fndesc.argtypes, args)
     with cgutils.if_unlikely(builder, status.err):
         context.return_errcode_propagate(builder, status.code)
     return retval
开发者ID:jiaxu825,项目名称:numba,代码行数:7,代码来源:imputils.py


示例8: get_constant_struct

    def get_constant_struct(self, builder, ty, val):
        assert self.is_struct_type(ty)
        module = cgutils.get_module(builder)

        if ty in types.complex_domain:
            if ty == types.complex64:
                innertype = types.float32
            elif ty == types.complex128:
                innertype = types.float64
            else:
                raise Exception("unreachable")

            real = self.get_constant(innertype, val.real)
            imag = self.get_constant(innertype, val.imag)
            const = Constant.struct([real, imag])
            return const

        elif isinstance(ty, types.Tuple):
            consts = [self.get_constant_generic(builder, ty.types[i], v) for i, v in enumerate(val)]
            return Constant.struct(consts)

        elif isinstance(ty, types.Record):
            consts = [self.get_constant(types.int8, b) for b in bytearray(val.tostring())]
            return Constant.array(consts[0].type, consts)

        else:
            raise NotImplementedError("%s as constant unsupported" % ty)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:27,代码来源:base.py


示例9: core

 def core(context, builder, sig, args):
     assert sig.return_type == types.boolean, nvname
     fty = context.get_value_type(ty)
     lmod = cgutils.get_module(builder)
     fnty = Type.function(Type.int(), [fty])
     fn = lmod.get_or_insert_function(fnty, name=nvname)
     result = builder.call(fn, args)
     return context.cast(builder, result, types.int32, types.boolean)
开发者ID:ASPP,项目名称:numba,代码行数:8,代码来源:libdevice.py


示例10: atan2_f64_impl

def atan2_f64_impl(context, builder, sig, args):
    assert len(args) == 2
    mod = cgutils.get_module(builder)
    fnty = Type.function(Type.double(), [Type.double(), Type.double()])
    # Workaround atan2() issues under Windows
    fname = "atan2_fixed" if sys.platform == "win32" else "atan2"
    fn = mod.get_or_insert_function(fnty, name=fname)
    return builder.call(fn, args)
开发者ID:johandroid,项目名称:numba,代码行数:8,代码来源:mathimpl.py


示例11: nrt_meminfo_data

 def nrt_meminfo_data(self, builder, meminfo):
     if not self.enable_nrt:
         raise Exception("Require NRT")
     mod = cgutils.get_module(builder)
     voidptr = llvmir.IntType(8).as_pointer()
     fnty = llvmir.FunctionType(voidptr, [voidptr])
     fn = mod.get_or_insert_function(fnty, name="NRT_MemInfo_data")
     return builder.call(fn, [meminfo])
开发者ID:meego,项目名称:numba,代码行数:8,代码来源:base.py


示例12: ptx_syncthreads

def ptx_syncthreads(context, builder, sig, args):
    assert not args
    fname = 'llvm.nvvm.barrier0'
    lmod = cgutils.get_module(builder)
    fnty = Type.function(Type.void(), ())
    sync = lmod.get_or_insert_function(fnty, name=fname)
    builder.call(sync, ())
    return context.get_dummy_value()
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:8,代码来源:cudaimpl.py


示例13: getitem_stringval

def getitem_stringval(context, builder, sig, args):
    module = cgutils.get_module(builder)
    precomp_func = context._get_precompiled_function("GetItemStringValImpl")
    func = module.get_or_insert_function(precomp_func.type.pointee, precomp_func.name)
    [s, i] = args
    cs = _conv_numba_struct_to_clang(builder, s, func.args[0].type)
    result = builder.call(func, [cs, i])
    return raise_return_type(context, builder, StringVal, result)
开发者ID:fkaufer,项目名称:impyla,代码行数:8,代码来源:target.py


示例14: nrt_meminfo_alloc

 def nrt_meminfo_alloc(self, builder, size):
     if not self.enable_nrt:
         raise Exception("Require NRT")
     mod = cgutils.get_module(builder)
     fnty = llvmir.FunctionType(llvmir.IntType(8).as_pointer(),
         [self.get_value_type(types.intp)])
     fn = mod.get_or_insert_function(fnty, name="NRT_MemInfo_alloc_safe")
     return builder.call(fn, [size])
开发者ID:meego,项目名称:numba,代码行数:8,代码来源:base.py


示例15: real_power_impl

def real_power_impl(context, builder, sig, args):
    x, y = args
    module = cgutils.get_module(builder)
    if context.implement_powi_as_math_call:
        imp = context.get_function(math.pow, sig)
        return imp(builder, args)
    else:
        fn = lc.Function.intrinsic(module, lc.INTR_POW, [y.type])
        return builder.call(fn, (x, y))
开发者ID:whalen53,项目名称:numba,代码行数:9,代码来源:builtins.py


示例16: get_constant_string

 def get_constant_string(self, builder, ty, val):
     assert ty == ntypes.string
     literal = lc.Constant.stringz(val)
     gv = cgutils.get_module(builder).add_global_variable(literal.type, 'str_literal')
     gv.linkage = lc.LINKAGE_PRIVATE
     gv.initializer = literal
     gv.global_constant = True
     # gep gets pointer to first element of the constant byte array
     return gv.gep([lc.Constant.int(lc.Type.int(32), 0)] * 2)
开发者ID:fkaufer,项目名称:impyla,代码行数:9,代码来源:target.py


示例17: int_upower_impl

def int_upower_impl(context, builder, sig, args):
    module = cgutils.get_module(builder)
    x, y = args
    if y.type.width > 32:
        y = builder.trunc(y, Type.int(32))
    elif y.type.width < 32:
        y = builder.zext(y, Type.int(32))
    powerfn = lc.Function.intrinsic(module, lc.INTR_POWI, [x.type])
    return builder.call(powerfn, (x, y))
开发者ID:aburan28,项目名称:numba,代码行数:9,代码来源:builtins.py


示例18: eq_stringval

def eq_stringval(context, builder, sig, args):
    module = cgutils.get_module(builder)
    precomp_func = context._get_precompiled_function("EqStringValImpl")
    func = module.get_or_insert_function(precomp_func.type.pointee, precomp_func.name)
    [s1, s2] = args
    cs1 = _conv_numba_struct_to_clang(builder, s1, func.args[0].type)
    cs2 = _conv_numba_struct_to_clang(builder, s2, func.args[1].type)
    result = builder.call(func, [cs1, cs2])
    return result # ret bool so no need to raise type
开发者ID:fkaufer,项目名称:impyla,代码行数:9,代码来源:target.py


示例19: round_impl_f64

def round_impl_f64(context, builder, sig, args):
    module = cgutils.get_module(builder)
    fnty = Type.function(Type.double(), [Type.double()])
    if utils.IS_PY3:
        fn = module.get_or_insert_function(fnty, name="numba.round")
    else:
        fn = module.get_or_insert_function(fnty, name="round")
    assert fn.is_declaration
    return builder.call(fn, args)
开发者ID:whalen53,项目名称:numba,代码行数:9,代码来源:builtins.py


示例20: string_capitalize

def string_capitalize(context, builder, sig, args):
    module = cgutils.get_module(builder)
    precomp_func = context._get_precompiled_function("StringCapitalizeImpl")
    func = module.get_or_insert_function(precomp_func.type.pointee, precomp_func.name)
    fnctx_arg = context.get_arguments(cgutils.get_function(builder))[0]
    cfnctx_arg = builder.bitcast(fnctx_arg, func.args[0].type)
    [s] = args
    cs = _conv_numba_struct_to_clang(builder, s, func.args[1].type)
    result = builder.call(func, [cfnctx_arg, cs])
    return raise_return_type(context, builder, StringVal, result)
开发者ID:carlotorniai,项目名称:impyla,代码行数:10,代码来源:stringimpl.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python cgutils.get_null_value函数代码示例发布时间:2022-05-27
下一篇:
Python cgutils.get_item_pointer函数代码示例发布时间: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