Skip to content

C4 Run-time dispatch ​

IDGroupTypeBackendsFigureProgram
C4ContractsCCPU (gfortran R4P, R8P, R16P; nvfortran); the CI matrixnogideon_test_dispatch

Case and scope ​

A solver that reads its order from input (ADAM's PRISM, fdv_order) calls a dispatcher, gideon_<data>_<op>_<bias>(order, q, [ds,] r), which selects the kernel by a select case on order. Two things can go wrong: a case calls the kernel of another order or operator, and an order with no kernel returns a number. ADAM returned 0 for an order it had no row for (audit item C), a plausible value that a caller cannot tell from a result. A GIDEON dispatcher returns GIDEON_NAN, a quiet NaN, for such an order: error stop is not device code.

Models and numerics ​

ItemChoiceCode
Dispatchersone per 1-D operator family and bias, generated with their windows as expressions of order (each checked by the generator against every kernel of the group)gideon_dispatch.F90 (generated), window_expr in gen_gideon.py
Equalityevery kernel against its dispatcher at the kernel's order, on the same random window, Δs=0.37: bitwisegideon_test_dispatch.F90, registry apply_dispatch
NaNevery dispatcher at an order without a kernel whose window stays inside the test's data (the largest order plus 2 for a centred family, plus 1 for an upwind one): the result must be a NaN (r /= r)registry apply_dispatch_bad
3-D operatorstheir dispatchers, and the NaN at order 3, are tested by A2

The window of a dispatcher grows with order, so a caller passes q(i+lo(order):i+hi(order)) and the dispatcher hands the whole section to the kernel. Every dispatcher, its window and the order of its NaN check:

64 dispatchers of the 1-D kernels, 8 of the 3-D operators.

Every dispatcher
DispatcherKernelsOrdersWindowOrder of the NaN check
fd_face_c52-10 (even)q(1-(order/2):order/2)12
fd_d1_c52-10 (even)q(-(order/2):order/2)12
fd_d2_c52-10 (even)q(-(order/2):order/2)12
fd_d3_c42-8 (even)q(-(order/2+1):order/2+1)10
fd_d4_c42-8 (even)q(-(order/2+1):order/2+1)10
fd_d5_c32-6 (even)q(-(order/2+2):order/2+2)8
fd_d6_c32-6 (even)q(-(order/2+2):order/2+2)8
fv_face_c52-10 (even)q(1-(order/2):order/2)12
fv_face_d1_c52-10 (even)q(1-(order/2):order/2)12
fv_face_d2_c42-8 (even)q(1-(order/2+1):order/2+1)10
fv_face_d3_c42-8 (even)q(1-(order/2+1):order/2+1)10
fv_face_d4_c32-6 (even)q(1-(order/2+2):order/2+2)8
fv_face_d5_c32-6 (even)q(1-(order/2+2):order/2+2)8
fv_d1_c52-10 (even)q(-(order/2):order/2)12
fv_d2_c52-10 (even)q(-(order/2):order/2)12
fv_d3_c42-8 (even)q(-(order/2+1):order/2+1)10
fv_d4_c42-8 (even)q(-(order/2+1):order/2+1)10
fv_d5_c32-6 (even)q(-(order/2+2):order/2+2)8
fv_d6_c32-6 (even)q(-(order/2+2):order/2+2)8
fv_face_ur91-9q(1:order)10
fv_face_ul91-9q(-(order-1):0)10
fv_face_d1_ur81-8q(1:order+1)9
fv_face_d1_ul81-8q(-(order):0)9
fv_face_d2_ur71-7q(1:order+2)8
fv_face_d2_ul71-7q(-(order+1):0)8
fv_face_d3_ur61-6q(1:order+3)7
fv_face_d3_ul61-6q(-(order+2):0)7
fv_face_d4_ur51-5q(1:order+4)6
fv_face_d4_ul51-5q(-(order+3):0)6
fv_face_d5_ur41-4q(1:order+5)5
fv_face_d5_ul41-4q(-(order+4):0)5
fv_d1_ur91-9q(0:order)10
fv_d1_ul91-9q(-(order):0)10
fv_d2_ur81-8q(0:order+1)9
fv_d2_ul81-8q(-(order+1):0)9
fv_d3_ur71-7q(0:order+2)8
fv_d3_ul71-7q(-(order+2):0)8
fv_d4_ur61-6q(0:order+3)7
fv_d4_ul61-6q(-(order+3):0)7
fv_d5_ur51-5q(0:order+4)6
fv_d5_ul51-5q(-(order+4):0)6
fv_d6_ur41-4q(0:order+5)5
fv_d6_ul41-4q(-(order+5):0)5
fv_point_c54-12 (even)q(-(order/2-1):order/2-1)14
fd_average_c54-12 (even)q(-(order/2-1):order/2-1)14
fd_face_d1_c52-10 (even)q(1-(order/2):order/2)12
fd_face_d2_c42-8 (even)q(1-(order/2+1):order/2+1)10
fd_face_d3_c42-8 (even)q(1-(order/2+1):order/2+1)10
fd_face_d4_c32-6 (even)q(1-(order/2+2):order/2+2)8
fd_face_d5_c32-6 (even)q(1-(order/2+2):order/2+2)8
fd_face_ur91-9q(1:order)10
fd_face_ul91-9q(-(order-1):0)10
fd_face_br43-9q(2-(order/2+1):order/2+1)10
fd_face_bl43-9q(-(order/2):order/2)10
fd_face_diss_c52-10 (even)q(1-(order/2):order/2)12
fv_face_diss_c52-10 (even)q(1-(order/2):order/2)12
fv_face_br43-9q(2-(order/2+1):order/2+1)10
fv_face_bl43-9q(-(order/2):order/2)10
fd_face_diss_br43-9q(1-(order/2+1):order/2+1)10
fd_face_diss_bl43-9q(1-(order/2+1):order/2+1)10
fv_face_diss_br43-9q(1-(order/2+1):order/2+1)10
fv_face_diss_bl43-9q(1-(order/2+1):order/2+1)10
fd_filter_c52-10 (even)q(-(order/2):order/2)12
fv_filter_c52-10 (even)q(-(order/2):order/2)12

Program ​

bash
./exe/gideon_test_dispatch

Results ​

BuildKernels (properties)FailuresKernels (dispatch)Failures
gfortran, R4P33203320
gfortran, R8P33203320
gfortran, R16P33203320
nvfortran -acc, R8P33203320

Findings ​

  • Every dispatcher returns its kernel's value bitwise, and a NaN for an order without a kernel, in every kind.
  • The NaN is a quiet NaN, a constant built by transfer from its bit pattern in each kind (gideon_kind_parameters): no floating-point operation produces it, so a build that traps invalid operations does not stop on it. A caller detects it with r /= r or ieee_is_nan; a NaN that reaches a solution field propagates instead of hiding.
  • The dispatch is not free: the select case is evaluated at every call and the compilers do not hoist it out of a loop with a loop-invariant order. Its cost against the kernel is measured in Performance; with an order known at compile time, call the kernel (A run-time order, fast).

Released under your choice of GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT.