From 8ecd0b5ff65c308b8a3a26d285869e11e0615a42 Mon Sep 17 00:00:00 2001 From: "Wu, You" <82619264+youwuyou@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:00:52 +0200 Subject: [PATCH] API Refactoring to export symbols in submodules explicitly (#51) --- Project.toml | 2 +- docs/src/getting_started.md | 2 +- examples/batcher.jl | 2 +- examples/diffusion_1d_mtl.jl | 2 +- examples/diffusion_2d.jl | 2 +- examples/diffusion_2d_mpi.jl | 3 +- examples/diffusion_2d_mpi_perf.jl | 3 +- examples/diffusion_2d_perf.jl | 2 +- examples/exchange_halo.jl | 2 +- examples/grids_2d.jl | 6 +- examples/grids_3d.jl | 8 +-- examples/sia.jl | 2 +- examples/stokes_2d_inc_ve_T.jl | 2 +- examples/stokes_2d_inc_ve_T_mpi.jl | 3 +- examples/stokes_3d_inc_ve_T.jl | 2 +- examples/stokes_3d_inc_ve_T_mpi.jl | 3 +- examples/stokes_3d_inc_ve_T_mpi_perf.jl | 3 +- src/Architectures.jl | 2 +- src/Chmy.jl | 82 +++++++++++++++++++++++-- test/test_architectures.jl | 8 +-- test/test_boundary_conditions.jl | 5 -- test/test_boundary_functions.jl | 4 -- test/test_fields.jl | 4 -- test/test_grids.jl | 3 - test/test_interpolations.jl | 5 -- test/test_workers.jl | 2 - 26 files changed, 102 insertions(+), 62 deletions(-) diff --git a/Project.toml b/Project.toml index d50b7017..0fd99f68 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Chmy" uuid = "33a72cf0-4690-46d7-b987-06506c2248b9" authors = ["Ivan Utkin , Ludovic Raess , and contributors"] -version = "0.1.20" +version = "0.1.21" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md index 2fab7841..6c49cac5 100644 --- a/docs/src/getting_started.md +++ b/docs/src/getting_started.md @@ -42,7 +42,7 @@ where $\frac{\partial C}{\partial \boldsymbol{n}}$ is the derivative of `C` norm As the first step, we need to load the main module and any necessary submodules of [Chmy.jl](https://github.com/PTsolvers/Chmy.jl). Moreover, we use [KernelAbstractions.jl](https://github.com/JuliaGPU/KernelAbstractions.jl) for writing backend-agnostic kernels that are compatible with Chmy.jl. ```julia -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions # for backend-agnostic kernels using Printf, CairoMakie # for I/O and plotting # using CUDA diff --git a/examples/batcher.jl b/examples/batcher.jl index ca7d4e8e..c439dd78 100644 --- a/examples/batcher.jl +++ b/examples/batcher.jl @@ -1,4 +1,4 @@ -using Chmy.Grids, Chmy.BoundaryConditions, Chmy.Architectures, Chmy.Fields +using Chmy using KernelAbstractions arch = Arch(CPU()) diff --git a/examples/diffusion_1d_mtl.jl b/examples/diffusion_1d_mtl.jl index 3ae5e253..4b0be271 100644 --- a/examples/diffusion_1d_mtl.jl +++ b/examples/diffusion_1d_mtl.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie diff --git a/examples/diffusion_2d.jl b/examples/diffusion_2d.jl index de50de63..9e0681fc 100644 --- a/examples/diffusion_2d.jl +++ b/examples/diffusion_2d.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie diff --git a/examples/diffusion_2d_mpi.jl b/examples/diffusion_2d_mpi.jl index 25354e5a..8e12ed69 100644 --- a/examples/diffusion_2d_mpi.jl +++ b/examples/diffusion_2d_mpi.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie @@ -8,7 +8,6 @@ using CairoMakie # using CUDA # CUDA.allowscalar(false) -using Chmy.Distributed using MPI MPI.Init() diff --git a/examples/diffusion_2d_mpi_perf.jl b/examples/diffusion_2d_mpi_perf.jl index 8be6cd47..eb2c81f6 100644 --- a/examples/diffusion_2d_mpi_perf.jl +++ b/examples/diffusion_2d_mpi_perf.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf # using CairoMakie @@ -8,7 +8,6 @@ AMDGPU.allowscalar(false) # using CUDA # CUDA.allowscalar(false) -using Chmy.Distributed using MPI MPI.Init() diff --git a/examples/diffusion_2d_perf.jl b/examples/diffusion_2d_perf.jl index 2ed3c301..0ab3fb7a 100644 --- a/examples/diffusion_2d_perf.jl +++ b/examples/diffusion_2d_perf.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf # using CairoMakie diff --git a/examples/exchange_halo.jl b/examples/exchange_halo.jl index 150b024d..c60aec5e 100644 --- a/examples/exchange_halo.jl +++ b/examples/exchange_halo.jl @@ -1,4 +1,4 @@ -using Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.Distributed +using Chmy using KernelAbstractions using AMDGPU diff --git a/examples/grids_2d.jl b/examples/grids_2d.jl index 2a252762..c9366845 100644 --- a/examples/grids_2d.jl +++ b/examples/grids_2d.jl @@ -1,4 +1,4 @@ -using Chmy.Grids +using Chmy using GLMakie import .Iterators: product, flatten @@ -34,8 +34,8 @@ yedges = collect(flatten(zip(nodes[:, 1:end-1], nodes[:, 2:end]))) linesegments!(ax, xedges; linewidth=1.5, color=:gray) linesegments!(ax, yedges; linewidth=1.5, color=:gray) -scatter!(ax, xface; marker=:hline, markersize=15, label=L"v_x", rotations=0) -scatter!(ax, yface; marker=:vline, markersize=15, label=L"v_y", rotations=0) +scatter!(ax, xface; marker=:hline, markersize=15, label=L"v_x", rotation=0) +scatter!(ax, yface; marker=:vline, markersize=15, label=L"v_y", rotation=0) scatter!(ax, cells; marker=:xcross, markersize=10, label=L"\sigma_{xx}\,,~\sigma_{yy}") scatter!(ax, xyedge; marker=:circle, markersize=10, label=L"\tau_{xy}") diff --git a/examples/grids_3d.jl b/examples/grids_3d.jl index cbc44782..abecdf60 100644 --- a/examples/grids_3d.jl +++ b/examples/grids_3d.jl @@ -1,4 +1,4 @@ -using Chmy.Grids, Chmy.Architectures +using Chmy using KernelAbstractions using GLMakie @@ -45,9 +45,9 @@ linesegments!(ax, xedges; linewidth=1.5, color=:gray) linesegments!(ax, yedges; linewidth=1.5, color=:gray) linesegments!(ax, zedges; linewidth=1.5, color=:gray) -scatter!(ax, xface; marker=:hline, markersize=15, label=L"v_x", rotations=0) -scatter!(ax, yface; marker=:hline, markersize=15, label=L"v_y", rotations=0) -scatter!(ax, zface; marker=:vline, markersize=15, label=L"v_z", rotations=0) +scatter!(ax, xface; marker=:hline, markersize=15, label=L"v_x", rotation=0) +scatter!(ax, yface; marker=:hline, markersize=15, label=L"v_y", rotation=0) +scatter!(ax, zface; marker=:vline, markersize=15, label=L"v_z", rotation=0) scatter!(ax, cells; marker=:xcross, markersize=10, label=L"\sigma_{xx}\,,~\sigma_{yy}\,,~\sigma_{zz}") scatter!(ax, xyedge; marker=:circle, markersize=10, label=L"\tau_{xy}") scatter!(ax, xzedge; marker=:circle, markersize=10, label=L"\tau_{xz}") diff --git a/examples/sia.jl b/examples/sia.jl index 71bca64d..ac33c459 100644 --- a/examples/sia.jl +++ b/examples/sia.jl @@ -1,4 +1,4 @@ -using Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators +using Chmy using KernelAbstractions using Printf diff --git a/examples/stokes_2d_inc_ve_T.jl b/examples/stokes_2d_inc_ve_T.jl index 7c1226a8..ec852e9d 100644 --- a/examples/stokes_2d_inc_ve_T.jl +++ b/examples/stokes_2d_inc_ve_T.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie diff --git a/examples/stokes_2d_inc_ve_T_mpi.jl b/examples/stokes_2d_inc_ve_T_mpi.jl index 2729bb3c..e0ca0320 100644 --- a/examples/stokes_2d_inc_ve_T_mpi.jl +++ b/examples/stokes_2d_inc_ve_T_mpi.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie @@ -8,7 +8,6 @@ AMDGPU.allowscalar(false) # using CUDA # CUDA.allowscalar(false) -using Chmy.Distributed using MPI MPI.Init() diff --git a/examples/stokes_3d_inc_ve_T.jl b/examples/stokes_3d_inc_ve_T.jl index 57eb7007..3b148b1c 100644 --- a/examples/stokes_3d_inc_ve_T.jl +++ b/examples/stokes_3d_inc_ve_T.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using CairoMakie diff --git a/examples/stokes_3d_inc_ve_T_mpi.jl b/examples/stokes_3d_inc_ve_T_mpi.jl index 453240ba..6e807c12 100644 --- a/examples/stokes_3d_inc_ve_T_mpi.jl +++ b/examples/stokes_3d_inc_ve_T_mpi.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using JSON @@ -9,7 +9,6 @@ AMDGPU.allowscalar(false) # using CUDA # CUDA.allowscalar(false) -using Chmy.Distributed using MPI MPI.Init() diff --git a/examples/stokes_3d_inc_ve_T_mpi_perf.jl b/examples/stokes_3d_inc_ve_T_mpi_perf.jl index 214b3585..7b03e5de 100644 --- a/examples/stokes_3d_inc_ve_T_mpi_perf.jl +++ b/examples/stokes_3d_inc_ve_T_mpi_perf.jl @@ -1,4 +1,4 @@ -using Chmy, Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators, Chmy.KernelLaunch +using Chmy using KernelAbstractions using Printf using JSON @@ -9,7 +9,6 @@ AMDGPU.allowscalar(false) # using CUDA # CUDA.allowscalar(false) -using Chmy.Distributed using MPI MPI.Init() diff --git a/src/Architectures.jl b/src/Architectures.jl index 1a76a34b..c054abfc 100644 --- a/src/Architectures.jl +++ b/src/Architectures.jl @@ -53,7 +53,7 @@ end Get the backend associated with a SingleDeviceArchitecture. """ -get_backend(arch::SingleDeviceArchitecture) = arch.backend +KernelAbstractions.get_backend(arch::SingleDeviceArchitecture) = arch.backend """ get_device(arch::SingleDeviceArchitecture) diff --git a/src/Chmy.jl b/src/Chmy.jl index 872626d5..b107271c 100644 --- a/src/Chmy.jl +++ b/src/Chmy.jl @@ -3,15 +3,79 @@ module Chmy using MacroTools using KernelAbstractions -export Dim, Side, Left, Right -export remove_dim, insert_dim +export + # utils + Dim, Side, Left, Right, remove_dim, insert_dim, Offset, -export Offset + # Architectures + Architecture, SingleDeviceArchitecture, Arch, get_backend, get_device, activate!, set_device!, heuristic_groupsize, pointertype, + + # BoundaryConditions + FieldBoundaryCondition, FirstOrderBC, Dirichlet, Neumann, bc!, + BoundaryFunction, + DimSide, + AbstractBatch, FieldBatch, ExchangeBatch, EmptyBatch, BatchSet, batch, + + # Distributed + CartesianTopology, global_rank, shared_rank, node_name, cart_comm, shared_comm, + dims, cart_coords, neighbors, neighbor, has_neighbor, global_size, node_size, + DistributedArchitecture, topology, + exchange_halo!, gather!, + + # DoubleBuffer + DoubleBuffer, swap!, front, back, + + # Fields + AbstractField, Field, VectorField, TensorField, ConstantField, ZeroField, OneField, ValueField, FunctionField, + location, halo, interior, set!, + divg, + + # Grids + Location, Center, Vertex, flip, + Connectivity, Bounded, Connected, Periodic, Flat, + AbstractAxis, UniformAxis, FunctionAxis, + StructuredGrid, UniformGrid, + nvertices, ncenters, spacing, inv_spacing, Δ, iΔ, volume, inv_volume, + coord, coords, center, vertex, centers, vertices, + origin, extent, bounds, axis, + direction, axes_names, expand_loc, + connectivity, + + Δx, Δy, Δz, + xcoord, ycoord, zcoord, + xcoords, ycoords, zcoords, + xvertex, yvertex, zvertex, + xcenter, ycenter, zcenter, + xvertices, yvertices, zvertices, + xcenters, ycenters, zcenters, + + # GridOperators + left, right, δ, ∂, + InterpolationRule, Linear, HarmonicLinear, + itp, lerp, hlerp, + divg, vmag, + AbstractMask, FieldMask, FieldMask1D, FieldMask2D, FieldMask3D, at, + + leftx, rightx, δx, ∂x, + lefty, righty, δy, ∂y, + leftz, rightz, δz, ∂z, + + leftx_masked, rightx_masked, δx_masked, ∂x_masked, + lefty_masked, righty_masked, δy_masked, ∂y_masked, + leftz_masked, rightz_masked, δz_masked, ∂z_masked, + + # KernelLaunch + Launcher, + worksize, outer_width, inner_worksize, inner_offset, outer_worksize, outer_offset, + + # Workers + Worker include("macros.jl") include("utils.jl") include("Architectures.jl") +include("DoubleBuffers.jl") include("Grids/Grids.jl") include("Fields/Fields.jl") include("GridOperators/GridOperators.jl") @@ -23,8 +87,14 @@ include("Distributed/Distributed.jl") include("KernelLaunch.jl") -using .Grids -using .Fields using .Architectures +using .BoundaryConditions +using .Distributed +using .DoubleBuffers +using .Fields +using .Grids +using .GridOperators +using .KernelLaunch +using .Workers -end # module Chmy +end # module Chmy \ No newline at end of file diff --git a/test/test_architectures.jl b/test/test_architectures.jl index 374255e3..cac21d98 100644 --- a/test/test_architectures.jl +++ b/test/test_architectures.jl @@ -1,7 +1,5 @@ include("common.jl") -using Chmy.Architectures - for backend in TEST_BACKENDS @testset "$(basename(@__FILE__)) (backend: $backend)" begin device = get_device(backend, 1) @@ -19,9 +17,9 @@ for backend in TEST_BACKENDS end # Test for functionality of methods @testset "Method functionalities" begin - @test Architectures.get_backend(arch) == backend - @test Architectures.get_device(arch) == device - @test Architectures.set_device!(arch.device) == device + @test get_backend(arch) == backend + @test get_device(arch) == device + @test set_device!(arch.device) == device end end end diff --git a/test/test_boundary_conditions.jl b/test/test_boundary_conditions.jl index bceb4762..be39db2e 100644 --- a/test/test_boundary_conditions.jl +++ b/test/test_boundary_conditions.jl @@ -1,10 +1,5 @@ include("common.jl") -using Chmy.Architectures -using Chmy.Fields -using Chmy.Grids -using Chmy.BoundaryConditions - for backend in TEST_BACKENDS, T in TEST_TYPES if !compatible(backend, T) continue diff --git a/test/test_boundary_functions.jl b/test/test_boundary_functions.jl index 86d9da33..58ce4575 100644 --- a/test/test_boundary_functions.jl +++ b/test/test_boundary_functions.jl @@ -1,9 +1,5 @@ include("common.jl") -using Chmy.Architectures -using Chmy.Grids -using Chmy.BoundaryConditions - for T in TEST_TYPES # deal with tolerances for isapprox tol = T==Float32 ? 1e-6 : 0 diff --git a/test/test_fields.jl b/test/test_fields.jl index 365eedb9..6c9880df 100644 --- a/test/test_fields.jl +++ b/test/test_fields.jl @@ -1,9 +1,5 @@ include("common.jl") -using Chmy.Architectures -using Chmy.Fields -using Chmy.Grids - using LinearAlgebra for backend in TEST_BACKENDS, T in TEST_TYPES diff --git a/test/test_grids.jl b/test/test_grids.jl index 1de01627..d4202151 100644 --- a/test/test_grids.jl +++ b/test/test_grids.jl @@ -1,8 +1,5 @@ include("common.jl") -using Chmy.Grids -using Chmy.Architectures - for T in TEST_TYPES @testset "$(basename(@__FILE__)) (backend: CPU, type: $T)" begin @testset "common" begin diff --git a/test/test_interpolations.jl b/test/test_interpolations.jl index 1a777e08..0e0f6fbf 100644 --- a/test/test_interpolations.jl +++ b/test/test_interpolations.jl @@ -1,10 +1,5 @@ include("common.jl") -using Chmy.Grids -using Chmy.GridOperators -using Chmy.Fields -using Chmy.Architectures - @views av4(A) = 0.25 .* (A[1:end-1, 1:end-1] .+ A[2:end, 1:end-1] .+ A[2:end, 2:end] .+ A[1:end-1, 2:end]) @views avx(A) = 0.5 .* (A[1:end-1, :] .+ A[2:end, :]) @views avy(A) = 0.5 .* (A[:, 1:end-1] .+ A[:, 2:end]) diff --git a/test/test_workers.jl b/test/test_workers.jl index d370a334..d6287012 100644 --- a/test/test_workers.jl +++ b/test/test_workers.jl @@ -1,7 +1,5 @@ include("common.jl") -using Chmy.Workers - @testset "$(basename(@__FILE__)) (backend: CPU)" begin @testset "workers" begin @testset "setup" begin