Ejemplo n.º 1
0
    def test_leapfrog_with_double(self):
        orig = get_config().use_double

        def _cleanup():
            get_config().use_double = orig
        get_config().use_double = True
        self.addCleanup(_cleanup)
        self.test_leapfrog()
Ejemplo n.º 2
0
 def __init__(self, acceleration_eval):
     self.object = acceleration_eval
     self.config = get_config()
     self.all_array_names = get_all_array_names(self.object.particle_arrays)
     self.known_types = get_known_types_for_arrays(self.all_array_names)
     self._ext_mod = None
     self._module = None
Ejemplo n.º 3
0
 def __init__(self, helper, c_acceleration_eval):
     self.helper = helper
     self.acceleration_eval = c_acceleration_eval
     self.nnps = None
     self.parallel_manager = None
     self._post_stage_callback = None
     self._use_double = get_config().use_double
     self._setup_methods()
Ejemplo n.º 4
0
 def _get_backend(self, backend):
     if not backend:
         cfg = get_config()
         if cfg.use_opencl:
             backend = 'opencl'
         else:
             backend = 'cython'
     return backend
Ejemplo n.º 5
0
 def get_code(self):
     path = os.path.join(os.path.dirname(__file__),
                         'acceleration_eval_opencl.mako')
     template = Template(filename=path)
     main = template.render(helper=self)
     from pyopencl._cluda import CLUDA_PREAMBLE
     double_support = get_config().use_double
     cluda = Template(CLUDA_PREAMBLE).render(double_support=double_support)
     main = "\n".join([cluda, main])
     return main
Ejemplo n.º 6
0
 def setUp(self):
     NNPSTestCase.setUp(self)
     cl = importorskip("pyopencl")
     from pysph.base import gpu_nnps
     cfg = get_config()
     self._orig_use_double = cfg.use_double
     cfg.use_double = True
     self.nps = gpu_nnps.ZOrderGPUNNPS(dim=3,
                                       particles=self.particles,
                                       radius_scale=2.0,
                                       backend='opencl')
Ejemplo n.º 7
0
    def test_precomputed_should_work_on_gpu_with_double(self):
        orig = get_config().use_double

        def _cleanup():
            get_config().use_double = orig
        get_config().use_double = True
        self.addCleanup(_cleanup)
        # Given
        pa = self.pa
        equations = [SummationDensity(dest='fluid', sources=['fluid'])]
        a_eval = self._make_accel_eval(equations)

        # When
        a_eval.compute(0.1, 0.1)

        # Then
        expect = np.asarray([7.357, 9.0, 9., 9., 9., 9., 9., 9.,  9.,  7.357])
        pa.gpu.pull('rho')

        print(pa.rho, pa.gpu.rho)
        self.assertTrue(np.allclose(expect, pa.rho, atol=1e-2))
Ejemplo n.º 8
0
 def setUp(self):
     NNPSTestCase.setUp(self)
     cl = importorskip("pyopencl")
     from pysph.base import gpu_nnps
     ctx = cl.create_some_context(interactive=False)
     cfg = get_config()
     self._orig_use_double = cfg.use_double
     cfg.use_double = True
     self.nps = gpu_nnps.ZOrderGPUNNPS(dim=3,
                                       particles=self.particles,
                                       radius_scale=2.0,
                                       ctx=ctx)
Ejemplo n.º 9
0
    def __init__(self, particle_array, backend=None):
        self.backend = get_backend(backend)
        self._particle_array = pa = particle_array
        use_double = get_config().use_double
        self._dtype = np.float64 if use_double else np.float32
        self.num_real_particles = pa.num_real_particles
        self._data = {}
        self.properties = []
        self.constants = []

        for prop, ary in pa.properties.items():
            self.add_prop(prop, ary)
        for prop, ary in pa.constants.items():
            self.add_const(prop, ary)
Ejemplo n.º 10
0
    def __init__(self, particle_array):
        self._particle_array = pa = particle_array
        self._queue = get_queue()
        self._ctx = get_context()
        use_double = get_config().use_double
        self._dtype = np.float64 if use_double else np.float32
        self._data = {}
        self.properties = []
        self.constants = []

        for prop, ary in pa.properties.items():
            self.add_prop(prop, ary)
        for prop, ary in pa.constants.items():
            self.add_const(prop, ary)
Ejemplo n.º 11
0
    def setUp(self):
        NNPSTestCase.setUp(self)
        cl = importorskip("pyopencl")
        from pysph.base import gpu_nnps
        cfg = get_config()
        self._orig_use_double = cfg.use_double
        cfg.use_double = False
        self.nps = gpu_nnps.ZOrderGPUNNPS(dim=3,
                                          particles=self.particles,
                                          radius_scale=2.0,
                                          backend='opencl')
        self.nps.spatially_order_particles(0)
        self.nps.spatially_order_particles(1)

        for pa in self.particles:
            pa.gpu.pull()
