本文整理汇总了Python中numba.cgutils.get_module函数的典型用法代码示例。如果您正苦于以下问题:Python get_module函数的具体用法?Python get_module怎么用?Python get_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_module函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')
示例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)
示例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
示例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
示例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)
示例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()
示例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
示例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)
示例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)
示例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)
示例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])
示例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()
示例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)
示例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])
示例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))