Skip to content

Commit

Permalink
Fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
utkinis committed Nov 17, 2023
1 parent 63b0f52 commit 52469fd
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions scripts_future_API/benchmark_diffusion_3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function compute(arch, grid, hide_boundaries, bc_q, bc_c, outer_width, qC, C, dc
return wtime
end

function diffusion_3D(ka_backend=CPU(), dTyp::DataType=Float64, dims=(0,0,0); do_visu=true)
function diffusion_3D(ka_backend=CPU(), dTyp::DataType=Float64, dims=(0, 0, 0); do_visu=true)
# setup arch
arch = Architecture(ka_backend, dims)
topo = details(arch)
Expand Down Expand Up @@ -85,16 +85,19 @@ function diffusion_3D(ka_backend=CPU(), dTyp::DataType=Float64, dims=(0,0,0); do
set!(C, grid, (x, y, z) -> exp(-x^2 - y^2 - z^2))
# boundary conditions
zero_flux_bc = DirichletBC{FullCell}(0.0)
bc_q = NamedTuple(comp => BoundaryConditionsBatch((qC[comp],), (zero_flux_bc,)) for comp in eachindex(qC))
# zero flux at physical boundaries and nothing at MPI boundaries
bc_q = override_boundary_conditions(arch, ((bc_q.x, bc_q.x), (bc_q.y, bc_q.y), (bc_q.z, bc_q.z)))
bc_q = ntuple(Val(3)) do D
ntuple(Val(2)) do S
has_neighbor(topo, D, S) ? nothing : BoundaryConditionsBatch((qC[D],), (zero_flux_bc,))
end
end
# nothing at physical boundaries and communication at MPI boundaries
bc_c = BoundaryConditionsBatch((C,), nothing)
bc_c = override_boundary_conditions(arch, ((bc_c, bc_c), (bc_c, bc_c), (bc_c, bc_c)); exchange=true)
ntuple(Val(ndims(grid))) do D
apply_boundary_conditions!(Val(1), Val(D), arch, grid, bc_c[D][1])
apply_boundary_conditions!(Val(2), Val(D), arch, grid, bc_c[D][2])
bc_c = ntuple(Val(3)) do D
ntuple(Val(2)) do S
has_neighbor(topo, D, S) ? BoundaryConditionsBatch((C,), (ExchangeInfo(Val(S), Val(D), C),)) : nothing
end
end
KernelLaunch.apply_all_boundary_conditions!(arch, grid, bc_c)
# # time loop
# for it in 1:nt
# (me == 0) && println("it = $it")
Expand All @@ -109,24 +112,25 @@ function diffusion_3D(ka_backend=CPU(), dTyp::DataType=Float64, dims=(0,0,0); do
# time
MPI.Barrier(comm)
for ex in 1:5
(me==0) && (sleep(2); println("Experiment = $ex"))
(me == 0) && (sleep(2); println("Experiment = $ex"))
MPI.Barrier(comm)
wtime = compute(arch, grid, hide_boundaries, bc_q, bc_c, outer_width, qC, C, dc, dt, Δ, (iters - warmup))
# report
A_eff = 8 / 1e9 * prod(size) * sizeof(dTyp)
wtime_it = wtime ./ (iters - warmup)
T_eff = A_eff ./ wtime_it
@printf(" Executed %d steps in = %1.3e sec (@ T_eff = %1.2f GB/s - device %s) \n", (iters - warmup), wtime, round(T_eff, sigdigits=3), AMDGPU.device_id(AMDGPU.device()))
@printf(" Executed %d steps in = %1.3e sec (@ T_eff = %1.2f GB/s - device %s) \n", (iters - warmup), wtime,
round(T_eff, sigdigits=3), AMDGPU.device_id(AMDGPU.device()))
end

if do_visu
ENV["GKSwstype"]="nul"
ENV["GKSwstype"] = "nul"
C_g = (me == 0) ? KernelAbstractions.allocate(CPU(), eltype(C), size_g) : nothing
C_v = Array(C)
gather!(arch, C_g, C_v)
if me == 0
p1 = heatmap(xcenters(global_grid), ycenters(global_grid), C_g[:, :, size_g[3]÷2];
aspect_ratio=1, xlims=extrema(xcenters(global_grid)), ylims=extrema(ycenters(global_grid)))
aspect_ratio=1, xlims=extrema(xcenters(global_grid)), ylims=extrema(ycenters(global_grid)))
png(p1, "C.png")
end
end
Expand Down

0 comments on commit 52469fd

Please sign in to comment.