Ejemplo n.º 12
0
    def __init__(self,
                 xmin=-1000.,
                 xmax=1000.,
                 ymin=0.,
                 ymax=0.,
                 zmin=0.,
                 zmax=0.,
                 periodic_in_x=False,
                 periodic_in_y=False,
                 periodic_in_z=False,
                 n_layers=2.0,
                 backend=None):
        """Constructor"""
        self.xmin = xmin
        self.xmax = xmax
        self.ymin = ymin
        self.ymax = ymax
        self.zmin = zmin
        self.zmax = zmax

        # Indicates if the domain is periodic
        self.periodic_in_x = periodic_in_x
        self.periodic_in_y = periodic_in_y
        self.periodic_in_z = periodic_in_z
        self.is_periodic = periodic_in_x or periodic_in_y or periodic_in_z
        self.n_layers = n_layers

        # get the translates in each coordinate direction
        self.xtranslate = xmax - xmin
        self.ytranslate = ymax - ymin
        self.ztranslate = zmax - zmin

        # empty list of particle array wrappers for now
        self.pa_wrappers = []
        self.narrays = 0

        # default value for the cell size
        self.cell_size = 1.0
        self.hmin = 1.0

        # default DomainManager in_parallel is set to False
        self.in_parallel = False

        use_double = get_config().use_double
        self.dtype = np.float64 if use_double else np.float32

        self.dtype_max = np.finfo(self.dtype).max
Ejemplo n.º 13
0
def teardown_module():
    get_config().use_openmp = False
Ejemplo n.º 14
0
 def __init__(self, helper):
     self.helper = helper
     self.particle_arrays = helper.object.particle_arrays
     self.nnps = None
     self._queue = helper._queue
     self._use_double = get_config().use_double
Ejemplo n.º 15
0
def convert_to_float_if_needed(code):
    use_double = get_config().use_double
    if not use_double:
        code = re.sub(r'\bdouble\b', 'float', code)
    return code
Ejemplo n.º 16
0
def run(nv, backend):
    e = Kernel(velocity, backend=backend)
    args = make_vortices(nv, backend)
    t1 = time.time()
    gs = ((nv + 128 - 1)//128)*128
    e(*args, global_size=(gs,))
    print(time.time() - t1)
    u = args[3]
    u.pull()
    print(u.data)
    return e, args


if __name__ == '__main__':
    from argparse import ArgumentParser
    p = ArgumentParser()
    p.add_argument(
        '-b', '--backend', action='store', dest='backend',
        default='opencl', help='Choose the backend.'
    )
    p.add_argument(
        '--use-double', action='store_true', dest='use_double',
        default=False,  help='Use double precision on the GPU.'
    )
    p.add_argument('-n', action='store', type=int, dest='n',
                   default=10000, help='Number of particles.')
    o = p.parse_args()
    get_config().use_double = o.use_double
    assert o.backend in ['opencl'], "Only OpenCL backend is supported."
    run(o.n, o.backend)
Ejemplo n.º 17
0
 def _cleanup():
     get_config().use_double = orig
Ejemplo n.º 18
0
 def setUp(self):
     get_config().use_opencl = False
     self.backend = None
Ejemplo n.º 19
0
 def tearDown(self):
     super(BruteForceNNPSTestCase, self).tearDown()
     get_config().use_double = self._orig_use_double
Ejemplo n.º 20
0
 def setUp(self):
     cu = pytest.importorskip("pycuda")
     get_config().use_double = True
     self.backend = 'cuda'
Ejemplo n.º 21
0
 def setUp(self):
     get_config().use_opencl = False
Ejemplo n.º 22
0
 def setUp(self):
     ocl = pytest.importorskip("pyopencl")
     get_config().use_double = True
     self.backend = 'opencl'
Ejemplo n.º 23
0
 def tearDown(self):
     super(ZOrderGPUDoubleNNPSTestCase, self).tearDown()
     get_config().use_double = self._orig_use_double
Ejemplo n.º 24
0
if __name__ == '__main__':
    from argparse import ArgumentParser
    p = ArgumentParser()
    p.add_argument('-b',
                   '--backend',
                   action='store',
                   dest='backend',
                   default='cython',
                   help='Choose the backend.')
    p.add_argument('--openmp',
                   action='store_true',
                   dest='openmp',
                   default=False,
                   help='Use OpenMP.')
    p.add_argument('--use-double',
                   action='store_true',
                   dest='use_double',
                   default=False,
                   help='Use double precision on the GPU.')
    p.add_argument('-n',
                   action='store',
                   type=int,
                   dest='n',
                   default=10000,
                   help='Number of particles.')
    o = p.parse_args()
    get_config().use_openmp = o.openmp
    get_config().use_double = o.use_double
    run(o.n, o.backend)
Ejemplo n.º 25
0
 def tearDown(self):
     super(TestZOrderGPUNNPSWithSorting, self).tearDown()
     get_config().use_double = self._orig_use_double
Ejemplo n.º 26
0
def setup_module():
    get_config().use_openmp = True