Skip to content

Commit

Permalink
Lapack: gesv, implementing review commments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Nov 21, 2023
1 parent 55433b9 commit 999c346
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
1 change: 1 addition & 0 deletions common/src/KokkosKernels_PrintConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ inline void print_enabled_tpls(std::ostream& os) {
#endif
print_cublas_version_if_enabled(os);
print_cusparse_version_if_enabled(os);
print_cusolver_version_if_enabled(os);
#ifdef KOKKOSKERNELS_ENABLE_TPL_ROCBLAS
os << " "
<< "KOKKOSKERNELS_ENABLE_TPL_ROCBLAS: yes\n";
Expand Down
92 changes: 47 additions & 45 deletions lapack/tpls/KokkosLapack_gesv_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void lapackGesvWrapper(const AViewType& A, const BViewType& B,
}
}

#define KOKKOSLAPACK_GESV_LAPACK(SCALAR, LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \
#define KOKKOSLAPACK_GESV_LAPACK(SCALAR, LAYOUT, MEM_SPACE) \
template <class ExecSpace> \
struct GESV< \
ExecSpace, \
Expand All @@ -86,7 +86,14 @@ void lapackGesvWrapper(const AViewType& A, const BViewType& B,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<int*, LAYOUT, Kokkos::Device<ExecSpace, Kokkos::HostSpace>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
true, ETI_SPEC_AVAIL> { \
true, \
gesv_tpl_spec_avail<ExecSpace,\
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<int*, LAYOUT, Kokkos::Device<ExecSpace, Kokkos::HostSpace>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>>::value> { \
using AViewType = \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>; \
Expand All @@ -107,21 +114,12 @@ void lapackGesvWrapper(const AViewType& A, const BViewType& B,
} \
};

KOKKOSLAPACK_GESV_LAPACK(float, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
KOKKOSLAPACK_GESV_LAPACK(float, Kokkos::LayoutLeft, Kokkos::HostSpace, false)

KOKKOSLAPACK_GESV_LAPACK(double, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
KOKKOSLAPACK_GESV_LAPACK(double, Kokkos::LayoutLeft, Kokkos::HostSpace, false)

KOKKOSLAPACK_GESV_LAPACK(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::HostSpace, true)
KOKKOSLAPACK_GESV_LAPACK(float, Kokkos::LayoutLeft, Kokkos::HostSpace)
KOKKOSLAPACK_GESV_LAPACK(double, Kokkos::LayoutLeft, Kokkos::HostSpace)
KOKKOSLAPACK_GESV_LAPACK(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::HostSpace, false)

KOKKOSLAPACK_GESV_LAPACK(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::HostSpace, true)
Kokkos::HostSpace)
KOKKOSLAPACK_GESV_LAPACK(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::HostSpace, false)
Kokkos::HostSpace)

} // namespace Impl
} // namespace KokkosLapack
Expand Down Expand Up @@ -390,7 +388,7 @@ KOKKOSLAPACK_CGESV_MAGMA(Kokkos::LayoutLeft, Kokkos::CudaSpace, false)
} // namespace KokkosLapack
#endif // KOKKOSKERNELS_ENABLE_TPL_MAGMA

// ROCSOLVER
// CUSOLVER
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSOLVER
#include "KokkosLapack_cusolver.hpp"

Expand Down Expand Up @@ -483,7 +481,7 @@ void cusolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
KOKKOS_CUSOLVER_SAFE_CALL_IMPL(cusolverDnSetStream(s.handle, NULL));
}

#define KOKKOSLAPACK_GESV_CUSOLVER(SCALAR, LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \
#define KOKKOSLAPACK_GESV_CUSOLVER(SCALAR, LAYOUT, MEM_SPACE) \
template <> \
struct GESV< \
Kokkos::Cuda, \
Expand All @@ -493,7 +491,14 @@ void cusolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<int*, LAYOUT, Kokkos::Device<Kokkos::Cuda, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
true, ETI_SPEC_AVAIL> { \
true, \
gesv_tpl_spec_avail<Kokkos::Cuda, \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<Kokkos::Cuda, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<Kokkos::Cuda, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<int*, LAYOUT, Kokkos::Device<Kokkos::Cuda, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>>::value> { \
using AViewType = Kokkos::View<SCALAR**, LAYOUT, \
Kokkos::Device<Kokkos::Cuda, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>; \
Expand All @@ -515,21 +520,21 @@ void cusolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
} \
};

