Skip to content

fix aosoa/controller lifetime issue and remove relaxed constexpr flag - #92

Merged
cwsmith merged 4 commits into
mainfrom
cws/removeRelaxConstExpr
Jul 24, 2026
Merged

fix aosoa/controller lifetime issue and remove relaxed constexpr flag #92
cwsmith merged 4 commits into
mainfrom
cws/removeRelaxConstExpr

Conversation

@cwsmith

@cwsmith cwsmith commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

KokkosController's std::tuple<Kokkos::View<Ts, MemorySpace>...> member forced NVCC to treat its constructor as __host__ __device__ whenever a ShapeField holding it (stored as ShapeField::meshField) was captured into a device lambda. Removing that member (which was unused... except for keeping the controller in-scope) eliminates the constexpr violation and the need for the --expt-relaxed-constexpr compiler flag.

Removing the compiler flag subsequently revealed a bug with the CabanaController. CabanaController's slices are non-owning views into its aosoa member, and ShapeField::meshField was the only thing keeping that aosoa alive past the factory function that created it (confirmed with asan).

Changes:

  • CabanaController::aosoa is now wrapped in std::shared_ptr - copies of the controller share (rather than duplicate/free) the underlying storage
  • CreateLagrangeField and CreateCoordinateField now return FieldWithController{ctrlr, field} instead of a bare field, making lifetime ownership of the Controller explicit to the caller instead of hidden inside ShapeField.
  • OmegahMeshField and all call sites updated accordingly.
  • Added ControllerLifetimeTest and CabanaControllerLifetimeTest as regression coverage for object lifetime

resolves #37 and #90

cwsmith added 4 commits July 22, 2026 14:02
this triggers the copy ctor which in turn requires the relaxed constexpr flag, see #37
I don't like the inconsistent treatment of the coordinate field inside omegahmeshfield (i.e., it owns the controller since it created the coord field in the ctor).  I'd also prefer that the user only had to deal with the field handles, not the controller lifetime.  Reference counting the aosoa so it remains alive and requiring the user to keep the controller alive for each field is the current compromise.  There is most certainly a better approach to keep host-only constructs off the device... but this will have to do for now.

all tests run under asan are now passing
@cwsmith cwsmith linked an issue Jul 23, 2026 that may be closed by this pull request
@cwsmith

cwsmith commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

/runtests

ShapeField(MeshFieldType &meshFieldIn, const MeshInfo &meshInfoIn,
Mixins... mixins)
: meshField(meshFieldIn), meshInfo(meshInfoIn), Mixins(mixins)... {};
ShapeField(const MeshInfo &meshInfoIn, Mixins... mixins)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will be resolved outside PR

@github-actions

Copy link
Copy Markdown

Test Result: success (details)

@cwsmith
cwsmith merged commit 6ce9e55 into main Jul 24, 2026
5 checks passed
@cwsmith
cwsmith deleted the cws/removeRelaxConstExpr branch July 24, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVCC Specific Compiler Flag Propagates to Downstream Fortran Compiler remove depency on --expt-relaxed-constexpr

2 participants