def test_mempool_2():
    from pyopencl.tools import MemoryPool
    from random import randrange

    for i in range(2000):
        s = randrange(1 << 31) >> randrange(32)
        bin_nr = MemoryPool.bin_number(s)
        asize = MemoryPool.alloc_size(bin_nr)

        assert asize >= s, s
        assert MemoryPool.bin_number(asize) == bin_nr, s
        assert asize < asize * (1 + 1 / 8)
Exemple #2
0
def test_mempool_2():
    from pyopencl.tools import MemoryPool
    from random import randrange

    for i in range(2000):
        s = randrange(1 << 31) >> randrange(32)
        bin_nr = MemoryPool.bin_number(s)
        asize = MemoryPool.alloc_size(bin_nr)

        assert asize >= s, s
        assert MemoryPool.bin_number(asize) == bin_nr, s
        assert asize < asize*(1+1/8)
Exemple #3
0
def test_mempool_2(ctx_factory):
    from pyopencl.tools import MemoryPool, ImmediateAllocator
    from random import randrange

    context = ctx_factory()
    queue = cl.CommandQueue(context)

    pool = MemoryPool(ImmediateAllocator(queue))

    for s in [randrange(1 << 31) >> randrange(32) for _ in range(2000)] + [2**30]:
        bin_nr = pool.bin_number(s)
        asize = pool.alloc_size(bin_nr)

        assert asize >= s, s
        assert pool.bin_number(asize) == bin_nr, s
        assert asize < asize*(1+1/8)
Exemple #4
0
    def __init__(self, beam_array):
        '''
            Creates a new beam from a an array of 6 columns, X rows
            representing the particles
            The columns of the array represents: theta, gamma, x, y, px, py
        '''
        assert beam_array.shape[0] == 6, "The rows must be 6"
        self.size = beam_array.shape[1]
        self.len = beam_array.shape[1]
        self.events = []

        if beam_array.dtype != cl_ftype:
            beam_array = beam_array.astype(cl_ftype)

        if not beam_array.flags.f_contiguous:
            beam_array = np.array(beam_array, order="C")

        self.allocator = MemoryPool(ImmediateAllocator(cl_queue)) 
        
        self.x     = cl_array.to_device(cl_queue, beam_array[0, :], allocator=self.allocator)
        self.px    = cl_array.to_device(cl_queue, beam_array[1, :], allocator=self.allocator)
        self.y     = cl_array.to_device(cl_queue, beam_array[2, :], allocator=self.allocator)
        self.py    = cl_array.to_device(cl_queue, beam_array[3, :], allocator=self.allocator)
        self.theta = cl_array.to_device(cl_queue, beam_array[4, :], allocator=self.allocator)
        self.gamma = cl_array.to_device(cl_queue, beam_array[5, :], allocator=self.allocator)
Exemple #5
0
def test_mempool(ctx_factory):
    from pyopencl.tools import MemoryPool, CLAllocator

    context = ctx_factory()

    pool = MemoryPool(CLAllocator(context))
    queue = []

    e0 = 12

    for e in range(e0-6, e0-4):
        for i in range(100):
            queue.append(pool.allocate(1 << e))
            if len(queue) > 10:
                queue.pop(0)
    del queue
    pool.stop_holding()
def test_mempool(ctx_factory):
    from pyopencl.tools import MemoryPool, ImmediateAllocator

    context = ctx_factory()
    queue = cl.CommandQueue(context)

    pool = MemoryPool(ImmediateAllocator(queue))
    alloc_queue = []

    e0 = 12

    for e in range(e0 - 6, e0 - 4):
        for i in range(100):
            alloc_queue.append(pool.allocate(1 << e))
            if len(alloc_queue) > 10:
                alloc_queue.pop(0)
    del alloc_queue
    pool.stop_holding()
Exemple #7
0
def test_mempool(ctx_factory):
    from pyopencl.tools import MemoryPool, ImmediateAllocator

    context = ctx_factory()
    queue = cl.CommandQueue(context)

    pool = MemoryPool(ImmediateAllocator(queue))
    alloc_queue = []

    e0 = 12

    for e in range(e0-6, e0-4):
        for i in range(100):
            alloc_queue.append(pool.allocate(1 << e))
            if len(alloc_queue) > 10:
                alloc_queue.pop(0)
    del alloc_queue
    pool.stop_holding()
Exemple #8
0
    def _init_data_on_dev(self):
        if 'Immobile' in self.Args.keys():
            args_strs = ['x', 'y', 'z', 'w']
        else:
            args_strs = ['x', 'y', 'z', 'px', 'py', 'pz', 'w', 'g_inv']

        for arg in args_strs:
            self.DataDev[arg] = self.dev_arr(shape=0, dtype=np.double)

        for arg in ['cell_offset', 'indx_in_cell', 'sort_indx', 'sum_in_cell']:
            allocator = ImmediateAllocator(self.comm.queue)
            self.DataDev[arg + '_mp'] = MemoryPool(allocator)