Skip to content

Commit

Permalink
WIP: sparse perf-test cleanup and ETI fixes
Browse files Browse the repository at this point in the history
- Cleaning up duplicated MatrixMarket code from
  perf_test/spmv that exists in IOUtils (kokkos#493)
- Changing the scalar/lno_t/size_type/layout to tolerate any ETI
  combination (previously, only double/int/int/left was really
  supported)
  • Loading branch information
brian-kelley committed Feb 27, 2020
1 parent aa011ab commit 8faaa76
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 593 deletions.
31 changes: 9 additions & 22 deletions perf_test/sparse/KokkosSparse_gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,20 @@
#include <KokkosBlas1_fill.hpp>
#include <KokkosBlas1_nrm2.hpp>
#include <KokkosKernels_config.h>
#include "KokkosSparse_perftest_types.hpp"
#include <iostream>
#include <vector>
#include <string>

using std::cout;
using std::string;

#if defined(KOKKOSKERNELS_INST_ORDINAL_INT)
typedef int default_lno_t;
#elif defined(KOKKOSKERNELS_INST_ORDINAL_INT64_T)
typedef int64_t default_lno_t;
#else
#error "Expect int and/or int64_t to be enabled as ORDINAL (lno_t) types"
#endif
//Prefer int as the default offset type, because cuSPARSE doesn't support size_t for rowptrs.
#if defined(KOKKOSKERNELS_INST_OFFSET_INT)
typedef int default_size_type;
#elif defined(KOKKOSKERNELS_INST_OFFSET_SIZE_T)
typedef size_t default_size_type;
#else
#error "Expect size_t and/or int to be enabled as OFFSET (size_type) types"
#endif

template<typename size_type, typename lno_t, typename device_t>
template<typename device_t>
void runGS(string matrixPath, string devName, bool symmetric)
{
typedef double scalar_t;
typedef default_scalar scalar_t;
typedef default_lno_t lno_t;
typedef default_size_type size_type;
typedef typename device_t::execution_space exec_space;
typedef typename device_t::memory_space mem_space;
typedef KokkosKernels::Experimental::KokkosKernelsHandle<size_type, lno_t, scalar_t, exec_space, mem_space, mem_space> KernelHandle;
Expand Down Expand Up @@ -239,28 +226,28 @@ int main(int argc, char** argv)
#ifdef KOKKOS_ENABLE_SERIAL
if(device == "serial")
{
runGS<default_size_type, default_lno_t, Kokkos::Serial>(matrixPath, device, sym);
runGS<Kokkos::Serial>(matrixPath, device, sym);
run = true;
}
#endif
#ifdef KOKKOS_ENABLE_OPENMP
if(device == "openmp")
{
runGS<default_size_type, default_lno_t, Kokkos::OpenMP>(matrixPath, device, sym);
runGS<Kokkos::OpenMP>(matrixPath, device, sym);
run = true;
}
#endif
#ifdef KOKKOS_ENABLE_THREADS
if(device == "threads")
{
runGS<default_size_type, default_lno_t, Kokkos::Threads>(matrixPath, device, sym);
runGS<Kokkos::Threads>(matrixPath, device, sym);
run = true;
}
#endif
#ifdef KOKKOS_ENABLE_CUDA
if(device == "cuda")
{
runGS<default_size_type, default_lno_t, Kokkos::Cuda>(matrixPath, device, sym);
runGS<Kokkos::Cuda>(matrixPath, device, sym);
run = true;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,43 @@
//@HEADER
*/

#ifndef KOKKOSKERNELS_SPMV_HPP_
#define KOKKOSKERNELS_SPMV_HPP_
#ifndef KOKKOSSPARSE_PERFTEST_TYPES_H
#define KOKKOSSPARSE_PERFTEST_TYPES_H

#ifdef MAKE_BUILD
#ifdef KOKKOS_ENABLE_CUDA
#define KOKKOSKERNELS_ETI_MANGLING_TYPEDEFS() \
typedef Kokkos::Device<Kokkos::Cuda, Kokkos::Cuda::memory_space> Kokkos_Device0Kokkos_Cuda_Kokkos_CudaSpace0; \
typedef Kokkos::complex<double> Kokkos_complex0double0; \
typedef long long longlong;
#include <Kokkos_Core.hpp>
#include <KokkosKernels_config.h> //for all the ETI #cmakedefine macros

#if defined(KOKKOSKERNELS_INST_ORDINAL_INT)
typedef int default_lno_t;
#elif defined(KOKKOSKERNELS_INST_ORDINAL_INT64_T)
typedef int64_t default_lno_t;
#else
#ifdef KOKKOS_ENABLE_OPENMP
#define KOKKOSKERNELS_ETI_MANGLING_TYPEDEFS() \
typedef Kokkos::Device<Kokkos::OpenMP, Kokkos::OpenMP::memory_space> Kokkos_Device0Kokkos_OpenMP_Kokkos_HostSpace0; \
typedef Kokkos::complex<double> Kokkos_complex0double0; \
typedef long long longlong;
#else
#ifdef KOKKOS_ENABLE_THREADS
#define KOKKOSKERNELS_ETI_MANGLING_TYPEDEFS() \
typedef Kokkos::Device<Kokkos::Threads, Kokkos::Threads::memory_space> Kokkos_Device0Kokkos_Threads_Kokkos_HostSpace0; \
typedef Kokkos::complex<double> Kokkos_complex0double0; \
typedef long long longlong;
#else
#define KOKKOSKERNELS_ETI_MANGLING_TYPEDEFS() \
typedef Kokkos::Device<Kokkos::OpenMP, Kokkos::HostSpace> Kokkos_Device0Kokkos_OpenMP_Kokkos_HostSpace0; \
typedef Kokkos::complex<double> Kokkos_complex0double0; \
typedef long long longlong;
#endif
#endif
#error "Expect INT and/or INT64_T to be enabled as ORDINAL (lno_t) types"
#endif

//Prefer int as the default offset type, because cuSPARSE doesn't support size_t for rowptrs.
#if defined(KOKKOSKERNELS_INST_OFFSET_INT)
typedef int default_size_type;
#elif defined(KOKKOSKERNELS_INST_OFFSET_SIZE_T)
typedef size_t default_size_type;
#else
#error "Expect SIZE_T and/or INT to be enabled as OFFSET (size_type) types"
#endif

#include <KokkosBlas.hpp>
#include <KokkosSparse_spmv.hpp>

#ifdef HAVE_KK_KERNELS
#if defined(KOKKOSKERNELS_INST_LAYOUTLEFT)
typedef Kokkos::LayoutLeft default_layout;
#elif defined(KOKKOSKERNELS_INST_LAYOUTRIGHT)
typedef Kokkos::LayoutRight default_layout;
#else
#error "Expect LAYOUTLEFT and/or LAYOUTRIGHT to be enabled as layout types"
#endif

#if defined(KOKKOSKERNELS_INST_DOUBLE)
typedef double default_scalar;
#elif defined(KOKKOSKERNELS_INST_FLOAT)
typedef float default_scalar;
#else
#error "Expect at least one real-valued scalar type (double or float) to be enabled"
#endif

template<typename AType, typename XType, typename YType>
void kokkoskernels_matvec(AType A, XType x, YType y, int rows_per_thread, int team_size, int vector_length) {
KokkosSparse::spmv (KokkosSparse::NoTranspose,1.0,A,x,0.0,y);
}
#endif

#endif /* KOKKOSKERNELS_SPMV_HPP_ */
44 changes: 8 additions & 36 deletions perf_test/sparse/KokkosSparse_spgemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@
*/
#include <iostream>
#include "KokkosKernels_config.h"
#if defined(KOKKOSKERNELS_INST_DOUBLE) && \
defined(KOKKOSKERNELS_INST_OFFSET_INT) && \
defined(KOKKOSKERNELS_INST_ORDINAL_INT)
#include "KokkosSparse_perftest_types.hpp"
#include "KokkosKernels_IOUtils.hpp"
#include "KokkosSparse_multimem_spgemm.hpp"


#define SIZE_TYPE int
#define INDEX_TYPE int
#define SCALAR_TYPE double
//double
typedef default_size_type size_type;
typedef default_lno_t lno_t;
typedef default_scalar scalar_t;

void print_options(){
std::cerr << "Options\n" << std::endl;
Expand Down Expand Up @@ -303,12 +299,12 @@ int main (int argc, char ** argv){
if (params.use_openmp) {
#ifdef KOKKOSKERNELS_INST_MEMSPACE_HBWSPACE
KokkosKernels::Experiment::run_multi_mem_spgemm
<SIZE_TYPE, INDEX_TYPE, SCALAR_TYPE, Kokkos::OpenMP, Kokkos::Experimental::HBWSpace, Kokkos::HostSpace>(
<size_type, lno_t, scalar_t, Kokkos::OpenMP, Kokkos::Experimental::HBWSpace, Kokkos::HostSpace>(
params
);
#else
KokkosKernels::Experiment::run_multi_mem_spgemm
<SIZE_TYPE, INDEX_TYPE, SCALAR_TYPE, Kokkos::OpenMP, Kokkos::OpenMP::memory_space, Kokkos::OpenMP::memory_space>(
<size_type, lno_t, scalar_t, Kokkos::OpenMP, Kokkos::OpenMP::memory_space, Kokkos::OpenMP::memory_space>(
params
);
#endif
Expand All @@ -319,45 +315,21 @@ int main (int argc, char ** argv){
if (params.use_cuda) {
#ifdef KOKKOSKERNELS_INST_MEMSPACE_CUDAHOSTPINNEDSPACE
KokkosKernels::Experiment::run_multi_mem_spgemm
<SIZE_TYPE, INDEX_TYPE, SCALAR_TYPE, Kokkos::Cuda, Kokkos::Cuda::memory_space, Kokkos::CudaHostPinnedSpace>(
<size_type, lno_t, scalar_t, Kokkos::Cuda, Kokkos::Cuda::memory_space, Kokkos::CudaHostPinnedSpace>(
params
);
#else
KokkosKernels::Experiment::run_multi_mem_spgemm
<SIZE_TYPE, INDEX_TYPE, SCALAR_TYPE, Kokkos::Cuda, Kokkos::Cuda::memory_space, Kokkos::Cuda::memory_space>(
<size_type, lno_t, scalar_t, Kokkos::Cuda, Kokkos::Cuda::memory_space, Kokkos::Cuda::memory_space>(
params
);

#endif
}
#else
#endif

Kokkos::finalize();

return 0;
}


#else
int main() {
#if !defined(KOKKOSKERNELS_INST_DOUBLE)
std::cout << " not defined KOKKOSKERNELS_INST_DOUBLE" << std::endl;
#endif

#if !defined(KOKKOSKERNELS_INST_OFFSET_INT)
std::cout << " not defined KOKKOSKERNELS_INST_OFFSET_INT" << std::endl;

#endif

#if !defined(KOKKOSKERNELS_INST_ORDINAL_INT)
std::cout << " not defined KOKKOSKERNELS_INST_ORDINAL_INT" << std::endl;

#endif
}
#endif





27 changes: 5 additions & 22 deletions perf_test/sparse/KokkosSparse_spiluk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,9 @@
#include "KokkosSparse_spmv.hpp"
#include "KokkosBlas1_nrm2.hpp"
#include "KokkosSparse_CrsMatrix.hpp"
#include "KokkosSparse_perftest_types.hpp"
#include <KokkosKernels_IOUtils.hpp>

#if defined(KOKKOSKERNELS_INST_ORDINAL_INT)
typedef int default_lno_t;
#elif defined(KOKKOSKERNELS_INST_ORDINAL_INT64_T)
typedef int64_t default_lno_t;
#else
#error "Expect int and/or int64_t to be enabled as ORDINAL (lno_t) types"
#endif
//Prefer int as the default offset type, because cuSPARSE doesn't support size_t for rowptrs.
#if defined(KOKKOSKERNELS_INST_OFFSET_INT)
typedef int default_size_type;
#elif defined(KOKKOSKERNELS_INST_OFFSET_SIZE_T)
typedef size_t default_size_type;
#else
#error "Expect size_t and/or int to be enabled as OFFSET (size_type) types"
#endif

#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA ) && (!defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION ))
using namespace KokkosSparse;
using namespace KokkosSparse::Experimental;
Expand All @@ -89,10 +74,8 @@ using namespace KokkosKernels::Experimental;

enum {DEFAULT, CUSPARSE, LVLSCHED_RP, LVLSCHED_TP1/*, LVLSCHED_TP2*/};

template<typename Scalar>
int test_spiluk_perf(std::vector<int> tests, std::string afilename, int K, int team_size, int vector_length, /*int idx_offset,*/ int loop) {

typedef Scalar scalar_t;
int test_spiluk_perf(std::vector<int> tests, std::string afilename, int k, int team_size, int vector_length, /*int idx_offset,*/ int loop) {
typedef default_scalar scalar_t;
typedef default_lno_t lno_t;
typedef default_size_type size_type;
typedef Kokkos::DefaultExecutionSpace execution_space;
Expand Down Expand Up @@ -314,7 +297,7 @@ int test_spiluk_perf(std::vector<int> tests, std::string afilename, int K, int t
return 1;
}
else {
Kokkos::View<lno_t*, Kokkos::LayoutLeft, Kokkos::HostSpace> h_tmp_entries ( "h_tmp_entries", a_row_end-a_row_start);
Kokkos::View<lno_t*, Kokkos::LayoutLeft, Kokkos::HostSpace> h_tmp_entries ( "h_tmp_entries", a_row_end-a_row_start);
Kokkos::View<scalar_t*, Kokkos::LayoutLeft, Kokkos::HostSpace> h_tmp_values ( "h_tmp_values", a_row_end-a_row_start);

Kokkos::deep_copy(subview(h_tmp_entries, Kokkos::make_pair(0,l_row_end-l_row_start)),
Expand Down Expand Up @@ -505,7 +488,7 @@ int main(int argc, char **argv)

Kokkos::initialize(argc,argv);
{
int total_errors = test_spiluk_perf<double>(tests, afilename, k, team_size, vector_length, /*idx_offset,*/ loop);
int total_errors = test_spiluk_perf(tests, afilename, k, team_size, vector_length, /*idx_offset,*/ loop);

if(total_errors == 0)
printf("Kokkos::SPILUK Test: Passed\n");
Expand Down
Loading

0 comments on commit 8faaa76

Please sign in to comment.