Skip to content

Commit

Permalink
Sparse Utils: fixing some spelling and alias namespaces
Browse files Browse the repository at this point in the history
Using namespace alias is preferable to importing the
content of namespaces since it avoids potential clashes.
Of course using fully specified function names is also fine.

Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
  • Loading branch information
lucbv committed Jul 14, 2022
1 parent 86ea702 commit 35e2f62
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 63 deletions.
2 changes: 1 addition & 1 deletion perf_test/sparse/KokkosSparse_block_pcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void run_experiment(
// typedef typename lno_nnz_view_t::value_type lno_t;
// typedef typename lno_view_t::value_type size_type;
// typedef typename scalar_view_t::value_type scalar_t;
KokkosSparse::Impl::kk_create_blockcrs_formated_point_crsmatrix(
KokkosSparse::Impl::kk_create_blockcrs_formatted_point_crsmatrix(
block_size, crsmat.numRows(), crsmat.numCols(), crsmat.graph.row_map,
crsmat.graph.entries, crsmat.values, out_r, out_c, pf_rm, pf_e, pf_v);

Expand Down
33 changes: 14 additions & 19 deletions perf_test/sparse/KokkosSparse_sptrsv_supernode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@

#include "KokkosSparse_sptrsv_aux.hpp"

using namespace KokkosKernels;
using namespace KokkosKernels::Impl;
using namespace KokkosKernels::Experimental;
using namespace KokkosSparse;
using namespace KokkosSparse::Impl;
using namespace KokkosSparse::Experimental;
using namespace KokkosSparse::PerfTest::Experimental;
namespace KSExp = KokkosSparse::Experimental;
namespace KSPTE = KokkosSparse::PerfTest::Experimental;

enum {
CUSPARSE,
Expand Down Expand Up @@ -213,23 +208,23 @@ int test_sptrsv_perf(std::vector<int> tests, bool verbose,
if (test == SUPERNODAL_NAIVE) {
std::cout << " > create handle for SUPERNODAL_NAIVE" << std::endl
<< std::endl;
khL.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_NAIVE, nrows,
khL.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_NAIVE, nrows,
true);
khU.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_NAIVE, nrows,
khU.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_NAIVE, nrows,
true);
} else if (test == SUPERNODAL_DAG) {
std::cout << " > create handle for SUPERNODAL_DAG" << std::endl
<< std::endl;
khL.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_DAG, nrows,
khL.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_DAG, nrows,
true);
khU.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_DAG, nrows,
khU.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_DAG, nrows,
true);
} else if (test == SUPERNODAL_SPMV_DAG) {
std::cout << " > create handle for SUPERNODAL_SPMV_DAG" << std::endl
<< std::endl;
khL.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_SPMV_DAG,
khL.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_SPMV_DAG,
nrows, true);
khU.create_sptrsv_handle(SPTRSVAlgorithm::SUPERNODAL_SPMV_DAG,
khU.create_sptrsv_handle(KSExp::SPTRSVAlgorithm::SUPERNODAL_SPMV_DAG,
nrows, true);
}
// verbose (optional, default is false)
Expand All @@ -255,13 +250,13 @@ int test_sptrsv_perf(std::vector<int> tests, bool verbose,
// graph/dag)
khU.get_sptrsv_handle()->set_column_major(
!khL.get_sptrsv_handle()->is_column_major());
sptrsv_supernodal_symbolic(nsuper, supercols.data(), etree, L.graph,
&khL, L.graph, &khU);
KSExp::sptrsv_supernodal_symbolic(nsuper, supercols.data(), etree, L.graph,
&khL, L.graph, &khU);

// ==============================================
// do numeric compute (copy numerical values from SuperLU data
// structure to our sptrsv data structure)
sptrsv_compute(&khL, L);
KSExp::sptrsv_compute(&khL, L);

// ==============================================
// Preaparing for the first solve
Expand All @@ -285,7 +280,7 @@ int test_sptrsv_perf(std::vector<int> tests, bool verbose,
// ==============================================
// do L solve
timer.reset();
sptrsv_solve(&khL, sol, rhs);
KSExp::sptrsv_solve(&khL, sol, rhs);
Kokkos::fence();
std::cout << " > Lower-TRI: " << std::endl;
std::cout << " Solve Time : " << timer.seconds() << std::endl;
Expand All @@ -297,7 +292,7 @@ int test_sptrsv_perf(std::vector<int> tests, bool verbose,
// Error Check ** on host **
Kokkos::fence();
std::cout << std::endl;
if (!check_errors(tol, A, rhs_host, sol_host)) {
if (!KSPTE::check_errors(tol, A, rhs_host, sol_host)) {
num_failed++;
}

Expand All @@ -309,7 +304,7 @@ int test_sptrsv_perf(std::vector<int> tests, bool verbose,
Kokkos::fence();
for (int i = 0; i < loop; i++) {
timer.reset();
sptrsv_solve(&khL, sol, rhs);
KSExp::sptrsv_solve(&khL, sol, rhs);
Kokkos::fence();
double time = timer.seconds();
ave_time += time;
Expand Down
6 changes: 3 additions & 3 deletions src/sparse/KokkosSparse_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Impl {
template <typename in_row_view_t, typename in_nnz_view_t,
typename in_val_view_t, typename out_row_view_t,
typename out_nnz_view_t, typename out_val_view_t>
void kk_create_blockcrs_formated_point_crsmatrix(
void kk_create_blockcrs_formatted_point_crsmatrix(
int block_size, size_t num_rows, size_t num_cols, in_row_view_t in_xadj,
in_nnz_view_t in_adj, in_val_view_t in_vals,

Expand Down Expand Up @@ -1958,7 +1958,7 @@ struct MatrixConverter<BlockCRS> {
KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>,
typename blockCrsMat_t = KokkosSparse::Experimental::BlockCrsMatrix<
scalar_t, lno_t, device, void, size_type>>
static blockCrsMat_t from_blockcrs_formated_point_crsmatrix(
static blockCrsMat_t from_blockcrs_formatted_point_crsmatrix(
const KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>
&mtx,
lno_t block_size) {
Expand All @@ -1972,7 +1972,7 @@ struct MatrixConverter<BSR> {
typename device,
typename bsrMtx_t = KokkosSparse::Experimental::BsrMatrix<
scalar_t, lno_t, device, void, size_type>>
static bsrMtx_t from_blockcrs_formated_point_crsmatrix(
static bsrMtx_t from_blockcrs_formatted_point_crsmatrix(
const KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>
&mtx,
lno_t block_size) {
Expand Down
68 changes: 28 additions & 40 deletions unit_test/sparse/Test_Sparse_block_gauss_seidel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,10 @@
#include <complex>
#include "KokkosSparse_gauss_seidel.hpp"

// #ifndef kokkos_complex_double
// #define kokkos_complex_double Kokkos::complex<double>
// #define kokkos_complex_float Kokkos::complex<float>
// #endif
using kokkos_complex_double = Kokkos::complex<double>;
using kokkos_complex_float = Kokkos::complex<float>;

typedef Kokkos::complex<double> kokkos_complex_double;
typedef Kokkos::complex<float> kokkos_complex_float;

using namespace KokkosKernels;
using namespace KokkosKernels::Impl;
using namespace KokkosKernels::Experimental;
using namespace KokkosSparse;
using namespace KokkosSparse::Impl;
using namespace KokkosSparse::Experimental;
namespace KSExp = KokkosSparse::Experimental;

namespace Test {

Expand All @@ -92,7 +82,7 @@ struct GSTestParams {

// Note: GS_DEFAULT is same as GS_TEAM and - for blocks - as GS_PERMUTED
// Note: GS_TWOSTAGE and GS_CLUSTER are not supported for blocks
std::vector<GSAlgorithm> gs_algorithms = {GS_DEFAULT};
std::vector<KokkosSparse::GSAlgorithm> gs_algorithms = {KokkosSparse::GS_DEFAULT};
std::vector<size_t> shmem_sizes = {
32128,
2008 // make the shmem small on gpus so that it will test 2 level
Expand Down Expand Up @@ -121,12 +111,11 @@ int run_block_gauss_seidel_1(
typedef typename lno_nnz_view_t::value_type lno_t;
typedef typename scalar_view_t::value_type scalar_t;

constexpr auto format = MatrixTraits<mtx_t>::format;
constexpr auto format = KokkosSparse::Impl::MatrixTraits<mtx_t>::format;

typedef KokkosKernelsHandle<
using KernelHandle = KokkosKernels::Experimental::KokkosKernelsHandle<
size_type, lno_t, scalar_t, typename mtx_t::execution_space,
typename mtx_t::memory_space, typename mtx_t::memory_space>
KernelHandle;
typename mtx_t::memory_space, typename mtx_t::memory_space>;
KernelHandle kh;
kh.set_team_work_size(16);
kh.set_shmem_size(shmem_size);
Expand All @@ -138,33 +127,33 @@ int run_block_gauss_seidel_1(
const int apply_count = 100;

if (!skip_symbolic) {
block_gauss_seidel_symbolic(&kh, num_rows_1, num_cols_1, block_size,
KSExp::block_gauss_seidel_symbolic(&kh, num_rows_1, num_cols_1, block_size,
input_mat.graph.row_map,
input_mat.graph.entries, is_symmetric_graph);
}

if (!skip_numeric) {
block_gauss_seidel_numeric<format>(
KSExp::block_gauss_seidel_numeric<format>(
&kh, num_rows_1, num_cols_1, block_size, input_mat.graph.row_map,
input_mat.graph.entries, input_mat.values, is_symmetric_graph);
}

switch (apply_type) {
case Test::forward_sweep:
forward_sweep_block_gauss_seidel_apply<format>(
KSExp::forward_sweep_block_gauss_seidel_apply<format>(
&kh, num_rows_1, num_cols_1, block_size, input_mat.graph.row_map,
input_mat.graph.entries, input_mat.values, x_vector, y_vector, false,
true, omega, apply_count);
break;
case Test::backward_sweep:
backward_sweep_block_gauss_seidel_apply<format>(
KSExp::backward_sweep_block_gauss_seidel_apply<format>(
&kh, num_rows_1, num_cols_1, block_size, input_mat.graph.row_map,
input_mat.graph.entries, input_mat.values, x_vector, y_vector, false,
true, omega, apply_count);
break;
case Test::symmetric:
default:
symmetric_block_gauss_seidel_apply<format>(
KSExp::symmetric_block_gauss_seidel_apply<format>(
&kh, num_rows_1, num_cols_1, block_size, input_mat.graph.row_map,
input_mat.graph.entries, input_mat.values, x_vector, y_vector, false,
true, omega, apply_count);
Expand All @@ -183,9 +172,9 @@ void test_block_gauss_seidel_rank1(lno_t numRows, size_type nnz,
lno_t bandwidth, lno_t row_size_variance) {
using namespace Test;
srand(245);
typedef
typename KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>
crsMat_t;
using crsMat_t =
typename KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>;
using MatrixConverter = KokkosSparse::Impl::MatrixConverter<mtx_format>;

typedef typename device::execution_space exec_space;
typedef typename crsMat_t::StaticCrsGraphType graph_t;
Expand Down Expand Up @@ -213,15 +202,15 @@ void test_block_gauss_seidel_rank1(lno_t numRows, size_type nnz,
// this makes consecutive 5 rows to have same columns.
// it will add scalar 0's for those entries that does not exists.
// the result is still a point crs matrix.
KokkosSparse::Impl::kk_create_blockcrs_formated_point_crsmatrix(
KokkosSparse::Impl::kk_create_blockcrs_formatted_point_crsmatrix(
block_size, crsmat.numRows(), crsmat.numCols(), crsmat.graph.row_map,
crsmat.graph.entries, crsmat.values, out_r, out_c, pf_rm, pf_e, pf_v);
graph_t static_graph2(pf_e, pf_rm);
crsMat_t crsmat2("CrsMatrix2", out_c, pf_v, static_graph2);

// this converts the previous generated matrix to block matrix.
auto input_mat =
MatrixConverter<mtx_format>::from_blockcrs_formated_point_crsmatrix(
MatrixConverter::from_blockcrs_formatted_point_crsmatrix(
crsmat2, block_size);

lno_t nv = ((crsmat2.numRows() + block_size - 1) / block_size) * block_size;
Expand Down Expand Up @@ -270,9 +259,9 @@ void test_block_gauss_seidel_rank2(lno_t numRows, size_type nnz,
lno_t bandwidth, lno_t row_size_variance) {
using namespace Test;
srand(245);
typedef
typename KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>
crsMat_t;
using crsMat_t =
typename KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type>;
using MatrixConverter = KokkosSparse::Impl::MatrixConverter<mtx_format>;

typedef typename device::execution_space exec_space;
typedef typename crsMat_t::StaticCrsGraphType graph_t;
Expand Down Expand Up @@ -301,14 +290,14 @@ void test_block_gauss_seidel_rank2(lno_t numRows, size_type nnz,
// this makes consecutive 5 rows to have same columns.
// it will add scalar 0's for those entries that does not exists.
// the result is still a point crs matrix.
KokkosSparse::Impl::kk_create_blockcrs_formated_point_crsmatrix(
KokkosSparse::Impl::kk_create_blockcrs_formatted_point_crsmatrix(
block_size, crsmat.numRows(), crsmat.numCols(), crsmat.graph.row_map,
crsmat.graph.entries, crsmat.values, out_r, out_c, pf_rm, pf_e, pf_v);
graph_t static_graph2(pf_e, pf_rm);
crsMat_t crsmat2("CrsMatrix2", out_c, pf_v, static_graph2);

auto input_mat =
MatrixConverter<mtx_format>::from_blockcrs_formated_point_crsmatrix(
MatrixConverter::from_blockcrs_formatted_point_crsmatrix(
crsmat2, block_size);

lno_t nv = ((crsmat2.numRows() + block_size - 1) / block_size) * block_size;
Expand Down Expand Up @@ -385,33 +374,32 @@ void test_block_gauss_seidel_empty() {
typedef typename graph_t::row_map_type::non_const_type row_map_type;
typedef typename graph_t::entries_type::non_const_type entries_type;
typedef typename crsMat_t::values_type::non_const_type scalar_view_t;
typedef KokkosKernelsHandle<
using KernelHandle = KokkosKernels::Experimental::KokkosKernelsHandle<
size_type, lno_t, scalar_t, typename device::execution_space,
typename device::memory_space, typename device::memory_space>
KernelHandle;
typename device::memory_space, typename device::memory_space>;
// The rowmap of a zero-row matrix can be length 0 or 1, so Gauss-Seidel
// should work with both (the setup and apply are essentially no-ops but they
// shouldn't crash or throw exceptions) For this test, create size-0 and
// size-1 rowmaps separately. Check also 5x5 matrix with empty rows (0-nnz),
// which can trigger different bugs.
for (const int rowmapLen : {0, 1, 5}) {
KernelHandle kh;
kh.create_gs_handle(GS_DEFAULT);
kh.create_gs_handle(KokkosSparse::GS_DEFAULT);
const auto num_rows = KOKKOSKERNELS_MACRO_MAX(0, rowmapLen - 1);
const lno_t block_size = 1; // irrelevant (no values here)
// initialized to 0
row_map_type rowmap("Rowmap", rowmapLen);
entries_type entries("Entries", 0);
scalar_view_t values("Values", 0);
// also, make sure graph symmetrization doesn't crash on zero rows
block_gauss_seidel_symbolic(&kh, num_rows, num_rows, block_size, rowmap,
KSExp::block_gauss_seidel_symbolic(&kh, num_rows, num_rows, block_size, rowmap,
entries, false);
block_gauss_seidel_numeric<mtx_format>(&kh, num_rows, num_rows, block_size,
KSExp::block_gauss_seidel_numeric<mtx_format>(&kh, num_rows, num_rows, block_size,
rowmap, entries, values, false);
scalar_view_t x("X", num_rows);
scalar_view_t y("Y", num_rows);
scalar_t omega(0.9);
symmetric_block_gauss_seidel_apply<mtx_format>(
KSExp::symmetric_block_gauss_seidel_apply<mtx_format>(
&kh, num_rows, num_rows, block_size, rowmap, entries, values, x, y,
false, true, omega, 3);
kh.destroy_gs_handle();
Expand Down

0 comments on commit 35e2f62

Please sign in to comment.