Skip to content

making asserts output array label #151

@gavinwhetstone

Description

@gavinwhetstone

added the following macro on line 111 of kokkos_types.h:

#ifndef NDEBUG
#define MATAR_CHECK_BOUNDS(i, dim, view)
if ((i) >= (dim)) {
printf("\n[MATAR BOUNDS ERROR]\n");
printf(" Location: %s:%d\n", FILE, LINE);
printf(" Array Label: %s\n", this_array_.label().c_str());
printf(" Attempted access at index [%zu], but dimension is %zu\n\n", (size_t)(i), (size_t)(dim));
assert(false);
}
#else
// In Release mode, this macro does absolutely nothing
#define MATAR_CHECK_BOUNDS(i, dim, view) ((void)0)
#endif

and then changed line 3670 (in the current repo numbering) to:

template <typename T, typename Layout, typename ExecSpace, typename MemoryTraits>
KOKKOS_INLINE_FUNCTION
T& CArrayKokkos<T,Layout,ExecSpace,MemoryTraits>::operator()(size_t i) const {
// This expands to the full check in Debug, and disappears in Release
MATAR_CHECK_BOUNDS(i, dims_[0], this_array_);

return this_array_(i);

}

and forced an out of bounds memory call for a CArrayKokkos 1D array to get the following output:
[MATAR BOUNDS ERROR]
Location: <path_to>kokkos_types.h:3687
Array Label: testing
Attempted access at index [5], but dimension is 4

Assertion failed: (false), function operator(), file kokkos_types.h, line 3687.

can be implemented for other data types to know which array had a bad memory access
the Location part could probably be deleted as it was intended to go to the executed code location but went to the header file instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions