Skip to content

Wrap scal#331

Draft
amklinv-nnl wants to merge 2 commits into
kokkos:mainfrom
amklinv-nnl:wrap_scal
Draft

Wrap scal#331
amklinv-nnl wants to merge 2 commits into
kokkos:mainfrom
amklinv-nnl:wrap_scal

Conversation

@amklinv-nnl
Copy link
Copy Markdown
Contributor

DO NOT MERGE.

For discussion in #328

Comment on lines +77 to +78
auto incx = x.stride(0);
if (x.is_strided() && n <= std::numeric_limits<CBLAS_INDEX>::max()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. Per [mdspan.layout.reqmnts] 19, we can't call x.stride(0) until we know that x.is_strided() is true.

  2. incx might be larger than n.

Suggested change
auto incx = x.stride(0);
if (x.is_strided() && n <= std::numeric_limits<CBLAS_INDEX>::max()) {
if (x.is_strided() && n <= std::numeric_limits<int>::max()) {
auto incx = x.stride(0);
if (incx > std::numeric_limits<int>::max()) {
return false;
}

Copy link
Copy Markdown
Contributor

@mhoemmen mhoemmen May 28, 2026

Choose a reason for hiding this comment

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

It's also acceptable to turn this into a compile-time check. We don't have to worry too much about weird layouts for which is_strided() is true sometimes but is_always_strided() is false.

if constexpr (! x.is_always_strided()) {
  return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, strided layout mappings can have stride zero. layout_stride cannot, unless its corresponding extent is also zero. If incx is zero, then we should also return false.

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