From 910c612835054990ea29c9f9523d7240b6ae1598 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 28 Jun 2019 23:23:43 -0500 Subject: [PATCH 1/3] remove import * --- test.py | 70 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/test.py b/test.py index 1bfe9c8..c9a95c1 100644 --- a/test.py +++ b/test.py @@ -15,7 +15,7 @@ from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) -from utilities import * +import utilities as u @pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ @@ -27,20 +27,20 @@ from utilities import * ]) def test_lax_wavespeeds( ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): - prg = get_weno_program_with_root_kernel("lax_wavespeeds") - queue = get_queue(ctx_factory) + prg = u.get_weno_program_with_root_kernel("lax_wavespeeds") + queue = u.get_queue(ctx_factory) nvars = 5 - lam_pointwise = expand_to_6(transposed_array_from_string(lam_pointwise_str)) - lam_roe = array_from_string(lam_roe_str) - lam_dev = empty_array_on_device(queue, nvars) + lam_pointwise = u.expand_to_6(u.transposed_array_from_string(lam_pointwise_str)) + lam_roe = u.array_from_string(lam_roe_str) + lam_dev = u.empty_array_on_device(queue, nvars) prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, lambda_roe=lam_roe, wavespeeds=lam_dev) - lam_expected = array_from_string(lam_expected_str) - compare_arrays(lam_dev.get(), lam_expected) + lam_expected = u.array_from_string(lam_expected_str) + u.compare_arrays(lam_dev.get(), lam_expected) @pytest.mark.parametrize("states_str,direction,lam_expected_str", [ @@ -71,20 +71,20 @@ def test_lax_wavespeeds( ]) def test_pointwise_eigenvalues( ctx_factory, states_str, direction, lam_expected_str): - prg = get_weno_program_with_root_kernel("pointwise_eigenvalues") - queue = get_queue(ctx_factory) + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") + queue = u.get_queue(ctx_factory) nvars = 5 dirs = {"x" : 1, "y" : 2, "z" : 3} - states = expand_to_6(transposed_array_from_string(states_str)) - lam_dev = empty_array_on_device(queue, nvars, 6) + states = u.expand_to_6(u.transposed_array_from_string(states_str)) + lam_dev = u.empty_array_on_device(queue, nvars, 6) prg(queue, nvars=nvars, d=dirs[direction], states=states, lambda_pointwise=lam_dev) - lam_expected = expand_to_6(transposed_array_from_string(lam_expected_str)) - compare_arrays(lam_dev.get(), lam_expected) + lam_expected = u.expand_to_6(u.transposed_array_from_string(lam_expected_str)) + u.compare_arrays(lam_dev.get(), lam_expected) @pytest.mark.parametrize("states_str,fluxes_str,direction", [ @@ -107,7 +107,7 @@ def test_roe_uniform_grid(ctx_factory, states_str, fluxes_str, direction): def check_roe_identity(states, R, Rinv): dState = states[:,1] - states[:,0] - compare_arrays(R@(Rinv@dState), dState) + u.compare_arrays(R@(Rinv@dState), dState) def check_roe_property(states, fluxes, R, Rinv, lam): dState = states[:,1] - states[:,0] @@ -115,22 +115,22 @@ def test_roe_uniform_grid(ctx_factory, states_str, fluxes_str, direction): temp = Rinv@dState temp = np.multiply(lam, temp) - compare_arrays(R@temp, dFlux) + u.compare_arrays(R@temp, dFlux) - prg = get_weno_program_with_root_kernel("roe_eigensystem") - queue = get_queue(ctx_factory) + prg = u.get_weno_program_with_root_kernel("roe_eigensystem") + queue = u.get_queue(ctx_factory) nvars = 5 ndim = 3 dirs = {"x" : 1, "y" : 2, "z" : 3} - states = transposed_array_from_string(states_str) - fluxes = transposed_array_from_string(fluxes_str) + states = u.transposed_array_from_string(states_str) + fluxes = u.transposed_array_from_string(fluxes_str) metrics_frozen = identity_matrix(ndim) - R_dev = empty_array_on_device(queue, nvars, nvars) - Rinv_dev = empty_array_on_device(queue, nvars, nvars) - lam_dev = empty_array_on_device(queue, nvars) + R_dev = u.empty_array_on_device(queue, nvars, nvars) + Rinv_dev = u.empty_array_on_device(queue, nvars, nvars) + lam_dev = u.empty_array_on_device(queue, nvars) prg(queue, nvars=nvars, ndim=ndim, d=dirs[direction], states=states, metrics_frozen=metrics_frozen, @@ -147,24 +147,24 @@ def test_roe_uniform_grid(ctx_factory, states_str, fluxes_str, direction): def test_matvec(ctx_factory): - prg = get_weno_program_with_root_kernel("mult_mat_vec") - queue = get_queue(ctx_factory) + prg = u.get_weno_program_with_root_kernel("mult_mat_vec") + queue = u.get_queue(ctx_factory) - a = random_array_on_device(queue, 10, 10) - b = random_array_on_device(queue, 10) + a = u.random_array_on_device(queue, 10, 10) + b = u.random_array_on_device(queue, 10) - c = empty_array_on_device(queue, 10) + c = u.empty_array_on_device(queue, 10) prg(queue, alpha=1.0, a=a, b=b, c=c) - compare_arrays(a.get()@b.get(), c.get()) + u.compare_arrays(a.get()@b.get(), c.get()) @pytest.mark.slow def test_compute_flux_derivatives(ctx_factory): - prg = get_weno_program() + prg = u.get_weno_program() - queue = get_queue(ctx_factory) + queue = u.get_queue(ctx_factory) prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, @@ -173,15 +173,15 @@ def test_compute_flux_derivatives(ctx_factory): @pytest.mark.slow def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): - prg = get_weno_program() - prg = transform_weno_for_gpu(prg) + prg = u.get_weno_program() + prg = u.transform_weno_for_gpu(prg) - queue = get_queue(ctx_factory) + queue = u.get_queue(ctx_factory) prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) prg = lp.set_options(prg, no_numpy=True) if write_code: - write_target_device_code(prg) + u.write_target_device_code(prg) lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) -- GitLab From 140e5c683304d627d641a7a7dad3e0766a28032f Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 28 Jun 2019 23:27:18 -0500 Subject: [PATCH 2/3] rename some test functions to clarify they assume ideal gas EOS --- test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index c9a95c1..b64ddfb 100644 --- a/test.py +++ b/test.py @@ -69,7 +69,7 @@ def test_lax_wavespeeds( ("1 -1 -2 -3 11,2 -4 -8 -12 64", "z", "-3 -3 -3 -1.50333705 -4.49666295,-6 -6 -6 -4.50333705 -7.49666295") ]) -def test_pointwise_eigenvalues( +def test_pointwise_eigenvalues_ideal_gas( ctx_factory, states_str, direction, lam_expected_str): prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") queue = u.get_queue(ctx_factory) @@ -101,7 +101,7 @@ def test_pointwise_eigenvalues( ("1 -1 -2 -3 11,2 -4 -8 -12 64", "-2 2 5.6 6 -25.2,-8 16 35.2 48 -268.8", "y"), ("1 -1 -2 -3 11,2 -4 -8 -12 64", "-3 3 6 10.6 -37.8,-12 24 48 75.2 -403.2", "z") ]) -def test_roe_uniform_grid(ctx_factory, states_str, fluxes_str, direction): +def test_roe_uniform_grid_ideal_gas(ctx_factory, states_str, fluxes_str, direction): def identity_matrix(n): return np.identity(n).astype(np.float32).copy(order="F") -- GitLab From 5ddfc414b4bd42a02160d9e753564803f96325dc Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 28 Jun 2019 23:32:45 -0500 Subject: [PATCH 3/3] remove import * from benchmark code --- benchmark.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmark.py b/benchmark.py index 71859c7..6d2b9b0 100644 --- a/benchmark.py +++ b/benchmark.py @@ -9,16 +9,16 @@ import sys import logging -from utilities import * +import utilities as u def benchmark_compute_flux_derivatives_gpu(ctx_factory, write_code=False): logging.basicConfig(level="INFO") - prg = get_weno_program() - prg = transform_weno_for_gpu(prg) + prg = u.get_weno_program() + prg = u.transform_weno_for_gpu(prg) - queue = get_queue(ctx_factory) + queue = u.get_queue(ctx_factory) prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) prg = lp.set_options(prg, no_numpy=True) prg = lp.set_options(prg, ignore_boostable_into=True) @@ -34,16 +34,16 @@ def benchmark_compute_flux_derivatives_gpu(ctx_factory, write_code=False): nz = n print("ARRAY GEN") - states = random_array_on_device(queue, nvars, nx+6, ny+6, nz+6) - fluxes = random_array_on_device(queue, nvars, ndim, nx+6, ny+6, nz+6) - metrics = random_array_on_device(queue, ndim, ndim, nx+6, ny+6, nz+6) - metric_jacobians = random_array_on_device(queue, nx+6, ny+6, nz+6) + states = u.random_array_on_device(queue, nvars, nx+6, ny+6, nz+6) + fluxes = u.random_array_on_device(queue, nvars, ndim, nx+6, ny+6, nz+6) + metrics = u.random_array_on_device(queue, ndim, ndim, nx+6, ny+6, nz+6) + metric_jacobians = u.random_array_on_device(queue, nx+6, ny+6, nz+6) print("END ARRAY GEN") - flux_derivatives_dev = empty_array_on_device(queue, nvars, ndim, nx+6, ny+6, nz+6) + flux_derivatives_dev = u.empty_array_on_device(queue, nvars, ndim, nx+6, ny+6, nz+6) if write_code: - write_target_device_code(prg) + u.write_target_device_code(prg) allocator = pyopencl.tools.MemoryPool(pyopencl.tools.ImmediateAllocator(queue)) -- GitLab