Skip to content

Better bounds checking#152

Open
jacob-moore22 wants to merge 8 commits intolanl:mainfrom
jacob-moore22:Better_bounds_checking
Open

Better bounds checking#152
jacob-moore22 wants to merge 8 commits intolanl:mainfrom
jacob-moore22:Better_bounds_checking

Conversation

@jacob-moore22
Copy link
Collaborator

Adds useful information for debugging with asserts to call out what data structure is the bad actor.

cursoragent and others added 3 commits February 12, 2026 18:13
This commit introduces enhanced bounds checking macros that provide
detailed error messages when bounds violations occur in debug mode.

Changes:
- Added MATAR_CHECK_BOUNDS macro for Kokkos View arrays with labels
- Added MATAR_CHECK_BOUNDS_NO_LABEL macro for raw pointer arrays
- Added MATAR_CHECK_BOUNDS_MATRIX macro for 1-based matrix indexing
- Added MATAR_CHECK_BOUNDS_MATRIX_NO_LABEL macro for View matrix types
- Added MATAR_CHECK_ORDER macro for order/rank validation
- Added MATAR_CHECK_ORDER_NO_LABEL macro for View types without labels
- Replaced 717 bounds checking assert statements with the new macros

The macros provide enhanced error output including:
- File location and line number
- Class name where the error occurred
- Array label (when available)
- Index name and value that caused the violation
- Expected dimension size or valid range

In release mode (NDEBUG defined), all macros compile to no-ops for
zero runtime overhead.

Addresses: lanl#151

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
The Location output (__FILE__:__LINE__) was pointing to the header file
rather than the user's code, making it unhelpful for debugging.
The array label and class name provide sufficient context for identifying
which array caused the bounds violation.

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
This improves debugging by showing the exact dimension of the array
operation that caused a bounds violation, e.g.:

[MATAR BOUNDS ERROR]
  Class: FArrayKokkos 3D
  Array Label: my_array
  Index 'k' = 10 is out of bounds (dimension size = 5)

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
@jacob-moore22 jacob-moore22 self-assigned this Feb 12, 2026
cursoragent and others added 5 commits February 12, 2026 20:12
This fixes compilation errors where the MATAR_CHECK_* macros expected
'this_array_' but matrix classes used 'this_matrix_' and ragged classes
used 'array_'.

Changes:
- Renamed this_matrix_ to this_array_ in all matrix classes (FMatrixKokkos,
  CMatrixKokkos, ViewFMatrixKokkos, ViewCMatrixKokkos, etc.)
- Renamed array_ to this_array_ in all ragged array classes
  (RaggedRightArrayKokkos, RaggedDownArrayKokkos, CSRArrayKokkos,
  CSCArrayKokkos, DynamicRaggedRightArrayKokkos, etc.)

This ensures consistent naming across all classes and allows the
MATAR_CHECK_BOUNDS macros to access the array label for error messages.

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
…kkos

The MATAR_CHECK_BOUNDS macro was incorrectly using 'd' instead of 'i'
as the first parameter in the dims() and dims_max() functions.

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
This allows the same macros to work with different array types:
- Regular Kokkos views: this_array_.label().c_str()
- Dual views (DCArrayKokkos, etc.): this_array_.h_view.label().c_str()
- View types (raw pointers): "" (empty string)

Changes:
- Consolidated MATAR_CHECK_BOUNDS and MATAR_CHECK_BOUNDS_NO_LABEL into
  single MATAR_CHECK_BOUNDS with label parameter
- Consolidated MATAR_CHECK_BOUNDS_MATRIX and MATAR_CHECK_BOUNDS_MATRIX_NO_LABEL
  into single MATAR_CHECK_BOUNDS_MATRIX with label parameter
- Consolidated MATAR_CHECK_ORDER and MATAR_CHECK_ORDER_NO_LABEL into
  single MATAR_CHECK_ORDER with label parameter
- Macros now conditionally print label only if non-empty
- Updated all 711 macro calls with appropriate label accessor

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
DDynamicRaggedRightArrayKokkos uses DualView, so it needs to access
the label via this_array_.h_view.label().c_str() instead of
this_array_.label().c_str().

Also fixed the class name in the error message from
'DynamicRaggedRightArrayKokkos' to 'DDynamicRaggedRightArrayKokkos'.

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
Fixed three bounds checks for the 'j' index in DRaggedRightArrayKokkos
that were incorrectly using this_array_.label() instead of
this_array_.h_view.label() for DualView access.

Also fixed class name in error messages from 'RaggedRightArrayKokkos'
to 'DRaggedRightArrayKokkos'.

Co-authored-by: Jacob Moore <jacob-moore22@users.noreply.github.com>
Copy link
Collaborator

@gavinwhetstone gavinwhetstone left a comment

Choose a reason for hiding this comment

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

i don't see any issues

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.

3 participants