Skip to content

Commit

Permalink
Unit test fixes with float enabled
Browse files Browse the repository at this point in the history
Addresses failing unit test and linking error in issue #322, also -Werror
  • Loading branch information
ndellingwood committed Oct 12, 2018
1 parent 83fca4a commit 74a7936
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 93 deletions.
6 changes: 4 additions & 2 deletions unit_test/batched/Test_Batched_VectorMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<value_type> random;
Expand All @@ -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);
}

{
Expand Down
34 changes: 21 additions & 13 deletions unit_test/blas/Test_Blas1_abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> 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);

Expand All @@ -52,16 +52,20 @@ namespace Test {

ScalarA expected_result = 0;
for(int i=0;i<N;i++)
expected_result += AT::abs(h_x(i)) * AT::abs(h_x(i));
{ expected_result += AT::abs(h_x(i)) * AT::abs(h_x(i)); }

KokkosBlas::abs(y,x);
ScalarB nonconst_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( nonconst_nonconst_result, expected_result, eps*expected_result);
{
ScalarB nonconst_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( nonconst_nonconst_result, expected_result, eps*expected_result);
}

Kokkos::deep_copy(b_y,b_org_y);
KokkosBlas::abs(y,c_x);
ScalarB const_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( const_nonconst_result, expected_result, eps*expected_result);
{
ScalarB const_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( const_nonconst_result, expected_result, eps*expected_result);
}
}

template<class ViewTypeA, class ViewTypeB, class Device>
Expand Down Expand Up @@ -92,8 +96,8 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> 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);

