Esempio n. 1
0
def test_free():
    h = Heap()

    addr1, block1, c1ptr = allocate_raw(h, 5)
    addr2, block2, c2ptr = allocate_raw(h, 5)

    assert len(h._arenas) == 1
    h.free(block2)

    addr3, block2, c2ptr = allocate_raw(h, 5)

    # Blocks get merged when free'd so that align blocks
    assert addr3 == addr2
Esempio n. 2
0
def test_free():
    h = Heap()

    addr1, block1, c1ptr = allocate_raw(h, 5)
    addr2, block2, c2ptr = allocate_raw(h, 5)

    assert len(h._arenas) == 1
    h.free(block2)

    addr3, block2, c2ptr = allocate_raw(h, 5)

    # Blocks get merged when free'd so that align blocks
    assert addr3 == addr2
Esempio n. 3
0
def execplan(context, plan):
    """ Takes a list of of instructions from the Pipeline and
    then allocates the necessary memory needed for the
    intermediates are temporaries. Then executes the plan
    returning the result. """

    instructions = context["instructions"]  # [ Instruction(...) ]
    symbols = context["symbols"]  # { %0 -> Array(...){...}
    operands = context["operand_dict"]  # { Array(...){...} -> Blaze Array }

    def getop(symbol):
        term = symbols[symbol]
        term_id = term.annotation.meta[0].label
        op = operands[term_id]
        return op

    h = Heap()
    ret = None

    for instruction in instructions:
        ops = map(getop, instruction.args)

        if not instruction.lhs:
            # lhs = h.allocate(instruction.lhs.size())
            lhs = blaze.zeros(instruction.datashape)
        else:
            lhs = getop(instruction.lhs)

        ret = instruction.execute(ops, lhs)

    # h.finalize()
    return ret
Esempio n. 4
0
def test_numba():
    @autojit
    def fill(x):
        for i in range(25):
            x[i] = i

    h = Heap()
    addr, block = allocate_numpy(h, np.dtype('int'), (25, ))
    fill(block)

    finalize(h)
Esempio n. 5
0
def execplan(context, plan, symbols):
    """ Takes a list of of instructions from the Pipeline and
    then allocates the necessary memory needed for the
    intermediates are temporaries """

    h = Heap()
    ret = None
    last = plan[-1]

    for instruction in plan:
        ops = [symbols[sym] for sym in symbols]
        dds = [op.asbuflist() for op in ops]
        dss = [op.datashape() for op in ops]

        if instruction.lhs:
            h.allocate(instruction.lhs.size())
            ret = instruction(dds, dss)
        else:
            instruction(dds, dss)

    h.finalize()
    return ret
Esempio n. 6
0
def test_iopro():
    # this is kind of stupid right now because it does a copy,
    # but Tight IOPro integration will be a priority...

    h = Heap()

    s = StringIO(','.join(letters))

    data = iopro.genfromtxt(s, dtype='c', delimiter=",")

    addr, block = allocate_numpy(h, data.dtype, data.shape)
    block[:] = data[:]

    assert not block.flags['OWNDATA']
    assert block.ctypes.data == addr

    assert len(h._arenas) == 1
    assert block.nbytes < h._lengths[0]

    finalize(h)
Esempio n. 7
0
def test_malloc():
    h = Heap()
    _, block, _ = allocate_raw(h, 1000)