include/pops/runtime/dynamic/abi_key.hpp File ReferenceΒΆ

adc_cpp: include/pops/runtime/dynamic/abi_key.hpp File Reference
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
abi_key.hpp File Reference

ABI key of the pops core: stable string identifying the (compiler, C++ standard, header tree signature) combination a unit was compiled with. More...

#include <pops/runtime/export.hpp>
#include <string>
+ Include dependency graph for abi_key.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  pops
 
namespace  pops::detail
 

Macros

#define POPS_HEADER_SIG   "unknown"
 
#define POPS_ABI_STR_(x)   #x
 
#define POPS_ABI_STR(x)   POPS_ABI_STR_(x)
 
#define POPS_ABI_KOKKOS   "0"
 
#define POPS_ABI_STDLIB   "unknown"
 
#define POPS_ABI_COMPILER   "unknown"
 
#define POPS_ABI_KEY_LITERAL
 

Functions

std::string pops::detail::abi_key_string ()
 ABI key of the current TU (cf.
 
POPS_EXPORT std::string pops::abi_key ()
 ABI key of the module (TU system.cpp).
 

Detailed Description

ABI key of the pops core: stable string identifying the (compiler, C++ standard, header tree signature) combination a unit was compiled with.

MOTIVATION ("production" DSL path). A .so loader generated by the DSL (cf. dsl.emit_cpp_native_loader) inlines the pops::add_compiled_model header template and calls out-of-line methods of pops::System DEFINED in the already-loaded _pops module. The loader and the module MUST share the same ABI (same headers, same compiler, same standard); otherwise the memory layout of objects crossing the boundary (System, GridContext, BlockClosures...) diverges -> SILENT undefined behavior. We make the incompatibility EXPLICIT: the loader exposes pops_native_abi_key() (key frozen at ITS compilation) and the System compares it against ITS own abi_key() at load time (add_native_block); a mismatch raises a clear error instead of UB.

Key construction (parallel to adc_cases/common/native.py::_abi_key):

  • VERSION: compiler identity + version (g++/clang++/Apple clang...);
  • cplusplus: effective C++ standard (thus -std= and the compiler mode);
  • POPS_HEADER_SIG: signature of the core header tree, INJECTED by the build (CMake on the module side, -D flag on the loader side); its value changes if a header changes, so the key changes and the incompatibility is detected. Absent (old build / manual build) -> literal token "unknown": the key stays stable and comparable, it then captures only compiler + standard (graceful degradation, never silent UB since both sides see the same "unknown" if built the same).
  • kokkos=0|1: POPS_HAS_KOKKOS of the unit. This macro CHANGES the layout of types crossing the boundary (allocator.hpp: Fab backing malloc vs Kokkos::SharedSpace pool; types.hpp: POPS_HD): a serial loader on a Kokkos module (or the reverse) was previously ACCEPTED by the key -> mute serial fallback in one direction, UB in the other. The divergence is now rejected explicitly; parity is restored via POPS_KOKKOS_ROOT (cf. dsl._native_kokkos_flags) or a serial module.
  • stdlib=...: C++ standard library linked (libc++ _LIBCPP_VERSION / libstdc++ __GLIBCXX). Two toolchains may share VERSION AND __cplusplus but link stdlibs with INCOMPATIBLE ABIs (std::string/std::function cross the loader boundary). Detects the clang -stdlib=libc++ vs libstdc++ mix (conda/system mix). The macros are visible here because <string> is included.

Macro Definition Documentation

◆ POPS_ABI_COMPILER

#define POPS_ABI_COMPILER   "unknown"

◆ POPS_ABI_KEY_LITERAL

#define POPS_ABI_KEY_LITERAL
Value:
"compiler=" POPS_ABI_COMPILER ";std=" POPS_ABI_STR(__cplusplus) ";headers=" POPS_HEADER_SIG \
";kokkos=" POPS_ABI_KOKKOS \
";stdlib=" POPS_ABI_STDLIB
#define POPS_ABI_KOKKOS
Definition abi_key.hpp:54
#define POPS_ABI_STDLIB
Definition abi_key.hpp:64
#define POPS_ABI_STR(x)
Definition abi_key.hpp:48
#define POPS_HEADER_SIG
Definition abi_key.hpp:42
#define POPS_ABI_COMPILER
Definition abi_key.hpp:75

◆ POPS_ABI_KOKKOS

#define POPS_ABI_KOKKOS   "0"

◆ POPS_ABI_STDLIB

#define POPS_ABI_STDLIB   "unknown"

◆ POPS_ABI_STR

#define POPS_ABI_STR (   x)    POPS_ABI_STR_(x)

◆ POPS_ABI_STR_

#define POPS_ABI_STR_ (   x)    #x

◆ POPS_HEADER_SIG

#define POPS_HEADER_SIG   "unknown"