Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luraess committed Feb 7, 2024
1 parent 547cf6d commit b85fcd5
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 1 deletion.
35 changes: 35 additions & 0 deletions docs/src/lib/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```
8 changes: 8 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions test/common.jl
Original file line number Diff line number Diff line change
@@ -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
73 changes: 72 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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())
54 changes: 54 additions & 0 deletions test/test_fields.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b85fcd5

Please sign in to comment.