Example #1
0
    def test_align(self):
        # Given
        dev_array = DeviceArray(np.int32)
        orig_array = cl.array.arange(get_queue(), 0, 16, 1, dtype=np.int32)
        dev_array.set_data(orig_array)
        indices = cl.array.arange(get_queue(), 15, -1, -1, dtype=np.int32)

        # When
        dev_array.align(indices)

        # Then
        assert np.all(dev_array.array.get() == indices.get())
Example #2
0
    def test_remove(self):
        # Given
        dev_array = DeviceArray(np.int32)
        orig_array = cl.array.arange(get_queue(), 0, 16, 1, dtype=np.int32)
        dev_array.set_data(orig_array)
        indices = cl.array.arange(get_queue(), 0, 8, 1, dtype=np.int32)

        # When
        dev_array.remove(indices)

        # Then
        assert np.all(dev_array.array.get() == (8 + indices).get())
Example #3
0
    def test_copy_values(self):
        # Given
        dev_array = self.make_dev_array()
        dev_array.fill(2)

        dest = cl.array.empty(get_queue(), 8, dtype=np.int32)
        indices = cl.array.arange(get_queue(), 0, 8, 1, dtype=np.int32)

        # When
        dev_array.copy_values(indices, dest)

        # Then
        assert np.all(dev_array.array[:len(indices)].get() == dest.get())
Example #4
0
    def test_extend(self):
        # Given
        dev_array = self.make_dev_array()
        cl_array = 2 + cl.array.zeros(get_queue(), 64, dtype=np.int32)

        # When
        dev_array.extend(cl_array)

        # Then
        assert np.all(dev_array.array[-len(cl_array)].get() == cl_array.get())
Example #5
0
    def test_add_particles(self):
        # Given
        pa = self.pa
        h = DeviceHelper(pa)

        # When
        pa.set_device_helper(h)
        x = cl.array.zeros(get_queue(), 4, np.float32)

        h.add_particles(x=x)

        # Then
        assert np.all(np.sort(h.x.get()) == np.array([0., 0., 0., 0., 0., 1.]))
Example #6
0
    def test_extract_particles(self):
        # Given
        pa = get_particle_array(name='f', x=[0.0, 1.0, 2.0, 3.0],
                                m=1.0, rho=2.0)
        h = DeviceHelper(pa)
        pa.set_device_helper(h)

        # When
        indices = np.array([1, 2], dtype=np.uint32)
        indices = cl.array.to_device(get_queue(), indices)

        result_pa = h.extract_particles(indices)

        # Then
        assert result_pa.gpu.get_number_of_particles() == 2
Example #7
0
    def test_align(self):
        # Given
        pa = self.pa
        h = DeviceHelper(pa)

        # When
        pa.set_device_helper(h)
        h.resize(5)
        h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype))

        indices = cl.array.arange(get_queue(), 4, -1, -1, dtype=np.int32)

        h.align(indices)

        # Then
        assert np.all(h.x.get() == np.array([6., 5., 4., 3., 2.]))
Example #8
0
    def test_remove_particles(self):
        # Given
        pa = self.pa
        h = DeviceHelper(pa)

        # When
        pa.set_device_helper(h)
        h.resize(5)
        h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype))

        indices = np.array([1, 2], dtype=np.uint32)
        indices = cl.array.to_device(get_queue(), indices)

        h.remove_particles(indices)

        # Then
        assert np.all(np.sort(h.x.get()) == np.array([2., 5., 6.]))
Example #9
0
 def __init__(self, acceleration_eval):
     self.object = acceleration_eval
     self.all_array_names = get_all_array_names(self.object.particle_arrays)
     self.known_types = get_known_types_for_arrays(self.all_array_names)
     add_address_space(self.known_types)
     predefined = dict(get_predefined_types(self.object.all_group.pre_comp))
     self.known_types.update(predefined)
     self.known_types['NBRS'] = KnownType('__global unsigned int*')
     self.data = []
     self._ctx = get_context()
     self._queue = get_queue()
     self._array_map = None
     self._array_index = None
     self._equations = {}
     self._cpu_structs = {}
     self._gpu_structs = {}
     self.calls = []
     self.program = None