예제 #1
0
파일: typeddict.py 프로젝트: jdburnet/numba
def box_dicttype(typ, val, c):
    context = c.context
    builder = c.builder

    # XXX deduplicate
    ctor = cgutils.create_struct_proxy(typ)
    dstruct = ctor(context, builder, value=val)
    # Returns the plain MemInfo
    boxed_meminfo = c.box(
        types.MemInfoPointer(types.voidptr),
        dstruct.meminfo,
    )

    modname = c.context.insert_const_string(
        c.builder.module, 'numba.typed.typeddict',
    )
    typeddict_mod = c.pyapi.import_module_noblock(modname)
    fmp_fn = c.pyapi.object_getattr_string(typeddict_mod, '_from_meminfo_ptr')

    dicttype_obj = c.pyapi.unserialize(c.pyapi.serialize_object(typ))

    res = c.pyapi.call_function_objargs(fmp_fn, (boxed_meminfo, dicttype_obj))
    c.pyapi.decref(fmp_fn)
    c.pyapi.decref(typeddict_mod)
    c.pyapi.decref(boxed_meminfo)
    return res
예제 #2
0
def allocator_UsmArray(typingctx, allocsize, align):
    def impl(context, builder, sig, args):
        context.nrt._require_nrt()
        size, align = args

        mod = builder.module
        u32 = ir.IntType(32)

        # Get the Numba external allocator for USM memory.
        ext_allocator_fnty = ir.FunctionType(cgutils.voidptr_t, [])
        ext_allocator_fn = cgutils.get_or_insert_function(
            mod, ext_allocator_fnty, name="usmarray_get_ext_allocator"
        )
        ext_allocator = builder.call(ext_allocator_fn, [])
        # Get the Numba function to allocate an aligned array with an external allocator.
        fnty = ir.FunctionType(
            cgutils.voidptr_t, [cgutils.intp_t, u32, cgutils.voidptr_t]
        )
        fn = cgutils.get_or_insert_function(
            mod, fnty, name="NRT_MemInfo_alloc_safe_aligned_external"
        )
        fn.return_value.add_attribute("noalias")
        if isinstance(align, builtins.int):
            align = context.get_constant(types.uint32, align)
        else:
            assert align.type == u32, "align must be a uint32"
        call = builder.call(fn, [size, align, ext_allocator])
        call.name = "allocate_UsmArray"
        return call

    mip = types.MemInfoPointer(types.voidptr)  # return untyped pointer
    sig = typing.signature(mip, allocsize, align)
    return sig, impl
예제 #3
0
파일: models.py 프로젝트: lilohuang/numba
 def __init__(self, dmm, fe_type):
     payload_type = types.ListPayload(fe_type)
     members = [
         # The meminfo data points to a ListPayload
         ('meminfo', types.MemInfoPointer(payload_type)),
     ]
     super(ListModel, self).__init__(dmm, fe_type, members)
예제 #4
0
파일: utils.py 프로젝트: DannyWeitekamp/ILP
    def codegen(context, builder, sig, args):
        d, = args

        ctor = cgutils.create_struct_proxy(inst_type)
        dstruct = ctor(context, builder, value=d)
        context.nrt.incref(builder, types.MemInfoPointer(types.voidptr),
                           dstruct.meminfo)
예제 #5
0
    def __init__(self, dmm, fe_type):

        members = [
            ('data_ptr', types.voidptr),                        # pointer to std::string_view
            ('meminfo', types.MemInfoPointer(types.voidptr)),   # NRT meminfo managing this memory
        ]
        models.StructModel.__init__(self, dmm, fe_type, members)
예제 #6
0
    def __init__(self, dmm, fe_type):

        members = [
            ('table_ptr', types.CPointer(types.uint8)),
            ('meminfo', types.MemInfoPointer(types.voidptr)),
        ]
        models.StructModel.__init__(self, dmm, fe_type, members)
예제 #7
0
파일: typeddict.py 프로젝트: jdburnet/numba
def unbox_dicttype(typ, val, c):
    context = c.context
    builder = c.builder

    miptr = c.pyapi.object_getattr_string(val, '_opaque')

    native = c.unbox(types.MemInfoPointer(types.voidptr), miptr)

    mi = native.value
    ctor = cgutils.create_struct_proxy(typ)
    dstruct = ctor(context, builder)

    data_pointer = context.nrt.meminfo_data(builder, mi)
    data_pointer = builder.bitcast(
        data_pointer,
        dictobject.ll_dict_type.as_pointer(),
    )

    dstruct.data = builder.load(data_pointer)
    dstruct.meminfo = mi

    dctobj = dstruct._getvalue()
    c.pyapi.decref(miptr)

    return NativeValue(dctobj)
