Skip to content

Fix inverted NDEBUG logic in mdspan precondition checking - #464

Merged
dalg24 merged 1 commit into
kokkos:stablefrom
rppawlo:rppawlo-fix-mdspan-performance
Jul 25, 2026
Merged

Fix inverted NDEBUG logic in mdspan precondition checking#464
dalg24 merged 1 commit into
kokkos:stablefrom
rppawlo:rppawlo-fix-mdspan-performance

Conversation

@rppawlo

@rppawlo rppawlo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

MDSPAN_IMPL_CHECK_PRECONDITION defaulted to enabled when NDEBUG was defined (Release builds) and disabled when NDEBUG was undefined (Debug builds) -- backwards from the usual assert()/NDEBUG convention. As a result, every View/DynRankView mapping construction paid for O(rank) overflow-checked multiplications in optimized builds, causing a large performance regression relative to the legacy View implementation (observed ~20x slower DynRankView construction in a Release build).

Swap the branches so precondition checks are enabled for debug builds and disabled for release builds, matching normal convention.

Details are in
kokkos/kokkos#9368
kokkos/kokkos#9374

MDSPAN_IMPL_CHECK_PRECONDITION defaulted to enabled when NDEBUG was
defined (Release builds) and disabled when NDEBUG was undefined (Debug
builds) -- backwards from the usual assert()/NDEBUG convention. As a
result, every View/DynRankView mapping construction paid for O(rank)
overflow-checked multiplications in optimized builds, causing a large
performance regression relative to the legacy View implementation
(observed ~20x slower DynRankView construction in a Release build).

Swap the branches so precondition checks are enabled for debug builds
and disabled for release builds, matching normal convention.

Signed-off-by: Roger Pawlowski <rppawlo@sandia.gov>
Assisted-by: Claude
@rppawlo

rppawlo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@dalg24

@dalg24 dalg24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you

@dalg24
dalg24 merged commit 88c0bc0 into kokkos:stable Jul 25, 2026
15 checks passed
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.

2 participants