Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
1a320a1
clareify back-end keyword arguments
omlins Dec 3, 2025
27aa271
update date docstring
omlins Dec 17, 2025
d56bb6f
update parallel kernel module
omlins Dec 17, 2025
dc4f5d8
add kernel abstractions to allocate docstrings
omlins Dec 17, 2025
21ab351
add kernel abstractions to init docstrings
omlins Dec 17, 2025
c32d159
add kernel abstractions to init docstrings
omlins Dec 17, 2025
59bc239
update PS module
omlins Dec 17, 2025
3126fb1
add kernel abstractions to parallel docstrings
omlins Dec 17, 2025
922bedc
add kernel abstractions to parallel docstrings
omlins Dec 17, 2025
3dbf3c1
add select hardware
omlins Dec 17, 2025
0c0b5f1
add select hardware
omlins Dec 17, 2025
960f76a
add kernel abstractions to printing docstrings
omlins Dec 17, 2025
08c0b0e
add select hardware
omlins Dec 18, 2025
4594eeb
add select hardware
omlins Dec 18, 2025
e61dac7
add select hardware
omlins Dec 18, 2025
06aa54f
add select hardware
omlins Dec 18, 2025
9c2c36e
at note on around time selection
omlins Dec 18, 2025
7037ad5
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
35103ba
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
8b24528
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
2b5267a
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
69c9580
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
21253e6
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
540b76b
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
478daca
and note about limited war-level primitive support
omlins Dec 18, 2025
1dbb864
and note about limited war-level primitive support
omlins Dec 18, 2025
a4987c5
add note on around time selection and kernel abstractions
omlins Dec 18, 2025
5e51b88
document kernel abstractions backend and runtime reselection system
omlins Dec 19, 2025
11a6711
document kernel abstractions backend and runtime reselection system
omlins Dec 19, 2025
f846fb3
add caller to the function signatures
omlins Jan 14, 2026
c080004
add caller to the function signatures
omlins Jan 14, 2026
e7da05a
Update test/runtests.jl from origin/main
omlins Jan 29, 2026
b161a82
add select hardware unit test
omlins Jan 30, 2026
e2d05ce
add select hardware unit test
omlins Jan 30, 2026
753e8e5
add initialization with hardware default unit tests
omlins Jan 30, 2026
023c44b
add initialization with hardware default unit tests
omlins Jan 30, 2026
4732f83
add KA allocator unit tests
omlins Jan 30, 2026
da0c4c0
add KA Kernel language tests
omlins Jan 30, 2026
405909c
add KA Kernel parallel tests
omlins Jan 30, 2026
df44d63
add KA Kernel language tests
omlins Jan 30, 2026
dfedc12
add KA Kernel parallel tests
omlins Jan 30, 2026
4d71832
add KA finite difference tests
omlins Jan 30, 2026
b936e00
add KA finite difference tests
omlins Jan 30, 2026
09249e6
add KA finite difference tests
omlins Jan 30, 2026
7588561
add diffusion 3D minimal for kernel abstractions
omlins Feb 2, 2026
9ffb561
add diffusion 3D minimal for kernel abstractions
omlins Feb 2, 2026
ddf7f12
add diffusion 3D minimal for kernel abstractions
omlins Feb 2, 2026
dbb23b7
add diffusion 3D kernel abstractions
omlins Feb 2, 2026
d7f6eeb
add diffusion 3D kernel abstractions
omlins Feb 2, 2026
da2ea1d
add diffusion 3D kernel abstractions
omlins Feb 2, 2026
36a6af1
add diffusion 3D kernel abstractions
omlins Feb 2, 2026
ce95f2f
add A hide communication tests
omlins Feb 3, 2026
9ba0c9f
add KA reset tests
omlins Feb 3, 2026
ee6c759
add KA reset tests
omlins Feb 3, 2026
0bfb0c0
add KA extensions tests
omlins Feb 3, 2026
fbd321b
add KA incremental compilation tests
omlins Feb 3, 2026
053855d
add KA package symbol
omlins Feb 3, 2026
36b34e9
add KA package symbol
omlins Feb 3, 2026
fdf91a6
add KA package to runtest
omlins Feb 3, 2026
ba9582e
remove kernel abstractions package symbol again
omlins Feb 3, 2026
a9fa7b1
add shared variables
omlins Feb 3, 2026
3ad15bb
add select and current hardware and handle
omlins Feb 3, 2026
e8c6e0a
add hardware initialization and state storage in metadata
omlins Feb 3, 2026
eddaf38
and hardware reset
omlins Feb 3, 2026
0fc7b6b
update initialization for hardware selection
omlins Feb 3, 2026
39a13dc
add KA allocators
omlins Feb 4, 2026
e4a0148
add KA language
omlins Feb 4, 2026
3c65e74
add KA parallel integration
omlins Feb 4, 2026
1320ecd
add KA shared variables
omlins Feb 4, 2026
29c802c
add kernel abstractions dependency
omlins Feb 4, 2026
3873055
include defaults in parallel kernel for KA
omlins Feb 4, 2026
afdf791
add KA allocators
omlins Feb 4, 2026
ee5cef9
add KA allocators
omlins Feb 4, 2026
53a8de8
include defaults in parallel kernel for KA
omlins Feb 4, 2026
4e78f57
define shared utilities for ka
omlins Feb 4, 2026
e76bc03
add kernel abstractions extension module
omlins Feb 4, 2026
3c1aa5f
add kernel abstractions hide communication integration
omlins Feb 4, 2026
cbe73fc
define shared things
omlins Feb 4, 2026
34b1a1a
integrate kernel abstructions into initialization
omlins Feb 4, 2026
82543c2
integrate kernel abstructions into memopt
omlins Feb 4, 2026
43024c3
integrate kernel abstructions into memopt
omlins Feb 4, 2026
91475bd
fix hardware default in metadata
omlins Feb 5, 2026
9cb7622
refactor AD initialization and documentation handling in init_paralle…
omlins Feb 5, 2026
9e60155
update tests to check for undefined Data and TData in hardware selection
omlins Feb 5, 2026
6b68362
remove unused import of @symbols in test_select_hardware
omlins Feb 5, 2026
7c09e84
improve summary message of runtest
omlins Feb 6, 2026
91ee050
add support for KernelAbstractions in gridDim, blockIdx, blockDim, th…
omlins Feb 6, 2026
e6926d7
update tests to check for hw_none in current_hardware after reset_par…
omlins Feb 6, 2026
55b9a26
update tests to check for hw_none in current_hardware for KernelAbstr…
omlins Feb 6, 2026
9f185c5
add kernel abstractions support for gridDim, blockIdx, blockDim, and …
omlins Feb 6, 2026
8253a2f
fix KA_auto macro usage
omlins Feb 9, 2026
053d146
introduce stop on fail mode in runtests
omlins Feb 9, 2026
fba1027
update README to reflect macro usage for runtime hardware selection
omlins Feb 11, 2026
da7135b
add export for @select_hardware and @current_hardware macros
omlins Feb 11, 2026
2a8181d
update exports for hardware selection macros to include @select_hardw…
omlins Feb 11, 2026
c16957b
refactor select_hardware and current_hardware functions to include pa…
omlins Feb 11, 2026
f3c64cd
enhance select_hardware and current_hardware functions to include pac…
omlins Feb 11, 2026
d1cec7f
refactor test_select_hardware to use macros for hardware selection
omlins Feb 11, 2026
c033593
refactor test_select_hardware to use macros for hardware selection
omlins Feb 11, 2026
473b680
fix import statements to use macros for hardware selection
omlins Feb 11, 2026
01f8db1
fix import statements to use macros for hardware selection
omlins Feb 11, 2026
663eb5e
refactor test_init_parallel_stencil to use macros for hardware selection
omlins Feb 11, 2026
aee65c7
fix import statement to correctly use macros for hardware selection
omlins Feb 11, 2026
356c35b
refactor test_parallel to use macros for hardware selection
omlins Feb 11, 2026
f26dcd9
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
b70e601
fix import statements to use macros for hardware selection
omlins Feb 11, 2026
17b347a
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
b5c78c1
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
c439657
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
2f9ffb0
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
6dd043e
fix import statements to correctly use macros for hardware selection
omlins Feb 11, 2026
e187abf
quote package in return expression
omlins Feb 11, 2026
d384b20
add @get_hardware import to ParallelKernel module
omlins Feb 11, 2026
07d74c7
add macro to retrieve hardware information in ParallelKernel
omlins Feb 11, 2026
3cf97c9
update hardware selection tests to use @get_hardware macro
omlins Feb 11, 2026
9fd048c
update test_select_hardware to use @get_hardware for default hardware…
omlins Feb 11, 2026
307bbd1
refactor get_hardware macro to use quote_expr for symbol evaluation
omlins Feb 12, 2026
3ab3473
simplify Metal package import logic in test_extensions.jl
omlins Feb 12, 2026
5947e2d
refactor Metal package import logic in test_FiniteDifferences1D.jl to…
omlins Feb 12, 2026
5b8b00d
refactor Metal package import logic in test_FiniteDifferences2D.jl to…
omlins Feb 12, 2026
06bef19
refactor Metal package import logic in test_FiniteDifferences3D.jl to…
omlins Feb 12, 2026
49b912d
refactor Metal package import logic in test_incremental_compilation.j…
omlins Feb 12, 2026
6c4ac33
refactor Metal package import logic in test_init_parallel_stencil.jl …
omlins Feb 12, 2026
a46e6d6
refactor Metal package import logic in test_kernel_language.jl to sim…
omlins Feb 12, 2026
ea49dd9
refactor Metal package import logic in test_parallel.jl to simplify p…
omlins Feb 12, 2026
84b6e4f
refactor Metal package import logic in test_reset_parallel_stencil.jl…
omlins Feb 12, 2026
debdf0e
refactor Metal package import logic in test_select_hardware.jl to sim…
omlins Feb 12, 2026
1bed96c
refactor Metal package import logic in test_hide_communication.jl to …
omlins Feb 12, 2026
f2dea19
refactor Metal package import logic in test_init_parallel_kernel.jl t…
omlins Feb 12, 2026
7a08700
refactor Metal package import logic in test_reset_parallel_kernel.jl …
omlins Feb 12, 2026
d9d7791
refactor Metal package import logic in test_select_hardware.jl to rem…
omlins Feb 12, 2026
ee88f7b
refactor handle function to include package argument for improved con…
omlins Feb 12, 2026
eb4038f
refactor test_select_hardware.jl to streamline valid symbol handling …
omlins Feb 12, 2026
cce3bad
refactor test_select_hardware.jl to simplify valid symbol handling an…
omlins Feb 12, 2026
c89fa05
include select_hardware.jl in ParallelStencil_KernelAbstractionsExt m…
omlins Feb 13, 2026
128cc27
refactor handle function to delegate hardware handling to handle_kern…
omlins Feb 13, 2026
9e8da55
add handle_kernelabstractions function to defaults.jl for kernel abst…
omlins Feb 13, 2026
de7f5b6
add handle_kernelabstractions function to select_hardware.jl for hard…
omlins Feb 13, 2026
3fd2015
implement handle_kernelabstractions function to raise error for unini…
omlins Feb 13, 2026
2b110a3
refactor hardware tests to use @get_hardware for consistency across p…
omlins Feb 13, 2026
8138009
update tests for KernelAbstractions to check symbol definitions condi…
omlins Feb 13, 2026
b0c0b34
refactor test_init_parallel_kernel.jl to use @get_hardware for defaul…
omlins Feb 13, 2026
5d5e153
refactor tests in test_init_parallel_stencil.jl to improve symbol che…
omlins Feb 13, 2026
00d06b8
refactor tests in test_init_parallel_kernel.jl to conditionally check…
omlins Feb 13, 2026
1f33a4b
refactor tests in test_init_parallel_stencil.jl to simplify symbol ch…
omlins Feb 13, 2026
9a3d4fc
refactor tests in test_init_parallel_kernel.jl to streamline symbol c…
omlins Feb 13, 2026
0682f04
add macros to check symbol definitions at runtime in shared.jl
omlins Feb 13, 2026
adf5356
refactor tests in test_init_parallel_stencil.jl to use @isdefined_at_…
omlins Feb 13, 2026
da5ff5e
refactor tests in test_init_parallel_kernel.jl to use @isdefined_at_p…
omlins Feb 13, 2026
0e21514
refactor package handling in allocator functions to use quoted expres…
omlins Feb 13, 2026
837b8c8
refactor ka_auto and create_synccall to include package handling for …
omlins Feb 13, 2026
65c84e2
extend allocators for ka
omlins Feb 16, 2026
460893a
fix KA allocater tests
omlins Feb 16, 2026
c383f08
add oneAPI support in Project.toml
omlins Feb 16, 2026
7cb18fe
include select_hardware.jl in ParallelStencil_AMDGPUExt module
omlins Feb 16, 2026
036cc23
include select_hardware.jl in ParallelStencil_CUDAExt module
omlins Feb 16, 2026
10c4378
include select_hardware.jl in ParallelStencil_MetalExt module
omlins Feb 16, 2026
3793be0
include select_hardware.jl in ParallelStencil_OneAPIExt module
omlins Feb 16, 2026
2e47eb1
include OneAPI defaults in ParallelKernel module
omlins Feb 16, 2026
586cc86
add handle_kernelabstractions_amd function to select_hardware.jl in A…
omlins Feb 16, 2026
6879d22
add select_hardware.jl with handle_kernelabstractions_amd function fo…
omlins Feb 16, 2026
634adf5
add handle_kernelabstractions_cuda function to select_hardware.jl for…
omlins Feb 16, 2026
51faf64
refactor handle_kernelabstractions function to use specific backend h…
omlins Feb 16, 2026
2e8301c
add handle_kernelabstractions_cuda function to defaults.jl for error …
omlins Feb 16, 2026
894242f
add handle_kernelabstractions_metal function to defaults.jl for Metal…
omlins Feb 16, 2026
76460e1
add handle_kernelabstractions_metal function to select_hardware.jl fo…
omlins Feb 16, 2026
5b2b161
add handle_kernelabstractions_oneapi function to defaults.jl for OneA…
omlins Feb 16, 2026
f7a8420
add handle_kernelabstractions_oneapi function to select_hardware.jl f…
omlins Feb 16, 2026
eb6144b
remove redundant hardware checks and update tests for kernel abstract…
omlins Feb 16, 2026
12ca5e1
refactor test_kernel_language.jl to use @static for THREADS package c…
omlins Feb 16, 2026
d314610
use @static for conditional checks on PKG_KERNELABSTRACTIONS in hardw…
omlins Feb 16, 2026
2276946
use @static for conditional checks on PKG_KERNELABSTRACTIONS in test_…
omlins Feb 16, 2026
681f4b0
use @static for conditional checks on PKG_KERNELABSTRACTIONS in test_…
omlins Feb 16, 2026
6913664
use @static for conditional checks on PKG_KERNELABSTRACTIONS in defau…
omlins Feb 16, 2026
86ee0e4
use @static for conditional checks on PKG_CUDA and PKG_KERNELABSTRACT…
omlins Feb 16, 2026
ebf7533
use @static for conditional check on PKG_KERNELABSTRACTIONS in test_p…
omlins Feb 16, 2026
996216a
use @static for conditional checks on PKG_KERNELABSTRACTIONS in test_…
omlins Feb 16, 2026
4ccd47e
add tests for KernelAbstractions in test_kernel_language.jl
omlins Feb 16, 2026
4af61ca
refactor: enhance package handling in ka_auto and create_synccall fun…
omlins Feb 17, 2026
e4a8bb2
fix: update handle calls to use current_hardware with explicit module…
omlins Feb 17, 2026
ec70b1c
fix: update handle calls to use explicit module reference for current…
omlins Feb 17, 2026
45d5c28
fix: update add_return calls to include package argument in parallel_…
omlins Feb 18, 2026
00b3d6a
fix: enhance package handling in parallel_kernel and add_threadids fu…
omlins Feb 18, 2026
db7e3bc
fix: modify add_return function to handle package-specific return beh…
omlins Feb 18, 2026
41eb8db
fix: update prettystring call for KernelAbstractions to include addit…
omlins Feb 18, 2026
f3123bf
update compatibility versions for AMDGPU and KernelAbstractions in Pr…
omlins Feb 19, 2026
669900c
simplify kernel abstractions macros for grid, block, and thread indices
omlins Feb 19, 2026
cb24e7e
enhance kernel handling in parallel_kernel and add support for index …
omlins Feb 19, 2026
e19eeb2
feat: add index group and local ntuple variable names, enhance Dim3 c…
omlins Feb 19, 2026
fd94b95
refactor: update test assertions to use simplified macro names in tes…
omlins Feb 19, 2026
c6de870
fix: update condition to exclude both POLYESTER and KERNELABSTRACTION…
omlins Feb 19, 2026
65a1634
fix: update kernel macro reference to use ParallelStencil.ParallelKer…
omlins Feb 20, 2026
61e4077
fix: remove hardware reset call from reset_parallel_kernel function
omlins Feb 20, 2026
212f1ab
fix: update kernel abstraction tests to handle CPU selection and corr…
omlins Feb 20, 2026
2461c75
fix: update hardware checks in reset_parallel_stencil tests for consi…
omlins Feb 20, 2026
72a67ee
fix: enhance hardware checks in reset_parallel_kernel tests for accuracy
omlins Feb 20, 2026
3b3556f
fix: add KernelAbstractions to test targets in Project.toml
omlins Feb 20, 2026
ca40ac6
fix: add tests for KernelAbstractions custom launch macro and argumen…
omlins Feb 20, 2026
a089592
fix: remove duplicate import of check_datatype_kernelabstractions in …
omlins Feb 20, 2026
88aabe2
fix: standardize import statements in shared.jl for consistency
omlins Feb 23, 2026
7818670
fix: remove platform-specific condition for Metal import in runtests.jl
omlins Feb 23, 2026
7a281c4
fix: add support check for memopt keyword argument in KernelAbstractions
omlins Feb 23, 2026
6b93cf5
fix: add synchronization support for KernelAbstractions in parallel.jl
omlins Feb 24, 2026
12a1bfa
fix: add tests for KernelAbstractions synchronization in test_paralle…
omlins Feb 24, 2026
bf28edd
fix: streamline synchronization for KernelAbstractions in create_sync…
omlins Feb 24, 2026
b0b4f2a
fix: update test assertions to use PKG_KERNELABSTRACTIONS instead of …
omlins Feb 24, 2026
7a2f9f0
fix: update test assertions to use PKG_KERNELABSTRACTIONS instead of …
omlins Feb 24, 2026
fa5af56
fix: update documentation and parameters to include KernelAbstraction…
omlins Feb 24, 2026
f868970
fix: update test assertions to use symbol syntax for PKG_KERNELABSTRA…
omlins Feb 24, 2026
9b3e6c0
fix: comment out redundant test assertions for @prettystring in test_…
omlins Feb 24, 2026
ebe080d
Merge branch 'main' into ka2
omlins Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"