예제 #8
0
 def __init__(self, dmm, fe_type):
     members = [
         ('parent', fe_type.parent),  # reference to the dict
         ('state', types.voidptr),  # iterator state in native code
         ('meminfo', types.MemInfoPointer(
             types.voidptr)),  # meminfo for allocated iter state
     ]
     super(ConcDictIterModel, self).__init__(dmm, fe_type, members)
예제 #9
0
    def codegen(context, builder, sig, args):
        _, meminfo = args

        st = cgutils.create_struct_proxy(inst_type)(context, builder)
        st.meminfo = meminfo
        #NOTE: Fixes sefault but not sure about it's lifecycle (i.e. watch out for memleaks)
        context.nrt.incref(builder, types.MemInfoPointer(types.voidptr), meminfo)

        return st._getvalue()
예제 #10
0
파일: models.py 프로젝트: lilohuang/numba
 def __init__(self, dmm, fe_type):
     payload_type = types.ListPayload(fe_type.list_type)
     members = [
         # The meminfo data points to a ListPayload (shared with the
         # original list object)
         ('meminfo', types.MemInfoPointer(payload_type)),
         ('index', types.EphemeralPointer(types.intp)),
     ]
     super(ListIterModel, self).__init__(dmm, fe_type, members)
예제 #11
0
 def __init__(self, dmm, fe_type):
     members = [
         ('num_items', types.uint64),
         ('num_total_chars', types.uint64),
         ('offsets', types.CPointer(offset_typ)),
         ('data', types.CPointer(char_typ)),
         ('meminfo', types.MemInfoPointer(str_arr_payload_type)),
     ]
     models.StructModel.__init__(self, dmm, fe_type, members)
예제 #12
0
 def __init__(self, dmm, fe_type):
     payload_type = types.SetPayload(fe_type)
     members = [
         # The meminfo data points to a SetPayload
         ('meminfo', types.MemInfoPointer(payload_type)),
         # This member is only used only for reflected sets
         ('parent', types.pyobject),
     ]
     super(SetModel, self).__init__(dmm, fe_type, members)
예제 #13
0
 def __init__(self, dmm, fe_type):
     payload_type = types.SetPayload(fe_type.container)
     members = [
         # The meminfo data points to a SetPayload (shared with the
         # original set object)
         ('meminfo', types.MemInfoPointer(payload_type)),
         # The index into the entries table
         ('index', types.EphemeralPointer(types.intp)),
     ]
     super(SetIterModel, self).__init__(dmm, fe_type, members)
예제 #14
0
    def codegen(context, builder, sig, args):
        [td] = sig.args
        [d] = args

        ctor = cgutils.create_struct_proxy(td)
        dstruct = ctor(context, builder, value=d)
        meminfo = dstruct.meminfo
        context.nrt.incref(builder, types.MemInfoPointer(types.voidptr), meminfo)
        # Returns the plain MemInfo
        return meminfo
예제 #15
0
 def __init__(self, dmm, fe_type):
     members = [
         ('data', types.voidptr),
         ('length', types.intp),
         ('kind', types.int32),
         ('meminfo', types.MemInfoPointer(types.voidptr)),
         # A pointer to the owner python str/unicode object
         ('parent', types.pyobject),
         ]
     models.StructModel.__init__(self, dmm, fe_type, members)
예제 #16
0
    def codegen(context, builder, sig, args):
        _,d = args

        ctor = cgutils.create_struct_proxy(inst_type)
        dstruct = ctor(context, builder, value=d)
        meminfo = dstruct.meminfo
        context.nrt.incref(builder, types.MemInfoPointer(types.voidptr), meminfo)

        st = cgutils.create_struct_proxy(cast_type)(context, builder)
        st.meminfo = meminfo
        
        return st._getvalue()
예제 #17
0
파일: models.py 프로젝트: lilohuang/numba
 def __init__(self, dmm, fe_type):
     ndim = fe_type.ndim
     members = [
         ('meminfo', types.MemInfoPointer(fe_type.dtype)),
         ('parent', types.pyobject),
         ('nitems', types.intp),
         ('itemsize', types.intp),
         ('data', types.CPointer(fe_type.dtype)),
         ('shape', types.UniTuple(types.intp, ndim)),
         ('strides', types.UniTuple(types.intp, ndim)),
     ]
     super(ArrayModel, self).__init__(dmm, fe_type, members)
