Skip to content
test.py 2.68 KiB
Newer Older
import numpy as np
import numpy.linalg as la
import pyopencl as cl
import pyopencl.array  # noqa
import pyopencl.tools  # noqa
import pyopencl.clrandom  # noqa
import loopy as lp  # noqa
from pyopencl.tools import (  # noqa
        pytest_generate_tests_for_pyopencl
        as pytest_generate_tests)

import fixtures
import comparison_fixtures as compare
def test_matvec(ctx_factory):
    a = fixtures.random_array(10, 10)
    b = fixtures.random_array(10)
    c = fixtures.mult_mat_vec(ctx_factory, a=a, b=b, alpha=1.0)
def test_compute_flux_derivatives(ctx_factory):
    logging.basicConfig(level="INFO")
    states = fixtures.random_array(nvars, nx+6, ny+6, nz+6)
    fluxes = fixtures.random_array(nvars, ndim, nx+6, ny+6, nz+6)
    metrics = fixtures.random_array(ndim, ndim, nx+6, ny+6, nz+6)
    metric_jacobians = fixtures.random_array(nx+6, ny+6, nz+6)
    fixtures.compute_flux_derivatives(ctx_factory,
            nvars=nvars, ndim=ndim, nx=nx, ny=ny, nz=nz,
            states=states, fluxes=fluxes, metrics=metrics,
            metric_jacobians=metric_jacobians)
Andreas Klöckner's avatar
Andreas Klöckner committed
def test_compute_flux_derivatives_gpu(ctx_factory):
    logging.basicConfig(level="INFO")

    queue = fixtures.get_queue(ctx_factory)
Andreas Klöckner's avatar
Andreas Klöckner committed

    ndim = 3
    nvars = 5
    nx = 10
    ny = 10
    nz = 10

    states = fixtures.f_array(queue, nvars, nx+6, ny+6, nz+6)
    fluxes = fixtures.f_array(queue, nvars, ndim, nx+6, ny+6, nz+6)
    metrics = fixtures.f_array(queue, ndim, ndim, nx+6, ny+6, nz+6)
    metric_jacobians = fixtures.f_array(queue, nx+6, ny+6, nz+6)
    flux_derivatives_dev = cl.array.empty(queue, (nvars, ndim, nx+6, ny+6,
        nz+6), dtype=np.float32, order="F")

    prg = prg.copy(target=lp.PyOpenCLTarget(queue.device))

Andreas Klöckner's avatar
Andreas Klöckner committed
    if 1:
        with open("gen-code.cl", "w") as outf:
            outf.write(lp.generate_code_v2(prg).device_code())

    prg = lp.set_options(prg, no_numpy=True)

    prg(queue, nvars=nvars, ndim=ndim,
            states=states, fluxes=fluxes, metrics=metrics,
            metric_jacobians=metric_jacobians,
            flux_derivatives=flux_derivatives_dev)

    prg(queue, nvars=nvars, ndim=ndim,
            states=states, fluxes=fluxes, metrics=metrics,
            metric_jacobians=metric_jacobians,
            flux_derivatives=flux_derivatives_dev)


Andreas Klöckner's avatar
Andreas Klöckner committed
# This lets you run 'python test.py test_case(cl._csc)' without pytest.
if __name__ == "__main__":
    if len(sys.argv) > 1:
        exec(sys.argv[1])
    else:
        from pytest import main
        main([__file__])