Skip to content

Commit 3d6e58c

Browse files
author
Thomas Baumann
committed
Added test for 2D differentiation matrix on GPU
1 parent 02ec1d9 commit 3d6e58c

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

pySDC/helpers/spectral_helper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,14 @@ def get_differentiation_matrix(self, p=1):
746746
k = self.get_wavenumbers()
747747

748748
if self.useGPU:
749-
# Have to raise the matrix to power p on CPU because the GPU equivalent is not implemented in CuPy at the time of writing.
750-
import scipy.sparse as sp
749+
if p > 1:
750+
# Have to raise the matrix to power p on CPU because the GPU equivalent is not implemented in CuPy at the time of writing.
751+
from scipy.sparse.linalg import matrix_power
751752

752-
D = self.sparse_lib.diags(1j * k).get()
753-
return self.sparse_lib.csc_matrix(sp.linalg.matrix_power(D, p))
753+
D = self.sparse_lib.diags(1j * k).get()
754+
return self.sparse_lib.csc_matrix(matrix_power(D, p))
755+
else:
756+
return self.sparse_lib.diags(1j * k)
754757
else:
755758
return self.linalg.matrix_power(self.sparse_lib.diags(1j * k), p)
756759

pySDC/tests/test_helpers/test_spectral_helper.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ def test_integration_matrix2D(nx, nz, variant, axes, useMPI=False, **kwargs):
5252
@pytest.mark.parametrize('axes', [(-2,), (-1,), (-2, -1)])
5353
@pytest.mark.parametrize('bx', ['cheby', 'fft'])
5454
@pytest.mark.parametrize('bz', ['cheby', 'fft'])
55-
def test_differentiation_matrix2D(nx, nz, variant, axes, bx, bz, **kwargs):
56-
import numpy as np
55+
def test_differentiation_matrix2D(nx, nz, variant, axes, bx, bz, useGPU=False, **kwargs):
5756
from pySDC.helpers.spectral_helper import SpectralHelper
5857

59-
helper = SpectralHelper(debug=True)
58+
helper = SpectralHelper(debug=True, useGPU=useGPU)
6059
helper.add_axis(base=bx, N=nx)
6160
helper.add_axis(base=bz, N=nz)
6261
helper.setup_fft()
6362

63+
np = helper.xp
64+
65+
if useGPU:
66+
import cupy
67+
68+
assert np == cupy
69+
6470
X, Z = helper.get_grid()
6571
conv = helper.get_basis_change_matrix()
6672
D = helper.get_differentiation_matrix(axes)
@@ -95,6 +101,14 @@ def test_differentiation_matrix2D(nx, nz, variant, axes, bx, bz, **kwargs):
95101
assert np.allclose(D_u, expect, atol=1e-11)
96102

97103

104+
@pytest.mark.cupy
105+
@pytest.mark.parametrize('axes', [(-2,), (-1,), (-2, -1)])
106+
@pytest.mark.parametrize('bx', ['cheby', 'fft'])
107+
@pytest.mark.parametrize('bz', ['cheby', 'fft'])
108+
def test_differentiation_matrix2D_GPU(bx, bz, axes):
109+
test_differentiation_matrix2D(32, 16, variant='T2U', bx=bx, bz=bz, axes=axes, useGPU=True)
110+
111+
98112
@pytest.mark.base
99113
@pytest.mark.parametrize('nx', [32])
100114
@pytest.mark.parametrize('nz', [16])

0 commit comments

Comments
 (0)