From d10c65d43919f5ee611fc4a0ef7c79f3c3e65822 Mon Sep 17 00:00:00 2001 From: zy69guqi <richard.angersbach@fau.de> Date: Tue, 18 Feb 2025 17:29:22 +0100 Subject: [PATCH] Catch CUDARuntimeError for mising CUDA capable device in reduction GPU test --- tests/kernelcreation/test_reduction.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/kernelcreation/test_reduction.py b/tests/kernelcreation/test_reduction.py index ec23297b0..992c328d7 100644 --- a/tests/kernelcreation/test_reduction.py +++ b/tests/kernelcreation/test_reduction.py @@ -2,6 +2,7 @@ import pytest import numpy as np import pystencils as ps +from cupy_backends.cuda.api.runtime import CUDARuntimeError from pystencils.sympyextensions import reduction_assignment_from_str INIT_W = 5 @@ -48,8 +49,15 @@ def test_reduction_cpu(instruction_set, dtype, op): @pytest.mark.parametrize('dtype', ["float64", "float32"]) @pytest.mark.parametrize("op", ["+", "-", "*", "min", "max"]) def test_reduction_gpu(dtype, op): - pytest.importorskip('cupy') - import cupy as cp + try: + import cupy as cp + + device_count = range(cp.cuda.runtime.getDeviceCount()) + print(f"Found {device_count} GPUs") + except ImportError: + pytest.skip(reason="CuPy is not available", allow_module_level=True) + except CUDARuntimeError: + pytest.skip(reason="No CUDA capable device is detected", allow_module_level=True) config = ps.CreateKernelConfig(target=ps.Target.GPU) -- GitLab