KOKKOSLAPACK_GESV_CUSOLVER(float, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
KOKKOSLAPACK_GESV_CUSOLVER(float, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)

KOKKOSLAPACK_GESV_CUSOLVER(double, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
KOKKOSLAPACK_GESV_CUSOLVER(double, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)

KOKKOSLAPACK_GESV_CUSOLVER(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::CudaSpace, true)
KOKKOSLAPACK_GESV_CUSOLVER(float, Kokkos::LayoutLeft, Kokkos::CudaSpace)
KOKKOSLAPACK_GESV_CUSOLVER(double, Kokkos::LayoutLeft, Kokkos::CudaSpace)
KOKKOSLAPACK_GESV_CUSOLVER(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::CudaSpace, false)

Kokkos::CudaSpace)
KOKKOSLAPACK_GESV_CUSOLVER(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::CudaSpace, true)
Kokkos::CudaSpace)

#if defined(KOKKOSKERNELS_INST_MEMSPACE_CUDAUVMSPACE)
KOKKOSLAPACK_GESV_CUSOLVER(float, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace)
KOKKOSLAPACK_GESV_CUSOLVER(double, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace)
KOKKOSLAPACK_GESV_CUSOLVER(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::CudaUVMSpace)
KOKKOSLAPACK_GESV_CUSOLVER(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::CudaSpace, false)
Kokkos::CudaUVMSpace)
#endif

} // namespace Impl
} // namespace KokkosLapack
Expand Down Expand Up @@ -590,7 +595,7 @@ void rocsolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
KOKKOS_ROCBLAS_SAFE_CALL_IMPL(rocblas_set_stream(s.handle, NULL));
}

#define KOKKOSLAPACK_GESV_ROCSOLVER(SCALAR, LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \
#define KOKKOSLAPACK_GESV_ROCSOLVER(SCALAR, LAYOUT, MEM_SPACE) \
template <class ExecSpace> \
struct GESV< \
ExecSpace, \
Expand All @@ -600,7 +605,13 @@ void rocsolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<rocblas_int*, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
true, ETI_SPEC_AVAIL> { \
true, gesv_tpl_spec_avail<ExecSpace, \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>, \
Kokkos::View<rocblas_int*, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>>::value> { \
using AViewType = \
Kokkos::View<SCALAR**, LAYOUT, Kokkos::Device<ExecSpace, MEM_SPACE>, \
Kokkos::MemoryTraits<Kokkos::Unmanaged>>; \
Expand All @@ -622,21 +633,12 @@ void rocsolverGesvWrapper(const ExecutionSpace& space, const IPIVViewType& IPIV,
} \
};

KOKKOSLAPACK_GESV_ROCSOLVER(float, Kokkos::LayoutLeft, Kokkos::HIPSpace, true)
KOKKOSLAPACK_GESV_ROCSOLVER(float, Kokkos::LayoutLeft, Kokkos::HIPSpace, false)

KOKKOSLAPACK_GESV_ROCSOLVER(double, Kokkos::LayoutLeft, Kokkos::HIPSpace, true)
KOKKOSLAPACK_GESV_ROCSOLVER(double, Kokkos::LayoutLeft, Kokkos::HIPSpace, false)

KOKKOSLAPACK_GESV_ROCSOLVER(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::HIPSpace, true)
KOKKOSLAPACK_GESV_ROCSOLVER(float, Kokkos::LayoutLeft, Kokkos::HIPSpace)
KOKKOSLAPACK_GESV_ROCSOLVER(double, Kokkos::LayoutLeft, Kokkos::HIPSpace)
KOKKOSLAPACK_GESV_ROCSOLVER(Kokkos::complex<float>, Kokkos::LayoutLeft,
Kokkos::HIPSpace, false)

KOKKOSLAPACK_GESV_ROCSOLVER(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::HIPSpace, true)
Kokkos::HIPSpace)
KOKKOSLAPACK_GESV_ROCSOLVER(Kokkos::complex<double>, Kokkos::LayoutLeft,
Kokkos::HIPSpace, false)
Kokkos::HIPSpace)

} // namespace Impl
} // namespace KokkosLapack
Expand Down
10 changes: 5 additions & 5 deletions lapack/unit_test/Test_Lapack_gesv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ void impl_test_gesv(const char* mode, const char* padding, int N) {
for (int i = 0; i < N; i++) {
if (ats::abs(h_B(i) - h_X0(i)) > eps) {
test_flag = false;
printf(
" Error %d, pivot %c, padding %c: result( %.15lf ) !="
"solution( %.15lf ) at (%d), error=%.15e, eps=%.15e\n",
N, mode[0], padding[0], ats::abs(h_B(i)), ats::abs(h_X0(i)), int(i),
ats::abs(h_B(i) - h_X0(i)), eps);
// printf(
// " Error %d, pivot %c, padding %c: result( %.15lf ) !="
// "solution( %.15lf ) at (%d), error=%.15e, eps=%.15e\n",
// N, mode[0], padding[0], ats::abs(h_B(i)), ats::abs(h_X0(i)), int(i),
// ats::abs(h_B(i) - h_X0(i)), eps);
// break;
}
}
Expand Down

0 comments on commit 999c346

Please sign in to comment.