Example #1
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)
Example #2
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)
Example #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)
Example #4
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()