From 74a7936e7f44a6bacb71b2eba99c7c992840bd6f Mon Sep 17 00:00:00 2001 From: Nathan Ellingwood Date: Fri, 12 Oct 2018 14:28:01 -0600 Subject: [PATCH] Unit test fixes with float enabled Addresses failing unit test and linking error in issue #322, also -Werror --- unit_test/batched/Test_Batched_VectorMath.hpp | 6 +- unit_test/blas/Test_Blas1_abs.hpp | 34 +++++---- unit_test/blas/Test_Blas1_nrm2.hpp | 8 +-- unit_test/blas/Test_Blas1_nrm2_squared.hpp | 18 +++-- unit_test/blas/Test_Blas1_reciprocal.hpp | 31 ++++---- unit_test/blas/Test_Blas1_scal.hpp | 64 ++++++++++++----- unit_test/blas/Test_Blas1_team_abs.hpp | 22 +++--- unit_test/blas/Test_Blas1_team_scal.hpp | 72 ++++++++++++------- unit_test/graph/Test_Graph_graph_color_d2.hpp | 3 +- unit_test/sparse/Test_Sparse_trsv.hpp | 3 +- 10 files changed, 168 insertions(+), 93 deletions(-) diff --git a/unit_test/batched/Test_Batched_VectorMath.hpp b/unit_test/batched/Test_Batched_VectorMath.hpp index 9e330e9b37..0cdb25f634 100644 --- a/unit_test/batched/Test_Batched_VectorMath.hpp +++ b/unit_test/batched/Test_Batched_VectorMath.hpp @@ -24,7 +24,9 @@ namespace Test { typedef typename ats::mag_type mag_type; vector_type a, b, aref, bref; + const value_type one(1.0); const value_type half(0.5); + const value_type maxmin(1.0e-7); const mag_type eps = 1.0e3 * ats::epsilon(); Random random; @@ -33,8 +35,8 @@ namespace Test { const auto aval = (random.value() + half); const auto bval = (random.value() + half); - aref[k] = max(min(aval, 1.0), 1.0e-7); - bref[k] = max(min(bval, 1.0), 1.0e-7); + aref[k] = max(min(aval, one), maxmin); + bref[k] = max(min(bval, one), maxmin); } { diff --git a/unit_test/blas/Test_Blas1_abs.hpp b/unit_test/blas/Test_Blas1_abs.hpp index 63d23488f9..aebdc2bceb 100644 --- a/unit_test/blas/Test_Blas1_abs.hpp +++ b/unit_test/blas/Test_Blas1_abs.hpp @@ -42,8 +42,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::deep_copy(b_org_y,b_y); @@ -52,16 +52,20 @@ namespace Test { ScalarA expected_result = 0; for(int i=0;i @@ -92,8 +96,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::deep_copy(b_org_y,b_y); @@ -106,10 +110,10 @@ namespace Test { for(int j=0;j::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*1000; Kokkos::View r("Dot::Result",K); @@ -117,7 +121,9 @@ namespace Test { KokkosBlas::dot(r,y,y); for(int k=0;k rand_pool(13718); - Kokkos::fill_random(b_a,rand_pool,ScalarA(10)); + Kokkos::fill_random(b_a,rand_pool,ScalarA(1)); Kokkos::fence(); @@ -38,7 +38,7 @@ namespace Test { typename AT::mag_type expected_result = 0; for(int i=0;i::sqrt(expected_result); typename AT::mag_type nonconst_result = KokkosBlas::nrm2(a); @@ -69,7 +69,7 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_a,rand_pool,ScalarA(10)); + Kokkos::fill_random(b_a,rand_pool,ScalarA(1)); Kokkos::fence(); @@ -81,7 +81,7 @@ namespace Test { for(int j=0;j::sqrt(expected_result[j]); } diff --git a/unit_test/blas/Test_Blas1_nrm2_squared.hpp b/unit_test/blas/Test_Blas1_nrm2_squared.hpp index 8eea18e5f5..b4f6dc7f10 100644 --- a/unit_test/blas/Test_Blas1_nrm2_squared.hpp +++ b/unit_test/blas/Test_Blas1_nrm2_squared.hpp @@ -27,7 +27,7 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_a,rand_pool,ScalarA(10)); + Kokkos::fill_random(b_a,rand_pool,ScalarA(1)); Kokkos::fence(); @@ -38,7 +38,7 @@ namespace Test { typename AT::mag_type expected_result = 0; for(int i=0;i rand_pool(13718); - Kokkos::fill_random(b_a,rand_pool,ScalarA(10)); + Kokkos::fill_random(b_a,rand_pool,ScalarA(1)); Kokkos::fence(); @@ -80,23 +80,27 @@ namespace Test { for(int j=0;j::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*1000; Kokkos::View r("Dot::Result",K); KokkosBlas::nrm2_squared(r,a); for(int k=0;k::type,Device> BaseTypeB; - double eps = std::is_same::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*2000; BaseTypeA b_x("X",N); BaseTypeB b_y("Y",N); @@ -42,8 +42,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -54,16 +54,19 @@ namespace Test { ScalarA expected_result = 0; for(int i=0;i @@ -94,8 +97,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -110,10 +113,10 @@ namespace Test { for(int j=0;j::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*2000; Kokkos::View r("Dot::Result",K); @@ -121,7 +124,9 @@ namespace Test { KokkosBlas::dot(r,y,y); for(int k=0;k AT; typedef Kokkos::View::type,Device> BaseTypeB; - ScalarA a = 3; - double eps = std::is_same::value?2*1e-5:1e-7; + ScalarA a(3); + typename AT::mag_type eps = AT::epsilon()*1000; BaseTypeA b_x("X",N); BaseTypeB b_y("Y",N); @@ -43,8 +44,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -55,16 +56,24 @@ namespace Test { ScalarA expected_result = 0; for(int i=0;i @@ -72,6 +81,7 @@ namespace Test { typedef typename ViewTypeA::value_type ScalarA; typedef typename ViewTypeB::value_type ScalarB; + typedef Kokkos::Details::ArithTraits AT; typedef multivector_layout_adapter vfA_type; typedef multivector_layout_adapter vfB_type; @@ -94,8 +104,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -104,7 +114,7 @@ namespace Test { Kokkos::deep_copy(h_b_x,b_x); Kokkos::deep_copy(h_b_y,b_y); - ScalarA a = 3; + ScalarA a(3.0); typename ViewTypeA::const_type c_x = x; ScalarA* expected_result = new ScalarA[K]; @@ -114,7 +124,7 @@ namespace Test { expected_result[j] += ScalarB(a*h_x(i,j)) * ScalarB(a*h_x(i,j)); } - double eps = std::is_same::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*1000; Kokkos::View r("Dot::Result",K); @@ -122,7 +132,9 @@ namespace Test { KokkosBlas::dot(r,y,y); for(int k=0;k params("Params",K); for(int j=0; j param_j(params,j); Kokkos::deep_copy(param_j,ScalarA(3+j)); } + // Update expected_result for next 3 vector tests + for(int j=0;j rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::deep_copy(b_org_y,b_y); @@ -117,8 +117,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::deep_copy(b_org_y,b_y); @@ -144,9 +144,12 @@ namespace Test { KokkosBlas::Experimental::abs(teamMember, Kokkos::subview(y,Kokkos::ALL(),teamId), Kokkos::subview(x,Kokkos::ALL(),teamId)); } ); - KokkosBlas::dot(r,y,y); for(int k=0;k AT; typedef Kokkos::View::type,Device> BaseTypeB; - ScalarA a = 3; - double eps = std::is_same::value?2*1e-5:1e-7; + ScalarA a(3); + typename AT::mag_type eps = AT::epsilon()*1000; BaseTypeA b_x("X",N); BaseTypeB b_y("Y",N); @@ -51,8 +52,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -63,27 +64,33 @@ namespace Test { ScalarA expected_result = 0; for(int i=0;i @@ -97,6 +104,7 @@ namespace Test { typedef typename ViewTypeA::value_type ScalarA; typedef typename ViewTypeB::value_type ScalarB; + typedef Kokkos::Details::ArithTraits AT; typedef multivector_layout_adapter vfA_type; typedef multivector_layout_adapter vfB_type; @@ -119,8 +127,8 @@ namespace Test { Kokkos::Random_XorShift64_Pool rand_pool(13718); - Kokkos::fill_random(b_x,rand_pool,ScalarA(10)); - Kokkos::fill_random(b_y,rand_pool,ScalarB(10)); + Kokkos::fill_random(b_x,rand_pool,ScalarA(1)); + Kokkos::fill_random(b_y,rand_pool,ScalarB(1)); Kokkos::fence(); @@ -129,7 +137,7 @@ namespace Test { Kokkos::deep_copy(h_b_x,b_x); Kokkos::deep_copy(h_b_y,b_y); - ScalarA a = 3; + ScalarA a(3); typename ViewTypeA::const_type c_x = x; ScalarA* expected_result = new ScalarA[K]; @@ -139,11 +147,10 @@ namespace Test { expected_result[j] += ScalarB(a*h_x(i,j)) * ScalarB(a*h_x(i,j)); } - double eps = std::is_same::value?2*1e-5:1e-7; + typename AT::mag_type eps = AT::epsilon()*1000; Kokkos::View r("Dot::Result",K); - //KokkosBlas::scal(y,a,x); Kokkos::parallel_for( policy, KOKKOS_LAMBDA ( const team_member &teamMember ) { const int teamId = teamMember.league_rank(); KokkosBlas::Experimental::scal(teamMember, Kokkos::subview(y,Kokkos::ALL(),teamId), a, Kokkos::subview(x,Kokkos::ALL(),teamId)); @@ -152,12 +159,13 @@ namespace Test { KokkosBlas::dot(r,y,y); for(int k=0;k params("Params",K); for(int j=0; j param_j(params,j); Kokkos::deep_copy(param_j,ScalarA(3+j)); } - //KokkosBlas::scal(y,params,x); + // Update expected_result for next 3 vector tests + for(int j=0;j(50000, 50000 * 30, 200, 10); \ test_coloring_d2(50000, 50000 * 30, 100, 10); \ } - +#if defined(KOKKOSKERNELS_INST_DOUBLE) #if (defined (KOKKOSKERNELS_INST_ORDINAL_INT) \ && defined (KOKKOSKERNELS_INST_OFFSET_INT) ) || (!defined(KOKKOSKERNELS_ETI_ONLY) && !defined(KOKKOSKERNELS_IMPL_CHECK_ETI_CALLS)) EXECUTE_TEST(double, int, int, TestExecSpace) @@ -245,3 +245,4 @@ TEST_F( TestCategory, graph ## _ ## graph_color_d2 ## _ ## SCALAR ## _ ## ORDINA && defined (KOKKOSKERNELS_INST_OFFSET_SIZE_T) ) || (!defined(KOKKOSKERNELS_ETI_ONLY) && !defined(KOKKOSKERNELS_IMPL_CHECK_ETI_CALLS)) EXECUTE_TEST(double, int64_t, size_t, TestExecSpace) #endif +#endif diff --git a/unit_test/sparse/Test_Sparse_trsv.hpp b/unit_test/sparse/Test_Sparse_trsv.hpp index 697d0b1708..169ed84bad 100644 --- a/unit_test/sparse/Test_Sparse_trsv.hpp +++ b/unit_test/sparse/Test_Sparse_trsv.hpp @@ -22,7 +22,8 @@ void check_trsv_mv(crsMat_t input_mat, x_vector_type x, y_vector_type b, y_vecto //typedef typename crsMat_t::StaticCrsGraphType graph_t; typedef typename crsMat_t::values_type::non_const_type scalar_view_t; typedef typename scalar_view_t::value_type ScalarA; - double eps = std::is_same::value?2*1e-2:1e-7; + double eps = (std::is_same::value ? 2*1e-2 + : (std::is_same>::value || std::is_same>::value )? 2*1e-1 : 1e-7 ); Kokkos::fence(); KokkosSparse::trsv(uplo, "N", "N", input_mat, b, x);