Skip to content

Commit

Permalink
Fix usage of RAII to set cusparse/rocsparse stream (#2141)
Browse files Browse the repository at this point in the history
Temporary objects like "A()" get destructed immediately.
For the object to have scope lifetime, it needs a name like "A a();".
This was causing cusparse/rocsparse spmv to always execute on the default stream,
causing incorrect timing in the spmv perf test.
  • Loading branch information
brian-kelley authored Mar 14, 2024
1 parent a3b7568 commit f492f59
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sparse/tpls/KokkosSparse_spmv_bsrmatrix_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void spmv_bsr_cusparse(const Kokkos::Cuda& exec, Handle* handle,
cusparseHandle_t cusparseHandle =
KokkosKernels::Impl::CusparseSingleton::singleton().cusparseHandle;
/* Set cuSPARSE to use the given stream until this function exits */
KokkosSparse::Impl::TemporarySetCusparseStream(cusparseHandle, exec);
KokkosSparse::Impl::TemporarySetCusparseStream tscs(cusparseHandle, exec);

/* Set the operation mode */
cusparseOperation_t myCusparseOperation;
Expand Down Expand Up @@ -487,7 +487,7 @@ void spmv_mv_bsr_cusparse(const Kokkos::Cuda& exec, Handle* handle,
cusparseHandle_t cusparseHandle =
KokkosKernels::Impl::CusparseSingleton::singleton().cusparseHandle;
/* Set cuSPARSE to use the given stream until this function exits */
KokkosSparse::Impl::TemporarySetCusparseStream(cusparseHandle, exec);
KokkosSparse::Impl::TemporarySetCusparseStream tscs(cusparseHandle, exec);

/* Set the operation mode */
cusparseOperation_t myCusparseOperation;
Expand Down
2 changes: 1 addition & 1 deletion sparse/tpls/KokkosSparse_spmv_mv_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void spmv_mv_cusparse(const Kokkos::Cuda &exec, Handle *handle,
cusparseHandle_t cusparseHandle =
KokkosKernels::Impl::CusparseSingleton::singleton().cusparseHandle;
/* Set cuSPARSE to use the given stream until this function exits */
TemporarySetCusparseStream(cusparseHandle, exec);
TemporarySetCusparseStream tscs(cusparseHandle, exec);

/* Check that cusparse can handle the types of the input Kokkos::CrsMatrix */
const cusparseIndexType_t myCusparseOffsetType =
Expand Down
4 changes: 2 additions & 2 deletions sparse/tpls/KokkosSparse_spmv_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void spmv_cusparse(const Kokkos::Cuda& exec, Handle* handle, const char mode[],
cusparseHandle_t cusparseHandle =
KokkosKernels::Impl::CusparseSingleton::singleton().cusparseHandle;
/* Set cuSPARSE to use the given stream until this function exits */
TemporarySetCusparseStream(cusparseHandle, exec);
TemporarySetCusparseStream tscs(cusparseHandle, exec);

/* Set the operation mode */
cusparseOperation_t myCusparseOperation;
Expand Down Expand Up @@ -389,7 +389,7 @@ void spmv_rocsparse(const Kokkos::HIP& exec, Handle* handle, const char mode[],
rocsparse_handle rocsparseHandle =
KokkosKernels::Impl::RocsparseSingleton::singleton().rocsparseHandle;
/* Set rocsparse to use the given stream until this function exits */
TemporarySetRocsparseStream(rocsparseHandle, exec);
TemporarySetRocsparseStream tsrs(rocsparseHandle, exec);

/* Set the operation mode */
rocsparse_operation myRocsparseOperation = mode_kk_to_rocsparse(mode);
Expand Down

0 comments on commit f492f59

Please sign in to comment.