Expand All @@ -106,26 +110,30 @@ namespace Test {
for(int j=0;j<K;j++) {
expected_result[j] = ScalarA();
for(int i=0;i<N;i++)
expected_result[j] += AT::abs(h_x(i,j)) * AT::abs(h_x(i,j));
{ expected_result[j] += AT::abs(h_x(i,j)) * AT::abs(h_x(i,j)); }
}

double eps = std::is_same<ScalarA,float>::value?2*1e-5:1e-7;
typename AT::mag_type eps = AT::epsilon()*1000;

Kokkos::View<ScalarB*,Kokkos::HostSpace> r("Dot::Result",K);

KokkosBlas::abs(y,x);
KokkosBlas::dot(r,y,y);
for(int k=0;k<K;k++) {
ScalarA nonconst_result = r(k);
EXPECT_NEAR_KK( nonconst_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs( nonconst_result - expected_result[k] )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

Kokkos::deep_copy(b_y,b_org_y);
KokkosBlas::abs(y,c_x);
KokkosBlas::dot(r,y,y);
for(int k=0;k<K;k++) {
ScalarA const_result = r(k);
EXPECT_NEAR_KK( const_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs( const_result - expected_result[k] )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

delete [] expected_result;
Expand Down
8 changes: 4 additions & 4 deletions unit_test/blas/Test_Blas1_nrm2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> rand_pool(13718);

Kokkos::fill_random(b_a,rand_pool,ScalarA(10));
Kokkos::fill_random(b_a,rand_pool,ScalarA(1));

Kokkos::fence();

Expand All @@ -38,7 +38,7 @@ namespace Test {

typename AT::mag_type expected_result = 0;
for(int i=0;i<N;i++)
expected_result += AT::abs(h_a(i))*AT::abs(h_a(i));
{ expected_result += AT::abs(h_a(i))*AT::abs(h_a(i)); }
expected_result = Kokkos::Details::ArithTraits<typename AT::mag_type>::sqrt(expected_result);

typename AT::mag_type nonconst_result = KokkosBlas::nrm2(a);
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> rand_pool(13718);

Kokkos::fill_random(b_a,rand_pool,ScalarA(10));
Kokkos::fill_random(b_a,rand_pool,ScalarA(1));

Kokkos::fence();

Expand All @@ -81,7 +81,7 @@ namespace Test {
for(int j=0;j<K;j++) {
expected_result[j] = typename AT::mag_type();
for(int i=0;i<N;i++)
expected_result[j] += AT::abs(h_a(i,j))*AT::abs(h_a(i,j));
{ expected_result[j] += AT::abs(h_a(i,j))*AT::abs(h_a(i,j)); }
expected_result[j] = Kokkos::Details::ArithTraits<typename AT::mag_type>::sqrt(expected_result[j]);
}

Expand Down
18 changes: 11 additions & 7 deletions unit_test/blas/Test_Blas1_nrm2_squared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> rand_pool(13718);

Kokkos::fill_random(b_a,rand_pool,ScalarA(10));
Kokkos::fill_random(b_a,rand_pool,ScalarA(1));

Kokkos::fence();

Expand All @@ -38,7 +38,7 @@ namespace Test {

typename AT::mag_type expected_result = 0;
for(int i=0;i<N;i++)
expected_result += AT::abs(h_a(i))*AT::abs(h_a(i));
{ expected_result += AT::abs(h_a(i))*AT::abs(h_a(i)); }

typename AT::mag_type nonconst_result = KokkosBlas::nrm2_squared(a);
EXPECT_NEAR_KK( nonconst_result, expected_result, eps*expected_result);
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> rand_pool(13718);

Kokkos::fill_random(b_a,rand_pool,ScalarA(10));
Kokkos::fill_random(b_a,rand_pool,ScalarA(1));

Kokkos::fence();

Expand All @@ -80,23 +80,27 @@ namespace Test {
for(int j=0;j<K;j++) {
expected_result[j] = typename AT::mag_type();
for(int i=0;i<N;i++)
expected_result[j] += AT::abs(h_a(i,j))*AT::abs(h_a(i,j));
{ expected_result[j] += AT::abs(h_a(i,j))*AT::abs(h_a(i,j)); }
}

double eps = std::is_same<ScalarA,float>::value?2*1e-5:1e-7;
typename AT::mag_type eps = AT::epsilon()*1000;

Kokkos::View<typename AT::mag_type*,Kokkos::HostSpace> r("Dot::Result",K);

KokkosBlas::nrm2_squared(r,a);
for(int k=0;k<K;k++) {
typename AT::mag_type nonconst_result = r(k);
EXPECT_NEAR_KK( nonconst_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs(nonconst_result - expected_result[k])/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

KokkosBlas::nrm2_squared(r,c_a);
for(int k=0;k<K;k++) {
typename AT::mag_type const_result = r(k);
EXPECT_NEAR_KK( const_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs(const_result - expected_result[k])/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

delete [] expected_result;
Expand Down
31 changes: 19 additions & 12 deletions unit_test/blas/Test_Blas1_reciprocal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Test {
Kokkos::LayoutRight, Kokkos::LayoutLeft>::type,Device> BaseTypeB;


double eps = std::is_same<ScalarA,float>::value?2*1e-5:1e-7;
typename AT::mag_type eps = AT::epsilon()*2000;

BaseTypeA b_x("X",N);
BaseTypeB b_y("Y",N);
Expand All @@ -42,8 +42,8 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> 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();

Expand All @@ -54,16 +54,19 @@ namespace Test {

ScalarA expected_result = 0;
for(int i=0;i<N;i++)
expected_result += AT::abs(AT::one()/h_x(i)) * AT::abs(AT::one()/h_x(i));
{ expected_result += AT::abs(AT::one()/h_x(i)) * AT::abs(AT::one()/h_x(i)); }

KokkosBlas::reciprocal(y,x);
ScalarB nonconst_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( nonconst_nonconst_result, expected_result, eps*expected_result);
typename AT::mag_type divisor = expected_result == AT::zero() ? AT::one() : expected_result;
typename AT::mag_type diff = AT::abs( nonconst_nonconst_result - expected_result )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );

Kokkos::deep_copy(b_y,b_org_y);
KokkosBlas::reciprocal(y,c_x);
ScalarB const_nonconst_result = KokkosBlas::dot(y,y);
EXPECT_NEAR_KK( const_nonconst_result, expected_result, eps*expected_result);
diff = AT::abs( const_nonconst_result - expected_result )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

template<class ViewTypeA, class ViewTypeB, class Device>
Expand Down Expand Up @@ -94,8 +97,8 @@ namespace Test {

Kokkos::Random_XorShift64_Pool<typename Device::execution_space> 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();

Expand All @@ -110,26 +113,30 @@ namespace Test {
for(int j=0;j<K;j++) {
expected_result[j] = ScalarA();
for(int i=0;i<N;i++)
expected_result[j] += AT::abs(AT::one()/h_x(i,j)) * AT::abs(AT::one()/h_x(i,j));
{ expected_result[j] += AT::abs(AT::one()/h_x(i,j)) * AT::abs(AT::one()/h_x(i,j)); }
}

double eps = std::is_same<ScalarA,float>::value?2*1e-5:1e-7;
typename AT::mag_type eps = AT::epsilon()*2000;

Kokkos::View<ScalarB*,Kokkos::HostSpace> r("Dot::Result",K);

KokkosBlas::reciprocal(y,x);
KokkosBlas::dot(r,y,y);
for(int k=0;k<K;k++) {
ScalarA nonconst_result = r(k);
EXPECT_NEAR_KK( nonconst_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs( nonconst_result - expected_result[k] )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

Kokkos::deep_copy(b_y,b_org_y);
KokkosBlas::reciprocal(y,c_x);
KokkosBlas::dot(r,y,y);
for(int k=0;k<K;k++) {
ScalarA const_result = r(k);
EXPECT_NEAR_KK( const_result, expected_result[k], eps*expected_result[k]);
typename AT::mag_type divisor = expected_result[k] == AT::zero() ? AT::one() : expected_result[k];
typename AT::mag_type diff = AT::abs( const_result - expected_result[k] )/divisor;
EXPECT_NEAR_KK( diff, AT::zero(), eps );
}

delete [] expected_result;
Expand Down
Loading

0 comments on commit 74a7936

Please sign in to comment.