예제 #18
0
 def __init__(self, dmm, fe_typ):
     cls_data_ty = types.ClassDataType(fe_typ)
     # MemInfoPointer uses the `dtype` attribute to traverse for nested
     # NRT MemInfo.  Since we handle nested NRT MemInfo ourselves,
     # we will replace provide MemInfoPointer with an opaque type
     # so that it does not raise exception for nested meminfo.
     dtype = types.Opaque('Opaque.' + str(cls_data_ty))
     members = [
         ('meminfo', types.MemInfoPointer(dtype)),
         ('data', types.CPointer(cls_data_ty)),
     ]
     super(InstanceModel, self).__init__(dmm, fe_typ, members)
예제 #19
0
    def codegen(context, builder, sig, args):
        [td] = sig.args
        [d] = args

        ctor = cgutils.create_struct_proxy(td)
        dstruct = ctor(context, builder, value=d)
        meminfo = dstruct.meminfo

        #Incref to prevent struct from being freed
        context.nrt.incref(builder, types.MemInfoPointer(types.voidptr), meminfo)

        res = builder.ptrtoint(dstruct.meminfo, cgutils.intp_t)

        return res
예제 #20
0
    def __init__(self, dmm, fe_type):
        # TODO: types other than Array and StringArray?
        if fe_type.dtype == string_type:
            members = [
                ('num_items', types.uint64),
                ('num_total_chars', types.uint64),
                ('offsets', types.CPointer(offset_typ)),
                ('data', types.CPointer(char_typ)),
                ('meminfo', types.MemInfoPointer(str_arr_payload_type)),
            ]
        else:
            ndim = 1
            members = [
                ('meminfo', types.MemInfoPointer(fe_type.dtype)),
                ('parent', types.pyobject),
                ('nitems', types.intp),
                ('itemsize', types.intp),
                ('data', types.CPointer(fe_type.dtype)),
                ('shape', types.UniTuple(types.intp, ndim)),
                ('strides', types.UniTuple(types.intp, ndim)),
            ]

        super(SeriesModel, self).__init__(dmm, fe_type, members)
예제 #21
0
    def __init__(self, dmm, fe_type):
        # TODO: types other than Array and StringArray?
        if fe_type.dtype == string_type:
            members = hpat.str_arr_ext.str_arr_model_members
        else:
            ndim = 1
            members = [
                ('meminfo', types.MemInfoPointer(fe_type.dtype)),
                ('parent', types.pyobject),
                ('nitems', types.intp),
                ('itemsize', types.intp),
                ('data', types.CPointer(fe_type.dtype)),
                ('shape', types.UniTuple(types.intp, ndim)),
                ('strides', types.UniTuple(types.intp, ndim)),
            ]

        super(SeriesModel, self).__init__(dmm, fe_type, members)
예제 #22
0
        def intrin_alloc(typingctx, allocsize, align):
            """Intrinsic to call into the allocator for Array
            """
            def codegen(context, builder, signature, args):
                [allocsize, align] = args

                # XXX: error are being eaten.
                #      example: replace the next line with `align_u32 = align`
                align_u32 = cast_integer(context, builder, align,
                                         signature.args[1], types.uint32)
                meminfo = context.nrt.meminfo_alloc_aligned(
                    builder, allocsize, align_u32)
                return meminfo

            from numba.core.typing import signature
            mip = types.MemInfoPointer(types.voidptr)  # return untyped pointer
            sig = signature(mip, allocsize, align)
            return sig, codegen
예제 #23
0
 def __init__(self, dmm, fe_type):
     dtype = SVCPayloadType()
     members = [
         ('meminfo', types.MemInfoPointer(dtype)),
         ]
     models.StructModel.__init__(self, dmm, fe_type, members)
예제 #24
0
            ('index_offsets', types.CPointer(offset_typ)),
            ('data_offsets', types.CPointer(offset_typ)),
            #('null_bitmap', types.CPointer(char_typ)),
        ]
        models.StructModel.__init__(self, dmm, fe_type, members)


