Skip to content

Commit

Permalink
remove loop on precision in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omlins committed Oct 31, 2024
1 parent 37047fd commit 3b2112d
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 91 deletions.
1 change: 1 addition & 0 deletions test/ParallelKernel/test_allocators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.
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).


@static for package in TEST_PACKAGES

eval(:(
Expand Down
13 changes: 6 additions & 7 deletions test/ParallelKernel/test_hide_communication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.

const TEST_PRECISIONS = [Float32, Float64]

@static for package in TEST_PACKAGES
for precision in TEST_PRECISIONS
(package == PKG_METAL && precision == Float64) ? continue : nothing # Metal does not support Float64
FloatDefault = (package == PKG_METAL) ? Float32 : Float64 # Metal does not support Float64

eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package))) (precision: $(nameof($precision)))" begin
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@testset "1. hide_communication macro" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized()
@testset "@hide_communication boundary_width block (macro expansion)" begin
@static if @isgpu($package)
Expand Down Expand Up @@ -180,7 +179,7 @@ eval(:(
end;
@testset "2. Exceptions" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized
@testset "arguments @hide_communication" begin
@test_throws ArgumentError checkargs_hide_communication(:boundary_width, :block) # Error: the last argument must be a code block.
Expand Down Expand Up @@ -222,4 +221,4 @@ eval(:(
end;
))

end end == nothing || true;
end == nothing || true;
1 change: 1 addition & 0 deletions test/ParallelKernel/test_init_parallel_kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.


@static for package in TEST_PACKAGES eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@testset "1. initialization of ParallelKernel" begin
Expand Down
23 changes: 11 additions & 12 deletions test/ParallelKernel/test_kernel_language.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.

const TEST_PRECISIONS = [Float32, Float64]

@static for package in TEST_PACKAGES
for precision in TEST_PRECISIONS
(package == PKG_METAL && precision == Float64) ? continue : nothing # Metal does not support Float64
FloatDefault = (package == PKG_METAL) ? Float32 : Float64 # Metal does not support Float64

eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package))) (precision: $(nameof($precision)))" begin
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@testset "1. kernel language macros" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized()
@testset "mapping to package" begin
if $package == $PKG_CUDA
Expand All @@ -41,7 +40,7 @@ eval(:(
@test @prettystring(1, @blockDim()) == "CUDA.blockDim()"
@test @prettystring(1, @threadIdx()) == "CUDA.threadIdx()"
@test @prettystring(1, @sync_threads()) == "CUDA.sync_threads()"
@test @prettystring(1, @sharedMem($precision, (2,3))) == "CUDA.@cuDynamicSharedMem $(nameof($precision)) (2, 3)"
@test @prettystring(1, @sharedMem($FloatDefault, (2,3))) == "CUDA.@cuDynamicSharedMem $(nameof($FloatDefault)) (2, 3)"
# @test @prettystring(1, @pk_show()) == "CUDA.@cushow"
# @test @prettystring(1, @pk_println()) == "CUDA.@cuprintln"
elseif $package == $AMDGPU
Expand All @@ -50,7 +49,7 @@ eval(:(
@test @prettystring(1, @blockDim()) == "AMDGPU.workgroupDim()"
@test @prettystring(1, @threadIdx()) == "AMDGPU.workitemIdx()"
@test @prettystring(1, @sync_threads()) == "AMDGPU.sync_workgroup()"
# @test @prettystring(1, @sharedMem($precision, (2,3))) == "" #TODO: not yet supported for AMDGPU
# @test @prettystring(1, @sharedMem($FloatDefault, (2,3))) == "" #TODO: not yet supported for AMDGPU
# @test @prettystring(1, @pk_show()) == "CUDA.@cushow" #TODO: not yet supported for AMDGPU
# @test @prettystring(1, @pk_println()) == "AMDGPU.@rocprintln"
elseif $package == $PKG_METAL
Expand All @@ -59,7 +58,7 @@ eval(:(
@test @prettystring(1, @blockDim()) == "Metal.threads_per_threadgroup_3d()"
@test @prettystring(1, @threadIdx()) == "Metal.thread_position_in_threadgroup_3d()"
@test @prettystring(1, @sync_threads()) == "Metal.threadgroup_barrier(; flag = Metal.MemoryFlagThreadGroup)"
@test @prettystring(1, @sharedMem($precision, (2,3))) == "ParallelStencil.ParallelKernel.@sharedMem_metal $(nameof($precision)) (2, 3)"
@test @prettystring(1, @sharedMem($FloatDefault, (2,3))) == "ParallelStencil.ParallelKernel.@sharedMem_metal $(nameof($FloatDefault)) (2, 3)"
# @test @prettystring(1, @pk_show()) == "Metal.@mtlshow" #TODO: not yet supported for Metal
# @test @prettystring(1, @pk_println()) == "Metal.@mtlprintln" #TODO: not yet supported for Metal
elseif @iscpu($package)
Expand All @@ -68,7 +67,7 @@ eval(:(
@test @prettystring(1, @blockDim()) == "ParallelStencil.ParallelKernel.@blockDim_cpu"
@test @prettystring(1, @threadIdx()) == "ParallelStencil.ParallelKernel.@threadIdx_cpu"
@test @prettystring(1, @sync_threads()) == "ParallelStencil.ParallelKernel.@sync_threads_cpu"
@test @prettystring(1, @sharedMem($precision, (2,3))) == "ParallelStencil.ParallelKernel.@sharedMem_cpu $(nameof($precision)) (2, 3)"
@test @prettystring(1, @sharedMem($FloatDefault, (2,3))) == "ParallelStencil.ParallelKernel.@sharedMem_cpu $(nameof($FloatDefault)) (2, 3)"
# @test @prettystring(1, @pk_show()) == "Base.@show"
# @test @prettystring(1, @pk_println()) == "Base.println()"
end;
Expand Down Expand Up @@ -138,7 +137,7 @@ eval(:(
end;
@testset "shared memory (allocation)" begin
@static if @iscpu($package)
@test typeof(@sharedMem($precision,(2,3))) == typeof(ParallelStencil.ParallelKernel.MArray{Tuple{2,3}, $precision, length((2,3)), prod((2,3))}(undef))
@test typeof(@sharedMem($FloatDefault,(2,3))) == typeof(ParallelStencil.ParallelKernel.MArray{Tuple{2,3}, $FloatDefault, length((2,3)), prod((2,3))}(undef))
@test typeof(@sharedMem(Bool,(2,3,4))) == typeof(ParallelStencil.ParallelKernel.MArray{Tuple{2,3,4}, Bool, length((2,3,4)), prod((2,3,4))}(undef))
end;
end;
Expand Down Expand Up @@ -214,7 +213,7 @@ eval(:(
@reset_parallel_kernel()
end;
@testset "2. Exceptions" begin
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized
@testset "no arguments" begin
@test_throws ArgumentError checknoargs(:(something)); # Error: length(args) != 0
Expand All @@ -229,4 +228,4 @@ eval(:(
end;
))

end end == nothing || true;
end == nothing || true;
19 changes: 9 additions & 10 deletions test/ParallelKernel/test_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ macro compute(A) esc(:($(INDICES[1]) + ($(INDICES[2])-1)*size($A,1)
macro compute_with_aliases(A) esc(:(ix + (iz -1)*size($A,1))) end
import Enzyme

const TEST_PRECISIONS = [Float32, Float64]

@static for package in TEST_PACKAGES
for precision in TEST_PRECISIONS
(package == PKG_METAL && precision == Float64) ? continue : nothing # Metal does not support Float64
FloatDefault = (package == PKG_METAL) ? Float32 : Float64 # Metal does not support Float64

eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package))) (precision: $(nameof($precision)))" begin
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@testset "1. parallel macros" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized()
@testset "@parallel" begin
@static if $package == $PKG_CUDA
Expand Down Expand Up @@ -123,8 +122,8 @@ eval(:(
= @ones(N)
A_ref = Array(A)
B_ref = Array(B)
Ā_ref = ones($precision, N)
B̄_ref = ones($precision, N)
Ā_ref = ones($FloatDefault, N)
B̄_ref = ones($FloatDefault, N)
@parallel_indices (ix) function f!(A, B, a)
A[ix] += a * B[ix] * 100.65
return
Expand Down Expand Up @@ -567,7 +566,7 @@ eval(:(
@testset "3. global defaults" begin
@testset "inbounds=true" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision, inbounds=true)
@init_parallel_kernel($package, $FloatDefault, inbounds=true)
@require @is_initialized
expansion = @prettystring(1, @parallel_indices (ix) inbounds=true f(A) = (2*A; return))
@test occursin("Base.@inbounds begin", expansion)
Expand Down Expand Up @@ -628,7 +627,7 @@ eval(:(
end;
@testset "5. Exceptions" begin
@require !@is_initialized()
@init_parallel_kernel($package, $precision)
@init_parallel_kernel($package, $FloatDefault)
@require @is_initialized
@testset "arguments @parallel" begin
@test_throws ArgumentError checkargs_parallel(); # Error: isempty(args)
Expand Down Expand Up @@ -665,4 +664,4 @@ eval(:(
end;
))

end end == nothing || true;
end == nothing || true;
1 change: 1 addition & 0 deletions test/ParallelKernel/test_reset_parallel_kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.


@static for package in TEST_PACKAGES eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@testset "1. Reset of ParallelKernel" begin
Expand Down
12 changes: 5 additions & 7 deletions test/test_FiniteDifferences1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.

const TEST_PRECISIONS = [Float32, Float64]

@static for package in TEST_PACKAGES
for precision in TEST_PRECISIONS
(package == PKG_METAL && precision == Float64) && continue # Metal does not support Float64
FloatDefault = (package == PKG_METAL) ? Float32 : Float64 # Metal does not support Float64

eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package))) (precision: $(nameof($precision)))" begin
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@require !@is_initialized()
@init_parallel_stencil($package, $precision, 1)
@init_parallel_stencil($package, $FloatDefault, 1)
@require @is_initialized()
nx = 7
A = @rand(nx );
Expand All @@ -56,7 +55,7 @@ eval(:(
end;
@testset "averages" begin
@parallel av!(R, Ax) = (@all(R) = @av(Ax); return)
R.=0; @parallel av!(R, Ax); @test all(Array(R .== (Ax[1:end-1].+Ax[2:end]).*$precision(0.5)))
R.=0; @parallel av!(R, Ax); @test all(Array(R .== (Ax[1:end-1].+Ax[2:end]).*$FloatDefault(0.5)))
end;
@testset "harmonic averages" begin
@parallel harm!(R, Ax) = (@all(R) = @harm(Ax); return)
Expand Down Expand Up @@ -89,5 +88,4 @@ eval(:(
end;
))

end
end == nothing || true;
21 changes: 10 additions & 11 deletions test/test_FiniteDifferences2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ end
end
Base.retry_load_extensions() # Potentially needed to load the extensions after the packages have been filtered.

const TEST_PRECISIONS = [Float32, Float64]

@static for package in TEST_PACKAGES
for precision in TEST_PRECISIONS
(package == PKG_METAL && precision == Float64) && continue # Metal does not support Float64
FloatDefault = (package == PKG_METAL) ? Float32 : Float64 # Metal does not support Float64

eval(:(
@testset "$(basename(@__FILE__)) (package: $(nameof($package))) (precision: $(nameof($precision)))" begin
@testset "$(basename(@__FILE__)) (package: $(nameof($package)))" begin
@require !@is_initialized()
@init_parallel_stencil($package, $precision, 2)
@init_parallel_stencil($package, $FloatDefault, 2)
@require @is_initialized()
nx, ny = 7, 5
A = @rand(nx, ny );
Expand Down Expand Up @@ -82,11 +81,11 @@ eval(:(
@parallel av_ya!(R, Ay) = (@all(R) = @av_ya(Ay); return)
@parallel av_xi!(R, Axyy) = (@all(R) = @av_xi(Axyy); return)
@parallel av_yi!(R, Axxy) = (@all(R) = @av_yi(Axxy); return)
R.=0; @parallel av!(R, Axy); @test all(Array(R .== (Axy[1:end-1,1:end-1].+Axy[2:end,1:end-1].+Axy[1:end-1,2:end].+Axy[2:end,2:end]).*$precision(0.25)))
R.=0; @parallel av_xa!(R, Ax); @test all(Array(R .== (Ax[2:end, :].+Ax[1:end-1, :]).*$precision(0.5)))
R.=0; @parallel av_ya!(R, Ay); @test all(Array(R .== (Ay[ :,2:end].+Ay[ :,1:end-1]).*$precision(0.5)))
R.=0; @parallel av_xi!(R, Axyy); @test all(Array(R .== (Axyy[2:end ,2:end-1].+Axyy[1:end-1,2:end-1]).*$precision(0.5)))
R.=0; @parallel av_yi!(R, Axxy); @test all(Array(R .== (Axxy[2:end-1,2:end ].+Axxy[2:end-1,1:end-1]).*$precision(0.5)))
R.=0; @parallel av!(R, Axy); @test all(Array(R .== (Axy[1:end-1,1:end-1].+Axy[2:end,1:end-1].+Axy[1:end-1,2:end].+Axy[2:end,2:end]).*$FloatDefault(0.25)))
R.=0; @parallel av_xa!(R, Ax); @test all(Array(R .== (Ax[2:end, :].+Ax[1:end-1, :]).*$FloatDefault(0.5)))
R.=0; @parallel av_ya!(R, Ay); @test all(Array(R .== (Ay[ :,2:end].+Ay[ :,1:end-1]).*$FloatDefault(0.5)))
R.=0; @parallel av_xi!(R, Axyy); @test all(Array(R .== (Axyy[2:end ,2:end-1].+Axyy[1:end-1,2:end-1]).*$FloatDefault(0.5)))
R.=0; @parallel av_yi!(R, Axxy); @test all(Array(R .== (Axxy[2:end-1,2:end ].+Axxy[2:end-1,1:end-1]).*$FloatDefault(0.5)))
end;
@testset "harmonic averages" begin
@parallel harm!(R, Axy) = (@all(R) = @harm(Axy); return)
Expand Down Expand Up @@ -130,4 +129,4 @@ eval(:(
end;
))

end end == nothing || true;
end == nothing || true;
Loading

0 comments on commit 3b2112d

Please sign in to comment.