selah_kernels_box
SELAH, L1: the box kernels, the stage operations over the box of a rank-5 field.
Every kernel is a pointwise update of the cells of the box (selah_box): never a ghost cell, never a pool slot past the active blocks. One source serves the host (plain loops, OpenMP with -fopenmp), OpenACC and OpenMP offload, by the backend macros of FUNDAL (fundal.H) in the directive style of ADAM's FNL kernels; in a device build every array argument, the coefficients included, must be device resident.
Mask. With mask present, a cell is active where mask(..., mask_comp) < 0 (ADAM's immersed-boundary distance, negative in the fluid; mask_comp defaults to the last component, ADAM's all-solids summary). The mask has the field's shape with its own number of components. Inactive cells are left untouched, except the step residual dq, which is 0 there, and the stage state with masked_q (stage_state_box), which is q there.
Summation order. The sums over registers form a private sum and store once, as ADAM's FNL kernels do, so the results are bitwise those of ADAM's device path (src/tests: the parity test).
Aliasing. The output arrays must not alias the inputs (Fortran's rule on dummy arguments).
One procedure per variant. The loop of a kernel is an include file (selah_kernel_<name>.INC), compiled once per variant: masked or not, once per layout, with the step residual or not, with the stage-state fill, with a = 0. Each variant is a private procedure of its own, made from the wrapper selah_kernel_<name>_proc.INC under the name given by the macro SELAH_PROC (the block of private procedures at the end of the module), and the public routines only dispatch to them. The reason is a defect of AMD's flang (AFAR 23.2.1 and 24.4.0): it pairs the host launch of an OpenMP target region with the device kernel of ANOTHER region when several regions of one procedure come from the same line of an included file, so that on an AMD GPU a call ran the kernel of an arbitrary variant: the time integrator did not advance the state (ADAM issue #155). The same included line in different procedures is not affected. Do not include one kernel file more than once in a procedure.
Source: src/lib/selah_kernels_box.F90
Dependencies
Contents
- copy_box
- axpy_box
- lincomb_box
- stage_state_box
- step_update_box
- shu_osher_2r_stage_box
- williamson_2n_stage_box
- stage_current_box
Subroutines
copy_box
y = x over the box.
subroutine copy_box(bx, x, y, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
x | real(kind=R_P) | in | Source. | |
y | real(kind=R_P) | inout | Destination. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
axpy_box
y = y + alpha x over the box (a partition update of a splitting scheme, a forward-Euler step).
subroutine axpy_box(bx, alpha, x, y, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
alpha | real(kind=R_P) | in | Coefficient. | |
x | real(kind=R_P) | in | Increment. | |
y | real(kind=R_P) | inout | Updated field. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
lincomb_box
y = alpha x + beta y over the box.
subroutine lincomb_box(bx, alpha, x, beta, y, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
alpha | real(kind=R_P) | in | Coefficient of x. | |
x | real(kind=R_P) | in | First field. | |
beta | real(kind=R_P) | in | Coefficient of y. | |
y | real(kind=R_P) | inout | Second field, overwritten. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
stage_state_box
u = q + sum_{k=1..n} dt coef(k) regs(k) over the box: the state of a stage of a Butcher form, from the solution and the residuals of the previous stages (coef = row s of A, n = s - 1). n = 0 gives u = q, through the copy kernel: the summing loop with nothing to sum ran at 0.57 of the copy's speed on the A30 (M5, job 1368098). With masked_q, the inactive cells of u take q (the stepper's mask policy) in the same pass, instead of being left untouched.
subroutine stage_state_box(bx, n, dt, coef, q, regs, u, mask, mask_comp, masked_q)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
n | integer(kind=I4P) | in | Registers summed. | |
dt | real(kind=R_P) | in | Time step. | |
coef | real(kind=R_P) | in | Coefficients [n or more]. | |
q | real(kind=R_P) | in | Solution. | |
regs | real(kind=R_P) | in | Residual registers [..., n or more]. | |
u | real(kind=R_P) | inout | Stage state. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
masked_q | logical | in | optional | The inactive cells of u take q (default .false.). |
Call graph
step_update_box
q = q + dt sum_{k=1..n} coef(k) regs(k) over the box: the end of a step of a Butcher form (coef = b, n = s), fused with the step residual dq = sum_k coef(k) regs(k) when dq is present (0 where the mask is inactive).
subroutine step_update_box(bx, n, dt, coef, regs, q, dq, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
n | integer(kind=I4P) | in | Registers summed. | |
dt | real(kind=R_P) | in | Time step. | |
coef | real(kind=R_P) | in | Weights [n or more]. | |
regs | real(kind=R_P) | in | Residual registers [..., n or more]. | |
q | real(kind=R_P) | inout | Solution, advanced. | |
dq | real(kind=R_P) | inout | optional | Step residual. |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
shu_osher_2r_stage_box
q = a q0 + b q + dt c r over the box: a stage of a two-register Shu–Osher form (q0 = u^n, r = F(q)).
subroutine shu_osher_2r_stage_box(bx, dt, a, b, c, q0, r, q, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
dt | real(kind=R_P) | in | Time step. | |
a | real(kind=R_P) | in | Stage coefficients. | |
b | real(kind=R_P) | in | Stage coefficients. | |
c | real(kind=R_P) | in | Stage coefficients. | |
q0 | real(kind=R_P) | in | Solution at the start of the step. | |
r | real(kind=R_P) | in | Residual of the current stage. | |
q | real(kind=R_P) | inout | Current stage, advanced. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
williamson_2n_stage_box
dqr = a dqr + dt r; q = q + b dqr over the box: a stage of a Williamson 2N form (r = F(q)). With a = 0 dqr is not read (dqr = dt r): the first stage needs no prior content of the register.
subroutine williamson_2n_stage_box(bx, dt, a, b, r, dqr, q, mask, mask_comp)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
dt | real(kind=R_P) | in | Time step. | |
a | real(kind=R_P) | in | Stage coefficients A_i, B_i. | |
b | real(kind=R_P) | in | Stage coefficients A_i, B_i. | |
r | real(kind=R_P) | in | Residual of the current stage. | |
dqr | real(kind=R_P) | inout | The Delta Q register. | |
q | real(kind=R_P) | inout | Current stage, advanced. | |
mask | real(kind=R_P) | in | optional | Active where mask(..., mask_comp) < 0. |
mask_comp | integer(kind=I4P) | in | optional | Mask component (default: the last). |
Call graph
stage_current_box
y = (h - sum_{r=1..n-1} coef(r) regs(r)) / coef(n) over the box: the stage current that makes the weighted sum of the stage currents equal a given one (coef = row n+1 of A, or b at the last stage; selah_stepper stage_current). One variant, so one loop: it needs no procedure of its own.
subroutine stage_current_box(bx, n, coef, h, regs, y)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
bx | type(box) | in | Box. | |
n | integer(kind=I4P) | in | Stage (coef(n) /= 0). | |
coef | real(kind=R_P) | in | Coefficients [n or more]. | |
h | real(kind=R_P) | in | The weighted sum wanted. | |
regs | real(kind=R_P) | in | The previous stage currents [..., n-1 or more]. | |
y | real(kind=R_P) | inout | Stage current n. |