diff --git a/docs/src/lib/modules.md b/docs/src/lib/modules.md index 1e454f82..2f6f845e 100644 --- a/docs/src/lib/modules.md +++ b/docs/src/lib/modules.md @@ -7,9 +7,44 @@ Modules = [Chmy.Grids] Order = [:type, :function] ``` +## Architectures + +```@autodocs +Modules = [Chmy.Architectures] +Order = [:type, :function] +``` + +## Fields + +```@autodocs +Modules = [Chmy.Fields] +Order = [:type, :function] +``` + +## Grid Operators + +```@autodocs +Modules = [Chmy.GridOperators] +Order = [:type, :function] +``` + +## Boundary Conditions + +```@autodocs +Modules = [Chmy.BoundaryConditions] +Order = [:type, :function] +``` + ## Distributed ```@autodocs Modules = [Chmy.Distributed] Order = [:type, :function] ``` + +## Workers + +```@autodocs +Modules = [Chmy.Workers] +Order = [:type, :function] +``` diff --git a/test/Project.toml b/test/Project.toml index c896c582..b7c500b4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,3 +3,11 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[weakdeps] +AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" + +[compat] +AMDGPU = "0.8" +CUDA = "5" diff --git a/test/common.jl b/test/common.jl new file mode 100644 index 00000000..dcb18a4a --- /dev/null +++ b/test/common.jl @@ -0,0 +1,15 @@ +using Test +using Chmy + +using KernelAbstractions + +# add KA backends +backends = KernelAbstractions.Backend[CPU()] + +if get(ENV, "JULIA_CHMY_BACKEND", "") == "AMDGPU" + using AMDGPU + AMDGPU.functional() && push!(backends, ROCBackend()) +elseif get(ENV, "JULIA_CHMY_BACKEND", "") == "CUDA" + using CUDA + CUDA.functional() && push!(backends, CUDABackend()) +end diff --git a/test/runtests.jl b/test/runtests.jl index 0291c60f..d8faa932 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,75 @@ using Test using Chmy -printstyled("Testing package Chmy.jl\n"; bold=true, color=:white) +using Pkg + +excludedfiles = ["test_excluded.jl"] + +# distributed +using MPI + +function parse_flags!(args, flag; default=nothing, typ=typeof(default)) + for f in args + startswith(f, flag) || continue + + if f != flag + val = split(f, '=')[2] + if !(typ ≡ nothing || typ <: AbstractString) + @show typ val + val = parse(typ, val) + end + else + val = default + end + + filter!(x -> x != f, args) + return true, val + end + return false, default +end + +function runtests() + exename = joinpath(Sys.BINDIR, Base.julia_exename()) + testdir = pwd() + istest(f) = endswith(f, ".jl") && startswith(basename(f), "test_") + testfiles = sort(filter(istest, vcat([joinpath.(root, files) for (root, dirs, files) in walkdir(testdir)]...))) + + nfail = 0 + printstyled("Testing package Chmy.jl\n"; bold=true, color=:white) + + for f in testfiles + println("") + if basename(f) ∈ excludedfiles + println("Test Skip:") + println("$f") + continue + end + try + # if basename(f) ∈ test_distributed + # nprocs = contains(f, "2D") ? nprocs_2D : nprocs_3D + # cmd(n=nprocs) = `$(mpiexec()) -n $n $exename --startup-file=no --color=yes $(joinpath(testdir, f))` + # withenv("JULIA_NUM_THREADS" => "4") do + # run(cmd()) + # end + # else + run(`$exename --startup-file=no $(joinpath(testdir, f))`) + # end + catch ex + @error ex + nfail += 1 + end + end + return nfail +end + +_, backend_name = parse_flags!(ARGS, "--backend"; default="CPU", typ=String) + +@static if backend_name == "AMDGPU" + Pkg.add("AMDGPU") + ENV["JULIA_CHMY_BACKEND"] = "AMDGPU" +elseif backend_name == "CUDA" + Pkg.add("CUDA") + ENV["JULIA_CHMY_BACKEND"] = "CUDA" +end + +exit(runtests()) diff --git a/test/test_fields.jl b/test/test_fields.jl new file mode 100644 index 00000000..eb8ec753 --- /dev/null +++ b/test/test_fields.jl @@ -0,0 +1,54 @@ +include("common.jl") + +using Chmy.Architectures +using Chmy.Fields +using Chmy.Grids + +for backend in backends + @testset "$(basename(@__FILE__)) (backend: $backend)" begin + arch = Arch(backend) + grid = UniformGrid(arch; origin=(0.0, 0.0, 0.0), extent=(1.0, 1.0, 1.0), dims=(2, 2, 2)) + loc = (Center(), Vertex(), Center()) + @testset "location" begin + @test location(Field(backend, grid, Center())) == (Center(), Center(), Center()) + @test location(Field(backend, grid, loc)) == loc + end + @testset "set" begin + f = Field(backend, grid, (Center(), Vertex(), Center()); halo=(1, 0, 1)) + @testset "discrete" begin + # no parameters vertex + fill!(parent(f), NaN) + set!(f, grid, (grid, loc, I) -> ycoord(grid, loc, I[2]); discrete=true) + @test Array(interior(f)) == [0.0; 0.0;; 0.5; 0.5;; 1.0; 1.0;;; + 0.0; 0.0;; 0.5; 0.5;; 1.0; 1.0] + # no parameters center + fill!(parent(f), NaN) + set!(f, grid, (grid, loc, I) -> xcoord(grid, loc, I[1]); discrete=true) + @test Array(interior(f)) == [0.25; 0.75;; 0.25; 0.75;; 0.25; 0.75;;; + 0.25; 0.75;; 0.25; 0.75;; 0.25; 0.75] + # with parameters + fill!(parent(f), NaN) + set!(f, grid, (grid, loc, I, sc) -> ycoord(grid, loc, I[2]) * sc; discrete=true, parameters=(2.0,)) + @test Array(interior(f)) == [0.0; 0.0;; 1.0; 1.0;; 2.0; 2.0;;; + 0.0; 0.0;; 1.0; 1.0;; 2.0; 2.0] + end + @testset "continuous" begin + # no parameters vertex + fill!(parent(f), NaN) + set!(f, grid, (x, y, z) -> y) + @test Array(interior(f)) == [0.0; 0.0;; 0.5; 0.5;; 1.0; 1.0;;; + 0.0; 0.0;; 0.5; 0.5;; 1.0; 1.0] + # no parameters center + fill!(parent(f), NaN) + set!(f, grid, (x, y, z) -> x) + @test Array(interior(f)) == [0.25; 0.75;; 0.25; 0.75;; 0.25; 0.75;;; + 0.25; 0.75;; 0.25; 0.75;; 0.25; 0.75] + # with parameters + fill!(parent(f), NaN) + set!(f, grid, (x, y, z, sc) -> y * sc; parameters=(2.0,)) + @test Array(interior(f)) == [0.0; 0.0;; 1.0; 1.0;; 2.0; 2.0;;; + 0.0; 0.0;; 1.0; 1.0;; 2.0; 2.0] + end + end + end +end