Skip to content

Ensure sort_crs_matrix in Kokkos is only performed on matrices with local column indices - #262

Merged
stevendargaville merged 1 commit into
mainfrom
kokkos_local_sort_indices
Aug 1, 2026
Merged

Ensure sort_crs_matrix in Kokkos is only performed on matrices with local column indices#262
stevendargaville merged 1 commit into
mainfrom
kokkos_local_sort_indices

Conversation

@stevendargaville

Copy link
Copy Markdown
Collaborator

Summary

In remove_small_from_sparse_kokkos, KokkosSparse::sort_crs_matrix was called on the nonlocal block while j_nonlocal_d still held global column indices, but the KokkosCsrMatrix was constructed with numCols = cols_ao (the local count). Global indices >= cols_ao can cause out-of-bounds access inside the sort.

  • Split rewrite_j_global_to_local into device-side helpers (rewrite_j_global_to_local_device + remap_j_to_local_device, reusing the existing binary_search_sorted device function) with the host garray copy kept in the original wrapper, whose signature is unchanged for its other callers.
  • In remove_small_from_sparse_kokkos, remap j_nonlocal_d to local indices before the lumping sort, and construct csrmat_nonlocal with the correct col_ao_output as numCols. The output block now just copies the device garray to the host.

MatAXPY_kokkos needs no change: it already performs the spadd in a merged-local column space.

Testing

  • Warning-clean build
  • make check and make tests_short pass: plain, with -mat_type aijkokkos -vec_type kokkos -dm_mat_type aijkokkos -dm_vec_type kokkos, and with PFLARE_KOKKOS_DEBUG=1

🤖 Generated with Claude Code

…ocal column indices to prevent OOB errors

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@stevendargaville
stevendargaville merged commit 3da7c42 into main Aug 1, 2026
19 checks passed
@stevendargaville
stevendargaville deleted the kokkos_local_sort_indices branch August 1, 2026 21:40
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.

1 participant