diff --git a/batched/dense/unit_test/Test_Batched_SerialGemm.hpp b/batched/dense/unit_test/Test_Batched_SerialGemm.hpp index 144bb2251e..0b2ed4a162 100644 --- a/batched/dense/unit_test/Test_Batched_SerialGemm.hpp +++ b/batched/dense/unit_test/Test_Batched_SerialGemm.hpp @@ -25,6 +25,7 @@ #include "KokkosBatched_Gemm_Serial_Impl.hpp" #include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestVanilla.hpp" using namespace KokkosBatched; diff --git a/batched/dense/unit_test/Test_Batched_SerialSVD.hpp b/batched/dense/unit_test/Test_Batched_SerialSVD.hpp index a30c9dcc89..586b69dc7f 100644 --- a/batched/dense/unit_test/Test_Batched_SerialSVD.hpp +++ b/batched/dense/unit_test/Test_Batched_SerialSVD.hpp @@ -18,6 +18,8 @@ #include "KokkosBatched_SVD_Decl.hpp" //For testing overall kernel #include "KokkosBatched_SVD_Serial_Internal.hpp" //For unit testing individual components #include "KokkosBatched_SetIdentity_Decl.hpp" +#include "KokkosKernels_TestMatrixUtils.hpp" +#include "KokkosKernels_TestVanilla.hpp" namespace Test { template diff --git a/blas/unit_test/Test_Blas2_gemv.hpp b/blas/unit_test/Test_Blas2_gemv.hpp index d70935c2ac..be6e4a6d51 100644 --- a/blas/unit_test/Test_Blas2_gemv.hpp +++ b/blas/unit_test/Test_Blas2_gemv.hpp @@ -19,6 +19,7 @@ #include #include #include +#include "KokkosKernels_TestVanilla.hpp" namespace Test { template diff --git a/perf_test/CMakeLists.txt b/perf_test/CMakeLists.txt index 28271dfb0d..8d740966f0 100644 --- a/perf_test/CMakeLists.txt +++ b/perf_test/CMakeLists.txt @@ -11,21 +11,6 @@ if (KokkosKernels_ENABLE_PERFTESTS) #build correctly with or without MPI, but only run them with a single #MPI process. - SET(GTEST_SOURCE_DIR ${PACKAGE_SOURCE_DIR}/tpls/gtest) - - KOKKOSKERNELS_ADD_TEST_LIBRARY( - kokkoskernelsperf_gtest - HEADERS ${GTEST_SOURCE_DIR}/gtest/gtest.h - SOURCES ${GTEST_SOURCE_DIR}/gtest/gtest-all.cc - ) - #Disables pthreads, this is a problem for serial builds in Trilinos & Sierra if it's enabled. - - TARGET_COMPILE_DEFINITIONS(kokkoskernelsperf_gtest PUBLIC "-DGTEST_HAS_PTHREAD=0") - TARGET_INCLUDE_DIRECTORIES(kokkoskernelsperf_gtest PUBLIC $) - - #Gtest minimally requires C++ 11 - TARGET_COMPILE_FEATURES(kokkoskernelsperf_gtest PUBLIC cxx_std_11) - KOKKOSKERNELS_INCLUDE_DIRECTORIES(sparse) if(KokkosKernels_ENABLE_TESTS_AND_PERFSUITE) diff --git a/perf_test/KokkosKernels_perf_test_utilities.hpp b/perf_test/KokkosKernels_perf_test_utilities.hpp index ec767c68f7..6d11e021a9 100644 --- a/perf_test/KokkosKernels_perf_test_utilities.hpp +++ b/perf_test/KokkosKernels_perf_test_utilities.hpp @@ -20,7 +20,7 @@ #ifndef KOKKOSKERNELS_PERF_TEST_UTILITIES_HPP #define KOKKOSKERNELS_PERF_TEST_UTILITIES_HPP -#include "KokkosKernels_TestUtils.hpp" // for string_compare_no_case +#include "KokkosKernels_TestStringUtils.hpp" // for string_compare_no_case // Namepsace that defines common utilities // for performance tests diff --git a/perf_test/blas/blas1/KokkosBlas_dot_mv_perf_test.cpp b/perf_test/blas/blas1/KokkosBlas_dot_mv_perf_test.cpp index 23d53ba106..49c7a76210 100644 --- a/perf_test/blas/blas1/KokkosBlas_dot_mv_perf_test.cpp +++ b/perf_test/blas/blas1/KokkosBlas_dot_mv_perf_test.cpp @@ -14,10 +14,12 @@ // //@HEADER +#include + #include #include #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" struct Params { int use_cuda = 0; diff --git a/perf_test/blas/blas1/KokkosBlas_dot_perf_test.cpp b/perf_test/blas/blas1/KokkosBlas_dot_perf_test.cpp index 8e6ebf985c..36f11733ce 100644 --- a/perf_test/blas/blas1/KokkosBlas_dot_perf_test.cpp +++ b/perf_test/blas/blas1/KokkosBlas_dot_perf_test.cpp @@ -14,12 +14,14 @@ // //@HEADER +#include + #include #include // For RPS implementation #include "KokkosBlas_dot_perf_test.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" struct Params { int use_cuda = 0; diff --git a/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test.cpp b/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test.cpp index 16dadd34b6..ca30ed50ac 100644 --- a/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test.cpp +++ b/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test.cpp @@ -14,10 +14,12 @@ // //@HEADER +#include + #include #include #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" struct Params { int use_cuda = 0; diff --git a/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test_benchmark.cpp b/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test_benchmark.cpp index 776c291ad0..ab0750e5b6 100644 --- a/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test_benchmark.cpp +++ b/perf_test/blas/blas1/KokkosBlas_team_dot_perf_test_benchmark.cpp @@ -42,10 +42,12 @@ //@HEADER */ +#include + #include #include #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include diff --git a/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test.cpp b/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test.cpp index 924b63ecee..90fb065741 100644 --- a/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test.cpp +++ b/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test.cpp @@ -16,7 +16,7 @@ #include "KokkosBlas2_gemv.hpp" #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" struct Params { int use_cuda = 0; diff --git a/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test_benchmark.cpp b/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test_benchmark.cpp index cdae173ce0..2ff22b7078 100644 --- a/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test_benchmark.cpp +++ b/perf_test/blas/blas2/KokkosBlas2_gemv_perf_test_benchmark.cpp @@ -19,7 +19,7 @@ #include "KokkosBlas2_gemv.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include diff --git a/perf_test/blas/blas2/KokkosBlas2_ger_perf_test_benchmark.cpp b/perf_test/blas/blas2/KokkosBlas2_ger_perf_test_benchmark.cpp index 8efd9920b1..2feeb2c2ff 100644 --- a/perf_test/blas/blas2/KokkosBlas2_ger_perf_test_benchmark.cpp +++ b/perf_test/blas/blas2/KokkosBlas2_ger_perf_test_benchmark.cpp @@ -21,7 +21,7 @@ #include "KokkosBlas2_ger.hpp" #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include diff --git a/perf_test/blas/blas3/CMakeLists.txt b/perf_test/blas/blas3/CMakeLists.txt index 80c9d25c1c..4dbf0ae5dd 100644 --- a/perf_test/blas/blas3/CMakeLists.txt +++ b/perf_test/blas/blas3/CMakeLists.txt @@ -4,7 +4,6 @@ KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) KOKKOSKERNELS_ADD_EXECUTABLE( KokkosBlas3_perf_test SOURCES KokkosBlas3_perf_test.cpp - TESTONLYLIBS kokkoskernelsperf_gtest ) KOKKOSKERNELS_ADD_EXECUTABLE( diff --git a/perf_test/blas/blas3/KokkosBlas3_gemm_perf_test.hpp b/perf_test/blas/blas3/KokkosBlas3_gemm_perf_test.hpp index 7e3b0061d8..65a5cdc549 100644 --- a/perf_test/blas/blas3/KokkosBlas3_gemm_perf_test.hpp +++ b/perf_test/blas/blas3/KokkosBlas3_gemm_perf_test.hpp @@ -25,11 +25,12 @@ #include +#include "Kokkos_ArithTraits.hpp" #include "KokkosBatched_HostLevel_Gemm.hpp" #include "KokkosBatched_Gemm_Decl.hpp" #include "KokkosBatched_Util.hpp" -#include "gtest/gtest.h" // EXPECT_NEAR -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" +#include "KokkosKernels_TestVanilla.hpp" #include @@ -1368,7 +1369,8 @@ static inline bool __gemm_print_compare_failure(ViewType h_expected, ViewType h_ */ template static inline bool __gemm_do_compare(view_type_3d expected, view_type_3d actual) { - double epsilon = Test::epsilon::value * 1e3; + double epsilon = Kokkos::ArithTraits::eps() * 1e3; + STATUS; typename view_type_3d::HostMirror h_expected = Kokkos::create_mirror_view(expected); diff --git a/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test.cpp b/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test.cpp index aead1cb46f..a9f8db5be4 100644 --- a/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test.cpp +++ b/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test.cpp @@ -16,7 +16,7 @@ #include "KokkosBlas3_gemm.hpp" #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" struct Params { int use_cuda = 0; diff --git a/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test_benchmark.cpp b/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test_benchmark.cpp index eee2eea53c..6f0737180e 100644 --- a/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test_benchmark.cpp +++ b/perf_test/blas/blas3/KokkosBlas3_gemm_standalone_perf_test_benchmark.cpp @@ -16,7 +16,7 @@ #include "KokkosBlas3_gemm.hpp" #include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include "Benchmark_Context.hpp" #include diff --git a/perf_test/graph/KokkosGraph_color.cpp b/perf_test/graph/KokkosGraph_color.cpp index 548abd0052..0c3706bdfe 100644 --- a/perf_test/graph/KokkosGraph_color.cpp +++ b/perf_test/graph/KokkosGraph_color.cpp @@ -26,7 +26,7 @@ #include "KokkosSparse_CrsMatrix.hpp" #include "KokkosKernels_TestParameters.hpp" #include "KokkosGraph_Distance1Color.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosSparse_IOUtils.hpp" void print_options(std::ostream &os, const char *app_name, unsigned int indent = 0) { diff --git a/perf_test/graph/KokkosGraph_color_d2.cpp b/perf_test/graph/KokkosGraph_color_d2.cpp index 0811f7c5b4..04242f31f0 100644 --- a/perf_test/graph/KokkosGraph_color_d2.cpp +++ b/perf_test/graph/KokkosGraph_color_d2.cpp @@ -36,7 +36,7 @@ #include #include #include "KokkosKernels_default_types.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosSparse_IOUtils.hpp" using namespace KokkosGraph; diff --git a/perf_test/graph/KokkosGraph_mis_d2.cpp b/perf_test/graph/KokkosGraph_mis_d2.cpp index 3d08db0a9f..952f28e64c 100644 --- a/perf_test/graph/KokkosGraph_mis_d2.cpp +++ b/perf_test/graph/KokkosGraph_mis_d2.cpp @@ -37,7 +37,7 @@ #include "KokkosSparse_spadd.hpp" #include "KokkosGraph_MIS2.hpp" #include "KokkosKernels_default_types.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosSparse_IOUtils.hpp" using namespace KokkosGraph; diff --git a/perf_test/graph/KokkosGraph_triangle.cpp b/perf_test/graph/KokkosGraph_triangle.cpp index cd5f40c376..84676607d9 100644 --- a/perf_test/graph/KokkosGraph_triangle.cpp +++ b/perf_test/graph/KokkosGraph_triangle.cpp @@ -18,7 +18,7 @@ #include "KokkosGraph_Triangle.hpp" #include "KokkosSparse_CrsMatrix.hpp" #include "KokkosSparse_IOUtils.hpp" //for read_kokkos_crst_graph -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_TestParameters.hpp" #include "KokkosKernels_perf_test_utilities.hpp" diff --git a/perf_test/lapack/KokkosLapack_SVD_benchmark.cpp b/perf_test/lapack/KokkosLapack_SVD_benchmark.cpp index 8336b3b737..55aa70b9cf 100644 --- a/perf_test/lapack/KokkosLapack_SVD_benchmark.cpp +++ b/perf_test/lapack/KokkosLapack_SVD_benchmark.cpp @@ -14,9 +14,11 @@ // //@HEADER -#include "KokkosLapack_svd.hpp" +#include -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_IOUtils.hpp" // getRandomBounds +#include "KokkosLapack_svd.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include @@ -72,7 +74,7 @@ void run_svd_benchmark(benchmark::State& state, const svd_parameters& svd_params // Initialize A with random numbers double randStart = 0, randEnd = 0; - Test::getRandomBounds(10.0, randStart, randEnd); + KokkosKernels::Impl::getRandomBounds(10.0, randStart, randEnd); Kokkos::fill_random(A, rand_pool, randStart, randEnd); for (auto _ : state) { diff --git a/perf_test/ode/KokkosODE_BDF.cpp b/perf_test/ode/KokkosODE_BDF.cpp index 60cc5e01ff..0b1ecdf276 100644 --- a/perf_test/ode/KokkosODE_BDF.cpp +++ b/perf_test/ode/KokkosODE_BDF.cpp @@ -16,7 +16,7 @@ #include "KokkosODE_BDF.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include diff --git a/perf_test/ode/KokkosODE_RK.cpp b/perf_test/ode/KokkosODE_RK.cpp index 83635d7af6..2c52cfbb5d 100644 --- a/perf_test/ode/KokkosODE_RK.cpp +++ b/perf_test/ode/KokkosODE_RK.cpp @@ -16,7 +16,7 @@ #include "KokkosODE_RungeKutta.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include diff --git a/perf_test/sparse/CMakeLists.txt b/perf_test/sparse/CMakeLists.txt index 514ef0ed82..70b5928efb 100644 --- a/perf_test/sparse/CMakeLists.txt +++ b/perf_test/sparse/CMakeLists.txt @@ -103,7 +103,6 @@ KOKKOSKERNELS_ADD_EXECUTABLE( KOKKOSKERNELS_ADD_EXECUTABLE( sparse_gs SOURCES KokkosSparse_gs.cpp - TESTONLYLIBS kokkoskernelsperf_gtest ) KOKKOSKERNELS_ADD_EXECUTABLE( diff --git a/perf_test/sparse/KokkosSparse_block_pcg.cpp b/perf_test/sparse/KokkosSparse_block_pcg.cpp index f1f9684dd6..91a599ad71 100644 --- a/perf_test/sparse/KokkosSparse_block_pcg.cpp +++ b/perf_test/sparse/KokkosSparse_block_pcg.cpp @@ -23,7 +23,7 @@ #include "KokkosKernels_Utils.hpp" #include "KokkosSparse_IOUtils.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #define MAXVAL 1 diff --git a/perf_test/sparse/KokkosSparse_gs.cpp b/perf_test/sparse/KokkosSparse_gs.cpp index 9c968c92cd..0ed984a8f8 100644 --- a/perf_test/sparse/KokkosSparse_gs.cpp +++ b/perf_test/sparse/KokkosSparse_gs.cpp @@ -14,10 +14,17 @@ // //@HEADER +#include +#include +#include +#include +#include + #include #include + #include -#include +#include #include #include #include @@ -25,11 +32,7 @@ #include #include "KokkosKernels_default_types.hpp" #include "KokkosSparse_IOUtils.hpp" -#include -#include -#include -#include -#include +#include "KokkosKernels_TestMatrixUtils.hpp" using std::cout; using std::string; diff --git a/perf_test/sparse/KokkosSparse_mdf.cpp b/perf_test/sparse/KokkosSparse_mdf.cpp index 4db45ce55f..0cd33f2eca 100644 --- a/perf_test/sparse/KokkosSparse_mdf.cpp +++ b/perf_test/sparse/KokkosSparse_mdf.cpp @@ -19,7 +19,7 @@ #include "KokkosKernels_Handle.hpp" #include "KokkosSparse_IOUtils.hpp" #include "KokkosSparse_Utils_cusparse.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include "KokkosSparse_mdf.hpp" diff --git a/perf_test/sparse/KokkosSparse_pcg.cpp b/perf_test/sparse/KokkosSparse_pcg.cpp index e1d469d6aa..00466ae6c9 100644 --- a/perf_test/sparse/KokkosSparse_pcg.cpp +++ b/perf_test/sparse/KokkosSparse_pcg.cpp @@ -20,7 +20,7 @@ #include "KokkosKernels_Utils.hpp" #include "KokkosKernels_IOUtils.hpp" #include "KokkosKernels_default_types.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosSparse_IOUtils.hpp" #include diff --git a/perf_test/sparse/KokkosSparse_spadd.cpp b/perf_test/sparse/KokkosSparse_spadd.cpp index d2b41608db..063c151812 100644 --- a/perf_test/sparse/KokkosSparse_spadd.cpp +++ b/perf_test/sparse/KokkosSparse_spadd.cpp @@ -20,7 +20,7 @@ #include "KokkosSparse_IOUtils.hpp" #include "KokkosSparse_Utils_cusparse.hpp" #include "KokkosSparse_Utils_mkl.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #include "KokkosSparse_spadd.hpp" diff --git a/perf_test/sparse/KokkosSparse_spgemm.cpp b/perf_test/sparse/KokkosSparse_spgemm.cpp index 0dd13f6804..2c63127c2d 100644 --- a/perf_test/sparse/KokkosSparse_spgemm.cpp +++ b/perf_test/sparse/KokkosSparse_spgemm.cpp @@ -23,7 +23,7 @@ #include "KokkosBlas1_nrminf.hpp" #include "KokkosBlas1_axpby.hpp" #include "KokkosKernels_TestParameters.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" #define TRANSPOSEFIRST false diff --git a/perf_test/sparse/KokkosSparse_spgemm_jacobi.cpp b/perf_test/sparse/KokkosSparse_spgemm_jacobi.cpp index 3b66889fab..a5646603b7 100644 --- a/perf_test/sparse/KokkosSparse_spgemm_jacobi.cpp +++ b/perf_test/sparse/KokkosSparse_spgemm_jacobi.cpp @@ -18,7 +18,7 @@ #include "KokkosKernels_default_types.hpp" #include "KokkosKernels_IOUtils.hpp" #include "KokkosSparse_run_spgemm_jacobi.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" void print_options() { std::cerr << "Options\n" << std::endl; diff --git a/perf_test/sparse/KokkosSparse_spmv_benchmark.cpp b/perf_test/sparse/KokkosSparse_spmv_benchmark.cpp index 5ecf2f7248..6a2f92165b 100644 --- a/perf_test/sparse/KokkosSparse_spmv_benchmark.cpp +++ b/perf_test/sparse/KokkosSparse_spmv_benchmark.cpp @@ -21,7 +21,7 @@ #include #include #include "KokkosKernels_default_types.hpp" -#include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestStringUtils.hpp" #include "KokkosKernels_perf_test_utilities.hpp" // Headers for benchmark library diff --git a/sparse/unit_test/Test_Sparse_gauss_seidel.hpp b/sparse/unit_test/Test_Sparse_gauss_seidel.hpp index ebfd2a6a18..3704b63fbd 100644 --- a/sparse/unit_test/Test_Sparse_gauss_seidel.hpp +++ b/sparse/unit_test/Test_Sparse_gauss_seidel.hpp @@ -14,6 +14,13 @@ // //@HEADER +#include +#include +#include +#include +#include +#include + #include #include @@ -25,17 +32,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include + #include "KokkosSparse_gauss_seidel.hpp" #include "KokkosSparse_partitioning_impl.hpp" #include "KokkosSparse_sor_sequential_impl.hpp" #include "KokkosSparse_SortCrs.hpp" #include "KokkosKernels_TestUtils.hpp" +#include "KokkosKernels_TestMatrixUtils.hpp" #include "Test_Sparse_Utils.hpp" // #ifndef kokkos_complex_double diff --git a/test_common/KokkosKernels_TestMatrixUtils.hpp b/test_common/KokkosKernels_TestMatrixUtils.hpp new file mode 100644 index 0000000000..998ccdba90 --- /dev/null +++ b/test_common/KokkosKernels_TestMatrixUtils.hpp @@ -0,0 +1,89 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#ifndef KOKKOSKERNELS_TESTMATRIXUTILS_HPP +#define KOKKOSKERNELS_TESTMATRIXUTILS_HPP + +#include + +#include "KokkosKernels_Utils.hpp" +#include "KokkosKernels_IOUtils.hpp" +#include "Kokkos_ArithTraits.hpp" +#include "KokkosBatched_Vector.hpp" +// Make this include-able from all subdirectories + +namespace Test { + +template +crsMat_t symmetrize(crsMat_t A) { + typedef typename crsMat_t::StaticCrsGraphType graph_t; + typedef typename crsMat_t::values_type::non_const_type scalar_view_t; + typedef typename graph_t::row_map_type::non_const_type lno_view_t; + typedef typename graph_t::entries_type::non_const_type lno_nnz_view_t; + auto host_rowmap = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.graph.row_map); + auto host_entries = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.graph.entries); + auto host_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.values); + lno_t numRows = A.numRows(); + // symmetrize as input_mat + input_mat^T, to still have a diagonally dominant + // matrix + typedef std::map Row; + std::vector symRows(numRows); + for (lno_t r = 0; r < numRows; r++) { + auto& row = symRows[r]; + for (size_type i = host_rowmap(r); i < host_rowmap(r + 1); i++) { + lno_t c = host_entries(i); + auto& col = symRows[c]; + auto it = row.find(c); + if (it == row.end()) + row[c] = host_values(i); + else + row[c] += host_values(i); + it = col.find(r); + if (it == col.end()) + col[r] = host_values(i); + else + col[r] += host_values(i); + } + } + // Count entries + Kokkos::View new_host_rowmap("Rowmap", numRows + 1); + size_t accum = 0; + for (lno_t r = 0; r <= numRows; r++) { + new_host_rowmap(r) = accum; + if (r < numRows) accum += symRows[r].size(); + } + // Allocate new entries/values + Kokkos::View new_host_entries("Entries", accum); + Kokkos::View new_host_values("Values", accum); + for (lno_t r = 0; r < numRows; r++) { + auto rowIt = symRows[r].begin(); + for (size_type i = new_host_rowmap(r); i < new_host_rowmap(r + 1); i++) { + new_host_entries(i) = rowIt->first; + new_host_values(i) = rowIt->second; + rowIt++; + } + } + lno_view_t new_rowmap("Rowmap", numRows + 1); + lno_nnz_view_t new_entries("Entries", accum); + scalar_view_t new_values("Values", accum); + Kokkos::deep_copy(new_rowmap, new_host_rowmap); + Kokkos::deep_copy(new_entries, new_host_entries); + Kokkos::deep_copy(new_values, new_host_values); + return crsMat_t("SymA", numRows, numRows, accum, new_values, new_rowmap, new_entries); +} + +} // namespace Test +#endif diff --git a/test_common/KokkosKernels_TestStringUtils.hpp b/test_common/KokkosKernels_TestStringUtils.hpp new file mode 100644 index 0000000000..fec1b09361 --- /dev/null +++ b/test_common/KokkosKernels_TestStringUtils.hpp @@ -0,0 +1,38 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#ifndef KOKKOSKERNELS_TESTSTRINGUTILS_HPP +#define KOKKOSKERNELS_TESTSTRINGUTILS_HPP + +#include +#include + +namespace Test { + +inline int string_compare_no_case(const char* str1, const char* str2) { + std::string str1_s(str1); + std::string str2_s(str2); + for (size_t i = 0; i < str1_s.size(); i++) str1_s[i] = std::tolower(str1_s[i]); + for (size_t i = 0; i < str2_s.size(); i++) str2_s[i] = std::tolower(str2_s[i]); + return std::strcmp(str1_s.c_str(), str2_s.c_str()); +} + +inline int string_compare_no_case(const std::string& str1, const std::string& str2) { + return string_compare_no_case(str1.c_str(), str2.c_str()); +} + +} // namespace Test +#endif diff --git a/test_common/KokkosKernels_TestUtils.hpp b/test_common/KokkosKernels_TestUtils.hpp index c829278867..1d33bc8b75 100644 --- a/test_common/KokkosKernels_TestUtils.hpp +++ b/test_common/KokkosKernels_TestUtils.hpp @@ -212,153 +212,6 @@ using halfScalarType = Kokkos::Experimental::half_t; using bhalfScalarType = Kokkos::Experimental::bhalf_t; #endif // KOKKOS_BHALF_T_IS_FLOAT -template -struct SharedVanillaGEMM { - bool A_t, B_t, A_c, B_c; - int C_rows, C_cols, A_cols; - ViewTypeA A; - ViewTypeB B; - ViewTypeC C; - - typedef typename ViewTypeA::value_type ScalarA; - typedef typename ViewTypeB::value_type ScalarB; - typedef typename ViewTypeC::value_type ScalarC; - typedef Kokkos::View SubviewTypeA; - typedef Kokkos::View SubviewTypeB; - typedef Kokkos::ArithTraits APT; - typedef typename APT::mag_type mag_type; - ScalarA alpha; - ScalarC beta; - - KOKKOS_INLINE_FUNCTION - void operator()(const typename Kokkos::TeamPolicy::member_type& team) const { - Kokkos::parallel_for(Kokkos::TeamThreadRange(team, C_rows), [&](const int& i) { - // Give each kokkos thread a vector of A - SubviewTypeA a_vec; - if (A_t) - a_vec = Kokkos::subview(A, Kokkos::ALL(), i); - else - a_vec = Kokkos::subview(A, i, Kokkos::ALL()); - - // Have all vector lanes perform the dot product - Kokkos::parallel_for(Kokkos::ThreadVectorRange(team, C_cols), [&](const int& j) { - SubviewTypeB b_vec; - if (B_t) - b_vec = Kokkos::subview(B, j, Kokkos::ALL()); - else - b_vec = Kokkos::subview(B, Kokkos::ALL(), j); - ScalarC ab = ScalarC(0); - for (int k = 0; k < A_cols; k++) { - auto a = A_c ? APT::conj(a_vec(k)) : a_vec(k); - auto b = B_c ? APT::conj(b_vec(k)) : b_vec(k); - ab += a * b; - } - C(i, j) = beta * C(i, j) + alpha * ab; - }); - }); - } -}; -// C(i,:,:) = alpha * (A(i,:,:) * B(i,:,:)) + beta * C(i,:,:) -template -struct Functor_BatchedVanillaGEMM { - bool A_t, B_t, A_c, B_c, batch_size_last_dim = false; - ViewTypeA A; - ViewTypeB B; - ViewTypeC C; - - using ScalarA = typename ViewTypeA::value_type; - using ScalarB = typename ViewTypeB::value_type; - using ScalarC = typename ViewTypeC::value_type; - using SubviewTypeA = typename Kokkos::View; - using SubviewTypeB = typename Kokkos::View; - using SubviewTypeC = typename Kokkos::View; - - ScalarA alpha; - ScalarC beta; - - KOKKOS_INLINE_FUNCTION - void operator()(const typename Kokkos::TeamPolicy::member_type& team) const { - int i = team.league_rank(); - SubviewTypeA _A; - SubviewTypeB _B; - SubviewTypeC _C; - - if (batch_size_last_dim) { - _A = Kokkos::subview(A, Kokkos::ALL(), Kokkos::ALL(), i); - _B = Kokkos::subview(B, Kokkos::ALL(), Kokkos::ALL(), i); - _C = Kokkos::subview(C, Kokkos::ALL(), Kokkos::ALL(), i); - } else { - _A = Kokkos::subview(A, i, Kokkos::ALL(), Kokkos::ALL()); - _B = Kokkos::subview(B, i, Kokkos::ALL(), Kokkos::ALL()); - _C = Kokkos::subview(C, i, Kokkos::ALL(), Kokkos::ALL()); - } - struct SharedVanillaGEMM vgemm; - vgemm.A_t = A_t; - vgemm.B_t = B_t; - vgemm.A_c = A_c; - vgemm.B_c = B_c; - vgemm.C_rows = batch_size_last_dim ? C.extent(0) : C.extent(1); - vgemm.C_cols = batch_size_last_dim ? C.extent(1) : C.extent(2); - vgemm.A_cols = batch_size_last_dim ? (A_t ? A.extent(0) : A.extent(1)) : (A_t ? A.extent(1) : A.extent(2)); - vgemm.A = _A; - vgemm.B = _B; - vgemm.C = _C; - vgemm.alpha = alpha; - vgemm.beta = beta; - vgemm(team); - } - - inline void run() { - Kokkos::parallel_for( - "Test::VanillaGEMM", - Kokkos::TeamPolicy(batch_size_last_dim ? C.extent(2) : C.extent(0), Kokkos::AUTO, - KokkosKernels::Impl::kk_get_max_vector_size()), - *this); - } -}; - -// Compute C := alpha * AB + beta * C -template -void vanillaGEMM(typename ViewTypeC::non_const_value_type alpha, const ViewTypeA& A, const ViewTypeB& B, - typename ViewTypeC::non_const_value_type beta, const ViewTypeC& C) { - using value_type = typename ViewTypeC::non_const_value_type; - using KAT = Kokkos::ArithTraits; - int m = A.extent(0); - int k = A.extent(1); - int n = B.extent(1); - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - value_type sum = KAT::zero(); - for (int ii = 0; ii < k; ii++) { - sum += A(i, ii) * B(ii, j); - } - C(i, j) = alpha * sum + beta * C(i, j); - } - } -} - -template -KOKKOS_INLINE_FUNCTION void vanillaGEMV(char mode, AlphaType alpha, const ViewTypeA& A, const ViewTypeX& x, - BetaType beta, const ViewTypeY& y) { - using ScalarY = typename ViewTypeY::non_const_value_type; - using KAT_A = Kokkos::ArithTraits; - const bool transposed = mode == 'T' || mode == 'C'; - const bool conjugated = mode == 'C'; - const bool has_beta = beta != Kokkos::ArithTraits::zero(); - int M = A.extent(transposed ? 1 : 0); - int N = A.extent(transposed ? 0 : 1); - for (int i = 0; i < M; i++) { - ScalarY y_i{}; - if (has_beta) y_i = beta * y(i); - for (int j = 0; j < N; j++) { - const auto a = transposed ? A(j, i) : A(i, j); - const auto Aij = conjugated ? KAT_A::conj(a) : a; - y_i += alpha * Aij * x(j); - } - y(i) = y_i; - } -} - template class epsilon { public: @@ -367,64 +220,6 @@ class epsilon { using KokkosKernels::Impl::getRandomBounds; -template -crsMat_t symmetrize(crsMat_t A) { - typedef typename crsMat_t::StaticCrsGraphType graph_t; - typedef typename crsMat_t::values_type::non_const_type scalar_view_t; - typedef typename graph_t::row_map_type::non_const_type lno_view_t; - typedef typename graph_t::entries_type::non_const_type lno_nnz_view_t; - auto host_rowmap = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.graph.row_map); - auto host_entries = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.graph.entries); - auto host_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.values); - lno_t numRows = A.numRows(); - // symmetrize as input_mat + input_mat^T, to still have a diagonally dominant - // matrix - typedef std::map Row; - std::vector symRows(numRows); - for (lno_t r = 0; r < numRows; r++) { - auto& row = symRows[r]; - for (size_type i = host_rowmap(r); i < host_rowmap(r + 1); i++) { - lno_t c = host_entries(i); - auto& col = symRows[c]; - auto it = row.find(c); - if (it == row.end()) - row[c] = host_values(i); - else - row[c] += host_values(i); - it = col.find(r); - if (it == col.end()) - col[r] = host_values(i); - else - col[r] += host_values(i); - } - } - // Count entries - Kokkos::View new_host_rowmap("Rowmap", numRows + 1); - size_t accum = 0; - for (lno_t r = 0; r <= numRows; r++) { - new_host_rowmap(r) = accum; - if (r < numRows) accum += symRows[r].size(); - } - // Allocate new entries/values - Kokkos::View new_host_entries("Entries", accum); - Kokkos::View new_host_values("Values", accum); - for (lno_t r = 0; r < numRows; r++) { - auto rowIt = symRows[r].begin(); - for (size_type i = new_host_rowmap(r); i < new_host_rowmap(r + 1); i++) { - new_host_entries(i) = rowIt->first; - new_host_values(i) = rowIt->second; - rowIt++; - } - } - lno_view_t new_rowmap("Rowmap", numRows + 1); - lno_nnz_view_t new_entries("Entries", accum); - scalar_view_t new_values("Values", accum); - Kokkos::deep_copy(new_rowmap, new_host_rowmap); - Kokkos::deep_copy(new_entries, new_host_entries); - Kokkos::deep_copy(new_values, new_host_values); - return crsMat_t("SymA", numRows, numRows, accum, new_values, new_rowmap, new_entries); -} - // create_random_x_vector and create_random_y_vector can be used together to // generate a random linear system Ax = y. template @@ -485,17 +280,6 @@ std::string value_type_name>() { return "::ComplexDouble"; } -int string_compare_no_case(const char* str1, const char* str2) { - std::string str1_s(str1); - std::string str2_s(str2); - for (size_t i = 0; i < str1_s.size(); i++) str1_s[i] = std::tolower(str1_s[i]); - for (size_t i = 0; i < str2_s.size(); i++) str2_s[i] = std::tolower(str2_s[i]); - return strcmp(str1_s.c_str(), str2_s.c_str()); -} - -int string_compare_no_case(const std::string& str1, const std::string& str2) { - return string_compare_no_case(str1.c_str(), str2.c_str()); -} /// /brief Coo matrix class for testing purposes. /// \tparam ScalarType /// \tparam LayoutType diff --git a/test_common/KokkosKernels_TestVanilla.hpp b/test_common/KokkosKernels_TestVanilla.hpp new file mode 100644 index 0000000000..43ab7a3cf0 --- /dev/null +++ b/test_common/KokkosKernels_TestVanilla.hpp @@ -0,0 +1,177 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#ifndef KOKKOSKERNELS_TESTVANILLA_HPP +#define KOKKOSKERNELS_TESTVANILLA_HPP + +#include + +#include "KokkosKernels_Utils.hpp" +#include "KokkosKernels_IOUtils.hpp" +#include "Kokkos_ArithTraits.hpp" +#include "KokkosBatched_Vector.hpp" + +namespace Test { + +template +struct SharedVanillaGEMM { + bool A_t, B_t, A_c, B_c; + int C_rows, C_cols, A_cols; + ViewTypeA A; + ViewTypeB B; + ViewTypeC C; + + typedef typename ViewTypeA::value_type ScalarA; + typedef typename ViewTypeB::value_type ScalarB; + typedef typename ViewTypeC::value_type ScalarC; + typedef Kokkos::View SubviewTypeA; + typedef Kokkos::View SubviewTypeB; + typedef Kokkos::ArithTraits APT; + typedef typename APT::mag_type mag_type; + ScalarA alpha; + ScalarC beta; + + KOKKOS_INLINE_FUNCTION + void operator()(const typename Kokkos::TeamPolicy::member_type& team) const { + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, C_rows), [&](const int& i) { + // Give each kokkos thread a vector of A + SubviewTypeA a_vec; + if (A_t) + a_vec = Kokkos::subview(A, Kokkos::ALL(), i); + else + a_vec = Kokkos::subview(A, i, Kokkos::ALL()); + + // Have all vector lanes perform the dot product + Kokkos::parallel_for(Kokkos::ThreadVectorRange(team, C_cols), [&](const int& j) { + SubviewTypeB b_vec; + if (B_t) + b_vec = Kokkos::subview(B, j, Kokkos::ALL()); + else + b_vec = Kokkos::subview(B, Kokkos::ALL(), j); + ScalarC ab = ScalarC(0); + for (int k = 0; k < A_cols; k++) { + auto a = A_c ? APT::conj(a_vec(k)) : a_vec(k); + auto b = B_c ? APT::conj(b_vec(k)) : b_vec(k); + ab += a * b; + } + C(i, j) = beta * C(i, j) + alpha * ab; + }); + }); + } +}; +// C(i,:,:) = alpha * (A(i,:,:) * B(i,:,:)) + beta * C(i,:,:) +template +struct Functor_BatchedVanillaGEMM { + bool A_t, B_t, A_c, B_c, batch_size_last_dim = false; + ViewTypeA A; + ViewTypeB B; + ViewTypeC C; + + using ScalarA = typename ViewTypeA::value_type; + using ScalarB = typename ViewTypeB::value_type; + using ScalarC = typename ViewTypeC::value_type; + using SubviewTypeA = typename Kokkos::View; + using SubviewTypeB = typename Kokkos::View; + using SubviewTypeC = typename Kokkos::View; + + ScalarA alpha; + ScalarC beta; + + KOKKOS_INLINE_FUNCTION + void operator()(const typename Kokkos::TeamPolicy::member_type& team) const { + int i = team.league_rank(); + SubviewTypeA _A; + SubviewTypeB _B; + SubviewTypeC _C; + + if (batch_size_last_dim) { + _A = Kokkos::subview(A, Kokkos::ALL(), Kokkos::ALL(), i); + _B = Kokkos::subview(B, Kokkos::ALL(), Kokkos::ALL(), i); + _C = Kokkos::subview(C, Kokkos::ALL(), Kokkos::ALL(), i); + } else { + _A = Kokkos::subview(A, i, Kokkos::ALL(), Kokkos::ALL()); + _B = Kokkos::subview(B, i, Kokkos::ALL(), Kokkos::ALL()); + _C = Kokkos::subview(C, i, Kokkos::ALL(), Kokkos::ALL()); + } + struct SharedVanillaGEMM vgemm; + vgemm.A_t = A_t; + vgemm.B_t = B_t; + vgemm.A_c = A_c; + vgemm.B_c = B_c; + vgemm.C_rows = batch_size_last_dim ? C.extent(0) : C.extent(1); + vgemm.C_cols = batch_size_last_dim ? C.extent(1) : C.extent(2); + vgemm.A_cols = batch_size_last_dim ? (A_t ? A.extent(0) : A.extent(1)) : (A_t ? A.extent(1) : A.extent(2)); + vgemm.A = _A; + vgemm.B = _B; + vgemm.C = _C; + vgemm.alpha = alpha; + vgemm.beta = beta; + vgemm(team); + } + + inline void run() { + Kokkos::parallel_for( + "Test::VanillaGEMM", + Kokkos::TeamPolicy(batch_size_last_dim ? C.extent(2) : C.extent(0), Kokkos::AUTO, + KokkosKernels::Impl::kk_get_max_vector_size()), + *this); + } +}; + +// Compute C := alpha * AB + beta * C +template +void vanillaGEMM(typename ViewTypeC::non_const_value_type alpha, const ViewTypeA& A, const ViewTypeB& B, + typename ViewTypeC::non_const_value_type beta, const ViewTypeC& C) { + using value_type = typename ViewTypeC::non_const_value_type; + using KAT = Kokkos::ArithTraits; + int m = A.extent(0); + int k = A.extent(1); + int n = B.extent(1); + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + value_type sum = KAT::zero(); + for (int ii = 0; ii < k; ii++) { + sum += A(i, ii) * B(ii, j); + } + C(i, j) = alpha * sum + beta * C(i, j); + } + } +} + +template +KOKKOS_INLINE_FUNCTION void vanillaGEMV(char mode, AlphaType alpha, const ViewTypeA& A, const ViewTypeX& x, + BetaType beta, const ViewTypeY& y) { + using ScalarY = typename ViewTypeY::non_const_value_type; + using KAT_A = Kokkos::ArithTraits; + const bool transposed = mode == 'T' || mode == 'C'; + const bool conjugated = mode == 'C'; + const bool has_beta = beta != Kokkos::ArithTraits::zero(); + int M = A.extent(transposed ? 1 : 0); + int N = A.extent(transposed ? 0 : 1); + for (int i = 0; i < M; i++) { + ScalarY y_i{}; + if (has_beta) y_i = beta * y(i); + for (int j = 0; j < N; j++) { + const auto a = transposed ? A(j, i) : A(i, j); + const auto Aij = conjugated ? KAT_A::conj(a) : a; + y_i += alpha * Aij * x(j); + } + y(i) = y_i; + } +} + +} // namespace Test +#endif