Skip to content

Commit

Permalink
minor tweaks in test_offloading to allow Py(CUDA|OpenCL) arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikcfd committed Jul 11, 2022
1 parent ff02e3c commit 6169a12
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/test_offloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
TrialFunction, Function, UnitSquareMesh,
SpatialCoordinate, inner, grad, dx, norm, pi, cos,
assemble)
import numpy as np
import firedrake_configuration
from pyop2.backends.cpu import cpu_backend

Expand All @@ -16,6 +15,13 @@
AVAILABLE_BACKENDS.append(cuda_backend)


def allclose(a, b, rtol=1e-05, atol=1e-08):
"""
Prefer this routine over np.allclose(...) to allow pycuda/pyopencl arrays
"""
return bool(abs(a - b) < (atol + rtol * abs(b)))


@pytest.mark.parametrize("offloading_backend", AVAILABLE_BACKENDS)
def test_nonlinear_variational_solver(offloading_backend):
set_offloading_backend(offloading_backend)
Expand Down Expand Up @@ -106,4 +112,4 @@ def test_data_manipulation_on_host(offloading_backend):
with offloading():
new_norm = norm(fem_soln)

np.testing.assert_allclose(kappa*old_norm, new_norm)
allclose(kappa*old_norm, new_norm)

0 comments on commit 6169a12

Please sign in to comment.