[extensions]
ParallelStencil_AMDGPUExt = "AMDGPU"
ParallelStencil_CUDAExt = "CUDA"
ParallelStencil_EnzymeExt = "Enzyme"
ParallelStencil_KernelAbstractionsExt = "KernelAbstractions"
ParallelStencil_MetalExt = "Metal"
ParallelStencil_OneAPIExt = "oneAPI"

[compat]
AMDGPU = "0.6, 0.7, 0.8, 0.9, 1"
AMDGPU = "1, 2"
CUDA = "3.12, 4, 5"
CellArrays = "0.3.2"
Enzyme = "0.12, 0.13"
KernelAbstractions = "0.9"
MacroTools = "0.5"
Metal = "1.2"
Polyester = "0.7"
Expand All @@ -38,4 +43,4 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "TOML", "AMDGPU", "CUDA", "Metal", "Enzyme", "Polyester"]
test = ["Test", "TOML", "AMDGPU", "CUDA", "Metal", "Enzyme", "Polyester", "KernelAbstractions"]
48 changes: 41 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ ParallelStencil empowers domain scientists to write architecture-agnostic high-l

<a id="fig_teff">![Performance ParallelStencil Teff](docs/images/perf_ps2.png)</a>

ParallelStencil relies on the native kernel programming capabilities of [CUDA.jl], [AMDGPU.jl], [Metal.jl] and on [Base.Threads] for high-performance computations on GPUs and CPUs, respectively. It is seamlessly interoperable with [ImplicitGlobalGrid.jl], which renders the distributed parallelization of stencil-based GPU and CPU applications on a regular staggered grid almost trivial and enables close to ideal weak scaling of real-world applications on thousands of GPUs \[[1][JuliaCon20a], [2][JuliaCon20b], [3][JuliaCon19], [4][PASC19]\]. Moreover, ParallelStencil enables hiding communication behind computation with a simple macro call and without any particular restrictions on the package used for communication. ParallelStencil has been designed in conjunction with [ImplicitGlobalGrid.jl] for simplest possible usage by domain-scientists, rendering fast and interactive development of massively scalable high performance multi-GPU applications readily accessible to them. Furthermore, we have developed a self-contained approach for "Solving Nonlinear Multi-Physics on GPU Supercomputers with Julia" relying on ParallelStencil and [ImplicitGlobalGrid.jl] \[[1][JuliaCon20a]\]. ParallelStencil's feature to hide communication behind computation was showcased when a close to ideal weak scaling was demonstrated for a 3-D poro-hydro-mechanical real-world application on up to 1024 GPUs on the Piz Daint Supercomputer \[[1][JuliaCon20a]\]:
ParallelStencil relies on the native kernel programming capabilities of [CUDA.jl], [AMDGPU.jl], [Metal.jl], the multi-architecture [KernelAbstractions.jl] package (enabling the runtime hardware selection workflow described in [Interactive prototyping with runtime hardware selection](#interactive-prototyping-with-runtime-hardware-selection)), and on [Polyester.jl] and [Base.Threads] for high-performance computations on GPUs and CPUs, respectively. It is seamlessly interoperable with [ImplicitGlobalGrid.jl], which renders the distributed parallelization of stencil-based GPU and CPU applications on a regular staggered grid almost trivial and enables close to ideal weak scaling of real-world applications on thousands of GPUs \[[1][JuliaCon20a], [2][JuliaCon20b], [3][JuliaCon19], [4][PASC19]\]. Moreover, ParallelStencil enables hiding communication behind computation with a simple macro call and without any particular restrictions on the package used for communication. ParallelStencil has been designed in conjunction with [ImplicitGlobalGrid.jl] for simplest possible usage by domain-scientists, rendering fast and interactive development of massively scalable high performance multi-GPU applications readily accessible to them. Furthermore, we have developed a self-contained approach for "Solving Nonlinear Multi-Physics on GPU Supercomputers with Julia" relying on ParallelStencil and [ImplicitGlobalGrid.jl] \[[1][JuliaCon20a]\]. ParallelStencil's feature to hide communication behind computation was showcased when a close to ideal weak scaling was demonstrated for a 3-D poro-hydro-mechanical real-world application on up to 1024 GPUs on the Piz Daint Supercomputer \[[1][JuliaCon20a]\]:

![Parallel efficiency of ParallelStencil with CUDA C backend](docs/images/par_eff_c_julia2.png)

A particularity of ParallelStencil is that it enables writing a single high-level Julia code that can be deployed both on a CPU or a GPU. In conjuction with [ImplicitGlobalGrid.jl] the same Julia code can even run on a single CPU thread or on thousands of GPUs/CPUs.

Beyond traditional high-performance computing, ParallelStencil supports automatic differentiation of architecture-agnostic parallel kernels relying on [Enzyme.jl], enabling both high-level and generic syntax for maximal flexibility.

## Contents
- [Contents](#contents)
## Contents <!-- omit in toc -->
- [Parallelization and optimization with one macro call](#parallelization-and-optimization-with-one-macro-call)
- [Stencil computations with math-close notation](#stencil-computations-with-math-close-notation)
- [50-lines example deployable on GPU and CPU](#50-lines-example-deployable-on-gpu-and-cpu)
- [50-lines multi-xPU example](#50-lines-multi-xpu-example)
- [Interactive prototyping with runtime hardware selection](#interactive-prototyping-with-runtime-hardware-selection)
- [Seamless interoperability with communication packages and hiding communication](#seamless-interoperability-with-communication-packages-and-hiding-communication)
- [Support for architecture-agnostic low level kernel programming](#support-for-architecture-agnostic-low-level-kernel-programming)
- [Support for logical arrays of small arrays / structs](#support-for-logical-arrays-of-small-arrays--structs)
Expand All @@ -43,7 +43,7 @@ Beyond traditional high-performance computing, ParallelStencil supports automati
- [References](#references)

## Parallelization and optimization with one macro call
A simple call to `@parallel` is enough to parallelize and optimize a function and to launch it. The package used underneath for parallelization is defined in a call to `@init_parallel_stencil` beforehand. Supported are [CUDA.jl], [AMDGPU.jl] and [Metal.jl] for running on GPU and [Base.Threads] for CPU. The following example outlines how to run parallel computations on a GPU using the native kernel programming capabilities of [CUDA.jl] underneath (omitted lines are represented with `#(...)`, omitted arguments with `...`):
A simple call to `@parallel` is enough to parallelize and optimize a function and to launch it. The package used underneath for parallelization is defined in a call to `@init_parallel_stencil` beforehand. Supported are [CUDA.jl], [AMDGPU.jl], [Metal.jl], and the multi-architecture [KernelAbstractions.jl] backend for running on GPU, and [Base.Threads] and [Polyester.jl] for executing on CPU; when using KernelAbstractions the session starts on the CPU and you can switch the hardware target mid-run via `select_hardware`/`current_hardware` as outlined in [Interactive prototyping with runtime hardware selection](#interactive-prototyping-with-runtime-hardware-selection). The following example outlines how to run parallel computations on a GPU using the native kernel programming capabilities of [CUDA.jl] underneath (omitted lines are represented with `#(...)`, omitted arguments with `...`):
```julia
#(...)
@init_parallel_stencil(CUDA,...)
Expand Down Expand Up @@ -257,6 +257,38 @@ Here is the resulting movie when running the application on 8 GPUs, solving 3-D

The corresponding file can be found [here](/examples/diffusion3D_multigpucpu_hidecomm.jl).

## Interactive prototyping with runtime hardware selection
The KernelAbstractions backend keeps the familiar parse-time `@init_parallel_stencil` workflow while enabling runtime hardware switches through the `@select_hardware` and `@current_hardware` macros; the runtime hardware target defaults to CPU and can be switched as many times as desired during a session without requiring redefinition of kernels or reinitialization of the backend (these macros insert calls to corresponding functions which will be executed at runtime, i.e. the hardware switch occurs at runtime, not at parse time, following the normal control flow of the user program). The following copy-pasteable example outlines this workflow with a simple SAXPY kernel, demonstrating initial execution on CPU followed by a switch to CUDA-capable GPU and a second execution there:

```julia
# --- Session setup -----------------------------------------------------
using ParallelStencil
@init_parallel_stencil(package=KernelAbstractions, numbertype=Float32) # 1 Initialize KernelAbstractions backend at parse time
const N = 1024
const α = 2.5

# --- Kernel definition -------------------------------------------------
@parallel_indices (i) function saxpy!(Y, α, X) # 2 Define a single time a hardware-agnostic SAXPY kernel
Y[i] = α * X[i] + Y[i]
return
end

# --- First run on default runtime hardware (CPU) -----------------------
println("Current runtime hardware target: ", @current_hardware()) # 3 Query current (default) runtime hardware target
X = @rand(N) # 4 Allocate data on the current target
Y = @rand(N) # 4 Allocate data on the current target
@parallel saxpy!(Y, α, X) # 5 Launch kernel on the current target

# --- Reselect runtime hardware to CUDA-capable GPU and run again -------
@select_hardware(:gpu_cuda) # 6 Switch runtime hardware target to CUDA-capable GPU
println("Current runtime hardware target: ", @current_hardware()) # 7 Confirm the CUDA-capable GPU runtime hardware target
X = @rand(N) # 8 Allocate data on the new target
Y = @rand(N) # 8 Allocate data on the new target
@parallel saxpy!(Y, α, X) # 9 Launch kernel on the new target without redefining anything
```
Type `?@select_hardware` and `?@current_hardware` in the [Julia REPL] to see what runtime hardware targets are supported and which symbols to use to select them.
Note that the KernelAbstractions backend comes with a trade-off: the convenience `Data`/`TData` modules for fixed data types and single-architecture backends are not available, as well as the warp-level primitives in `@parallel_indices` kernels (see [Support for architecture-agnostic low level kernel programming](#support-for-architecture-agnostic-low-level-kernel-programming)).

## Seamless interoperability with communication packages and hiding communication
The previous multi-xPU example shows that ParallelStencil is seamlessly interoperable with [ImplicitGlobalGrid.jl]. The same is a priori true for any communication package that allows to explicitly decide when the required communication occurs; an example is [MPI.jl] (besides, [MPI.jl] is also seamlessly interoperable with [ImplicitGlobalGrid.jl] and can extend its functionality).

Expand Down Expand Up @@ -284,7 +316,7 @@ It can be launched as follows:
```julia
@parallel (1:size(A,1), 1:size(A,3)) bc_y!(A)
```
Furthermore, a set of architecture-agnostic low level kernel language constructs is supported in these `@parallel_indices` kernels (see in [Module documentation callable from the Julia REPL / IJulia](#module-documentation-callable-from-the-julia-repl--ijulia)). They enable, e.g., explicit usage of shared memory (see [this 2-D heat diffusion example](/examples/diffusion2D_shmem_novis.jl)).
Furthermore, a set of architecture-agnostic low level kernel language constructs is supported in these `@parallel_indices` kernels (see in [Module documentation callable from the Julia REPL / IJulia](#module-documentation-callable-from-the-julia-repl--ijulia)). They enable, e.g., explicit usage of shared memory (see [this 2-D heat diffusion example](/examples/diffusion2D_shmem_novis.jl)) and usage of warp-level primitives.

## Support for logical arrays of small arrays / structs
Logical arrays of small arrays / structs enabling optimized data access can be conveniently created with the architecture-agnostic allocation macros earlier introduced (see [Parallelization and optimization with one macro call](#parallelization-with-one-macro-call)). To this purpose, ParallelStencil leverages `CellArray`s (from [CellArrays.jl], which relies in turn on [StaticArrays.jl]). To create a logical array of small arrays, it is sufficient to pass to any of these allocation macros the keyword `celldims` with the dimensions of the inner arrays, e.g.:
Expand Down Expand Up @@ -440,7 +472,7 @@ Using simple array broadcasting capabilities both with GPU and CPU arrays within
* [Hydro-mechanical porosity waves 2-D app](#hydro-mechanical-porosity-waves-2-d-app)
* More to come, stay tuned...

All miniapp codes follow a similar structure and permit serial and threaded CPU as well as Nvidia GPU execution. The first line of each miniapp code permits to enable the CUDA GPU backend upon setting the `USE_GPU` flag to `true`.
All miniapp codes follow a similar structure and permit serial and threaded CPU as well as Nvidia GPU execution. The first line of each miniapp code permits to enable the CUDA.jl GPU backend upon setting the `USE_GPU` flag to `true`.

All the miniapps can be interactively executed within the [Julia REPL] (this includes the multi-xPU versions when using a single CPU or GPU). Note that for optimal performance the miniapp script of interest `<miniapp_code>` should be launched from the shell using the project's dependencies `--project`, disabling array bound checking `--check-bounds=no`, and using optimization level 3 `-O3`.
```sh
Expand Down Expand Up @@ -518,7 +550,7 @@ The hydro-mechanical porosity wave example resolves solitary waves in 2-D owing
*The animation depicts the formation of fluid escape pipes in two-phase media, owing to decompaction weakening running the miniapp [HydroMech2D.jl](/miniapps/HydroMech2D.jl). Top row: evolution of the porosity distribution and effective pressure. Bottom row: Darcy flux (relative fluid to solid motion) and solid (porous matrix) deformation.*

## Dependencies
ParallelStencil relies on the Julia packages ([CUDA.jl] \[[5][Julia CUDA paper 1], [6][Julia CUDA paper 2]\]), [AMDGPU.jl], [MacroTools.jl], [CellArrays.jl] and [StaticArrays.jl].
ParallelStencil relies on the Julia packages ([CUDA.jl] \[[5][Julia CUDA paper 1], [6][Julia CUDA paper 2]\]), [AMDGPU.jl], [Metal.jl], [KernelAbstractions.jl], [Polyester.jl], [MacroTools.jl], [CellArrays.jl], [StaticArrays.jl] and [Enzyme.jl]. However, thanks to usage of Julia's extensions feature, only [CellArrays.jl], [MacroTools.jl] and [StaticArrays.jl] are fix dependencies that will be automatically installed when installing ParallelStencil; the other packages are only required when using the respective backends or features.

## Installation
ParallelStencil may be installed directly with the [Julia package manager](https://docs.julialang.org/en/v1/stdlib/Pkg/index.html) from the REPL:
Expand Down Expand Up @@ -557,6 +589,7 @@ Please open an issue to discuss your idea for a contribution beforehand. Further
[JuliaCon20b]: https://www.youtube.com/watch?v=1t1AKnnGRqA
[JuliaCon19]: https://www.youtube.com/watch?v=b90qqbYJ58Q
[PASC19]: https://pasc19.pasc-conference.org/program/schedule/index.html%3Fpost_type=page&p=10&id=msa218&sess=sess144.html
[Polyester.jl]: https://github.com/JuliaSIMD/Polyester.jl
[Base.Threads]: https://docs.julialang.org/en/v1/base/multi-threading/
[ImplicitGlobalGrid.jl]: https://github.com/eth-cscs/ImplicitGlobalGrid.jl
[JULIA_NUM_THREADS]:https://docs.julialang.org/en/v1.0.0/manual/environment-variables/#JULIA_NUM_THREADS-1
Expand All @@ -565,6 +598,7 @@ Please open an issue to discuss your idea for a contribution beforehand. Further
[CUDA.jl]: https://github.com/JuliaGPU/CUDA.jl
[AMDGPU.jl]: https://github.com/JuliaGPU/AMDGPU.jl
[Metal.jl]: https://github.com/JuliaGPU/Metal.jl
[KernelAbstractions.jl]: https://github.com/JuliaGPU/KernelAbstractions.jl
[Enzyme.jl]: https://github.com/EnzymeAD/Enzyme.jl
[MacroTools.jl]: https://github.com/FluxML/MacroTools.jl
[StaticArrays.jl]: https://github.com/JuliaArrays/StaticArrays.jl
Expand Down
1 change: 1 addition & 0 deletions ext/ParallelStencil_AMDGPUExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module ParallelStencil_AMDGPUExt
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "AMDGPUExt", "shared.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "AMDGPUExt", "select_hardware.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "AMDGPUExt", "allocators.jl"))
end
1 change: 1 addition & 0 deletions ext/ParallelStencil_CUDAExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module ParallelStencil_CUDAExt
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "CUDAExt", "shared.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "CUDAExt", "select_hardware.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "CUDAExt", "allocators.jl"))
end
5 changes: 5 additions & 0 deletions ext/ParallelStencil_KernelAbstractionsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ParallelStencil_KernelAbstractionsExt
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "KernelAbstractionsExt", "shared.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "KernelAbstractionsExt", "select_hardware.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "KernelAbstractionsExt", "allocators.jl"))
end
1 change: 1 addition & 0 deletions ext/ParallelStencil_MetalExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module ParallelStencil_MetalExt
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "MetalExt", "shared.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "MetalExt", "select_hardware.jl"))
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "MetalExt", "allocators.jl"))
end
3 changes: 3 additions & 0 deletions ext/ParallelStencil_OneAPIExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ParallelStencil_OneAPIExt
include(joinpath(@__DIR__, "..", "src", "ParallelKernel", "OneAPIExt", "select_hardware.jl"))
end
5 changes: 5 additions & 0 deletions src/ParallelKernel/AMDGPUExt/defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ function get_rocstream end
function get_amdgpu_compute_capability end


# select_hardware.jl

handle_kernelabstractions_amd(arg...) = @NotLoadedError(ERRMSG_AMDGPUEXT_NOT_LOADED)


# allocators.jl

zeros_amdgpu(arg...) = @NotLoadedError(ERRMSG_AMDGPUEXT_NOT_LOADED)
Expand Down
5 changes: 5 additions & 0 deletions src/ParallelKernel/AMDGPUExt/select_hardware.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## FUNCTIONS TO TRANSLATE KERNELABSTRACTIONS GPU SYMBOLS TO AMDGPU BACKEND HANDLES

function ParallelStencil.ParallelKernel.handle_kernelabstractions_amd()
return AMDGPU.ROCBackend()
end
5 changes: 5 additions & 0 deletions src/ParallelKernel/CUDAExt/defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ function get_custream end
function get_cuda_compute_capability end


# select_hardware.jl

handle_kernelabstractions_cuda(arg...) = @NotLoadedError(ERRMSG_CUDAEXT_NOT_LOADED)


# allocators.jl

zeros_cuda(arg...) = @NotLoadedError(ERRMSG_CUDAEXT_NOT_LOADED)
Expand Down
5 changes: 5 additions & 0 deletions src/ParallelKernel/CUDAExt/select_hardware.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## FUNCTIONS TO TRANSLATE KERNELABSTRACTIONS GPU SYMBOLS TO CUDA BACKEND HANDLES

function ParallelStencil.ParallelKernel.handle_kernelabstractions_cuda()
return CUDA.CUDABackend()
end
Loading
Loading