From acb6e252995be9c1c4ccf810c374522d22c3c4a8 Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Thu, 22 Oct 2026 22:18:57 +0200 Subject: [PATCH 1/2] Tests: per-backend test environments (test/Project.toml, GPU backend installed by the test runner) The test target installed CUDA, AMDGPU, Metal, Enzyme, KernelAbstractions and Polyester together on every platform, which held each GPU package back (CUDA 6.2.2, AMDGPU 2.7.0 on Julia 1.13) and has no solution on Julia pre. - test/Project.toml replaces the [extras]/[targets] test target; it holds only the always-needed test dependencies, no GPU package. - runtests.jl installs the backend given by PS_TEST_BACKEND (CUDA with CUDA_Runtime_jll, AMDGPU or Metal) into the temporary test environment of Pkg.test if it is not installed; the tests of that backend must then run. The CI jobs only set the variable. - test/packages.jl replaces the backend-selection preamble repeated in 18 test files; GPU packages that are not installed are replaced by empty placeholder modules, as the test files refer to the packages by name. - select_hardware tests: KernelAbstractions GPU backend types referred to qualified; test_allocators.jl: CellArrays type definitions selected with @static if; TEST_PACKAGES is a copy of SUPPORTED_PACKAGES instead of an alias. - Docs: Testing page updated. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/ci.yml | 2 + .gitignore | 1 + Project.toml | 8 ---- ci/cscs-gh200.yml | 2 +- ci/cscs-mi250.yml | 2 +- ci/cscs-mi300.yml | 2 +- docs/src/testing.md | 10 +++-- test/ParallelKernel/test_allocators.jl | 28 ++----------- .../ParallelKernel/test_hide_communication.jl | 22 +--------- .../test_init_parallel_kernel.jl | 22 +--------- test/ParallelKernel/test_kernel_language.jl | 22 +--------- test/ParallelKernel/test_overlap.jl | 22 +--------- test/ParallelKernel/test_parallel.jl | 22 +--------- .../test_reset_parallel_kernel.jl | 22 +--------- test/ParallelKernel/test_select_hardware.jl | 34 +++------------ test/Project.toml | 13 ++++++ test/packages.jl | 34 +++++++++++++++ test/runtests.jl | 42 ++++++++++++------- test/test_FiniteDifferences1D.jl | 22 +--------- test/test_FiniteDifferences2D.jl | 22 +--------- test/test_FiniteDifferences3D.jl | 22 +--------- test/test_extensions.jl | 21 +--------- test/test_incremental_compilation.jl | 21 +--------- test/test_init_parallel_stencil.jl | 22 +--------- test/test_kernel_language.jl | 28 +------------ test/test_parallel.jl | 28 +------------ test/test_reset_parallel_stencil.jl | 22 +--------- test/test_select_hardware.jl | 34 +++------------ 28 files changed, 118 insertions(+), 434 deletions(-) create mode 100644 test/Project.toml create mode 100644 test/packages.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fce0570..8ae92aca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.version == 'pre' }} + env: + PS_TEST_BACKEND: ${{ startsWith(matrix.os, 'macOS') && 'Metal' || '' }} # The macOS runners (Apple silicon) have a functional Metal GPU: the test runner installs Metal into the test environment and the Metal tests must run. strategy: fail-fast: false matrix: diff --git a/.gitignore b/.gitignore index 180a8947..a045779a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store Manifest.toml +test/Manifest.toml miniapps/Manifest.toml *.cov lcov.info diff --git a/Project.toml b/Project.toml index 6038e7ee..b7694dce 100644 --- a/Project.toml +++ b/Project.toml @@ -37,11 +37,3 @@ Metal = "1.2" Polyester = "0.7" StaticArrays = "1" julia = "1.10" # Minimum version supporting Data module creation - -[extras] -CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2" -TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test", "TOML", "AMDGPU", "CUDA", "CUDA_Runtime_jll", "Metal", "Enzyme", "Polyester", "KernelAbstractions"] diff --git a/ci/cscs-gh200.yml b/ci/cscs-gh200.yml index 447dc33b..7f9135b8 100644 --- a/ci/cscs-gh200.yml +++ b/ci/cscs-gh200.yml @@ -12,7 +12,7 @@ include: JULIA_UENV: 'julia/26.3:v1' JULIA_CUDA_USE_COMPAT: 'false' JULIA_NUM_THREADS: 2 - PS_TEST_BACKEND: 'CUDA' # Fail instead of skipping the GPU tests if CUDA is not functional. + PS_TEST_BACKEND: 'CUDA' # The test runner installs CUDA into the test environment; fail instead of skipping the GPU tests if it is not functional. PS_TEST_FILES: '' # Test files to run (default: all). script: - ulimit -c 0 diff --git a/ci/cscs-mi250.yml b/ci/cscs-mi250.yml index 3ecac170..41882f10 100644 --- a/ci/cscs-mi250.yml +++ b/ci/cscs-mi250.yml @@ -15,7 +15,7 @@ include: JULIA_AMDGPU_CORE_MUST_LOAD: '1' JULIA_AMDGPU_HIP_MUST_LOAD: '1' JULIA_NUM_THREADS: 2 - PS_TEST_BACKEND: 'AMDGPU' # Fail instead of skipping the GPU tests if AMDGPU is not functional. + PS_TEST_BACKEND: 'AMDGPU' # The test runner installs AMDGPU into the test environment; fail instead of skipping the GPU tests if it is not functional. PS_TEST_FILES: '' # Test files to run (default: all). script: - ulimit -c 0 diff --git a/ci/cscs-mi300.yml b/ci/cscs-mi300.yml index 18f1853a..dfc31f4b 100644 --- a/ci/cscs-mi300.yml +++ b/ci/cscs-mi300.yml @@ -15,7 +15,7 @@ include: JULIA_AMDGPU_CORE_MUST_LOAD: '1' JULIA_AMDGPU_HIP_MUST_LOAD: '1' JULIA_NUM_THREADS: 2 - PS_TEST_BACKEND: 'AMDGPU' # Fail instead of skipping the GPU tests if AMDGPU is not functional. + PS_TEST_BACKEND: 'AMDGPU' # The test runner installs AMDGPU into the test environment; fail instead of skipping the GPU tests if it is not functional. PS_TEST_FILES: '' # Test files to run (default: all). script: - ulimit -c 0 diff --git a/docs/src/testing.md b/docs/src/testing.md index 4f1e6af2..80f1e206 100644 --- a/docs/src/testing.md +++ b/docs/src/testing.md @@ -9,13 +9,13 @@ Each test file runs in its own Julia process. Test files can be selected by file import Pkg; Pkg.test("ParallelStencil"; test_args=["ParallelKernel/test_parallel.jl", "--stop-on-fail"]) ``` -The tests of the CUDA, AMDGPU and Metal backends run if the corresponding package is functional, and are skipped otherwise. The following environment variable controls the test run: +The GPU packages (CUDA, AMDGPU and Metal) are not dependencies of the test environment (`test/Project.toml`), as resolving them all together holds each of them back to an old version. The GPU backend to test is selected with the following environment variable; the test runner installs its package into the (temporary) test environment of `Pkg.test`, and its tests must run: | Variable | Description | |:----------------- |:----------------------------------------------------------------------------------------------------------------------------------------- | -| `PS_TEST_BACKEND` | GPU backend that must be functional (`CUDA`, `AMDGPU` or `Metal`); if it is not, the test run fails instead of skipping the tests of this backend. | +| `PS_TEST_BACKEND` | GPU backend to test (`CUDA`, `AMDGPU` or `Metal`): its package is installed into the test environment if it is not already, and the test run fails instead of skipping the tests of this backend if it is not functional. | -For example, to make sure that the GPU tests are run: +Without it, the CPU backends (Threads, Polyester and KernelAbstractions on the CPU) are tested, and the tests of a GPU backend run only if its package is already installed in the test environment and functional. For example, to test a GPU backend: :::code-group @@ -36,6 +36,8 @@ julia --project -e 'import Pkg; Pkg.test()' ::: +The test environment of `Pkg.test` is temporary, so the installation is repeated at each test run (it is fast once the package is in the depot). To avoid it, the package can be added permanently to the test environment with `julia --project=test -e 'import Pkg; Pkg.add("CUDA")'`; this modifies `test/Project.toml` (do not commit this change) and `test/Manifest.toml` (not tracked by git). + ## Continuous integration - **GitHub Actions** (CPUs, and Apple GPUs on the macOS runners): Julia `min` and `1` on Linux and macOS (Apple silicon), and Julia `pre` on Linux (allowed to fail) (`.github/workflows/ci.yml`). @@ -45,4 +47,6 @@ julia --project -e 'import Pkg; Pkg.test()' For pull requests by other contributors, a maintainer starts the pipelines by commenting `cscs-ci run`. + Each job sets `PS_TEST_BACKEND` to the GPU backend it tests (`CUDA` on Daint, `AMDGPU` on Beverin and `Metal` on the macOS runners of GitHub Actions); the Linux jobs of GitHub Actions test the CPU backends only. + Coverage of all jobs is uploaded to [Codecov](https://app.codecov.io/gh/omlins/ParallelStencil.jl) (flags `cpu`, `gh200`, `mi250` and `mi300`). diff --git a/test/ParallelKernel/test_allocators.jl b/test/ParallelKernel/test_allocators.jl index e20ec9f6..70b0fe70 100644 --- a/test/ParallelKernel/test_allocators.jl +++ b/test/ParallelKernel/test_allocators.jl @@ -8,30 +8,10 @@ import ParallelStencil.ParallelKernel: checkargs_CellType, _CellType using ParallelStencil.ParallelKernel.FieldAllocators import ParallelStencil.ParallelKernel.FieldAllocators: checksargs_field_macros, checkargs_allocate using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end - @define_CuCellArray -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end - @define_ROCCellArray -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end - @define_MtlCellArray -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. +@static if (PKG_CUDA in TEST_PACKAGES) @define_CuCellArray end # NOTE: @static, as the macros import the GPU package at expansion time. +@static if (PKG_AMDGPU in TEST_PACKAGES) @define_ROCCellArray end +@static if (PKG_METAL in TEST_PACKAGES) @define_MtlCellArray end const DATA_INDEX = ParallelStencil.INT_THREADS # TODO: using Data.Index does not work in combination with @reset_parallel_kernel, because the macros from module Test alternate the order of evaluation, resulting in the Data module being replaced with an empty module before Data.Index is evaluated. If at some point the indexing varies depending on the used package, then something more sophisticated is needed here (e.g., wrapping the test for each package in a module and using then Data.Index everywhere). kernelabstractions_valid_symbols() = Tuple(filter(!isnothing, ( :cpu, diff --git a/test/ParallelKernel/test_hide_communication.jl b/test/ParallelKernel/test_hide_communication.jl index cff447ec..d52325c4 100644 --- a/test/ParallelKernel/test_hide_communication.jl +++ b/test/ParallelKernel/test_hide_communication.jl @@ -5,27 +5,7 @@ import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, import ParallelStencil.ParallelKernel: @require, @prettyexpand, @gorgeousexpand, gorgeousstring, @isgpu import ParallelStencil.ParallelKernel: checkargs_hide_communication, hide_communication_gpu using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/ParallelKernel/test_init_parallel_kernel.jl b/test/ParallelKernel/test_init_parallel_kernel.jl index e171b60b..416ce26d 100644 --- a/test/ParallelKernel/test_init_parallel_kernel.jl +++ b/test/ParallelKernel/test_init_parallel_kernel.jl @@ -5,27 +5,7 @@ import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, import ParallelStencil.ParallelKernel: @require, @symbols import ParallelStencil.ParallelKernel: extract_posargs_init, extract_kwargs_init, check_already_initialized, set_initialized, is_initialized, check_initialized using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/ParallelKernel/test_kernel_language.jl b/test/ParallelKernel/test_kernel_language.jl index b68b68f4..742e6bf6 100644 --- a/test/ParallelKernel/test_kernel_language.jl +++ b/test/ParallelKernel/test_kernel_language.jl @@ -5,27 +5,7 @@ import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, import ParallelStencil.ParallelKernel: @require, @prettystring, @iscpu, @select_hardware, @current_hardware, handle import ParallelStencil.ParallelKernel: checknoargs, checkargs_sharedMem, Dim3 using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal # Import also on non-Apple systems to test macro expansions - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. macro expr_allocated(ex) diff --git a/test/ParallelKernel/test_overlap.jl b/test/ParallelKernel/test_overlap.jl index e8018a80..2fe83589 100644 --- a/test/ParallelKernel/test_overlap.jl +++ b/test/ParallelKernel/test_overlap.jl @@ -5,27 +5,7 @@ import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, import ParallelStencil.ParallelKernel: @require, @gorgeousexpand, @isgpu import ParallelStencil.ParallelKernel: checkargs_overlap, @overlap, overlap_gpu using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - @static if Sys.isapple() - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end - else - TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) - end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. for package in TEST_PACKAGES diff --git a/test/ParallelKernel/test_parallel.jl b/test/ParallelKernel/test_parallel.jl index 60021e17..fbd25866 100644 --- a/test/ParallelKernel/test_parallel.jl +++ b/test/ParallelKernel/test_parallel.jl @@ -7,27 +7,7 @@ import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, import ParallelStencil.ParallelKernel: @require, @prettystring, @gorgeousstring, @isgpu, @iscpu, interpolate, @select_hardware, @current_hardware, handle import ParallelStencil.ParallelKernel: checkargs_parallel, checkargs_parallel_indices, parallel_indices, maxsize, compute_nthreads, NTHREADS_X_MAX_AMDGPU, NTHREADS_MAX using ParallelStencil.ParallelKernel.Exceptions -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. macro compute(A) esc(:($(INDICES[1]) + ($(INDICES[2])-1)*size($A,1))) end macro compute_with_aliases(A) esc(:(ix + (iz -1)*size($A,1))) end diff --git a/test/ParallelKernel/test_reset_parallel_kernel.jl b/test/ParallelKernel/test_reset_parallel_kernel.jl index 56c57db5..8bd54d64 100644 --- a/test/ParallelKernel/test_reset_parallel_kernel.jl +++ b/test/ParallelKernel/test_reset_parallel_kernel.jl @@ -3,27 +3,7 @@ import ParallelStencil using ParallelStencil.ParallelKernel import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @is_initialized, @isdefined_at_pt, @get_package, @get_numbertype, @get_hardware, @select_hardware, @current_hardware, SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS, PKG_POLYESTER, PKG_NONE, NUMBERTYPE_NONE import ParallelStencil.ParallelKernel: @require, @symbols -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/ParallelKernel/test_select_hardware.jl b/test/ParallelKernel/test_select_hardware.jl index ae483c72..b8540949 100644 --- a/test/ParallelKernel/test_select_hardware.jl +++ b/test/ParallelKernel/test_select_hardware.jl @@ -2,32 +2,10 @@ using Test using ParallelStencil.ParallelKernel import ParallelStencil.ParallelKernel: @reset_parallel_kernel, @init_parallel_kernel, @is_initialized, @select_hardware, @current_hardware, @get_hardware, handle, SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_THREADS, PKG_POLYESTER, PKG_KERNELABSTRACTIONS import ParallelStencil.ParallelKernel: @require, @prettystring -@static if PKG_KERNELABSTRACTIONS in SUPPORTED_PACKAGES - import KernelAbstractions: CPU, CUDABackend, ROCBackend, MetalBackend, oneAPIBackend -end +import KernelAbstractions: CPU # NOTE: the GPU backend types (e.g. CUDABackend) are defined by the extensions of KernelAbstractions, i.e. only if the corresponding GPU package is loaded; they are referred to qualified below. -TEST_PACKAGES = SUPPORTED_PACKAGES +include(joinpath(@__DIR__, "../packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x -> x ≠ PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x -> x ≠ PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x -> x ≠ PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -Base.retry_load_extensions() @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. @@ -83,13 +61,13 @@ for package in TEST_PACKAGES eval(:( if symbol == :cpu @test handle(symbol, package_symbol) == CPU() elseif symbol == :gpu_cuda - @test handle(symbol, package_symbol) == CUDABackend() + @test handle(symbol, package_symbol) == KernelAbstractions.CUDABackend() elseif symbol == :gpu_amd - @test handle(symbol, package_symbol) == ROCBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.ROCBackend() elseif symbol == :gpu_metal - @test handle(symbol, package_symbol) == MetalBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.MetalBackend() elseif symbol == :gpu_oneapi - @test handle(symbol, package_symbol) == oneAPIBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.oneAPIBackend() end end end diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 00000000..65377bc1 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,13 @@ +# Test environment of ParallelStencil. The GPU packages (CUDA, AMDGPU, Metal) are NOT dependencies: resolving them all together holds +# each of them back to an old version (or fails altogether). The test runner (runtests.jl) installs the one given by the environment +# variable PS_TEST_BACKEND into the temporary test environment of Pkg.test, see the Testing page of the documentation. Without it, only +# the CPU backends are tested. +[deps] +CellArrays = "d35fcfd7-7af4-4c67-b1aa-d78070614af4" +Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" +KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/packages.jl b/test/packages.jl new file mode 100644 index 00000000..f95a954d --- /dev/null +++ b/test/packages.jl @@ -0,0 +1,34 @@ +# Selection of the packages (backends) to test, shared by all test files: `TEST_PACKAGES` contains the supported packages that are +# installed in the test environment and functional; they are imported into Main for the test files. +# NOTE: the GPU packages are not dependencies of test/Project.toml, as resolving them all together holds each of them back to an old +# version (or fails altogether); the test runner (runtests.jl) installs the one given by PS_TEST_BACKEND into the test environment (see +# the Testing page of the documentation). The test files of the test projects (test/test_projects) are only run for the packages in +# `TEST_PACKAGES`. +import ParallelStencil +import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS, PKG_POLYESTER + +is_installed(package::Symbol) = !isnothing(Base.find_package(string(package))) + +# Import the GPU packages that are installed; the others are replaced by empty modules of the same name, as the test files refer to the +# packages by their names (e.g. `$package == $PKG_CUDA` compares the modules `Threads` and `CUDA`). +for package in (PKG_CUDA, PKG_AMDGPU, PKG_METAL) + if is_installed(package) Core.eval(@__MODULE__, :(import $package)) + else Core.eval(@__MODULE__, :(module $package end)) + end +end +import KernelAbstractions, Polyester + +TEST_PACKAGES = copy(SUPPORTED_PACKAGES) +if (PKG_CUDA in TEST_PACKAGES && !(is_installed(PKG_CUDA) && CUDA.functional())) filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end +if (PKG_AMDGPU in TEST_PACKAGES && !(is_installed(PKG_AMDGPU) && AMDGPU.functional())) filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end +if (PKG_METAL in TEST_PACKAGES && !(is_installed(PKG_METAL) && Metal.functional())) filter!(x->x≠PKG_METAL, TEST_PACKAGES) end +if (PKG_KERNELABSTRACTIONS in TEST_PACKAGES && !KernelAbstractions.functional(KernelAbstractions.CPU())) filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end +Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. + +# Hardware symbols of the GPU packages to test with the KernelAbstractions package. +const KA_GPU_SYMBOLS = filter(!isnothing, ( + PKG_CUDA in TEST_PACKAGES ? :gpu_cuda : nothing, + PKG_AMDGPU in TEST_PACKAGES ? :gpu_amd : nothing, + PKG_METAL in TEST_PACKAGES ? :gpu_metal : nothing, + (isdefined(ParallelStencil.ParallelKernel, :PKG_ONEAPI) && ParallelStencil.ParallelKernel.PKG_ONEAPI in TEST_PACKAGES) ? :gpu_oneapi : nothing +)) diff --git a/test/runtests.jl b/test/runtests.jl index 2a4e253a..60404768 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,10 @@ # (e.g. "test_parallel.jl", matching all files of this name) or by path relative to the test folder (e.g. "ParallelKernel/test_parallel.jl"). # The option "--stop-on-fail" stops the test run at the first test file with failed or errored tests. The following environment variable # controls the test run: -# PS_TEST_BACKEND: GPU backend that must be functional ("CUDA", "AMDGPU" or "Metal"); if it is not, the test run fails instead of skipping the tests of this backend. +# PS_TEST_BACKEND: GPU backend to test ("CUDA", "AMDGPU" or "Metal"): its package is installed into the test environment if it is not already, +# and the test run fails instead of skipping the tests of this backend if it is not functional. +# The GPU packages are not dependencies of the test environment (test/Project.toml), as resolving them all together holds each of them back to +# an old version; the one to test is installed into the (temporary) test environment by this file (see the Testing page of the documentation). const PREIMPORT_STDERR_SUPPRESSION_RULES = ( (name="Metal OS support warnings", start=r"^┌ Error: Metal\.jl is only supported on (macOS|Apple Silicon)$", stop=r"^└ @ Metal .*$"), @@ -52,9 +55,23 @@ end import ParallelStencil # Precompile it. import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS -@static if (PKG_CUDA in SUPPORTED_PACKAGES) import CUDA end -@static if (PKG_AMDGPU in SUPPORTED_PACKAGES) import AMDGPU end -@static if (PKG_METAL in SUPPORTED_PACKAGES) import_with_filtered_stderr(:Metal) end +is_installed(package::Symbol) = !isnothing(Base.find_package(string(package))) + +backend = get(ENV, "PS_TEST_BACKEND", "") +if !(backend in ["", string(PKG_CUDA), string(PKG_AMDGPU), string(PKG_METAL)]) + error("PS_TEST_BACKEND: invalid value ($backend). Valid values are: $PKG_CUDA, $PKG_AMDGPU, $PKG_METAL or empty.") +end +if (!isempty(backend) && !is_installed(Symbol(backend))) + import Pkg + packages = (backend == string(PKG_CUDA)) ? ["CUDA", "CUDA_Runtime_jll"] : [backend] # NOTE: CUDA_Runtime_jll must be a direct dependency of the test environment for a local CUDA runtime preference (e.g. of an HPC system) to apply. + printstyled("Installing $(join(packages, ", ")) into the test environment (PS_TEST_BACKEND=$backend)\n"; bold=true, color=:white) + Pkg.add(packages) +end + +# NOTE: the GPU packages are only imported if they are installed in the test environment. +@static if (PKG_CUDA in SUPPORTED_PACKAGES && is_installed(PKG_CUDA)) import CUDA end +@static if (PKG_AMDGPU in SUPPORTED_PACKAGES && is_installed(PKG_AMDGPU)) import AMDGPU end +@static if (PKG_METAL in SUPPORTED_PACKAGES && is_installed(PKG_METAL)) import_with_filtered_stderr(:Metal) end @static if (PKG_KERNELABSTRACTIONS in SUPPORTED_PACKAGES) import KernelAbstractions end # KernelAbstractions does not require extra harness env vars beyond the existing CUDA/AMDGPU settings. excludedfiles = [ "test_excluded.jl", "test_incremental_compilation.jl", "test_revise.jl"]; # TODO: test_incremental_compilation has to be deactivated until Polyester support released @@ -76,7 +93,6 @@ function runtests(testfiles=String[]; stop_on_fail=false) if (!isempty(unknown)) error("Test files not found: $(join(unknown, ", ")).") end testfiles = filter(f -> basename(f) ∈ selected || relpath(f, testdir) ∈ selected, testfiles) end - backend = get(ENV, "PS_TEST_BACKEND", "") nabort = 0 nfail = 0 @@ -85,23 +101,19 @@ function runtests(testfiles=String[]; stop_on_fail=false) first_fail_file = "" printstyled("Testing package ParallelStencil.jl\n"; bold=true, color=:white) - if !(backend in ["", string(PKG_CUDA), string(PKG_AMDGPU), string(PKG_METAL)]) - error("PS_TEST_BACKEND: invalid value ($backend). Valid values are: $PKG_CUDA, $PKG_AMDGPU, $PKG_METAL or empty.") - end - - if (PKG_CUDA in SUPPORTED_PACKAGES && !CUDA.functional()) + if (PKG_CUDA in SUPPORTED_PACKAGES && (!is_installed(PKG_CUDA) || !CUDA.functional())) if (backend == string(PKG_CUDA)) error("PS_TEST_BACKEND=$backend, but CUDA is not functional (type `import CUDA; CUDA.functional(true)` to debug your CUDA installation).") end - @warn "Test Skip: All CUDA tests will be skipped because CUDA is not functional (if this is unexpected type `import CUDA; CUDA.functional(true)` to debug your CUDA installation)." + @warn "Test Skip: All CUDA tests will be skipped because CUDA is not installed in the test environment or not functional (if this is unexpected type `import CUDA; CUDA.functional(true)` to debug your CUDA installation)." end - if (PKG_AMDGPU in SUPPORTED_PACKAGES && !AMDGPU.functional()) + if (PKG_AMDGPU in SUPPORTED_PACKAGES && (!is_installed(PKG_AMDGPU) || !AMDGPU.functional())) if (backend == string(PKG_AMDGPU)) error("PS_TEST_BACKEND=$backend, but AMDGPU is not functional (type `import AMDGPU; AMDGPU.functional()` to debug your AMDGPU installation).") end - @warn "Test Skip: All AMDGPU tests will be skipped because AMDGPU is not functional (if this is unexpected type `import AMDGPU; AMDGPU.functional()` to debug your AMDGPU installation)." + @warn "Test Skip: All AMDGPU tests will be skipped because AMDGPU is not installed in the test environment or not functional (if this is unexpected type `import AMDGPU; AMDGPU.functional()` to debug your AMDGPU installation)." end - if (PKG_METAL in SUPPORTED_PACKAGES && (!Sys.isapple() || !Metal.functional())) + if (PKG_METAL in SUPPORTED_PACKAGES && (!is_installed(PKG_METAL) || !Sys.isapple() || !Metal.functional())) if (backend == string(PKG_METAL)) error("PS_TEST_BACKEND=$backend, but Metal is not functional (type `import Metal; Metal.functional()` to debug your Metal installation).") end - @warn "Test Skip: All Metal tests will be skipped because Metal is not functional (if this is unexpected type `import Metal; Metal.functional()` to debug your Metal installation)." + @warn "Test Skip: All Metal tests will be skipped because Metal is not installed in the test environment or not functional (if this is unexpected type `import Metal; Metal.functional()` to debug your Metal installation)." end if (PKG_KERNELABSTRACTIONS in SUPPORTED_PACKAGES && !KernelAbstractions.functional(KernelAbstractions.CPU())) diff --git a/test/test_FiniteDifferences1D.jl b/test/test_FiniteDifferences1D.jl index 56ad9ceb..4bb709ee 100644 --- a/test/test_FiniteDifferences1D.jl +++ b/test/test_FiniteDifferences1D.jl @@ -5,27 +5,7 @@ import ParallelStencil: @require, interpolate using ParallelStencil.FiniteDifferences1D using ParallelStencil.FieldAllocators import ParallelStencil.FieldAllocators: @IField -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/test_FiniteDifferences2D.jl b/test/test_FiniteDifferences2D.jl index b2430cc7..76c7fee5 100644 --- a/test/test_FiniteDifferences2D.jl +++ b/test/test_FiniteDifferences2D.jl @@ -5,27 +5,7 @@ import ParallelStencil: @require, interpolate using ParallelStencil.FiniteDifferences2D using ParallelStencil.FieldAllocators import ParallelStencil.FieldAllocators: @IField, @XXYField, @XYYField -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/test_FiniteDifferences3D.jl b/test/test_FiniteDifferences3D.jl index 18ecb3f1..29ae47ce 100644 --- a/test/test_FiniteDifferences3D.jl +++ b/test/test_FiniteDifferences3D.jl @@ -5,27 +5,7 @@ import ParallelStencil: @require, interpolate using ParallelStencil.FiniteDifferences3D using ParallelStencil.FieldAllocators import ParallelStencil.FieldAllocators: @IField, @XXYField, @XYYField, @XYZField, @XXYZField, @XYYZField, @XYZZField, @XXYYField, @XXZZField, @YYZZField, @XXYYZField, @XYYZZField, @XXYZZField -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/test_extensions.jl b/test/test_extensions.jl index 08fc6695..9f7d6d45 100644 --- a/test/test_extensions.jl +++ b/test/test_extensions.jl @@ -1,27 +1,8 @@ using Test import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS, PKG_POLYESTER, @select_hardware, @current_hardware import ParallelStencil.ParallelKernel: handle -TEST_PACKAGES = SUPPORTED_PACKAGES +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. TEST_PACKAGES = filter!(x->x≠PKG_POLYESTER, TEST_PACKAGES) # NOTE: Polyester is not tested here, because the CPU case is sufficiently covered by the test of the Threads package. -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end exename = joinpath(Sys.BINDIR, Base.julia_exename()) const TEST_PROJECTS = ["Diffusion3D_minimal"] # ["Diffusion3D_minimal", "Diffusion3D", "Diffusion"] diff --git a/test/test_incremental_compilation.jl b/test/test_incremental_compilation.jl index fa12559e..0ef1ad3f 100644 --- a/test/test_incremental_compilation.jl +++ b/test/test_incremental_compilation.jl @@ -1,25 +1,6 @@ using Test import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS, PKG_POLYESTER, @select_hardware, @current_hardware -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. exename = joinpath(Sys.BINDIR, Base.julia_exename()) diff --git a/test/test_init_parallel_stencil.jl b/test/test_init_parallel_stencil.jl index 72ceed94..12680877 100644 --- a/test/test_init_parallel_stencil.jl +++ b/test/test_init_parallel_stencil.jl @@ -5,27 +5,7 @@ import ParallelStencil: @require, @symbols import ParallelStencil: extract_posargs_init, extract_kwargs_init, check_already_initialized, set_initialized, is_initialized, check_initialized, set_package, set_numbertype, set_ndims, set_inbounds, set_padding, set_memopt, set_nonconst_metadata using ParallelStencil.Exceptions import ParallelStencil.ParallelKernel: handle, @isdefined_at_pt -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/test_kernel_language.jl b/test/test_kernel_language.jl index cbc4afe2..1f007da0 100644 --- a/test/test_kernel_language.jl +++ b/test/test_kernel_language.jl @@ -4,33 +4,7 @@ import ParallelStencil: @reset_parallel_stencil, @is_initialized, SUPPORTED_PACK import ParallelStencil: @require, @prettystring, @iscpu import ParallelStencil.ParallelKernel: handle -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() - TEST_PACKAGES = filter!(x -> x ≠ PKG_CUDA, TEST_PACKAGES) - end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() - TEST_PACKAGES = filter!(x -> x ≠ PKG_AMDGPU, TEST_PACKAGES) - end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) - TEST_PACKAGES = filter!(x -> x ≠ PKG_KERNELABSTRACTIONS, TEST_PACKAGES) - end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. for package in TEST_PACKAGES diff --git a/test/test_parallel.jl b/test/test_parallel.jl index 5e03715a..cdf03257 100644 --- a/test/test_parallel.jl +++ b/test/test_parallel.jl @@ -14,33 +14,7 @@ ixi, iyi, izi = INDICES_INN[1], INDICES_INN[2], INDICES_INN[3] ixd, iyd, izd = INDICES_DIR[1], INDICES_DIR[2], INDICES_DIR[3] ix_s, iy_s, iz_s = "var\"$ix\"", "var\"$iy\"", "var\"$iz\"" end_s = string(:(A[end]))[3:end-1] # NOTE: `end` as printed in an indexing expression (Julia >= 1.13 prints var"end"). -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end - const KA_GPU_SYMBOLS = filter(!isnothing, ( - PKG_CUDA in TEST_PACKAGES ? :gpu_cuda : nothing, - PKG_AMDGPU in TEST_PACKAGES ? :gpu_amd : nothing, - PKG_METAL in TEST_PACKAGES ? :gpu_metal : nothing, - (isdefined(ParallelStencil.ParallelKernel, :PKG_ONEAPI) && ParallelStencil.ParallelKernel.PKG_ONEAPI in TEST_PACKAGES) ? :gpu_oneapi : nothing - )) -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. parallel_indices(args::Union{Symbol,Expr}...; package::Symbol=ParallelStencil.ParallelKernel.get_package(@__MODULE__)) = (ParallelStencil.checkargs_parallel_indices(args...); ParallelStencil.parallel_indices(LineNumberNode(@__LINE__, Symbol(@__FILE__)), @__MODULE__, args...; package=package)) diff --git a/test/test_reset_parallel_stencil.jl b/test/test_reset_parallel_stencil.jl index 63230092..574921e8 100644 --- a/test/test_reset_parallel_stencil.jl +++ b/test/test_reset_parallel_stencil.jl @@ -3,27 +3,7 @@ using ParallelStencil import ParallelStencil: @reset_parallel_stencil, @is_initialized, @get_package, @get_numbertype, @get_hardware, @get_ndims, @select_hardware, @current_hardware, SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_KERNELABSTRACTIONS, PKG_POLYESTER, PKG_NONE, NUMBERTYPE_NONE, NDIMS_NONE import ParallelStencil.ParallelKernel: @isdefined_at_pt import ParallelStencil: @require, @symbols -TEST_PACKAGES = SUPPORTED_PACKAGES -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x->x≠PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x->x≠PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x->x≠PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered. +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. diff --git a/test/test_select_hardware.jl b/test/test_select_hardware.jl index c153dc71..ea8f49ed 100644 --- a/test/test_select_hardware.jl +++ b/test/test_select_hardware.jl @@ -3,32 +3,10 @@ using ParallelStencil import ParallelStencil: @reset_parallel_stencil, @init_parallel_stencil, @is_initialized, @select_hardware, @current_hardware, @get_hardware, SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_THREADS, PKG_POLYESTER, PKG_KERNELABSTRACTIONS import ParallelStencil: @require, @symbols import ParallelStencil.ParallelKernel: handle -@static if PKG_KERNELABSTRACTIONS in SUPPORTED_PACKAGES - import KernelAbstractions: CPU, CUDABackend, ROCBackend, MetalBackend, oneAPIBackend -end +import KernelAbstractions: CPU # NOTE: the GPU backend types (e.g. CUDABackend) are defined by the extensions of KernelAbstractions, i.e. only if the corresponding GPU package is loaded; they are referred to qualified below. -TEST_PACKAGES = SUPPORTED_PACKAGES +include(joinpath(@__DIR__, "packages.jl")) # Selection of the packages to test (TEST_PACKAGES), imports of the backend packages. -@static if PKG_CUDA in TEST_PACKAGES - import CUDA - if !CUDA.functional() TEST_PACKAGES = filter!(x -> x ≠ PKG_CUDA, TEST_PACKAGES) end -end -@static if PKG_AMDGPU in TEST_PACKAGES - import AMDGPU - if !AMDGPU.functional() TEST_PACKAGES = filter!(x -> x ≠ PKG_AMDGPU, TEST_PACKAGES) end -end -@static if PKG_METAL in TEST_PACKAGES - import Metal - if !Metal.functional() TEST_PACKAGES = filter!(x->x≠PKG_METAL, TEST_PACKAGES) end -end -@static if PKG_POLYESTER in TEST_PACKAGES - import Polyester -end -@static if PKG_KERNELABSTRACTIONS in TEST_PACKAGES - import KernelAbstractions - if !KernelAbstractions.functional(KernelAbstractions.CPU()) TEST_PACKAGES = filter!(x -> x ≠ PKG_KERNELABSTRACTIONS, TEST_PACKAGES) end -end -Base.retry_load_extensions() @testset "$(basename(@__FILE__))" verbose=true begin # NOTE: the package testsets are nested in this testset (and the package loop is run at run time) in order to test all packages even if the tests of one package fail. @@ -93,13 +71,13 @@ for package in TEST_PACKAGES eval(:( if symbol == :cpu @test handle(symbol, package_symbol) == CPU() elseif symbol == :gpu_cuda - @test handle(symbol, package_symbol) == CUDABackend() + @test handle(symbol, package_symbol) == KernelAbstractions.CUDABackend() elseif symbol == :gpu_amd - @test handle(symbol, package_symbol) == ROCBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.ROCBackend() elseif symbol == :gpu_metal - @test handle(symbol, package_symbol) == MetalBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.MetalBackend() elseif symbol == :gpu_oneapi - @test handle(symbol, package_symbol) == oneAPIBackend() + @test handle(symbol, package_symbol) == KernelAbstractions.oneAPIBackend() end end end From 47c2df998f43d2304d888f5a0e16c28b482558f9 Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Thu, 22 Oct 2026 22:35:51 +0200 Subject: [PATCH 2/2] Tests: precompile the test environment explicitly after installing the GPU backend Pkg's automatic precompilation after Pkg.add fails with "Unknown package" for indirect dependencies whose version changed (GPUCompiler when adding AMDGPU), as it identifies them by name in the test environment. --- test/runtests.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 60404768..2daa363a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -65,7 +65,10 @@ if (!isempty(backend) && !is_installed(Symbol(backend))) import Pkg packages = (backend == string(PKG_CUDA)) ? ["CUDA", "CUDA_Runtime_jll"] : [backend] # NOTE: CUDA_Runtime_jll must be a direct dependency of the test environment for a local CUDA runtime preference (e.g. of an HPC system) to apply. printstyled("Installing $(join(packages, ", ")) into the test environment (PS_TEST_BACKEND=$backend)\n"; bold=true, color=:white) - Pkg.add(packages) + withenv("JULIA_PKG_PRECOMPILE_AUTO" => "0") do # NOTE: the automatic precompilation after Pkg.add fails with "Unknown package" for indirect dependencies whose version changed (e.g. GPUCompiler when adding AMDGPU), as it identifies them by name in the test environment; the environment is precompiled explicitly instead. + Pkg.add(packages) + end + Pkg.precompile() end # NOTE: the GPU packages are only imported if they are installed in the test environment.