Skip to content

Commit

Permalink
API Refactoring to export symbols in submodules explicitly (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
youwuyou authored Oct 23, 2024
1 parent 4aee5f4 commit 8ecd0b5
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Chmy"
uuid = "33a72cf0-4690-46d7-b987-06506c2248b9"
authors = ["Ivan Utkin <[email protected]>, Ludovic Raess <[email protected]>, and contributors"]
version = "0.1.20"
version = "0.1.21"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/batcher.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chmy.Grids, Chmy.BoundaryConditions, Chmy.Architectures, Chmy.Fields
using Chmy
using KernelAbstractions

arch = Arch(CPU())
Expand Down
2 changes: 1 addition & 1 deletion examples/diffusion_1d_mtl.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/diffusion_2d.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/diffusion_2d_mpi.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +8,6 @@ using CairoMakie
# using CUDA
# CUDA.allowscalar(false)

using Chmy.Distributed
using MPI
MPI.Init()

Expand Down
3 changes: 1 addition & 2 deletions examples/diffusion_2d_mpi_perf.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +8,6 @@ AMDGPU.allowscalar(false)
# using CUDA
# CUDA.allowscalar(false)

using Chmy.Distributed
using MPI
MPI.Init()

Expand Down
2 changes: 1 addition & 1 deletion examples/diffusion_2d_perf.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/exchange_halo.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.Distributed
using Chmy

using KernelAbstractions
using AMDGPU
Expand Down
6 changes: 3 additions & 3 deletions examples/grids_2d.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chmy.Grids
using Chmy
using GLMakie

import .Iterators: product, flatten
Expand Down Expand Up @@ -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}")

Expand Down
8 changes: 4 additions & 4 deletions examples/grids_3d.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chmy.Grids, Chmy.Architectures
using Chmy
using KernelAbstractions
using GLMakie

Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion examples/sia.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chmy.Architectures, Chmy.Grids, Chmy.Fields, Chmy.BoundaryConditions, Chmy.GridOperators
using Chmy
using KernelAbstractions

using Printf
Expand Down
2 changes: 1 addition & 1 deletion examples/stokes_2d_inc_ve_T.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/stokes_2d_inc_ve_T_mpi.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +8,6 @@ AMDGPU.allowscalar(false)
# using CUDA
# CUDA.allowscalar(false)

using Chmy.Distributed
using MPI
MPI.Init()

Expand Down
2 changes: 1 addition & 1 deletion examples/stokes_3d_inc_ve_T.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/stokes_3d_inc_ve_T_mpi.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +9,6 @@ AMDGPU.allowscalar(false)
# using CUDA
# CUDA.allowscalar(false)

using Chmy.Distributed
using MPI
MPI.Init()

Expand Down
3 changes: 1 addition & 2 deletions examples/stokes_3d_inc_ve_T_mpi_perf.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +9,6 @@ AMDGPU.allowscalar(false)
# using CUDA
# CUDA.allowscalar(false)

using Chmy.Distributed
using MPI
MPI.Init()

Expand Down
2 changes: 1 addition & 1 deletion src/Architectures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
82 changes: 76 additions & 6 deletions src/Chmy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
8 changes: 3 additions & 5 deletions test/test_architectures.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
5 changes: 0 additions & 5 deletions test/test_boundary_conditions.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/test_boundary_functions.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/test_fields.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/test_grids.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions test/test_interpolations.jl
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
2 changes: 0 additions & 2 deletions test/test_workers.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
include("common.jl")

using Chmy.Workers

@testset "$(basename(@__FILE__)) (backend: CPU)" begin
@testset "workers" begin
@testset "setup" begin
Expand Down

2 comments on commit 8ecd0b5

@utkinis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117891

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.21 -m "<description of version>" 8ecd0b5ff65c308b8a3a26d285869e11e0615a42
git push origin v0.1.21

Please sign in to comment.