Skip to content

precondition checks in extents constructors#410

Merged
nmm0 merged 8 commits intokokkos:stablefrom
nmm0:409-check-preconditions-in-extents-constructors
Feb 16, 2026
Merged

precondition checks in extents constructors#410
nmm0 merged 8 commits intokokkos:stablefrom
nmm0:409-check-preconditions-in-extents-constructors

Conversation

@nmm0
Copy link
Contributor

@nmm0 nmm0 commented Jun 2, 2025

This adds the missing precondition checks for mdspan.extents.cons

auto test_precondition_indices_not_representable = [] {
[[maybe_unused]] auto exts = Kokkos::dextents< std::int8_t, 2 >{ 500, 500 };
};
EXPECT_DEATH(test_precondition_indices_not_representable(), "");
Copy link
Member

Choose a reason for hiding this comment

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

We do not want to ensure that the error message matches some regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can at least for CPU but it won't work with CUDA. So I just decided not to since it doesn't matter a whole lot

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean it won't work with CUDA?
We do check error messages from the device in Kokkos so there is some level of support.

Copy link
Contributor Author

@nmm0 nmm0 Jun 19, 2025

Choose a reason for hiding this comment

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

So for now the CUDA precondition violation handler prints to stdout. EXPECT_DEATH checks stderr -- we could do something like:

#if defined(MDSPAN_IMPL_HAS_CUDA) || defined(MDSPAN_IMPL_HAS_HIP) || defined(MDSPAN_IMPL_HAS_SYCL)
  EXPECT_DEATH(test_precondition_indices_not_representable(), "");
#else
  EXPECT_DEATH(test_precondition_indices_not_representable(), "extent_is_representable");
#endif

We do this elsewhere. But really the precondition handler doesn't print the best errors anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated to test the message on host. On device the message is kinda useless:

void Kokkos::detail::default_precondition_violation_handler(const char*, const char*, unsigned int): Assertion `0' failed.

So I think we should avoid testing device messages for now until we update our precondition violation handler on device (likely a separate PR)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, because we call printf(...) and assert(false) instead of __assert_fail(...) like we do in Kokkos

@nmm0 nmm0 force-pushed the 409-check-preconditions-in-extents-constructors branch from 290c211 to 8cb9a2c Compare June 18, 2025 06:20
@nmm0 nmm0 requested a review from dalg24 June 25, 2025 14:56
@nmm0 nmm0 merged commit 3b0c6e2 into kokkos:stable Feb 16, 2026
15 checks passed
@nmm0 nmm0 deleted the 409-check-preconditions-in-extents-constructors branch February 16, 2026 14:22
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