Esempio n. 1
0
 def codegen(context, builder, signature, args):
     [
         dst_val, dst_offset_val, src_val, src_offset_val, nbytes_val,
         align_val
     ] = args
     src_ptr = builder.gep(src_val, [src_offset_val])
     dst_ptr = builder.gep(dst_val, [dst_offset_val])
     cgutils.raw_memcpy(builder, dst_ptr, src_ptr, nbytes_val, align_val)
     return context.get_dummy_value()
Esempio n. 2
0
    def _copy_payload(self, src_payload):
        """
        Raw-copy the given payload into self.
        """
        context = self._context
        builder = self._builder

        ok = cgutils.alloca_once_value(builder, cgutils.true_bit)

        intp_t = context.get_value_type(types.intp)
        zero = ir.Constant(intp_t, 0)
        one = ir.Constant(intp_t, 1)

        payload_type = context.get_data_type(types.SetPayload(self._ty))
        payload_size = context.get_abi_sizeof(payload_type)
        entry_size = self._entrysize
        # Account for the fact that the payload struct already contains an entry
        payload_size -= entry_size

        mask = src_payload.mask
        nentries = builder.add(one, mask)

        # Total allocation size = <payload header size> + nentries * entry_size
        # (note there can't be any overflow since we're reusing an existing
        #  payload's parameters)
        allocsize = builder.add(
            ir.Constant(intp_t, payload_size),
            builder.mul(ir.Constant(intp_t, entry_size), nentries))

        with builder.if_then(builder.load(ok), likely=True):
            meminfo = context.nrt.meminfo_new_varsize(builder, size=allocsize)
            alloc_ok = cgutils.is_null(builder, meminfo)

            with builder.if_else(cgutils.is_null(builder, meminfo),
                                 likely=False) as (if_error, if_ok):
                with if_error:
                    builder.store(cgutils.false_bit, ok)
                with if_ok:
                    self._set.meminfo = meminfo
                    payload = self.payload
                    payload.used = src_payload.used
                    payload.fill = src_payload.fill
                    payload.finger = zero
                    payload.mask = mask
                    cgutils.raw_memcpy(builder, payload.entries,
                                       src_payload.entries, nentries,
                                       entry_size)

                    if DEBUG_ALLOCS:
                        context.printf(
                            builder,
                            "allocated %zd bytes for set at %p: mask = %zd\n",
                            allocsize, payload.ptr, mask)

        return builder.load(ok)
Esempio n. 3
0
    def _copy_payload(self, src_payload):
        """
        Raw-copy the given payload into self.
        """
        context = self._context
        builder = self._builder

        ok = cgutils.alloca_once_value(builder, cgutils.true_bit)

        intp_t = context.get_value_type(types.intp)
        zero = ir.Constant(intp_t, 0)
        one = ir.Constant(intp_t, 1)

        payload_type = context.get_data_type(types.SetPayload(self._ty))
        payload_size = context.get_abi_sizeof(payload_type)
        entry_size = self._entrysize
        # Account for the fact that the payload struct already contains an entry
        payload_size -= entry_size

        mask = src_payload.mask
        nentries = builder.add(one, mask)

        # Total allocation size = <payload header size> + nentries * entry_size
        # (note there can't be any overflow since we're reusing an existing
        #  payload's parameters)
        allocsize = builder.add(ir.Constant(intp_t, payload_size),
                                builder.mul(ir.Constant(intp_t, entry_size),
                                            nentries))

        with builder.if_then(builder.load(ok), likely=True):
            meminfo = context.nrt.meminfo_new_varsize(builder, size=allocsize)
            alloc_ok = cgutils.is_null(builder, meminfo)

            with builder.if_else(cgutils.is_null(builder, meminfo),
                                 likely=False) as (if_error, if_ok):
                with if_error:
                    builder.store(cgutils.false_bit, ok)
                with if_ok:
                    self._set.meminfo = meminfo
                    payload = self.payload
                    payload.used = src_payload.used
                    payload.fill = src_payload.fill
                    payload.finger = zero
                    payload.mask = mask
                    cgutils.raw_memcpy(builder, payload.entries,
                                       src_payload.entries, nentries,
                                       entry_size)

                    if DEBUG_ALLOCS:
                        context.printf(builder,
                                       "allocated %zd bytes for set at %p: mask = %zd\n",
                                       allocsize, payload.ptr, mask)

        return builder.load(ok)
