Skip to content

Commit

Permalink
Sparse - sptrsv: final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed May 21, 2024
1 parent e5bfc84 commit 83c9200
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions sparse/src/KokkosSparse_sptrsv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ void sptrsv_symbolic(ExecutionSpace &space, KernelHandle *handle,
Entries_Internal entries_i = entries;
Values_Internal values_i = values;

typedef typename KernelHandle::SPTRSVHandleType sptrsvHandleType;
sptrsvHandleType *sh = handle->get_sptrsv_handle();
// typedef typename KernelHandle::SPTRSVHandleType sptrsvHandleType;
// sptrsvHandleType *sh = handle->get_sptrsv_handle();
// auto nrows = sh->get_nrows();

std::string label = "KokkosSparse::sptrsv[TPL_CUSPARSE,"
Expand Down
12 changes: 7 additions & 5 deletions sparse/tpls/KokkosSparse_sptrsv_solve_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,
using size_type = typename KernelHandle::size_type;
using scalar_type = typename KernelHandle::scalar_t;

const idx_type nrows = sptrsv_handle->get_nrows();

#if (CUDA_VERSION >= 11030)
using memory_space = typename KernelHandle::memory_space;

Expand All @@ -49,7 +51,7 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,

// cusparseDnVecDescr_t vecBDescr, vecXDescr;

const idx_type nrows = sptrsv_handle->get_nrows();
// const idx_type nrows = sptrsv_handle->get_nrows();
typename KernelHandle::SPTRSVcuSparseHandleType *h =
sptrsv_handle->get_cuSparseHandle();

Expand Down Expand Up @@ -80,7 +82,7 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,

cusparseStatus_t status;

const idx_type nrows = sptrsv_handle->get_nrows();
// const idx_type nrows = sptrsv_handle->get_nrows();
typename KernelHandle::SPTRSVcuSparseHandleType *h =
sptrsv_handle->get_cuSparseHandle();

Expand Down Expand Up @@ -108,7 +110,7 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,

if (CUSPARSE_STATUS_SUCCESS != status)
std::cout << "solve status error name " << (status) << std::endl;
} else if (std::is_same<scalar_type, float>::value) {
} else if constexpr (std::is_same<scalar_type, float>::value) {
if (h->pBuffer == nullptr) {
std::cout << " pBuffer invalid" << std::endl;
}
Expand All @@ -121,7 +123,7 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,

if (CUSPARSE_STATUS_SUCCESS != status)
std::cout << "solve status error name " << (status) << std::endl;
} else if (std::is_same<scalar_type, Kokkos::complex<double> >::value) {
} else if constexpr (std::is_same_v<scalar_type, Kokkos::complex<double> >) {
cuDoubleComplex cualpha;
cualpha.x = 1.0;
cualpha.y = 0.0;
Expand All @@ -132,7 +134,7 @@ void sptrsv_solve_cusparse(ExecutionSpace& space,

if (CUSPARSE_STATUS_SUCCESS != status)
std::cout << "solve status error name " << (status) << std::endl;
} else if (std::is_same<scalar_type, Kokkos::complex<float> >::value) {
} else if constexpr (std::is_same_v<scalar_type, Kokkos::complex<float> >) {
cuComplex cualpha;
cualpha.x = 1.0;
cualpha.y = 0.0;
Expand Down
25 changes: 12 additions & 13 deletions sparse/tpls/KokkosSparse_sptrsv_symbolic_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle
ain_nonzero_index_view_type entries,
ain_values_scalar_view_type values, const bool trans) {
using idx_type = typename KernelHandle::nnz_lno_t;
using size_type = typename KernelHandle::size_type;
using scalar_type = typename KernelHandle::scalar_t;
using memory_space = typename KernelHandle::memory_space;

const idx_type nrows = sptrsv_handle->get_nrows();

#if (CUDA_VERSION >= 11030)
using nnz_scalar_view_t = typename KernelHandle::nnz_scalar_view_t;
Expand All @@ -45,7 +45,6 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle
const bool is_lower = sptrsv_handle->is_lower_tri();
sptrsv_handle->create_cuSPARSE_Handle(trans, is_lower);

const idx_type nrows = sptrsv_handle->get_nrows();
typename KernelHandle::SPTRSVcuSparseHandleType *h =
sptrsv_handle->get_cuSparseHandle();

Expand Down Expand Up @@ -122,11 +121,11 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle
int nnz = entries.extent_int(0);
int pBufferSize;

const scalar_type *vals = values.data();
// const scalar_type *vals = values.data();

if constexpr (std::is_same<scalar_type, double>::value) {
KOKKOS_CUSPARSE_SAFE_CALL(cusparseDcsrsv2_bufferSize(h->handle, h->transpose, nrows, nnz, h->descr,
values.data(), row_map.data(), entries.data(),
const_cast<double*>(values.data()), row_map.data(), entries.data(),
h->info, &pBufferSize));

// pBuffer returned by cudaMalloc is automatically aligned to 128 bytes.
Expand All @@ -140,9 +139,9 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle
KOKKOS_CUSPARSE_SAFE_CALL(cusparseDcsrsv2_analysis(
h->handle, h->transpose, nrows, nnz, h->descr, values.data(),
row_map.data(), entries.data(), h->info, h->policy, h->pBuffer));
} else if (std::is_same<scalar_type, float>::value) {
} else if constexpr (std::is_same<scalar_type, float>::value) {
KOKKOS_CUSPARSE_SAFE_CALL(cusparseScsrsv2_bufferSize(h->handle, h->transpose, nrows, nnz, h->descr,
values.data(), row_map.data(), entries.data(), h->info,
const_cast<float*>(values.data()), row_map.data(), entries.data(), h->info,
&pBufferSize));

// pBuffer returned by cudaMalloc is automatically aligned to 128 bytes.
Expand All @@ -155,9 +154,9 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle

KOKKOS_CUSPARSE_SAFE_CALL(cusparseScsrsv2_analysis(h->handle, h->transpose, nrows, nnz, h->descr, values.data(),
row_map.data(), entries.data(), h->info, h->policy, h->pBuffer));
} else if (std::is_same<scalar_type, Kokkos::complex<double> >::value) {
} else if constexpr (std::is_same<scalar_type, Kokkos::complex<double> >::value) {
KOKKOS_CUSPARSE_SAFE_CALL(cusparseZcsrsv2_bufferSize(h->handle, h->transpose, nrows, nnz, h->descr,
reinterpret_cast<cuDoubleComplex *>(values.data()), row_map.data(),
reinterpret_cast<cuDoubleComplex *>(const_cast<Kokkos::complex<double>*>(values.data())), row_map.data(),
entries.data(), h->info, &pBufferSize));

// pBuffer returned by cudaMalloc is automatically aligned to 128 bytes.
Expand All @@ -169,11 +168,11 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle
<< cudaGetErrorString(my_error) << std::endl;

KOKKOS_CUSPARSE_SAFE_CALL(cusparseZcsrsv2_analysis(h->handle, h->transpose, nrows, nnz,
h->descr, reinterpret_cast<cuDoubleComplex *>(values.data()),
h->descr, reinterpret_cast<cuDoubleComplex *>(const_cast<Kokkos::complex<double>*>(values.data())),
row_map.data(), entries.data(), h->info, h->policy, h->pBuffer));
} else if (std::is_same<scalar_type, Kokkos::complex<float> >::value) {
} else if constexpr (std::is_same<scalar_type, Kokkos::complex<float> >::value) {
KOKKOS_CUSPARSE_SAFE_CALL(cusparseCcsrsv2_bufferSize(h->handle, h->transpose, nrows, nnz, h->descr,
reinterpret_cast<cuComplex *>(values.data()),
reinterpret_cast<cuComplex *>(const_cast<Kokkos::complex<float>*>(values.data())),
row_map.data(), entries.data(), h->info, &pBufferSize));

// pBuffer returned by cudaMalloc is automatically aligned to 128 bytes.
Expand All @@ -186,7 +185,7 @@ void sptrsv_analysis_cusparse(ExecutionSpace &space, KernelHandle *sptrsv_handle

KOKKOS_CUSPARSE_SAFE_CALL(cusparseCcsrsv2_analysis(
h->handle, h->transpose, nrows, nnz, h->descr,
reinterpret_cast<cuComplex *>(values.data()),
reinterpret_cast<cuComplex *>(const_cast<Kokkos::complex<float>*>(values.data())),
row_map.data(), entries.data(), h->info, h->policy, h->pBuffer));
}
#endif // CUDA_VERSION >= 11030
Expand Down
21 changes: 10 additions & 11 deletions sparse/unit_test/Test_Sparse_sptrsv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ struct SptrsvTest {
}

#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSPARSE
if (std::is_same<size_type, int>::value &&
std::is_same<lno_t, int>::value &&
std::is_same<typename device::execution_space, Kokkos::Cuda>::value) {
if (std::is_same_v<size_type, int> &&
std::is_same_v<lno_t, int> &&
std::is_same_v<typename device::execution_space, Kokkos::Cuda>) {
{
Kokkos::deep_copy(lhs, ZERO);
KernelHandle kh;
Expand Down Expand Up @@ -480,9 +480,9 @@ struct SptrsvTest {
}

#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSPARSE
if (std::is_same<size_type, int>::value &&
std::is_same<lno_t, int>::value &&
std::is_same<typename device::execution_space, Kokkos::Cuda>::value) {
if (std::is_same_v<size_type, int> &&
std::is_same_v<lno_t, int> &&
std::is_same_v<typename device::execution_space, Kokkos::Cuda>) {
Kokkos::deep_copy(lhs, ZERO);
KernelHandle kh;
bool is_lower_tri = true;
Expand Down Expand Up @@ -657,7 +657,7 @@ struct SptrsvTest {
// not enough resource to partition
bool run_streams_test = true;
#ifdef KOKKOS_ENABLE_OPENMP
if (std::is_same<typename device::execution_space, Kokkos::OpenMP>::value) {
if (std::is_same_v<typename device::execution_space, Kokkos::OpenMP>) {
int exec_concurrency = execution_space().concurrency();
if (exec_concurrency < nstreams) {
run_streams_test = false;
Expand Down Expand Up @@ -840,7 +840,6 @@ template <typename scalar_t, typename lno_t, typename size_type,
void test_sptrsv() {
using TestStruct = Test::SptrsvTest<scalar_t, lno_t, size_type, device>;
TestStruct::run_test_sptrsv();
std::cout << "Done with test_sptrsv" << std::endl;
}

template <typename scalar_t, typename lno_t, typename size_type,
Expand All @@ -858,15 +857,15 @@ void test_sptrsv_streams() {
TestStruct::run_test_sptrsv_streams(1, 4);

#if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOSKERNELS_ENABLE_TPL_CUSPARSE)
if (std::is_same<lno_t, int>::value &&
std::is_same<typename device::execution_space, Kokkos::Cuda>::value) {
if (std::is_same_v<size_type, int> &&
std::is_same_v<lno_t, int> &&
std::is_same_v<typename device::execution_space, Kokkos::Cuda>) {
TestStruct::run_test_sptrsv_streams(2, 1);
TestStruct::run_test_sptrsv_streams(2, 2);
TestStruct::run_test_sptrsv_streams(2, 3);
TestStruct::run_test_sptrsv_streams(2, 4);
}
#endif
std::cout << "Done with test_sptrsv_streams" << std::endl;
}

#define KOKKOSKERNELS_EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \
Expand Down

0 comments on commit 83c9200

Please sign in to comment.