str_arr_model_members = [
    ('num_items', types.uint64),  # number of lists
    #('num_total_strs', types.uint64),  # number of strings total
    #('num_total_chars', types.uint64),
    ('index_offsets', types.CPointer(offset_typ)),
    ('data_offsets', types.CPointer(offset_typ)),
    ('data', data_ctypes_type),
    #('null_bitmap', types.CPointer(char_typ)),
    ('meminfo', types.MemInfoPointer(str_arr_split_view_payload_type)),
]


@register_model(StringArraySplitViewType)
class StringArrayModel(models.StructModel):
    def __init__(self, dmm, fe_type):

        models.StructModel.__init__(self, dmm, fe_type, str_arr_model_members)


make_attribute_wrapper(StringArraySplitViewType, 'num_items', '_num_items')
make_attribute_wrapper(StringArraySplitViewType, 'index_offsets',
                       '_index_offsets')
make_attribute_wrapper(StringArraySplitViewType, 'data_offsets',
                       '_data_offsets')
예제 #25
0
    Type,
)
from numba.typeconv import Conversion
from numba.targets.imputils import impl_ret_borrowed, RefType
from numba.errors import TypingError
from numba import typing

ll_dict_type = cgutils.voidptr_t
ll_dictiter_type = cgutils.voidptr_t
ll_voidptr_type = cgutils.voidptr_t
ll_status = cgutils.int32_t
ll_ssize_t = cgutils.intp_t
ll_hash = ll_ssize_t
ll_bytes = cgutils.voidptr_t

_meminfo_dictptr = types.MemInfoPointer(types.voidptr)

# The following enums must match _dictobject.c


class DKIX(IntEnum):
    """Special return value of dict lookup.
    """
    EMPTY = -1


class Status(IntEnum):
    """Status code for other dict operations.
    """
    OK = 0
    OK_REPLACED = 1
예제 #26
0
파일: utils.py 프로젝트: DannyWeitekamp/ILP
 def codegen(context, builder, sig, args):
     raw_ptr, = args
     meminfo = builder.inttoptr(raw_ptr, cgutils.voidptr_t)
     context.nrt.decref(builder, types.MemInfoPointer(types.voidptr),
                        meminfo)
예제 #27
0
def typeof_meminfo(val, c):
    return types.MemInfoPointer(types.voidptr)
예제 #28
0
파일: models.py 프로젝트: shinjia0801/numba
 def __init__(self, dmm, fe_type):
     # ndim = fe_type.ndim
     members = [('data', types.CPointer(fe_type.dtype)),
                ('meminfo', types.MemInfoPointer(fe_type.dtype))]
     super(ArrayCTypesModel, self).__init__(dmm, fe_type, members)
예제 #29
0
    _as_bytes,
    _cast,
    _nonoptional,
    _get_incref_decref,
    _container_get_data,
    _container_get_meminfo,
)

ll_list_type = cgutils.voidptr_t
ll_listiter_type = cgutils.voidptr_t
ll_voidptr_type = cgutils.voidptr_t
ll_status = cgutils.int32_t
ll_ssize_t = cgutils.intp_t
ll_bytes = cgutils.voidptr_t

_meminfo_listptr = types.MemInfoPointer(types.voidptr)

INDEXTY = types.intp

index_types = types.integer_domain


@register_model(ListType)
class ListModel(models.StructModel):
    def __init__(self, dmm, fe_type):
        members = [
            ('meminfo', _meminfo_listptr),
            ('data', types.voidptr),  # ptr to the C list
        ]
        super(ListModel, self).__init__(dmm, fe_type, members)
예제 #30
0
파일: utils.py 프로젝트: DannyWeitekamp/ILP

@njit(Tuple([u2, u8, u1])(u8), cache=True)
def decode_idrec(idrec):
    t_id = idrec >> 48
    f_id = (idrec >> 8) & 0x000FFFFF
    a_id = idrec & 0xF
    return (t_id, f_id, a_id)


@njit(u8(u2, u8, u1), cache=True)
def encode_idrec(t_id, f_id, a_id):
    return (t_id << 48) | (f_id << 8) | a_id


meminfo_type = types.MemInfoPointer(types.voidptr)


@intrinsic
def lower_setattr(typingctx, inst_type, attr_type, val_type):
    if (isinstance(attr_type, types.Literal)
            and isinstance(inst_type, types.StructRef)):

        attr = attr_type.literal_value

        def codegen(context, builder, sig, args):
            [instance, attr_v, val] = args

            utils = _Utils(context, builder, inst_type)
            dataval = utils.get_data_struct(instance)
            # cast val to the correct type