Esempio n. 4
0
File: cv_ext.py Progetto: rowhit/sdc
def _image_to_array(context, builder, shapes_array, arrtype, data, img):
    # allocate array
    shapes = cgutils.unpack_tuple(builder, builder.load(shapes_array))
    ary = _empty_nd_impl(context, builder, arrtype, shapes)
    cgutils.raw_memcpy(builder,
                       ary.data,
                       builder.load(data),
                       ary.nitems,
                       ary.itemsize,
                       align=1)

    # clean up cv::Mat image
    fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
    fn_release = builder.module.get_or_insert_function(fnty,
                                                       name="cv_mat_release")
    builder.call(fn_release, [img])

    return impl_ret_new_ref(context, builder, arrtype, ary._getvalue())
Esempio n. 5
0
File: cv_ext.py Progetto: rowhit/sdc
    def codegen(context, builder, sig, args):
        assert (len(args) == 2)
        data = args[0]
        shape = args[1]
        # XXX: unnecessary allocation and copy, reuse data pointer
        shape_list = cgutils.unpack_tuple(builder, shape, shape.type.count)
        ary = _empty_nd_impl(context, builder, arr_typ, shape_list)
        cgutils.raw_memcpy(builder,
                           ary.data,
                           data,
                           ary.nitems,
                           ary.itemsize,
                           align=1)

        # clean up image buffer
        fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
        fn_release = builder.module.get_or_insert_function(
            fnty, name="cv_delete_buf")
        builder.call(fn_release, [data])

        return impl_ret_new_ref(context, builder, sig.return_type,
                                ary._getvalue())
Esempio n. 6
0
def nt2nd(context, builder, ptr, ary_type):
    '''Generate ir code to convert a pointer-to-daal-numeric-table to a ndarray'''

    # we need to prepare the shape array and a pointer
    shape_type = lir.ArrayType(lir.IntType(64), 2)
    shape = cgutils.alloca_once(builder, shape_type)
    data = cgutils.alloca_once(builder, lir.DoubleType().as_pointer())
    assert(ary_type in [dtable_type, ftable_type, itable_type,])
    # we also need indicate the type of the array (e.g. what we expect)
    d4ptype = context.get_constant(types.byte, d4ptypes[ary_type])
    # we can now declare and call our conversion function
    fnty = lir.FunctionType(lir.VoidType(),
                            [lir.IntType(8).as_pointer(), # actually pointer to numeric table
                             lir.DoubleType().as_pointer().as_pointer(),
                             shape_type.as_pointer(),
                             lir.IntType(8)])
    fn = builder.module.get_or_insert_function(fnty, name='to_c_array')
    builder.call(fn, [ptr, data, shape, d4ptype])
    # convert to ndarray
    shape = cgutils.unpack_tuple(builder, builder.load(shape))
    ary = _empty_nd_impl(context, builder, ary_type, shape)
    cgutils.raw_memcpy(builder, ary.data, builder.load(data), ary.nitems, ary.itemsize, align=1)
    # we are done!
    return impl_ret_new_ref(context, builder, ary_type, ary._getvalue())
Esempio n. 7
0
File: bytes.py Progetto: numba/numba
 def codegen(context, builder, signature, args):
     [dst_val, dst_offset_val, src_val, src_offset_val, nbytes_val, align_val] = args
     src_ptr = builder.gep(src_val, [src_offset_val])
     dst_ptr = builder.gep(dst_val, [dst_offset_val])
     cgutils.raw_memcpy(builder, dst_ptr, src_ptr, nbytes_val, align_val)
     return context.get_dummy_value()
Esempio n. 8
0
 def codegen(context, builder, sig, args):
     ptr, ind, _str, len_str = args
     ptr = builder.gep(ptr, [ind])
     cgutils.raw_memcpy(builder, ptr, _str, len_str, 1)
     return context.get_dummy_value()
Esempio n. 9
0
 def codegen(context, builder, sig, args):
     buff_arr, ind, str, len_str = args
     buff_arr = context.make_array(sig.args[0])(context, builder, buff_arr)
     ptr = builder.gep(buff_arr.data, [ind])
     cgutils.raw_memcpy(builder, ptr, str, len_str, 1)
     return context.get_dummy_value()