-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |