Skip to content

Commit

Permalink
Sparse: fix some issues raised in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Sep 21, 2023
1 parent 934c5e9 commit 090d799
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
8 changes: 0 additions & 8 deletions sparse/impl/KokkosSparse_CrsMatrix_traversal_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ int64_t crsmatrix_traversal_launch_parameters(int64_t numRows, int64_t nnz,

rows_per_team = rows_per_thread * team_size;

if (rows_per_team < 0) {
int64_t nnz_per_team = 4096;
int64_t conc = execution_space().concurrency();
while ((conc * nnz_per_team * 4 > nnz) && (nnz_per_team > 256))
nnz_per_team /= 2;
rows_per_team = (nnz_per_team + nnz_per_row - 1) / nnz_per_row;
}

return rows_per_team;
}

Expand Down
38 changes: 37 additions & 1 deletion sparse/src/KokkosSparse_CrsMatrix_traversal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/// \file KokkosSparse_CrsMatrix_traversal.hpp
/// \brief Traversal method to access all entries in a CrsMatrix
///
/// blah
/// This file provides a public interface to traversal
/// methods that are used as a common and efficient way
/// to access entries in a matrix on host and/or device.

#ifndef KOKKOSSPARSE_CRSMATRIX_TRAVERSAL_HPP
#define KOKKOSSPARSE_CRSMATRIX_TRAVERSAL_HPP
Expand All @@ -32,9 +34,30 @@
namespace KokkosSparse {
namespace Experimental {


/// \brief Public interface to sparse matrix traversal algorithm.
///
/// Loop over the entries of the input matrix and apply the functor
/// to them. The functor itself may contain its own data to save results
/// after the traversal completes.
///
/// \tparam execution_space
/// \tparam crsmatrix_type
/// \tparam functor_type
///
/// \param space [in] execution space instance that specifies where the kernel
/// will be executed.
/// \param matrix [in] the matrix to be traversed.
/// \param functor [in] a functor that is being called on each local entries
/// of the crsmatrix and that implement a user defined capabilities.
///
template <class execution_space, class crsmatrix_type, class functor_type>
void crsmatrix_traversal(const execution_space& space,
const crsmatrix_type& matrix, functor_type& functor) {

// Check if a quick return can be performed
if(!matrix.nnz()) { return; }

// Choose between device and host implementation
if constexpr (KokkosKernels::Impl::kk_is_gpu_exec_space<execution_space>()) {
KokkosSparse::Impl::crsmatrix_traversal_on_gpu(space, matrix, functor);
Expand All @@ -43,6 +66,19 @@ void crsmatrix_traversal(const execution_space& space,
}
}

/// \brief Public interface to sparse matrix traversal algorithm.
///
/// Loop over the entries of the input matrix and apply the functor
/// to them. The functor itself may contain its own data to save results
/// after the traversal completes.
///
/// \tparam crsmatrix_type
/// \tparam functor_type
///
/// \param matrix [in] the matrix to be traversed.
/// \param functor [in] a functor that is being called on each local entries
/// of the crsmatrix and that implement a user defined capabilities.
///
template <class crsmatrix_type, class functor_type>
void crsmatrix_traversal(const crsmatrix_type& matrix, functor_type& functor) {
using execution_space = typename crsmatrix_type::execution_space;
Expand Down

0 comments on commit 090d799

Please sign in to comment.