Updating Kokkos library--adding new folder
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13922 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
92
lib/kokkos/containers/unit_tests/Makefile
Normal file
92
lib/kokkos/containers/unit_tests/Makefile
Normal file
@ -0,0 +1,92 @@
|
||||
KOKKOS_PATH = ../..
|
||||
|
||||
GTEST_PATH = ../../TPL/gtest
|
||||
|
||||
vpath %.cpp ${KOKKOS_PATH}/containers/unit_tests
|
||||
|
||||
default: build_all
|
||||
echo "End Build"
|
||||
|
||||
|
||||
include $(KOKKOS_PATH)/Makefile.kokkos
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_CUDA), 1)
|
||||
CXX = nvcc_wrapper
|
||||
CXXFLAGS ?= -O3
|
||||
LINK = $(CXX)
|
||||
LDFLAGS ?= -lpthread
|
||||
else
|
||||
CXX ?= g++
|
||||
CXXFLAGS ?= -O3
|
||||
LINK ?= $(CXX)
|
||||
LDFLAGS ?= -lpthread
|
||||
endif
|
||||
|
||||
KOKKOS_CXXFLAGS += -I$(GTEST_PATH) -I${KOKKOS_PATH}/containers/unit_tests
|
||||
|
||||
TEST_TARGETS =
|
||||
TARGETS =
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_CUDA), 1)
|
||||
OBJ_CUDA = TestCuda.o UnitTestMain.o gtest-all.o
|
||||
TARGETS += KokkosContainers_UnitTest_Cuda
|
||||
TEST_TARGETS += test-cuda
|
||||
endif
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_PTHREADS), 1)
|
||||
OBJ_THREADS = TestThreads.o UnitTestMain.o gtest-all.o
|
||||
TARGETS += KokkosContainers_UnitTest_Threads
|
||||
TEST_TARGETS += test-threads
|
||||
endif
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_OPENMP), 1)
|
||||
OBJ_OPENMP = TestOpenMP.o UnitTestMain.o gtest-all.o
|
||||
TARGETS += KokkosContainers_UnitTest_OpenMP
|
||||
TEST_TARGETS += test-openmp
|
||||
endif
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_SERIAL), 1)
|
||||
OBJ_SERIAL = TestSerial.o UnitTestMain.o gtest-all.o
|
||||
TARGETS += KokkosContainers_UnitTest_Serial
|
||||
TEST_TARGETS += test-serial
|
||||
endif
|
||||
|
||||
KokkosContainers_UnitTest_Cuda: $(OBJ_CUDA) $(KOKKOS_LINK_DEPENDS)
|
||||
$(LINK) $(KOKKOS_LDFLAGS) $(LDFLAGS) $(EXTRA_PATH) $(OBJ_CUDA) $(KOKKOS_LIBS) $(LIB) -o KokkosContainers_UnitTest_Cuda
|
||||
|
||||
KokkosContainers_UnitTest_Threads: $(OBJ_THREADS) $(KOKKOS_LINK_DEPENDS)
|
||||
$(LINK) $(KOKKOS_LDFLAGS) $(LDFLAGS) $(EXTRA_PATH) $(OBJ_THREADS) $(KOKKOS_LIBS) $(LIB) -o KokkosContainers_UnitTest_Threads
|
||||
|
||||
KokkosContainers_UnitTest_OpenMP: $(OBJ_OPENMP) $(KOKKOS_LINK_DEPENDS)
|
||||
$(LINK) $(KOKKOS_LDFLAGS) $(LDFLAGS) $(EXTRA_PATH) $(OBJ_OPENMP) $(KOKKOS_LIBS) $(LIB) -o KokkosContainers_UnitTest_OpenMP
|
||||
|
||||
KokkosContainers_UnitTest_Serial: $(OBJ_SERIAL) $(KOKKOS_LINK_DEPENDS)
|
||||
$(LINK) $(KOKKOS_LDFLAGS) $(LDFLAGS) $(EXTRA_PATH) $(OBJ_SERIAL) $(KOKKOS_LIBS) $(LIB) -o KokkosContainers_UnitTest_Serial
|
||||
|
||||
test-cuda: KokkosContainers_UnitTest_Cuda
|
||||
./KokkosContainers_UnitTest_Cuda
|
||||
|
||||
test-threads: KokkosContainers_UnitTest_Threads
|
||||
./KokkosContainers_UnitTest_Threads
|
||||
|
||||
test-openmp: KokkosContainers_UnitTest_OpenMP
|
||||
./KokkosContainers_UnitTest_OpenMP
|
||||
|
||||
test-serial: KokkosContainers_UnitTest_Serial
|
||||
./KokkosContainers_UnitTest_Serial
|
||||
|
||||
build_all: $(TARGETS)
|
||||
|
||||
test: $(TEST_TARGETS)
|
||||
|
||||
clean: kokkos-clean
|
||||
rm -f *.o $(TARGETS)
|
||||
|
||||
# Compilation rules
|
||||
|
||||
%.o:%.cpp $(KOKKOS_CPP_DEPENDS)
|
||||
$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c $<
|
||||
|
||||
gtest-all.o:$(GTEST_PATH)/gtest/gtest-all.cc
|
||||
$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c $(GTEST_PATH)/gtest/gtest-all.cc
|
||||
|
||||
285
lib/kokkos/containers/unit_tests/TestBitset.hpp
Normal file
285
lib/kokkos/containers/unit_tests/TestBitset.hpp
Normal file
@ -0,0 +1,285 @@
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
|
||||
#ifndef KOKKOS_TEST_BITSET_HPP
|
||||
#define KOKKOS_TEST_BITSET_HPP
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
template <typename Bitset, bool Set>
|
||||
struct TestBitset
|
||||
{
|
||||
typedef Bitset bitset_type;
|
||||
typedef typename bitset_type::execution_space execution_space;
|
||||
typedef uint32_t value_type;
|
||||
|
||||
bitset_type m_bitset;
|
||||
|
||||
TestBitset( bitset_type const& bitset)
|
||||
: m_bitset(bitset)
|
||||
{}
|
||||
|
||||
unsigned testit(unsigned collisions)
|
||||
{
|
||||
execution_space::fence();
|
||||
|
||||
unsigned count = 0;
|
||||
Kokkos::parallel_reduce( m_bitset.size()*collisions, *this, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void init( value_type & v ) const { v = 0; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void join( volatile value_type & dst, const volatile value_type & src ) const
|
||||
{ dst += src; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(uint32_t i, value_type & v) const
|
||||
{
|
||||
i = i % m_bitset.size();
|
||||
if (Set) {
|
||||
if (m_bitset.set(i)) {
|
||||
if (m_bitset.test(i)) ++v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_bitset.reset(i)) {
|
||||
if (!m_bitset.test(i)) ++v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename Bitset>
|
||||
struct TestBitsetTest
|
||||
{
|
||||
typedef Bitset bitset_type;
|
||||
typedef typename bitset_type::execution_space execution_space;
|
||||
typedef uint32_t value_type;
|
||||
|
||||
bitset_type m_bitset;
|
||||
|
||||
TestBitsetTest( bitset_type const& bitset)
|
||||
: m_bitset(bitset)
|
||||
{}
|
||||
|
||||
unsigned testit()
|
||||
{
|
||||
execution_space::fence();
|
||||
|
||||
unsigned count = 0;
|
||||
Kokkos::parallel_reduce( m_bitset.size(), *this, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void init( value_type & v ) const { v = 0; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void join( volatile value_type & dst, const volatile value_type & src ) const
|
||||
{ dst += src; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(uint32_t i, value_type & v) const
|
||||
{
|
||||
if (m_bitset.test( i )) ++v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Bitset, bool Set>
|
||||
struct TestBitsetAny
|
||||
{
|
||||
typedef Bitset bitset_type;
|
||||
typedef typename bitset_type::execution_space execution_space;
|
||||
typedef uint32_t value_type;
|
||||
|
||||
bitset_type m_bitset;
|
||||
|
||||
TestBitsetAny( bitset_type const& bitset)
|
||||
: m_bitset(bitset)
|
||||
{}
|
||||
|
||||
unsigned testit()
|
||||
{
|
||||
execution_space::fence();
|
||||
|
||||
unsigned count = 0;
|
||||
Kokkos::parallel_reduce( m_bitset.size(), *this, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void init( value_type & v ) const { v = 0; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void join( volatile value_type & dst, const volatile value_type & src ) const
|
||||
{ dst += src; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(uint32_t i, value_type & v) const
|
||||
{
|
||||
bool result = false;
|
||||
unsigned attempts = 0;
|
||||
uint32_t hint = (i >> 4) << 4;
|
||||
while (attempts < m_bitset.max_hint()) {
|
||||
if (Set) {
|
||||
Kokkos::tie(result, hint) = m_bitset.find_any_unset_near(hint, i);
|
||||
if (result && m_bitset.set(hint)) {
|
||||
++v;
|
||||
break;
|
||||
}
|
||||
else if (!result) {
|
||||
++attempts;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Kokkos::tie(result, hint) = m_bitset.find_any_set_near(hint, i);
|
||||
if (result && m_bitset.reset(hint)) {
|
||||
++v;
|
||||
break;
|
||||
}
|
||||
else if (!result) {
|
||||
++attempts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
|
||||
template <typename Device>
|
||||
void test_bitset()
|
||||
{
|
||||
typedef Kokkos::Bitset< Device > bitset_type;
|
||||
typedef Kokkos::ConstBitset< Device > const_bitset_type;
|
||||
|
||||
//unsigned test_sizes[] = { 0u, 1000u, 1u<<14, 1u<<16, 10000001 };
|
||||
unsigned test_sizes[] = { 1000u, 1u<<14, 1u<<16, 10000001 };
|
||||
|
||||
for (int i=0, end = sizeof(test_sizes)/sizeof(unsigned); i<end; ++i) {
|
||||
|
||||
//std::cout << "Bitset " << test_sizes[i] << std::endl;
|
||||
|
||||
bitset_type bitset(test_sizes[i]);
|
||||
|
||||
//std::cout << " Check inital count " << std::endl;
|
||||
// nothing should be set
|
||||
{
|
||||
Impl::TestBitsetTest< bitset_type > f(bitset);
|
||||
uint32_t count = f.testit();
|
||||
EXPECT_EQ(0u, count);
|
||||
EXPECT_EQ(count, bitset.count());
|
||||
}
|
||||
|
||||
//std::cout << " Check set() " << std::endl;
|
||||
bitset.set();
|
||||
// everything should be set
|
||||
{
|
||||
Impl::TestBitsetTest< const_bitset_type > f(bitset);
|
||||
uint32_t count = f.testit();
|
||||
EXPECT_EQ(bitset.size(), count);
|
||||
EXPECT_EQ(count, bitset.count());
|
||||
}
|
||||
|
||||
//std::cout << " Check reset() " << std::endl;
|
||||
bitset.reset();
|
||||
EXPECT_EQ(0u, bitset.count());
|
||||
|
||||
//std::cout << " Check set(i) " << std::endl;
|
||||
// test setting bits
|
||||
{
|
||||
Impl::TestBitset< bitset_type, true > f(bitset);
|
||||
uint32_t count = f.testit(10u);
|
||||
EXPECT_EQ( bitset.size(), bitset.count());
|
||||
EXPECT_EQ( bitset.size(), count );
|
||||
}
|
||||
|
||||
//std::cout << " Check reset(i) " << std::endl;
|
||||
// test resetting bits
|
||||
{
|
||||
Impl::TestBitset< bitset_type, false > f(bitset);
|
||||
uint32_t count = f.testit(10u);
|
||||
EXPECT_EQ( bitset.size(), count);
|
||||
EXPECT_EQ( 0u, bitset.count() );
|
||||
}
|
||||
|
||||
|
||||
//std::cout << " Check find_any_set(i) " << std::endl;
|
||||
// test setting any bits
|
||||
{
|
||||
Impl::TestBitsetAny< bitset_type, true > f(bitset);
|
||||
uint32_t count = f.testit();
|
||||
EXPECT_EQ( bitset.size(), bitset.count());
|
||||
EXPECT_EQ( bitset.size(), count );
|
||||
}
|
||||
|
||||
//std::cout << " Check find_any_unset(i) " << std::endl;
|
||||
// test resetting any bits
|
||||
{
|
||||
Impl::TestBitsetAny< bitset_type, false > f(bitset);
|
||||
uint32_t count = f.testit();
|
||||
EXPECT_EQ( bitset.size(), count);
|
||||
EXPECT_EQ( 0u, bitset.count() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif //KOKKOS_TEST_BITSET_HPP
|
||||
|
||||
264
lib/kokkos/containers/unit_tests/TestComplex.hpp
Normal file
264
lib/kokkos/containers/unit_tests/TestComplex.hpp
Normal file
@ -0,0 +1,264 @@
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
|
||||
|
||||
#ifndef KOKKOS_TEST_COMPLEX_HPP
|
||||
#define KOKKOS_TEST_COMPLEX_HPP
|
||||
|
||||
//#include <Kokkos_Complex.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
template <typename RealType>
|
||||
void testComplexConstructors () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
|
||||
complex_type z1;
|
||||
complex_type z2 (0.0, 0.0);
|
||||
complex_type z3 (1.0, 0.0);
|
||||
complex_type z4 (0.0, 1.0);
|
||||
complex_type z5 (-1.0, -2.0);
|
||||
|
||||
ASSERT_TRUE( z1 == z2 );
|
||||
ASSERT_TRUE( z1 != z3 );
|
||||
ASSERT_TRUE( z1 != z4 );
|
||||
ASSERT_TRUE( z1 != z5 );
|
||||
|
||||
ASSERT_TRUE( z2 != z3 );
|
||||
ASSERT_TRUE( z2 != z4 );
|
||||
ASSERT_TRUE( z2 != z5 );
|
||||
|
||||
ASSERT_TRUE( z3 != z4 );
|
||||
ASSERT_TRUE( z3 != z5 );
|
||||
|
||||
complex_type z6 (-1.0, -2.0);
|
||||
ASSERT_TRUE( z5 == z6 );
|
||||
|
||||
// Make sure that complex has value semantics, in particular, that
|
||||
// equality tests use values and not pointers, so that
|
||||
// reassignment actually changes the value.
|
||||
z1 = complex_type (-3.0, -4.0);
|
||||
ASSERT_TRUE( z1.real () == -3.0 );
|
||||
ASSERT_TRUE( z1.imag () == -4.0 );
|
||||
ASSERT_TRUE( z1 != z2 );
|
||||
|
||||
complex_type z7 (1.0);
|
||||
ASSERT_TRUE( z3 == z7 );
|
||||
ASSERT_TRUE( z7 == 1.0 );
|
||||
ASSERT_TRUE( z7 != -1.0 );
|
||||
|
||||
z7 = complex_type (5.0);
|
||||
ASSERT_TRUE( z7.real () == 5.0 );
|
||||
ASSERT_TRUE( z7.imag () == 0.0 );
|
||||
}
|
||||
|
||||
template <typename RealType>
|
||||
void testPlus () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
|
||||
complex_type z1 (1.0, -1.0);
|
||||
complex_type z2 (-1.0, 1.0);
|
||||
complex_type z3 = z1 + z2;
|
||||
ASSERT_TRUE( z3 == complex_type (0.0, 0.0) );
|
||||
}
|
||||
|
||||
template <typename RealType>
|
||||
void testMinus () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
|
||||
// Test binary minus.
|
||||
complex_type z1 (1.0, -1.0);
|
||||
complex_type z2 (-1.0, 1.0);
|
||||
complex_type z3 = z1 - z2;
|
||||
ASSERT_TRUE( z3 == complex_type (2.0, -2.0) );
|
||||
|
||||
// Test unary minus.
|
||||
complex_type z4 (3.0, -4.0);
|
||||
ASSERT_TRUE( -z1 == complex_type (-3.0, 4.0) );
|
||||
}
|
||||
|
||||
template <typename RealType>
|
||||
void testTimes () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
|
||||
complex_type z1 (1.0, -1.0);
|
||||
complex_type z2 (-1.0, 1.0);
|
||||
complex_type z3 = z1 - z2;
|
||||
ASSERT_TRUE( z3 == complex_type (2.0, -2.0) );
|
||||
|
||||
// Test unary minus.
|
||||
complex_type z4 (3.0, -4.0);
|
||||
ASSERT_TRUE( z4 == complex_type (3.0, -4.0) );
|
||||
ASSERT_TRUE( -z4 == complex_type (-3.0, 4.0) );
|
||||
ASSERT_TRUE( z4 == -complex_type (-3.0, 4.0) );
|
||||
}
|
||||
|
||||
template <typename RealType>
|
||||
void testDivide () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
|
||||
// Test division of a complex number by a real number.
|
||||
complex_type z1 (1.0, -1.0);
|
||||
complex_type z2 (1.0 / 2.0, -1.0 / 2.0);
|
||||
ASSERT_TRUE( z1 / 2.0 == z2 );
|
||||
|
||||
// (-1+2i)/(1-i) == ((-1+2i)(1+i)) / ((1-i)(1+i))
|
||||
// (-1+2i)(1+i) == -3 + i
|
||||
complex_type z3 (-1.0, 2.0);
|
||||
complex_type z4 (1.0, -1.0);
|
||||
complex_type z5 (-3.0, 1.0);
|
||||
ASSERT_TRUE(z3 * Kokkos::conj (z4) == z5 );
|
||||
|
||||
// Test division of a complex number by a complex number.
|
||||
// This assumes that RealType is a floating-point type.
|
||||
complex_type z6 (Kokkos::real (z5) / 2.0,
|
||||
Kokkos::imag (z5) / 2.0);
|
||||
|
||||
complex_type z7 = z3 / z4;
|
||||
ASSERT_TRUE( z7 == z6 );
|
||||
}
|
||||
|
||||
template <typename RealType>
|
||||
void testOutsideKernel () {
|
||||
testComplexConstructors<RealType> ();
|
||||
testPlus<RealType> ();
|
||||
testTimes<RealType> ();
|
||||
testDivide<RealType> ();
|
||||
}
|
||||
|
||||
|
||||
template<typename RealType, typename Device>
|
||||
void testCreateView () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
Kokkos::View<complex_type*, Device> x ("x", 10);
|
||||
ASSERT_TRUE( x.dimension_0 () == 10 );
|
||||
|
||||
// Test that View assignment works.
|
||||
Kokkos::View<complex_type*, Device> x_nonconst = x;
|
||||
Kokkos::View<const complex_type*, Device> x_const = x;
|
||||
}
|
||||
|
||||
template<typename RealType, typename Device>
|
||||
class Fill {
|
||||
public:
|
||||
typedef typename Device::execution_space execution_space;
|
||||
|
||||
typedef Kokkos::View<Kokkos::complex<RealType>*, Device> view_type;
|
||||
typedef typename view_type::size_type size_type;
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator () (const size_type i) const {
|
||||
x_(i) = val_;
|
||||
}
|
||||
|
||||
Fill (const view_type& x, const Kokkos::complex<RealType>& val) :
|
||||
x_ (x), val_ (val)
|
||||
{}
|
||||
|
||||
private:
|
||||
view_type x_;
|
||||
const Kokkos::complex<RealType> val_;
|
||||
};
|
||||
|
||||
template<typename RealType, typename Device>
|
||||
class Sum {
|
||||
public:
|
||||
typedef typename Device::execution_space execution_space;
|
||||
|
||||
typedef Kokkos::View<const Kokkos::complex<RealType>*, Device> view_type;
|
||||
typedef typename view_type::size_type size_type;
|
||||
typedef Kokkos::complex<RealType> value_type;
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator () (const size_type i, Kokkos::complex<RealType>& sum) const {
|
||||
sum += x_(i);
|
||||
}
|
||||
|
||||
Sum (const view_type& x) : x_ (x) {}
|
||||
|
||||
private:
|
||||
view_type x_;
|
||||
};
|
||||
|
||||
template<typename RealType, typename Device>
|
||||
void testInsideKernel () {
|
||||
typedef Kokkos::complex<RealType> complex_type;
|
||||
typedef Kokkos::View<complex_type*, Device> view_type;
|
||||
typedef typename view_type::size_type size_type;
|
||||
|
||||
const size_type N = 1000;
|
||||
view_type x ("x", N);
|
||||
ASSERT_TRUE( x.dimension_0 () == N );
|
||||
|
||||
// Kokkos::parallel_reduce (N, [=] (const size_type i, complex_type& result) {
|
||||
// result += x[i];
|
||||
// });
|
||||
|
||||
Kokkos::parallel_for (N, Fill<RealType, Device> (x, complex_type (1.0, -1.0)));
|
||||
|
||||
complex_type sum;
|
||||
Kokkos::parallel_reduce (N, Sum<RealType, Device> (x), sum);
|
||||
|
||||
ASSERT_TRUE( sum.real () == 1000.0 && sum.imag () == -1000.0 );
|
||||
}
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
template <typename Device>
|
||||
void testComplex ()
|
||||
{
|
||||
Impl::testOutsideKernel<float> ();
|
||||
Impl::testOutsideKernel<double> ();
|
||||
|
||||
Impl::testCreateView<float, Device> ();
|
||||
Impl::testCreateView<double, Device> ();
|
||||
|
||||
Impl::testInsideKernel<float, Device> ();
|
||||
Impl::testInsideKernel<double, Device> ();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif // KOKKOS_TEST_COMPLEX_HPP
|
||||
206
lib/kokkos/containers/unit_tests/TestCuda.cpp
Normal file
206
lib/kokkos/containers/unit_tests/TestCuda.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
#include <Kokkos_Bitset.hpp>
|
||||
#include <Kokkos_UnorderedMap.hpp>
|
||||
#include <Kokkos_Vector.hpp>
|
||||
|
||||
#include <TestBitset.hpp>
|
||||
#include <TestUnorderedMap.hpp>
|
||||
#include <TestStaticCrsGraph.hpp>
|
||||
#include <TestVector.hpp>
|
||||
#include <TestDualView.hpp>
|
||||
#include <TestSegmentedView.hpp>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef KOKKOS_HAVE_CUDA
|
||||
|
||||
namespace Test {
|
||||
|
||||
class cuda : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
std::cout << std::setprecision(5) << std::scientific;
|
||||
Kokkos::HostSpace::execution_space::initialize();
|
||||
Kokkos::Cuda::initialize( Kokkos::Cuda::SelectDevice(0) );
|
||||
}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
Kokkos::Cuda::finalize();
|
||||
Kokkos::HostSpace::execution_space::finalize();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F( cuda , staticcrsgraph )
|
||||
{
|
||||
TestStaticCrsGraph::run_test_graph< Kokkos::Cuda >();
|
||||
TestStaticCrsGraph::run_test_graph2< Kokkos::Cuda >();
|
||||
}
|
||||
|
||||
|
||||
void cuda_test_insert_close( uint32_t num_nodes
|
||||
, uint32_t num_inserts
|
||||
, uint32_t num_duplicates
|
||||
)
|
||||
{
|
||||
test_insert< Kokkos::Cuda >( num_nodes, num_inserts, num_duplicates, true);
|
||||
}
|
||||
|
||||
void cuda_test_insert_far( uint32_t num_nodes
|
||||
, uint32_t num_inserts
|
||||
, uint32_t num_duplicates
|
||||
)
|
||||
{
|
||||
test_insert< Kokkos::Cuda >( num_nodes, num_inserts, num_duplicates, false);
|
||||
}
|
||||
|
||||
void cuda_test_failed_insert( uint32_t num_nodes )
|
||||
{
|
||||
test_failed_insert< Kokkos::Cuda >( num_nodes );
|
||||
}
|
||||
|
||||
void cuda_test_deep_copy( uint32_t num_nodes )
|
||||
{
|
||||
test_deep_copy< Kokkos::Cuda >( num_nodes );
|
||||
}
|
||||
|
||||
void cuda_test_vector_combinations(unsigned int size)
|
||||
{
|
||||
test_vector_combinations<int,Kokkos::Cuda>(size);
|
||||
}
|
||||
|
||||
void cuda_test_dualview_combinations(unsigned int size)
|
||||
{
|
||||
test_dualview_combinations<int,Kokkos::Cuda>(size);
|
||||
}
|
||||
|
||||
void cuda_test_segmented_view(unsigned int size)
|
||||
{
|
||||
test_segmented_view<double,Kokkos::Cuda>(size);
|
||||
}
|
||||
|
||||
void cuda_test_bitset()
|
||||
{
|
||||
test_bitset<Kokkos::Cuda>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*TEST_F( cuda, bitset )
|
||||
{
|
||||
cuda_test_bitset();
|
||||
}*/
|
||||
|
||||
#define CUDA_INSERT_TEST( name, num_nodes, num_inserts, num_duplicates, repeat ) \
|
||||
TEST_F( cuda, UnorderedMap_insert_##name##_##num_nodes##_##num_inserts##_##num_duplicates##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
cuda_test_insert_##name(num_nodes,num_inserts,num_duplicates); \
|
||||
}
|
||||
|
||||
#define CUDA_FAILED_INSERT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( cuda, UnorderedMap_failed_insert_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
cuda_test_failed_insert(num_nodes); \
|
||||
}
|
||||
|
||||
#define CUDA_ASSIGNEMENT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( cuda, UnorderedMap_assignment_operators_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
cuda_test_assignment_operators(num_nodes); \
|
||||
}
|
||||
|
||||
#define CUDA_DEEP_COPY( num_nodes, repeat ) \
|
||||
TEST_F( cuda, UnorderedMap_deep_copy##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
cuda_test_deep_copy(num_nodes); \
|
||||
}
|
||||
|
||||
#define CUDA_VECTOR_COMBINE_TEST( size ) \
|
||||
TEST_F( cuda, vector_combination##size##x) { \
|
||||
cuda_test_vector_combinations(size); \
|
||||
}
|
||||
|
||||
#define CUDA_DUALVIEW_COMBINE_TEST( size ) \
|
||||
TEST_F( cuda, dualview_combination##size##x) { \
|
||||
cuda_test_dualview_combinations(size); \
|
||||
}
|
||||
|
||||
#define CUDA_SEGMENTEDVIEW_TEST( size ) \
|
||||
TEST_F( cuda, segmentedview_##size##x) { \
|
||||
cuda_test_segmented_view(size); \
|
||||
}
|
||||
|
||||
CUDA_DUALVIEW_COMBINE_TEST( 10 )
|
||||
CUDA_VECTOR_COMBINE_TEST( 10 )
|
||||
CUDA_VECTOR_COMBINE_TEST( 3057 )
|
||||
|
||||
|
||||
CUDA_INSERT_TEST(close, 100000, 90000, 100, 500)
|
||||
CUDA_INSERT_TEST(far, 100000, 90000, 100, 500)
|
||||
CUDA_DEEP_COPY( 10000, 1 )
|
||||
CUDA_FAILED_INSERT_TEST( 10000, 1000 )
|
||||
CUDA_SEGMENTEDVIEW_TEST( 200 )
|
||||
|
||||
|
||||
#undef CUDA_INSERT_TEST
|
||||
#undef CUDA_FAILED_INSERT_TEST
|
||||
#undef CUDA_ASSIGNEMENT_TEST
|
||||
#undef CUDA_DEEP_COPY
|
||||
#undef CUDA_VECTOR_COMBINE_TEST
|
||||
#undef CUDA_DUALVIEW_COMBINE_TEST
|
||||
#undef CUDA_SEGMENTEDVIEW_TEST
|
||||
}
|
||||
|
||||
#endif /* #ifdef KOKKOS_HAVE_CUDA */
|
||||
|
||||
121
lib/kokkos/containers/unit_tests/TestDualView.hpp
Normal file
121
lib/kokkos/containers/unit_tests/TestDualView.hpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_TEST_DUALVIEW_HPP
|
||||
#define KOKKOS_TEST_DUALVIEW_HPP
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <impl/Kokkos_Timer.hpp>
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
struct test_dualview_combinations
|
||||
{
|
||||
typedef test_dualview_combinations<Scalar,Device> self_type;
|
||||
|
||||
typedef Scalar scalar_type;
|
||||
typedef Device execution_space;
|
||||
|
||||
Scalar reference;
|
||||
Scalar result;
|
||||
|
||||
template <typename ViewType>
|
||||
Scalar run_me(unsigned int n,unsigned int m){
|
||||
if(n<10) n = 10;
|
||||
if(m<3) m = 3;
|
||||
ViewType a("A",n,m);
|
||||
|
||||
Kokkos::deep_copy( a.d_view , 1 );
|
||||
|
||||
a.template modify<typename ViewType::execution_space>();
|
||||
a.template sync<typename ViewType::host_mirror_space>();
|
||||
|
||||
a.h_view(5,1) = 3;
|
||||
a.h_view(6,1) = 4;
|
||||
a.h_view(7,2) = 5;
|
||||
a.template modify<typename ViewType::host_mirror_space>();
|
||||
ViewType b = Kokkos::subview(a,std::pair<unsigned int, unsigned int>(6,9),std::pair<unsigned int, unsigned int>(0,1));
|
||||
a.template sync<typename ViewType::execution_space>();
|
||||
b.template modify<typename ViewType::execution_space>();
|
||||
|
||||
Kokkos::deep_copy( b.d_view , 2 );
|
||||
|
||||
a.template sync<typename ViewType::host_mirror_space>();
|
||||
Scalar count = 0;
|
||||
for(unsigned int i = 0; i<a.d_view.dimension_0(); i++)
|
||||
for(unsigned int j = 0; j<a.d_view.dimension_1(); j++)
|
||||
count += a.h_view(i,j);
|
||||
return count - a.d_view.dimension_0()*a.d_view.dimension_1()-2-4-3*2;
|
||||
}
|
||||
|
||||
|
||||
test_dualview_combinations(unsigned int size)
|
||||
{
|
||||
result = run_me< Kokkos::DualView<Scalar**,Kokkos::LayoutLeft,Device> >(size,3);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_combinations(unsigned int size)
|
||||
{
|
||||
Impl::test_dualview_combinations<Scalar,Device> test(size);
|
||||
ASSERT_EQ( test.result,0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif //KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
162
lib/kokkos/containers/unit_tests/TestOpenMP.cpp
Normal file
162
lib/kokkos/containers/unit_tests/TestOpenMP.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
#include <Kokkos_Bitset.hpp>
|
||||
#include <Kokkos_UnorderedMap.hpp>
|
||||
#include <Kokkos_Vector.hpp>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#include <TestBitset.hpp>
|
||||
#include <TestUnorderedMap.hpp>
|
||||
#include <TestStaticCrsGraph.hpp>
|
||||
#include <TestVector.hpp>
|
||||
#include <TestDualView.hpp>
|
||||
#include <TestSegmentedView.hpp>
|
||||
#include <TestComplex.hpp>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
namespace Test {
|
||||
|
||||
#ifdef KOKKOS_HAVE_OPENMP
|
||||
class openmp : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
std::cout << std::setprecision(5) << std::scientific;
|
||||
|
||||
unsigned threads_count = 4 ;
|
||||
|
||||
if ( Kokkos::hwloc::available() ) {
|
||||
threads_count = Kokkos::hwloc::get_available_numa_count() *
|
||||
Kokkos::hwloc::get_available_cores_per_numa();
|
||||
}
|
||||
|
||||
Kokkos::OpenMP::initialize( threads_count );
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
Kokkos::OpenMP::finalize();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F( openmp, complex )
|
||||
{
|
||||
testComplex<Kokkos::OpenMP> ();
|
||||
}
|
||||
|
||||
TEST_F( openmp, bitset )
|
||||
{
|
||||
test_bitset<Kokkos::OpenMP>();
|
||||
}
|
||||
|
||||
TEST_F( openmp , staticcrsgraph )
|
||||
{
|
||||
TestStaticCrsGraph::run_test_graph< Kokkos::OpenMP >();
|
||||
TestStaticCrsGraph::run_test_graph2< Kokkos::OpenMP >();
|
||||
}
|
||||
|
||||
#define OPENMP_INSERT_TEST( name, num_nodes, num_inserts, num_duplicates, repeat, near ) \
|
||||
TEST_F( openmp, UnorderedMap_insert_##name##_##num_nodes##_##num_inserts##_##num_duplicates##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_insert<Kokkos::OpenMP>(num_nodes,num_inserts,num_duplicates, near); \
|
||||
}
|
||||
|
||||
#define OPENMP_FAILED_INSERT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( openmp, UnorderedMap_failed_insert_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_failed_insert<Kokkos::OpenMP>(num_nodes); \
|
||||
}
|
||||
|
||||
#define OPENMP_ASSIGNEMENT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( openmp, UnorderedMap_assignment_operators_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_assignement_operators<Kokkos::OpenMP>(num_nodes); \
|
||||
}
|
||||
|
||||
#define OPENMP_DEEP_COPY( num_nodes, repeat ) \
|
||||
TEST_F( openmp, UnorderedMap_deep_copy##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_deep_copy<Kokkos::OpenMP>(num_nodes); \
|
||||
}
|
||||
|
||||
#define OPENMP_VECTOR_COMBINE_TEST( size ) \
|
||||
TEST_F( openmp, vector_combination##size##x) { \
|
||||
test_vector_combinations<int,Kokkos::OpenMP>(size); \
|
||||
}
|
||||
|
||||
#define OPENMP_DUALVIEW_COMBINE_TEST( size ) \
|
||||
TEST_F( openmp, dualview_combination##size##x) { \
|
||||
test_dualview_combinations<int,Kokkos::OpenMP>(size); \
|
||||
}
|
||||
|
||||
#define OPENMP_SEGMENTEDVIEW_TEST( size ) \
|
||||
TEST_F( openmp, segmentedview_##size##x) { \
|
||||
test_segmented_view<double,Kokkos::OpenMP>(size); \
|
||||
}
|
||||
|
||||
OPENMP_INSERT_TEST(close, 100000, 90000, 100, 500, true)
|
||||
OPENMP_INSERT_TEST(far, 100000, 90000, 100, 500, false)
|
||||
OPENMP_FAILED_INSERT_TEST( 10000, 1000 )
|
||||
OPENMP_DEEP_COPY( 10000, 1 )
|
||||
|
||||
OPENMP_VECTOR_COMBINE_TEST( 10 )
|
||||
OPENMP_VECTOR_COMBINE_TEST( 3057 )
|
||||
OPENMP_DUALVIEW_COMBINE_TEST( 10 )
|
||||
OPENMP_SEGMENTEDVIEW_TEST( 10000 )
|
||||
|
||||
#undef OPENMP_INSERT_TEST
|
||||
#undef OPENMP_FAILED_INSERT_TEST
|
||||
#undef OPENMP_ASSIGNEMENT_TEST
|
||||
#undef OPENMP_DEEP_COPY
|
||||
#undef OPENMP_VECTOR_COMBINE_TEST
|
||||
#undef OPENMP_DUALVIEW_COMBINE_TEST
|
||||
#undef OPENMP_SEGMENTEDVIEW_TEST
|
||||
#endif
|
||||
} // namespace test
|
||||
|
||||
708
lib/kokkos/containers/unit_tests/TestSegmentedView.hpp
Normal file
708
lib/kokkos/containers/unit_tests/TestSegmentedView.hpp
Normal file
@ -0,0 +1,708 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_TEST_SEGMENTEDVIEW_HPP
|
||||
#define KOKKOS_TEST_SEGMENTEDVIEW_HPP
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
#if ! defined( KOKKOS_USING_EXPERIMENTAL_VIEW )
|
||||
|
||||
#include <Kokkos_SegmentedView.hpp>
|
||||
#include <impl/Kokkos_Timer.hpp>
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
template<class ViewType , class ExecutionSpace, int Rank = ViewType::Rank>
|
||||
struct GrowTest;
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 1> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+team_member.team_size());
|
||||
value += team_idx + team_member.team_rank();
|
||||
|
||||
if((a.dimension_0()>team_idx+team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+team_member.team_rank()))
|
||||
a(team_idx+team_member.team_rank()) = team_idx+team_member.team_rank();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 2> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
value += team_idx + team_member.team_rank() + 13*k;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++) {
|
||||
a(team_idx+ team_member.team_rank(),k) =
|
||||
team_idx+ team_member.team_rank() + 13*k;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 3> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
value += team_idx + team_member.team_rank() + 13*k + 3*l;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
a(team_idx+ team_member.team_rank(),k,l) =
|
||||
team_idx+ team_member.team_rank() + 13*k + 3*l;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 4> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<2;m++)
|
||||
value += team_idx + team_member.team_rank() + 13*k + 3*l + 7*m;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
a(team_idx+ team_member.team_rank(),k,l,m) =
|
||||
team_idx+ team_member.team_rank() + 13*k + 3*l + 7*m;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 5> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<2;m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<3;n++)
|
||||
value +=
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
a(team_idx+ team_member.team_rank(),k,l,m,n) =
|
||||
team_idx+ team_member.team_rank() + 13*k + 3*l + 7*m + 5*n;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 6> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<2;m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<3;n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<2;o++)
|
||||
value +=
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o ;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
a(team_idx+ team_member.team_rank(),k,l,m,n,o) =
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o ;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 7> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
a.grow(team_member , team_idx+ team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<2;m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<3;n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<2;o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<4;p++)
|
||||
value +=
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o + 15*p ;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<a.dimension_6();p++)
|
||||
a(team_idx+ team_member.team_rank(),k,l,m,n,o,p) =
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o + 15*p ;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct GrowTest<ViewType , ExecutionSpace , 8> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
GrowTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
a.grow(team_member , team_idx + team_member.team_size());
|
||||
|
||||
for( typename ExecutionSpace::size_type k=0;k<7;k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<3;l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<2;m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<3;n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<2;o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<4;p++)
|
||||
for( typename ExecutionSpace::size_type q=0;q<3;q++)
|
||||
value +=
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o + 15*p + 17*q;
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<a.dimension_6();p++)
|
||||
for( typename ExecutionSpace::size_type q=0;q<a.dimension_7();q++)
|
||||
a(team_idx+ team_member.team_rank(),k,l,m,n,o,p,q) =
|
||||
team_idx + team_member.team_rank() + 13*k + 3*l + 7*m + 5*n + 2*o + 15*p + 17*q;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace, int Rank = ViewType::Rank>
|
||||
struct VerifyTest;
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 1> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
value += a(team_idx+ team_member.team_rank());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 2> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
value += a(team_idx+ team_member.team_rank(),k);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 3> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 4> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l,m);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 5> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l,m,n);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 6> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l,m,n,o);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 7> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<a.dimension_6();p++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l,m,n,o,p);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class ViewType , class ExecutionSpace>
|
||||
struct VerifyTest<ViewType , ExecutionSpace , 8> {
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
typedef typename Policy::member_type team_type;
|
||||
typedef double value_type;
|
||||
|
||||
ViewType a;
|
||||
|
||||
VerifyTest(ViewType in):a(in) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() (team_type team_member, double& value) const {
|
||||
unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if((a.dimension_0()>team_idx+ team_member.team_rank()) &&
|
||||
(a.dimension(0)>team_idx+ team_member.team_rank())) {
|
||||
for( typename ExecutionSpace::size_type k=0;k<a.dimension_1();k++)
|
||||
for( typename ExecutionSpace::size_type l=0;l<a.dimension_2();l++)
|
||||
for( typename ExecutionSpace::size_type m=0;m<a.dimension_3();m++)
|
||||
for( typename ExecutionSpace::size_type n=0;n<a.dimension_4();n++)
|
||||
for( typename ExecutionSpace::size_type o=0;o<a.dimension_5();o++)
|
||||
for( typename ExecutionSpace::size_type p=0;p<a.dimension_6();p++)
|
||||
for( typename ExecutionSpace::size_type q=0;q<a.dimension_7();q++)
|
||||
value += a(team_idx+ team_member.team_rank(),k,l,m,n,o,p,q);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar, class ExecutionSpace>
|
||||
struct test_segmented_view
|
||||
{
|
||||
typedef test_segmented_view<Scalar,ExecutionSpace> self_type;
|
||||
|
||||
typedef Scalar scalar_type;
|
||||
typedef ExecutionSpace execution_space;
|
||||
typedef Kokkos::TeamPolicy<execution_space> Policy;
|
||||
|
||||
double result;
|
||||
double reference;
|
||||
|
||||
template <class ViewType>
|
||||
void run_me(ViewType a, int max_length){
|
||||
const int team_size = Policy::team_size_max( GrowTest<ViewType,execution_space>(a) );
|
||||
const int nteams = max_length/team_size;
|
||||
|
||||
reference = 0;
|
||||
result = 0;
|
||||
|
||||
Kokkos::parallel_reduce(Policy(nteams,team_size),GrowTest<ViewType,execution_space>(a),reference);
|
||||
Kokkos::fence();
|
||||
Kokkos::parallel_reduce(Policy(nteams,team_size),VerifyTest<ViewType,execution_space>(a),result);
|
||||
Kokkos::fence();
|
||||
}
|
||||
|
||||
|
||||
test_segmented_view(unsigned int size,int rank)
|
||||
{
|
||||
reference = 0;
|
||||
result = 0;
|
||||
|
||||
const int dim_1 = 7;
|
||||
const int dim_2 = 3;
|
||||
const int dim_3 = 2;
|
||||
const int dim_4 = 3;
|
||||
const int dim_5 = 2;
|
||||
const int dim_6 = 4;
|
||||
//const int dim_7 = 3;
|
||||
|
||||
if(rank==1) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*,Kokkos::LayoutLeft,ExecutionSpace> rank1_view;
|
||||
run_me< rank1_view >(rank1_view("Rank1",128,size), size);
|
||||
}
|
||||
if(rank==2) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar**,Kokkos::LayoutLeft,ExecutionSpace> rank2_view;
|
||||
run_me< rank2_view >(rank2_view("Rank2",128,size,dim_1), size);
|
||||
}
|
||||
if(rank==3) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*[7][3][2],Kokkos::LayoutRight,ExecutionSpace> rank3_view;
|
||||
run_me< rank3_view >(rank3_view("Rank3",128,size), size);
|
||||
}
|
||||
if(rank==4) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar****,Kokkos::LayoutRight,ExecutionSpace> rank4_view;
|
||||
run_me< rank4_view >(rank4_view("Rank4",128,size,dim_1,dim_2,dim_3), size);
|
||||
}
|
||||
if(rank==5) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*[7][3][2][3],Kokkos::LayoutLeft,ExecutionSpace> rank5_view;
|
||||
run_me< rank5_view >(rank5_view("Rank5",128,size), size);
|
||||
}
|
||||
if(rank==6) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*****[2],Kokkos::LayoutRight,ExecutionSpace> rank6_view;
|
||||
run_me< rank6_view >(rank6_view("Rank6",128,size,dim_1,dim_2,dim_3,dim_4), size);
|
||||
}
|
||||
if(rank==7) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*******,Kokkos::LayoutLeft,ExecutionSpace> rank7_view;
|
||||
run_me< rank7_view >(rank7_view("Rank7",128,size,dim_1,dim_2,dim_3,dim_4,dim_5,dim_6), size);
|
||||
}
|
||||
if(rank==8) {
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*****[2][4][3],Kokkos::LayoutLeft,ExecutionSpace> rank8_view;
|
||||
run_me< rank8_view >(rank8_view("Rank8",128,size,dim_1,dim_2,dim_3,dim_4), size);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename Scalar, class ExecutionSpace>
|
||||
void test_segmented_view(unsigned int size)
|
||||
{
|
||||
{
|
||||
typedef Kokkos::Experimental::SegmentedView<Scalar*****[2][4][3],Kokkos::LayoutLeft,ExecutionSpace> view_type;
|
||||
view_type a("A",128,size,7,3,2,3);
|
||||
double reference;
|
||||
|
||||
Impl::GrowTest<view_type,ExecutionSpace> f(a);
|
||||
|
||||
const int team_size = Kokkos::TeamPolicy<ExecutionSpace>::team_size_max( f );
|
||||
const int nteams = (size+team_size-1)/team_size;
|
||||
|
||||
Kokkos::parallel_reduce(Kokkos::TeamPolicy<ExecutionSpace>(nteams,team_size),f,reference);
|
||||
|
||||
size_t real_size = ((size+127)/128)*128;
|
||||
|
||||
ASSERT_EQ(real_size,a.dimension_0());
|
||||
ASSERT_EQ(7,a.dimension_1());
|
||||
ASSERT_EQ(3,a.dimension_2());
|
||||
ASSERT_EQ(2,a.dimension_3());
|
||||
ASSERT_EQ(3,a.dimension_4());
|
||||
ASSERT_EQ(2,a.dimension_5());
|
||||
ASSERT_EQ(4,a.dimension_6());
|
||||
ASSERT_EQ(3,a.dimension_7());
|
||||
ASSERT_EQ(real_size,a.dimension(0));
|
||||
ASSERT_EQ(7,a.dimension(1));
|
||||
ASSERT_EQ(3,a.dimension(2));
|
||||
ASSERT_EQ(2,a.dimension(3));
|
||||
ASSERT_EQ(3,a.dimension(4));
|
||||
ASSERT_EQ(2,a.dimension(5));
|
||||
ASSERT_EQ(4,a.dimension(6));
|
||||
ASSERT_EQ(3,a.dimension(7));
|
||||
ASSERT_EQ(8,a.Rank);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,1);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,2);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,3);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,4);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,5);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,6);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,7);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
{
|
||||
Impl::test_segmented_view<Scalar,ExecutionSpace> test(size,8);
|
||||
ASSERT_EQ(test.reference,test.result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#else
|
||||
|
||||
template <typename Scalar, class ExecutionSpace>
|
||||
void test_segmented_view(unsigned int ) {}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef KOKKOS_TEST_SEGMENTEDVIEW_HPP */
|
||||
|
||||
158
lib/kokkos/containers/unit_tests/TestSerial.cpp
Normal file
158
lib/kokkos/containers/unit_tests/TestSerial.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
#if ! defined(KOKKOS_HAVE_SERIAL)
|
||||
# error "It doesn't make sense to build this file unless the Kokkos::Serial device is enabled. If you see this message, it probably means that there is an error in Kokkos' CMake build infrastructure."
|
||||
#else
|
||||
|
||||
#include <Kokkos_Bitset.hpp>
|
||||
#include <Kokkos_UnorderedMap.hpp>
|
||||
#include <Kokkos_Vector.hpp>
|
||||
|
||||
#include <TestBitset.hpp>
|
||||
#include <TestUnorderedMap.hpp>
|
||||
#include <TestStaticCrsGraph.hpp>
|
||||
#include <TestVector.hpp>
|
||||
#include <TestDualView.hpp>
|
||||
#include <TestSegmentedView.hpp>
|
||||
#include <TestComplex.hpp>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
namespace Test {
|
||||
|
||||
class serial : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestCase () {
|
||||
std::cout << std::setprecision(5) << std::scientific;
|
||||
Kokkos::Serial::initialize ();
|
||||
}
|
||||
|
||||
static void TearDownTestCase () {
|
||||
Kokkos::Serial::finalize ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TEST_F( serial , staticcrsgraph )
|
||||
{
|
||||
TestStaticCrsGraph::run_test_graph< Kokkos::Serial >();
|
||||
TestStaticCrsGraph::run_test_graph2< Kokkos::Serial >();
|
||||
}
|
||||
|
||||
TEST_F( serial, complex )
|
||||
{
|
||||
testComplex<Kokkos::Serial> ();
|
||||
}
|
||||
|
||||
TEST_F( serial, bitset )
|
||||
{
|
||||
test_bitset<Kokkos::Serial> ();
|
||||
}
|
||||
|
||||
#define SERIAL_INSERT_TEST( name, num_nodes, num_inserts, num_duplicates, repeat, near ) \
|
||||
TEST_F( serial, UnorderedMap_insert_##name##_##num_nodes##_##num_inserts##_##num_duplicates##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_insert<Kokkos::Serial> (num_nodes, num_inserts, num_duplicates, near); \
|
||||
}
|
||||
|
||||
#define SERIAL_FAILED_INSERT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( serial, UnorderedMap_failed_insert_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_failed_insert<Kokkos::Serial> (num_nodes); \
|
||||
}
|
||||
|
||||
#define SERIAL_ASSIGNEMENT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( serial, UnorderedMap_assignment_operators_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_assignement_operators<Kokkos::Serial> (num_nodes); \
|
||||
}
|
||||
|
||||
#define SERIAL_DEEP_COPY( num_nodes, repeat ) \
|
||||
TEST_F( serial, UnorderedMap_deep_copy##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_deep_copy<Kokkos::Serial> (num_nodes); \
|
||||
}
|
||||
|
||||
#define SERIAL_VECTOR_COMBINE_TEST( size ) \
|
||||
TEST_F( serial, vector_combination##size##x) { \
|
||||
test_vector_combinations<int,Kokkos::Serial>(size); \
|
||||
}
|
||||
|
||||
#define SERIAL_DUALVIEW_COMBINE_TEST( size ) \
|
||||
TEST_F( serial, dualview_combination##size##x) { \
|
||||
test_dualview_combinations<int,Kokkos::Serial>(size); \
|
||||
}
|
||||
|
||||
#define SERIAL_SEGMENTEDVIEW_TEST( size ) \
|
||||
TEST_F( serial, segmentedview_##size##x) { \
|
||||
test_segmented_view<double,Kokkos::Serial>(size); \
|
||||
}
|
||||
|
||||
SERIAL_INSERT_TEST(close, 100000, 90000, 100, 500, true)
|
||||
SERIAL_INSERT_TEST(far, 100000, 90000, 100, 500, false)
|
||||
SERIAL_FAILED_INSERT_TEST( 10000, 1000 )
|
||||
SERIAL_DEEP_COPY( 10000, 1 )
|
||||
|
||||
SERIAL_VECTOR_COMBINE_TEST( 10 )
|
||||
SERIAL_VECTOR_COMBINE_TEST( 3057 )
|
||||
SERIAL_DUALVIEW_COMBINE_TEST( 10 )
|
||||
SERIAL_SEGMENTEDVIEW_TEST( 10000 )
|
||||
|
||||
#undef SERIAL_INSERT_TEST
|
||||
#undef SERIAL_FAILED_INSERT_TEST
|
||||
#undef SERIAL_ASSIGNEMENT_TEST
|
||||
#undef SERIAL_DEEP_COPY
|
||||
#undef SERIAL_VECTOR_COMBINE_TEST
|
||||
#undef SERIAL_DUALVIEW_COMBINE_TEST
|
||||
#undef SERIAL_SEGMENTEDVIEW_TEST
|
||||
|
||||
} // namespace test
|
||||
|
||||
#endif // KOKKOS_HAVE_SERIAL
|
||||
|
||||
|
||||
149
lib/kokkos/containers/unit_tests/TestStaticCrsGraph.hpp
Normal file
149
lib/kokkos/containers/unit_tests/TestStaticCrsGraph.hpp
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Kokkos_StaticCrsGraph.hpp>
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
namespace TestStaticCrsGraph {
|
||||
|
||||
template< class Space >
|
||||
void run_test_graph()
|
||||
{
|
||||
typedef Kokkos::StaticCrsGraph< unsigned , Space > dView ;
|
||||
typedef typename dView::HostMirror hView ;
|
||||
|
||||
const unsigned LENGTH = 1000 ;
|
||||
dView dx ;
|
||||
hView hx ;
|
||||
|
||||
std::vector< std::vector< int > > graph( LENGTH );
|
||||
|
||||
for ( size_t i = 0 ; i < LENGTH ; ++i ) {
|
||||
graph[i].reserve(8);
|
||||
for ( size_t j = 0 ; j < 8 ; ++j ) {
|
||||
graph[i].push_back( i + j * 3 );
|
||||
}
|
||||
}
|
||||
|
||||
dx = Kokkos::create_staticcrsgraph<dView>( "dx" , graph );
|
||||
hx = Kokkos::create_mirror( dx );
|
||||
|
||||
ASSERT_EQ( hx.row_map.dimension_0() - 1 , LENGTH );
|
||||
|
||||
for ( size_t i = 0 ; i < LENGTH ; ++i ) {
|
||||
const size_t begin = hx.row_map[i];
|
||||
const size_t n = hx.row_map[i+1] - begin ;
|
||||
ASSERT_EQ( n , graph[i].size() );
|
||||
for ( size_t j = 0 ; j < n ; ++j ) {
|
||||
ASSERT_EQ( (int) hx.entries( j + begin ) , graph[i][j] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template< class Space >
|
||||
void run_test_graph2()
|
||||
{
|
||||
typedef Kokkos::StaticCrsGraph< unsigned[3] , Space > dView ;
|
||||
typedef typename dView::HostMirror hView ;
|
||||
|
||||
const unsigned LENGTH = 10 ;
|
||||
|
||||
std::vector< size_t > sizes( LENGTH );
|
||||
|
||||
size_t total_length = 0 ;
|
||||
|
||||
for ( size_t i = 0 ; i < LENGTH ; ++i ) {
|
||||
total_length += ( sizes[i] = 6 + i % 4 );
|
||||
}
|
||||
|
||||
dView dx = Kokkos::create_staticcrsgraph<dView>( "test" , sizes );
|
||||
hView hx = Kokkos::create_mirror( dx );
|
||||
hView mx = Kokkos::create_mirror( dx );
|
||||
|
||||
ASSERT_EQ( (size_t) dx.row_map.dimension_0() , (size_t) LENGTH + 1 );
|
||||
ASSERT_EQ( (size_t) hx.row_map.dimension_0() , (size_t) LENGTH + 1 );
|
||||
ASSERT_EQ( (size_t) mx.row_map.dimension_0() , (size_t) LENGTH + 1 );
|
||||
|
||||
ASSERT_EQ( (size_t) dx.entries.dimension_0() , (size_t) total_length );
|
||||
ASSERT_EQ( (size_t) hx.entries.dimension_0() , (size_t) total_length );
|
||||
ASSERT_EQ( (size_t) mx.entries.dimension_0() , (size_t) total_length );
|
||||
|
||||
ASSERT_EQ( (size_t) dx.entries.dimension_1() , (size_t) 3 );
|
||||
ASSERT_EQ( (size_t) hx.entries.dimension_1() , (size_t) 3 );
|
||||
ASSERT_EQ( (size_t) mx.entries.dimension_1() , (size_t) 3 );
|
||||
|
||||
for ( size_t i = 0 ; i < LENGTH ; ++i ) {
|
||||
const size_t entry_begin = hx.row_map[i];
|
||||
const size_t entry_end = hx.row_map[i+1];
|
||||
for ( size_t j = entry_begin ; j < entry_end ; ++j ) {
|
||||
hx.entries(j,0) = j + 1 ;
|
||||
hx.entries(j,1) = j + 2 ;
|
||||
hx.entries(j,2) = j + 3 ;
|
||||
}
|
||||
}
|
||||
|
||||
Kokkos::deep_copy( dx.entries , hx.entries );
|
||||
Kokkos::deep_copy( mx.entries , dx.entries );
|
||||
|
||||
ASSERT_EQ( mx.row_map.dimension_0() , (size_t) LENGTH + 1 );
|
||||
|
||||
for ( size_t i = 0 ; i < LENGTH ; ++i ) {
|
||||
const size_t entry_begin = mx.row_map[i];
|
||||
const size_t entry_end = mx.row_map[i+1];
|
||||
ASSERT_EQ( ( entry_end - entry_begin ) , sizes[i] );
|
||||
for ( size_t j = entry_begin ; j < entry_end ; ++j ) {
|
||||
ASSERT_EQ( (size_t) mx.entries( j , 0 ) , ( j + 1 ) );
|
||||
ASSERT_EQ( (size_t) mx.entries( j , 1 ) , ( j + 2 ) );
|
||||
ASSERT_EQ( (size_t) mx.entries( j , 2 ) , ( j + 3 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace TestStaticCrsGraph */
|
||||
|
||||
|
||||
168
lib/kokkos/containers/unit_tests/TestThreads.cpp
Normal file
168
lib/kokkos/containers/unit_tests/TestThreads.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
#if defined( KOKKOS_HAVE_PTHREAD )
|
||||
|
||||
#include <Kokkos_Bitset.hpp>
|
||||
#include <Kokkos_UnorderedMap.hpp>
|
||||
|
||||
#include <Kokkos_Vector.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#include <TestBitset.hpp>
|
||||
#include <TestUnorderedMap.hpp>
|
||||
#include <TestStaticCrsGraph.hpp>
|
||||
|
||||
#include <TestVector.hpp>
|
||||
#include <TestDualView.hpp>
|
||||
#include <TestSegmentedView.hpp>
|
||||
|
||||
namespace Test {
|
||||
|
||||
class threads : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
std::cout << std::setprecision(5) << std::scientific;
|
||||
|
||||
unsigned num_threads = 4;
|
||||
|
||||
if (Kokkos::hwloc::available()) {
|
||||
num_threads = Kokkos::hwloc::get_available_numa_count()
|
||||
* Kokkos::hwloc::get_available_cores_per_numa()
|
||||
// * Kokkos::hwloc::get_available_threads_per_core()
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
std::cout << "Threads: " << num_threads << std::endl;
|
||||
|
||||
Kokkos::Threads::initialize( num_threads );
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
Kokkos::Threads::finalize();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F( threads , staticcrsgraph )
|
||||
{
|
||||
TestStaticCrsGraph::run_test_graph< Kokkos::Threads >();
|
||||
TestStaticCrsGraph::run_test_graph2< Kokkos::Threads >();
|
||||
}
|
||||
|
||||
/*TEST_F( threads, bitset )
|
||||
{
|
||||
test_bitset<Kokkos::Threads>();
|
||||
}*/
|
||||
|
||||
#define THREADS_INSERT_TEST( name, num_nodes, num_inserts, num_duplicates, repeat, near ) \
|
||||
TEST_F( threads, UnorderedMap_insert_##name##_##num_nodes##_##num_inserts##_##num_duplicates##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_insert<Kokkos::Threads>(num_nodes,num_inserts,num_duplicates, near); \
|
||||
}
|
||||
|
||||
#define THREADS_FAILED_INSERT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( threads, UnorderedMap_failed_insert_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_failed_insert<Kokkos::Threads>(num_nodes); \
|
||||
}
|
||||
|
||||
#define THREADS_ASSIGNEMENT_TEST( num_nodes, repeat ) \
|
||||
TEST_F( threads, UnorderedMap_assignment_operators_##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_assignement_operators<Kokkos::Threads>(num_nodes); \
|
||||
}
|
||||
|
||||
#define THREADS_DEEP_COPY( num_nodes, repeat ) \
|
||||
TEST_F( threads, UnorderedMap_deep_copy##num_nodes##_##repeat##x) { \
|
||||
for (int i=0; i<repeat; ++i) \
|
||||
test_deep_copy<Kokkos::Threads>(num_nodes); \
|
||||
}
|
||||
|
||||
#define THREADS_VECTOR_COMBINE_TEST( size ) \
|
||||
TEST_F( threads, vector_combination##size##x) { \
|
||||
test_vector_combinations<int,Kokkos::Threads>(size); \
|
||||
}
|
||||
|
||||
#define THREADS_DUALVIEW_COMBINE_TEST( size ) \
|
||||
TEST_F( threads, dualview_combination##size##x) { \
|
||||
test_dualview_combinations<int,Kokkos::Threads>(size); \
|
||||
}
|
||||
|
||||
#define THREADS_SEGMENTEDVIEW_TEST( size ) \
|
||||
TEST_F( threads, segmentedview_##size##x) { \
|
||||
test_segmented_view<double,Kokkos::Threads>(size); \
|
||||
}
|
||||
|
||||
|
||||
THREADS_INSERT_TEST(far, 100000, 90000, 100, 500, false)
|
||||
THREADS_FAILED_INSERT_TEST( 10000, 1000 )
|
||||
THREADS_DEEP_COPY( 10000, 1 )
|
||||
|
||||
THREADS_VECTOR_COMBINE_TEST( 10 )
|
||||
THREADS_VECTOR_COMBINE_TEST( 3057 )
|
||||
THREADS_DUALVIEW_COMBINE_TEST( 10 )
|
||||
THREADS_SEGMENTEDVIEW_TEST( 10000 )
|
||||
|
||||
|
||||
#undef THREADS_INSERT_TEST
|
||||
#undef THREADS_FAILED_INSERT_TEST
|
||||
#undef THREADS_ASSIGNEMENT_TEST
|
||||
#undef THREADS_DEEP_COPY
|
||||
#undef THREADS_VECTOR_COMBINE_TEST
|
||||
#undef THREADS_DUALVIEW_COMBINE_TEST
|
||||
#undef THREADS_SEGMENTEDVIEW_TEST
|
||||
|
||||
} // namespace Test
|
||||
|
||||
|
||||
#endif /* #if defined( KOKKOS_HAVE_PTHREAD ) */
|
||||
|
||||
313
lib/kokkos/containers/unit_tests/TestUnorderedMap.hpp
Normal file
313
lib/kokkos/containers/unit_tests/TestUnorderedMap.hpp
Normal file
@ -0,0 +1,313 @@
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
|
||||
#ifndef KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
#define KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
template <typename MapType, bool Near = false>
|
||||
struct TestInsert
|
||||
{
|
||||
typedef MapType map_type;
|
||||
typedef typename map_type::execution_space execution_space;
|
||||
typedef uint32_t value_type;
|
||||
|
||||
map_type map;
|
||||
uint32_t inserts;
|
||||
uint32_t collisions;
|
||||
|
||||
TestInsert( map_type arg_map, uint32_t arg_inserts, uint32_t arg_collisions)
|
||||
: map(arg_map)
|
||||
, inserts(arg_inserts)
|
||||
, collisions(arg_collisions)
|
||||
{}
|
||||
|
||||
void testit( bool rehash_on_fail = true )
|
||||
{
|
||||
execution_space::fence();
|
||||
|
||||
uint32_t failed_count = 0;
|
||||
do {
|
||||
failed_count = 0;
|
||||
Kokkos::parallel_reduce(inserts, *this, failed_count);
|
||||
|
||||
if (rehash_on_fail && failed_count > 0u) {
|
||||
const uint32_t new_capacity = map.capacity() + ((map.capacity()*3ull)/20u) + failed_count/collisions ;
|
||||
map.rehash( new_capacity );
|
||||
}
|
||||
} while (rehash_on_fail && failed_count > 0u);
|
||||
|
||||
execution_space::fence();
|
||||
}
|
||||
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void init( value_type & failed_count ) const { failed_count = 0; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void join( volatile value_type & failed_count, const volatile value_type & count ) const
|
||||
{ failed_count += count; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(uint32_t i, value_type & failed_count) const
|
||||
{
|
||||
const uint32_t key = Near ? i/collisions : i%(inserts/collisions);
|
||||
if (map.insert(key,i).failed()) ++failed_count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename MapType, bool Near>
|
||||
struct TestErase
|
||||
{
|
||||
typedef TestErase<MapType, Near> self_type;
|
||||
|
||||
typedef MapType map_type;
|
||||
typedef typename MapType::execution_space execution_space;
|
||||
|
||||
map_type m_map;
|
||||
uint32_t m_num_erase;
|
||||
uint32_t m_num_duplicates;
|
||||
|
||||
TestErase(map_type map, uint32_t num_erases, uint32_t num_duplicates)
|
||||
: m_map(map)
|
||||
, m_num_erase(num_erases)
|
||||
, m_num_duplicates(num_duplicates)
|
||||
{}
|
||||
|
||||
void testit()
|
||||
{
|
||||
execution_space::fence();
|
||||
Kokkos::parallel_for(m_num_erase, *this);
|
||||
execution_space::fence();
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(typename execution_space::size_type i) const
|
||||
{
|
||||
if (Near) {
|
||||
m_map.erase(i/m_num_duplicates);
|
||||
}
|
||||
else {
|
||||
m_map.erase(i%(m_num_erase/m_num_duplicates));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template <typename MapType>
|
||||
struct TestFind
|
||||
{
|
||||
typedef MapType map_type;
|
||||
typedef typename MapType::execution_space::execution_space execution_space;
|
||||
typedef uint32_t value_type;
|
||||
|
||||
map_type m_map;
|
||||
uint32_t m_num_insert;
|
||||
uint32_t m_num_duplicates;
|
||||
uint32_t m_max_key;
|
||||
|
||||
TestFind(map_type map, uint32_t num_inserts, uint32_t num_duplicates)
|
||||
: m_map(map)
|
||||
, m_num_insert(num_inserts)
|
||||
, m_num_duplicates(num_duplicates)
|
||||
, m_max_key( ((num_inserts + num_duplicates) - 1)/num_duplicates )
|
||||
{}
|
||||
|
||||
void testit(value_type &errors)
|
||||
{
|
||||
execution_space::execution_space::fence();
|
||||
Kokkos::parallel_reduce(m_map.capacity(), *this, errors);
|
||||
execution_space::execution_space::fence();
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
static void init( value_type & dst)
|
||||
{
|
||||
dst = 0;
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
static void join( volatile value_type & dst, const volatile value_type & src)
|
||||
{ dst += src; }
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(typename execution_space::size_type i, value_type & errors) const
|
||||
{
|
||||
const bool expect_to_find_i = (i < m_max_key);
|
||||
|
||||
const bool exists = m_map.exists(i);
|
||||
|
||||
if (expect_to_find_i && !exists) ++errors;
|
||||
if (!expect_to_find_i && exists) ++errors;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
|
||||
template <typename Device>
|
||||
void test_insert( uint32_t num_nodes , uint32_t num_inserts , uint32_t num_duplicates , bool near )
|
||||
{
|
||||
typedef Kokkos::UnorderedMap<uint32_t,uint32_t, Device> map_type;
|
||||
typedef Kokkos::UnorderedMap<const uint32_t,const uint32_t, Device> const_map_type;
|
||||
|
||||
const uint32_t expected_inserts = (num_inserts + num_duplicates -1u) / num_duplicates;
|
||||
|
||||
map_type map;
|
||||
map.rehash(num_nodes,false);
|
||||
|
||||
if (near) {
|
||||
Impl::TestInsert<map_type,true> test_insert(map, num_inserts, num_duplicates);
|
||||
test_insert.testit();
|
||||
} else
|
||||
{
|
||||
Impl::TestInsert<map_type,false> test_insert(map, num_inserts, num_duplicates);
|
||||
test_insert.testit();
|
||||
}
|
||||
|
||||
const bool print_list = false;
|
||||
if (print_list) {
|
||||
Kokkos::Impl::UnorderedMapPrint<map_type> f(map);
|
||||
f.apply();
|
||||
}
|
||||
|
||||
const uint32_t map_size = map.size();
|
||||
|
||||
ASSERT_FALSE( map.failed_insert());
|
||||
{
|
||||
EXPECT_EQ(expected_inserts, map_size);
|
||||
|
||||
{
|
||||
uint32_t find_errors = 0;
|
||||
Impl::TestFind<const_map_type> test_find(map, num_inserts, num_duplicates);
|
||||
test_find.testit(find_errors);
|
||||
EXPECT_EQ( 0u, find_errors);
|
||||
}
|
||||
|
||||
map.begin_erase();
|
||||
Impl::TestErase<map_type,false> test_erase(map, num_inserts, num_duplicates);
|
||||
test_erase.testit();
|
||||
map.end_erase();
|
||||
EXPECT_EQ(0u, map.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Device>
|
||||
void test_failed_insert( uint32_t num_nodes)
|
||||
{
|
||||
typedef Kokkos::UnorderedMap<uint32_t,uint32_t, Device> map_type;
|
||||
|
||||
map_type map(num_nodes);
|
||||
Impl::TestInsert<map_type> test_insert(map, 2u*num_nodes, 1u);
|
||||
test_insert.testit(false /*don't rehash on fail*/);
|
||||
Device::execution_space::fence();
|
||||
|
||||
EXPECT_TRUE( map.failed_insert() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename Device>
|
||||
void test_deep_copy( uint32_t num_nodes )
|
||||
{
|
||||
typedef Kokkos::UnorderedMap<uint32_t,uint32_t, Device> map_type;
|
||||
typedef Kokkos::UnorderedMap<const uint32_t, const uint32_t, Device> const_map_type;
|
||||
|
||||
typedef typename map_type::HostMirror host_map_type ;
|
||||
// typedef Kokkos::UnorderedMap<uint32_t, uint32_t, typename Device::host_mirror_execution_space > host_map_type;
|
||||
|
||||
map_type map;
|
||||
map.rehash(num_nodes,false);
|
||||
|
||||
{
|
||||
Impl::TestInsert<map_type> test_insert(map, num_nodes, 1);
|
||||
test_insert.testit();
|
||||
ASSERT_EQ( map.size(), num_nodes);
|
||||
ASSERT_FALSE( map.failed_insert() );
|
||||
{
|
||||
uint32_t find_errors = 0;
|
||||
Impl::TestFind<map_type> test_find(map, num_nodes, 1);
|
||||
test_find.testit(find_errors);
|
||||
EXPECT_EQ( find_errors, 0u);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
host_map_type hmap;
|
||||
Kokkos::deep_copy(hmap, map);
|
||||
|
||||
ASSERT_EQ( map.size(), hmap.size());
|
||||
ASSERT_EQ( map.capacity(), hmap.capacity());
|
||||
{
|
||||
uint32_t find_errors = 0;
|
||||
Impl::TestFind<host_map_type> test_find(hmap, num_nodes, 1);
|
||||
test_find.testit(find_errors);
|
||||
EXPECT_EQ( find_errors, 0u);
|
||||
}
|
||||
|
||||
map_type mmap;
|
||||
Kokkos::deep_copy(mmap, hmap);
|
||||
|
||||
const_map_type cmap = mmap;
|
||||
|
||||
EXPECT_EQ( cmap.size(), num_nodes);
|
||||
|
||||
{
|
||||
uint32_t find_errors = 0;
|
||||
Impl::TestFind<const_map_type> test_find(cmap, num_nodes, 1);
|
||||
test_find.testit(find_errors);
|
||||
EXPECT_EQ( find_errors, 0u);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif //KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
131
lib/kokkos/containers/unit_tests/TestVector.hpp
Normal file
131
lib/kokkos/containers/unit_tests/TestVector.hpp
Normal file
@ -0,0 +1,131 @@
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
|
||||
#ifndef KOKKOS_TEST_VECTOR_HPP
|
||||
#define KOKKOS_TEST_VECTOR_HPP
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <impl/Kokkos_Timer.hpp>
|
||||
|
||||
namespace Test {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
struct test_vector_combinations
|
||||
{
|
||||
typedef test_vector_combinations<Scalar,Device> self_type;
|
||||
|
||||
typedef Scalar scalar_type;
|
||||
typedef Device execution_space;
|
||||
|
||||
Scalar reference;
|
||||
Scalar result;
|
||||
|
||||
template <typename Vector>
|
||||
Scalar run_me(unsigned int n){
|
||||
Vector a(n,1);
|
||||
|
||||
|
||||
a.push_back(2);
|
||||
a.resize(n+4);
|
||||
a[n+1] = 3;
|
||||
a[n+2] = 4;
|
||||
a[n+3] = 5;
|
||||
|
||||
|
||||
Scalar temp1 = a[2];
|
||||
Scalar temp2 = a[n];
|
||||
Scalar temp3 = a[n+1];
|
||||
|
||||
a.assign(n+2,-1);
|
||||
|
||||
a[2] = temp1;
|
||||
a[n] = temp2;
|
||||
a[n+1] = temp3;
|
||||
|
||||
Scalar test1 = 0;
|
||||
for(unsigned int i=0; i<a.size(); i++)
|
||||
test1+=a[i];
|
||||
|
||||
a.assign(n+1,-2);
|
||||
Scalar test2 = 0;
|
||||
for(unsigned int i=0; i<a.size(); i++)
|
||||
test2+=a[i];
|
||||
|
||||
a.reserve(n+10);
|
||||
|
||||
Scalar test3 = 0;
|
||||
for(unsigned int i=0; i<a.size(); i++)
|
||||
test3+=a[i];
|
||||
|
||||
|
||||
return (test1*test2+test3)*test2+test1*test3;
|
||||
}
|
||||
|
||||
|
||||
test_vector_combinations(unsigned int size)
|
||||
{
|
||||
reference = run_me<std::vector<Scalar> >(size);
|
||||
result = run_me<Kokkos::vector<Scalar,Device> >(size);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_vector_combinations(unsigned int size)
|
||||
{
|
||||
Impl::test_vector_combinations<Scalar,Device> test(size);
|
||||
ASSERT_EQ( test.reference, test.result);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif //KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
50
lib/kokkos/containers/unit_tests/UnitTestMain.cpp
Normal file
50
lib/kokkos/containers/unit_tests/UnitTestMain.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 2.0
|
||||
// Copyright (2014) Sandia Corporation
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user