Beispiel #1
0
def get_target(lang, device=None, compiler=None):
    """

    Parameters
    ----------
    lang : str
        One of the supported languages, {'c', 'cuda', 'opencl'}
    device : :class:`pyopencl.Device`
        If supplied, and lang is 'opencl', passed to the
        :class:`loopy.PyOpenCLTarget`
    compiler: str
        If supplied, the C-compiler to use

    Returns
    -------
    The correct loopy target type
    """

    utils.check_lang(lang)

    # set target
    if lang == 'opencl':
        return lp.PyOpenCLTarget(device=device)
    elif lang == 'c':
        return lp.ExecutableCTarget(compiler=compiler)
    elif lang == 'cuda':
        return lp.CudaTarget()
    elif lang == 'ispc':
        return lp.ISPCTarget()
Beispiel #2
0
def test_scalar_global_args():
    n = np.random.default_rng().integers(30, 100)
    evt, (out, ) = lp.make_kernel("{[i]: 0<=i<n}",
                                  "res  = sum(i, i)",
                                  target=lp.ExecutableCTarget())(n=n)

    assert out == (n * (n - 1) / 2)
Beispiel #3
0
    def __init__(self, energy, Stepper, mpl=1., dtype=np.float64):
        self.mpl = mpl
        from pystella.step import LowStorageRKStepper

        self.is_low_storage = LowStorageRKStepper in Stepper.__bases__
        num_copies = Stepper.__dict__.get("num_copies", 1)
        shape = (num_copies,)
        arg_shape = (1,) if self.is_low_storage else tuple()
        self.a = np.ones(shape, dtype=dtype)
        self.adot = self.adot_friedmann_1(self.a, energy)
        self.hubble = self.adot / self.a

        slc = (0,) if self.is_low_storage else ()
        from pystella import Field
        _a = Field("a", indices=[], shape=arg_shape)[slc]
        _adot = Field("adot", indices=[], shape=arg_shape)[slc]
        from pymbolic import var
        _e = var("energy")
        _p = var("pressure")
        rhs_dict = {_a: _adot,
                    _adot: self.addot_friedmann_2(_a, _e, _p)}

        from pystella import DisableLogging
        from loopy.target.c.c_execution import logger as c_logger
        with DisableLogging(c_logger):  # silence GCCToolchain warning
            self.stepper = Stepper(rhs_dict, rank_shape=(0, 0, 0),
                                   halo_shape=0, dtype=dtype,
                                   target=lp.ExecutableCTarget())
Beispiel #4
0
def test_one_length_loop():
    # https://github.com/inducer/loopy/issues/239
    knl = lp.make_kernel("{[i]: 0<=i<1}",
                         """
            a[i] = 42.0
            """,
                         target=lp.ExecutableCTarget())

    _, (out, ) = knl()
    assert out == 42
def _create(order='C', target=lp.ExecutableCTarget()):
    # create a test kernel
    arg1 = lp.GlobalArg('a1', shape=(10, 10), order=order)
    arg2 = lp.GlobalArg('a2', shape=(16, 16), order=order)

    return lp.make_kernel('{[i]: 0 <= i < 10}',
                          """
            a1[0, i] = 1 {id=a1}
            a2[0, i] = 1 {id=a2}
        """, [arg1, arg2],
                          target=target)
Beispiel #6
0
def test_int_max_min_c_target(ctx_factory, which):
    from numpy.random import default_rng
    from pymbolic import parse
    rng = default_rng()

    n = 100
    arr1 = rng.integers(-100, 100, n)
    arr2 = rng.integers(-100, 100, n)
    np_func = getattr(np, f"{which}imum")

    knl = lp.make_kernel(
        "{[i]: 0<=i<100}",
        [lp.Assignment(parse("out[i]"), parse(f"{which}(arr1[i], arr2[i])"))],
        target=lp.ExecutableCTarget())

    _, (out, ) = knl(arr1=arr1, arr2=arr2)
    np.testing.assert_allclose(np_func(arr1, arr2), out)