Update Kokkos library in LAMMPS to v3.6.0
This commit is contained in:
@ -4,16 +4,11 @@ KOKKOS_INCLUDE_DIRECTORIES(REQUIRED_DURING_INSTALLATION_TESTING ${CMAKE_CURRENT_
|
||||
KOKKOS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../src )
|
||||
|
||||
foreach(Tag Threads;OpenMP;Cuda;HPX;HIP)
|
||||
# Because there is always an exception to the rule
|
||||
if(Tag STREQUAL "Threads")
|
||||
set(DEVICE "PTHREAD")
|
||||
else()
|
||||
string(TOUPPER ${Tag} DEVICE)
|
||||
endif()
|
||||
string(TOUPPER ${Tag} DEVICE)
|
||||
string(TOLOWER ${Tag} dir)
|
||||
|
||||
if(Kokkos_ENABLE_${DEVICE})
|
||||
message(STATUS "Sources Test${Tag}.cpp")
|
||||
message(STATUS "Sources Test${Tag}.cpp")
|
||||
|
||||
set(SOURCES
|
||||
TestMain.cpp
|
||||
|
||||
@ -37,7 +37,7 @@ ifeq ($(KOKKOS_INTERNAL_USE_HIP), 1)
|
||||
TEST_TARGETS += test-hip
|
||||
endif
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_PTHREADS), 1)
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_THREADS), 1)
|
||||
OBJ_THREADS = TestThreads.o TestMain.o gtest-all.o
|
||||
TARGETS += KokkosContainers_PerformanceTest_Threads
|
||||
TEST_TARGETS += test-threads
|
||||
|
||||
@ -10,8 +10,8 @@ KOKKOS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
SET(KOKKOS_CONTAINERS_SRCS)
|
||||
APPEND_GLOB(KOKKOS_CONTAINERS_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp)
|
||||
SET(KOKKOS_CONTAINER_HEADERS)
|
||||
APPEND_GLOB(KOKKOS_CONTAINERS_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.hpp)
|
||||
APPEND_GLOB(KOKKOS_CONTAINERS_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
|
||||
APPEND_GLOB(KOKKOS_CONTAINERS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.hpp)
|
||||
APPEND_GLOB(KOKKOS_CONTAINERS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
|
||||
|
||||
|
||||
INSTALL (
|
||||
@ -23,7 +23,7 @@ INSTALL (
|
||||
KOKKOS_ADD_LIBRARY(
|
||||
kokkoscontainers
|
||||
SOURCES ${KOKKOS_CONTAINERS_SRCS}
|
||||
HEADERS ${KOKKOS_CONTAINER_HEADERS}
|
||||
HEADERS ${KOKKOS_CONTAINERS_HEADERS}
|
||||
)
|
||||
|
||||
KOKKOS_LIB_INCLUDE_DIRECTORIES(kokkoscontainers
|
||||
|
||||
@ -73,7 +73,7 @@ void deep_copy(ConstBitset<DstDevice>& dst, ConstBitset<SrcDevice> const& src);
|
||||
template <typename Device>
|
||||
class Bitset {
|
||||
public:
|
||||
using execution_space = Device;
|
||||
using execution_space = typename Device::execution_space;
|
||||
using size_type = unsigned int;
|
||||
|
||||
static constexpr unsigned BIT_SCAN_REVERSE = 1u;
|
||||
@ -142,11 +142,12 @@ class Bitset {
|
||||
|
||||
if (m_last_block_mask) {
|
||||
// clear the unused bits in the last block
|
||||
using raw_deep_copy =
|
||||
Kokkos::Impl::DeepCopy<typename execution_space::memory_space,
|
||||
Kokkos::HostSpace>;
|
||||
raw_deep_copy(m_blocks.data() + (m_blocks.extent(0) - 1u),
|
||||
&m_last_block_mask, sizeof(unsigned));
|
||||
Kokkos::Impl::DeepCopy<typename Device::memory_space, Kokkos::HostSpace>(
|
||||
m_blocks.data() + (m_blocks.extent(0) - 1u), &m_last_block_mask,
|
||||
sizeof(unsigned));
|
||||
Kokkos::fence(
|
||||
"Bitset::set: fence after clearing unused bits copying from "
|
||||
"HostSpace");
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,8 +190,12 @@ class Bitset {
|
||||
KOKKOS_FORCEINLINE_FUNCTION
|
||||
bool test(unsigned i) const {
|
||||
if (i < m_size) {
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
const unsigned block = Kokkos::atomic_load(&m_blocks[i >> block_shift]);
|
||||
#else
|
||||
const unsigned block = volatile_load(&m_blocks[i >> block_shift]);
|
||||
const unsigned mask = 1u << static_cast<int>(i & block_mask);
|
||||
#endif
|
||||
const unsigned mask = 1u << static_cast<int>(i & block_mask);
|
||||
return block & mask;
|
||||
}
|
||||
return false;
|
||||
@ -213,7 +218,11 @@ class Bitset {
|
||||
const unsigned block_idx =
|
||||
(hint >> block_shift) < m_blocks.extent(0) ? (hint >> block_shift) : 0;
|
||||
const unsigned offset = hint & block_mask;
|
||||
unsigned block = volatile_load(&m_blocks[block_idx]);
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
unsigned block = Kokkos::atomic_load(&m_blocks[block_idx]);
|
||||
#else
|
||||
unsigned block = volatile_load(&m_blocks[block_idx]);
|
||||
#endif
|
||||
block = !m_last_block_mask || (block_idx < (m_blocks.extent(0) - 1))
|
||||
? block
|
||||
: block & m_last_block_mask;
|
||||
@ -231,7 +240,11 @@ class Bitset {
|
||||
unsigned scan_direction = BIT_SCAN_FORWARD_MOVE_HINT_FORWARD) const {
|
||||
const unsigned block_idx = hint >> block_shift;
|
||||
const unsigned offset = hint & block_mask;
|
||||
unsigned block = volatile_load(&m_blocks[block_idx]);
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
unsigned block = Kokkos::atomic_load(&m_blocks[block_idx]);
|
||||
#else
|
||||
unsigned block = volatile_load(&m_blocks[block_idx]);
|
||||
#endif
|
||||
block = !m_last_block_mask || (block_idx < (m_blocks.extent(0) - 1))
|
||||
? ~block
|
||||
: ~block & m_last_block_mask;
|
||||
@ -268,7 +281,7 @@ class Bitset {
|
||||
block = Impl::rotate_right(block, offset);
|
||||
return (((!(scan_direction & BIT_SCAN_REVERSE)
|
||||
? Impl::bit_scan_forward(block)
|
||||
: ::Kokkos::log2(block)) +
|
||||
: Impl::int_log2(block)) +
|
||||
offset) &
|
||||
block_mask) +
|
||||
block_start;
|
||||
@ -288,7 +301,7 @@ class Bitset {
|
||||
private:
|
||||
unsigned m_size;
|
||||
unsigned m_last_block_mask;
|
||||
View<unsigned*, execution_space, MemoryTraits<RandomAccess> > m_blocks;
|
||||
View<unsigned*, Device, MemoryTraits<RandomAccess> > m_blocks;
|
||||
|
||||
private:
|
||||
template <typename DDevice>
|
||||
@ -313,7 +326,7 @@ class Bitset {
|
||||
template <typename Device>
|
||||
class ConstBitset {
|
||||
public:
|
||||
using execution_space = Device;
|
||||
using execution_space = typename Device::execution_space;
|
||||
using size_type = unsigned int;
|
||||
|
||||
private:
|
||||
@ -369,7 +382,7 @@ class ConstBitset {
|
||||
|
||||
private:
|
||||
unsigned m_size;
|
||||
View<const unsigned*, execution_space, MemoryTraits<RandomAccess> > m_blocks;
|
||||
View<const unsigned*, Device, MemoryTraits<RandomAccess> > m_blocks;
|
||||
|
||||
private:
|
||||
template <typename DDevice>
|
||||
@ -394,11 +407,12 @@ void deep_copy(Bitset<DstDevice>& dst, Bitset<SrcDevice> const& src) {
|
||||
"Error: Cannot deep_copy bitsets of different sizes!");
|
||||
}
|
||||
|
||||
using raw_deep_copy =
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>;
|
||||
raw_deep_copy(dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence before copy operation");
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>(
|
||||
dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence after copy operation");
|
||||
}
|
||||
|
||||
template <typename DstDevice, typename SrcDevice>
|
||||
@ -408,11 +422,12 @@ void deep_copy(Bitset<DstDevice>& dst, ConstBitset<SrcDevice> const& src) {
|
||||
"Error: Cannot deep_copy bitsets of different sizes!");
|
||||
}
|
||||
|
||||
using raw_deep_copy =
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>;
|
||||
raw_deep_copy(dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence before copy operation");
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>(
|
||||
dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence after copy operation");
|
||||
}
|
||||
|
||||
template <typename DstDevice, typename SrcDevice>
|
||||
@ -422,11 +437,12 @@ void deep_copy(ConstBitset<DstDevice>& dst, ConstBitset<SrcDevice> const& src) {
|
||||
"Error: Cannot deep_copy bitsets of different sizes!");
|
||||
}
|
||||
|
||||
using raw_deep_copy =
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>;
|
||||
raw_deep_copy(dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence before copy operation");
|
||||
Kokkos::Impl::DeepCopy<typename DstDevice::memory_space,
|
||||
typename SrcDevice::memory_space>(
|
||||
dst.m_blocks.data(), src.m_blocks.data(),
|
||||
sizeof(unsigned) * src.m_blocks.extent(0));
|
||||
Kokkos::fence("Bitset::deep_copy: fence after copy operation");
|
||||
}
|
||||
|
||||
} // namespace Kokkos
|
||||
|
||||
@ -260,9 +260,13 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
|
||||
: modified_flags(t_modified_flags("DualView::modified_flags")),
|
||||
d_view(arg_prop, n0, n1, n2, n3, n4, n5, n6, n7),
|
||||
h_view(create_mirror_view(d_view)) // without UVM, host View mirrors
|
||||
{}
|
||||
d_view(arg_prop, n0, n1, n2, n3, n4, n5, n6, n7) {
|
||||
// without UVM, host View mirrors
|
||||
if (Kokkos::Impl::has_type<Impl::WithoutInitializing_t, P...>::value)
|
||||
h_view = Kokkos::create_mirror_view(Kokkos::WithoutInitializing, d_view);
|
||||
else
|
||||
h_view = Kokkos::create_mirror_view(d_view);
|
||||
}
|
||||
|
||||
//! Copy constructor (shallow copy)
|
||||
template <class SS, class LS, class DS, class MS>
|
||||
@ -895,23 +899,22 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
/// This discards any existing contents of the objects, and resets
|
||||
/// their modified flags. It does <i>not</i> copy the old contents
|
||||
/// of either View into the new View objects.
|
||||
void realloc(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
template <class... I>
|
||||
void impl_realloc(const size_t n0, const size_t n1, const size_t n2,
|
||||
const size_t n3, const size_t n4, const size_t n5,
|
||||
const size_t n6, const size_t n7, const I&... arg_prop) {
|
||||
const size_t new_extents[8] = {n0, n1, n2, n3, n4, n5, n6, n7};
|
||||
const bool sizeMismatch =
|
||||
Impl::size_mismatch(h_view, h_view.rank_dynamic, new_extents);
|
||||
|
||||
if (sizeMismatch) {
|
||||
::Kokkos::realloc(d_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
h_view = create_mirror_view(d_view);
|
||||
} else
|
||||
::Kokkos::realloc(arg_prop..., d_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
h_view = create_mirror_view(arg_prop..., typename t_host::memory_space(),
|
||||
d_view);
|
||||
} else if (!Kokkos::Impl::has_type<Kokkos::Impl::WithoutInitializing_t,
|
||||
I...>::value) {
|
||||
::Kokkos::deep_copy(d_view, typename t_dev::value_type{});
|
||||
}
|
||||
|
||||
/* Reset dirty flags */
|
||||
if (modified_flags.data() == nullptr) {
|
||||
@ -920,18 +923,38 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
modified_flags(1) = modified_flags(0) = 0;
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
impl_realloc(n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
std::enable_if_t<Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
impl_realloc(n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
|
||||
}
|
||||
|
||||
/// \brief Resize both views, copying old contents into new if necessary.
|
||||
///
|
||||
/// This method only copies the old contents into the new View
|
||||
/// objects for the device which was last marked as modified.
|
||||
void resize(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
template <class... I>
|
||||
void impl_resize(const size_t n0, const size_t n1, const size_t n2,
|
||||
const size_t n3, const size_t n4, const size_t n5,
|
||||
const size_t n6, const size_t n7, const I&... arg_prop) {
|
||||
const size_t new_extents[8] = {n0, n1, n2, n3, n4, n5, n6, n7};
|
||||
const bool sizeMismatch =
|
||||
Impl::size_mismatch(h_view, h_view.rank_dynamic, new_extents);
|
||||
@ -942,8 +965,9 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
if (modified_flags(1) >= modified_flags(0)) {
|
||||
/* Resize on Device */
|
||||
if (sizeMismatch) {
|
||||
::Kokkos::resize(d_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
h_view = create_mirror_view(d_view);
|
||||
::Kokkos::resize(arg_prop..., d_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
h_view = create_mirror_view(arg_prop...,
|
||||
typename t_host::memory_space(), d_view);
|
||||
|
||||
/* Mark Device copy as modified */
|
||||
modified_flags(1) = modified_flags(1) + 1;
|
||||
@ -951,8 +975,9 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
} else {
|
||||
/* Realloc on Device */
|
||||
if (sizeMismatch) {
|
||||
::Kokkos::resize(h_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
d_view = create_mirror_view(typename t_dev::execution_space(), h_view);
|
||||
::Kokkos::resize(arg_prop..., h_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
d_view = create_mirror_view(arg_prop..., typename t_dev::memory_space(),
|
||||
h_view);
|
||||
|
||||
/* Mark Host copy as modified */
|
||||
modified_flags(0) = modified_flags(0) + 1;
|
||||
@ -960,6 +985,30 @@ class DualView : public ViewTraits<DataType, Arg1Type, Arg2Type, Arg3Type> {
|
||||
}
|
||||
}
|
||||
|
||||
void resize(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
impl_resize(n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
template <class I>
|
||||
std::enable_if_t<Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
impl_resize(n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
|
||||
}
|
||||
|
||||
//@}
|
||||
//! \name Methods for getting capacity, stride, or dimension(s).
|
||||
//@{
|
||||
@ -1081,12 +1130,29 @@ void resize(DualView<Properties...>& dv, Args&&... args) noexcept(
|
||||
dv.resize(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class I, class... Properties, class... Args>
|
||||
std::enable_if_t<Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop, DualView<Properties...>& dv,
|
||||
Args&&... args) noexcept(noexcept(dv.resize(arg_prop,
|
||||
std::forward<Args>(args)...))) {
|
||||
dv.resize(arg_prop, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class... Properties, class... Args>
|
||||
void realloc(DualView<Properties...>& dv, Args&&... args) noexcept(
|
||||
noexcept(dv.realloc(std::forward<Args>(args)...))) {
|
||||
dv.realloc(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class I, class... Properties, class... Args>
|
||||
std::enable_if_t<Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop, DualView<Properties...>& dv,
|
||||
Args&&... args) noexcept(noexcept(dv.realloc(arg_prop,
|
||||
std::forward<Args>(
|
||||
args)...))) {
|
||||
dv.realloc(arg_prop, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // end namespace Kokkos
|
||||
|
||||
#endif
|
||||
|
||||
@ -284,18 +284,17 @@ KOKKOS_INLINE_FUNCTION void dyn_rank_view_verify_operator_bounds(
|
||||
}
|
||||
|
||||
if (!dyn_rank_view_verify_operator_bounds<0>(rank, map, args...)) {
|
||||
#if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
|
||||
enum { LEN = 1024 };
|
||||
char buffer[LEN];
|
||||
const std::string label = tracker.template get_label<MemorySpace>();
|
||||
int n = snprintf(buffer, LEN, "DynRankView bounds error of view %s (",
|
||||
label.c_str());
|
||||
dyn_rank_view_error_operator_bounds<0>(buffer + n, LEN - n, map, args...);
|
||||
Kokkos::Impl::throw_runtime_exception(std::string(buffer));
|
||||
#else
|
||||
(void)tracker;
|
||||
Kokkos::abort("DynRankView bounds error");
|
||||
#endif
|
||||
KOKKOS_IF_ON_HOST(
|
||||
(enum {LEN = 1024}; char buffer[LEN];
|
||||
const std::string label = tracker.template get_label<MemorySpace>();
|
||||
int n = snprintf(buffer, LEN, "DynRankView bounds error of view %s (",
|
||||
label.c_str());
|
||||
dyn_rank_view_error_operator_bounds<0>(buffer + n, LEN - n, map,
|
||||
args...);
|
||||
Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
|
||||
|
||||
KOKKOS_IF_ON_DEVICE(
|
||||
((void)tracker; Kokkos::abort("DynRankView bounds error");))
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,18 +575,22 @@ class DynRankView : public ViewTraits<DataType, Properties...> {
|
||||
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
|
||||
|
||||
// rank of the calling operator - included as first argument in ARG
|
||||
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
|
||||
typename traits::memory_space>::check(); \
|
||||
Kokkos::Impl::dyn_rank_view_verify_operator_bounds< \
|
||||
typename traits::memory_space> \
|
||||
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::runtime_check_memory_access_violation< \
|
||||
typename traits::memory_space>( \
|
||||
"Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
|
||||
"space"); \
|
||||
Kokkos::Impl::dyn_rank_view_verify_operator_bounds< \
|
||||
typename traits::memory_space> \
|
||||
ARG;
|
||||
|
||||
#else
|
||||
|
||||
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
|
||||
typename traits::memory_space>::check();
|
||||
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::runtime_check_memory_access_violation< \
|
||||
typename traits::memory_space>( \
|
||||
"Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
|
||||
"space");
|
||||
|
||||
#endif
|
||||
|
||||
@ -1682,10 +1685,46 @@ struct DynRankViewRemap {
|
||||
|
||||
namespace Kokkos {
|
||||
|
||||
namespace Impl {
|
||||
|
||||
/* \brief Returns a View of the requested rank, aliasing the
|
||||
underlying memory, to facilitate implementation of deep_copy() and
|
||||
other routines that are defined on View */
|
||||
template <unsigned N, typename T, typename... Args>
|
||||
auto as_view_of_rank_n(DynRankView<T, Args...> v) {
|
||||
if (v.rank() != N) {
|
||||
Kokkos::Impl::throw_runtime_exception(
|
||||
"Converting DynRankView of rank " + std::to_string(v.rank()) +
|
||||
" to a View of mis-matched rank " + std::to_string(N));
|
||||
}
|
||||
|
||||
return View<typename RankDataType<T, N>::type, Args...>(v.data(), v.layout());
|
||||
}
|
||||
|
||||
template <typename Function, typename... Args>
|
||||
void apply_to_view_of_static_rank(Function&& f, DynRankView<Args...> a) {
|
||||
switch (rank(a)) {
|
||||
case 0: f(as_view_of_rank_n<0>(a)); break;
|
||||
case 1: f(as_view_of_rank_n<1>(a)); break;
|
||||
case 2: f(as_view_of_rank_n<2>(a)); break;
|
||||
case 3: f(as_view_of_rank_n<3>(a)); break;
|
||||
case 4: f(as_view_of_rank_n<4>(a)); break;
|
||||
case 5: f(as_view_of_rank_n<5>(a)); break;
|
||||
case 6: f(as_view_of_rank_n<6>(a)); break;
|
||||
case 7: f(as_view_of_rank_n<7>(a)); break;
|
||||
default:
|
||||
Kokkos::Impl::throw_runtime_exception(
|
||||
"Trying to apply a function to a view of unexpected rank " +
|
||||
std::to_string(rank(a)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
/** \brief Deep copy a value from Host memory into a view. */
|
||||
template <class DT, class... DP>
|
||||
template <class ExecSpace, class DT, class... DP>
|
||||
inline void deep_copy(
|
||||
const DynRankView<DT, DP...>& dst,
|
||||
const ExecSpace& e, const DynRankView<DT, DP...>& dst,
|
||||
typename ViewTraits<DT, DP...>::const_value_type& value,
|
||||
typename std::enable_if<std::is_same<
|
||||
typename ViewTraits<DT, DP...>::specialize, void>::value>::type* =
|
||||
@ -1695,39 +1734,100 @@ inline void deep_copy(
|
||||
typename ViewTraits<DT, DP...>::value_type>::value,
|
||||
"deep_copy requires non-const type");
|
||||
|
||||
Kokkos::fence(
|
||||
"Kokkos::deep_copy(DynRankView, value_type): fence before filling view");
|
||||
Kokkos::Impl::DynRankViewFill<DynRankView<DT, DP...> >(dst, value);
|
||||
Kokkos::fence(
|
||||
"Kokkos::deep_copy(DynRankView, value_type): fence after filling view");
|
||||
Impl::apply_to_view_of_static_rank(
|
||||
[=](auto view) { deep_copy(e, view, value); }, dst);
|
||||
}
|
||||
|
||||
template <class DT, class... DP>
|
||||
inline void deep_copy(
|
||||
const DynRankView<DT, DP...>& dst,
|
||||
typename ViewTraits<DT, DP...>::const_value_type& value,
|
||||
typename std::enable_if<std::is_same<
|
||||
typename ViewTraits<DT, DP...>::specialize, void>::value>::type* =
|
||||
nullptr) {
|
||||
Impl::apply_to_view_of_static_rank([=](auto view) { deep_copy(view, value); },
|
||||
dst);
|
||||
}
|
||||
|
||||
/** \brief Deep copy into a value in Host memory from a view. */
|
||||
template <class ExecSpace, class ST, class... SP>
|
||||
inline void deep_copy(
|
||||
const ExecSpace& e,
|
||||
typename ViewTraits<ST, SP...>::non_const_value_type& dst,
|
||||
const DynRankView<ST, SP...>& src,
|
||||
typename std::enable_if<std::is_same<
|
||||
typename ViewTraits<ST, SP...>::specialize, void>::value>::type* = 0) {
|
||||
deep_copy(e, dst, Impl::as_view_of_rank_n<0>(src));
|
||||
}
|
||||
|
||||
template <class ST, class... SP>
|
||||
inline void deep_copy(
|
||||
typename ViewTraits<ST, SP...>::non_const_value_type& dst,
|
||||
const DynRankView<ST, SP...>& src,
|
||||
typename std::enable_if<std::is_same<
|
||||
typename ViewTraits<ST, SP...>::specialize, void>::value>::type* = 0) {
|
||||
if (src.rank() != 0) {
|
||||
Kokkos::abort("");
|
||||
}
|
||||
|
||||
using src_traits = ViewTraits<ST, SP...>;
|
||||
using src_memory_space = typename src_traits::memory_space;
|
||||
Kokkos::fence(
|
||||
"Kokkos::deep_copy(value_type, DynRankView): fence before copying "
|
||||
"value");
|
||||
Kokkos::Impl::DeepCopy<HostSpace, src_memory_space>(&dst, src.data(),
|
||||
sizeof(ST));
|
||||
Kokkos::fence(
|
||||
"Kokkos::deep_copy(value_type, DynRankView): fence after copying value");
|
||||
deep_copy(dst, Impl::as_view_of_rank_n<0>(src));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/** \brief A deep copy between views of the default specialization, compatible
|
||||
* type, same rank, same contiguous layout.
|
||||
*
|
||||
* A rank mismatch will error out in the attempt to convert to a View
|
||||
*/
|
||||
template <class ExecSpace, class DstType, class SrcType>
|
||||
inline void deep_copy(
|
||||
const ExecSpace& exec_space, const DstType& dst, const SrcType& src,
|
||||
typename std::enable_if<
|
||||
(std::is_same<typename DstType::traits::specialize, void>::value &&
|
||||
std::is_same<typename SrcType::traits::specialize, void>::value &&
|
||||
(Kokkos::is_dyn_rank_view<DstType>::value ||
|
||||
Kokkos::is_dyn_rank_view<SrcType>::value))>::type* = nullptr) {
|
||||
static_assert(
|
||||
std::is_same<typename DstType::traits::value_type,
|
||||
typename DstType::traits::non_const_value_type>::value,
|
||||
"deep_copy requires non-const destination type");
|
||||
|
||||
switch (rank(dst)) {
|
||||
case 0:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<0>(dst),
|
||||
Impl::as_view_of_rank_n<0>(src));
|
||||
break;
|
||||
case 1:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<1>(dst),
|
||||
Impl::as_view_of_rank_n<1>(src));
|
||||
break;
|
||||
case 2:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<2>(dst),
|
||||
Impl::as_view_of_rank_n<2>(src));
|
||||
break;
|
||||
case 3:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<3>(dst),
|
||||
Impl::as_view_of_rank_n<3>(src));
|
||||
break;
|
||||
case 4:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<4>(dst),
|
||||
Impl::as_view_of_rank_n<4>(src));
|
||||
break;
|
||||
case 5:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<5>(dst),
|
||||
Impl::as_view_of_rank_n<5>(src));
|
||||
break;
|
||||
case 6:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<6>(dst),
|
||||
Impl::as_view_of_rank_n<6>(src));
|
||||
break;
|
||||
case 7:
|
||||
deep_copy(exec_space, Impl::as_view_of_rank_n<7>(dst),
|
||||
Impl::as_view_of_rank_n<7>(src));
|
||||
break;
|
||||
default:
|
||||
Kokkos::Impl::throw_runtime_exception(
|
||||
"Calling DynRankView deep_copy with a view of unexpected rank " +
|
||||
std::to_string(rank(dst)));
|
||||
}
|
||||
}
|
||||
|
||||
template <class DstType, class SrcType>
|
||||
inline void deep_copy(
|
||||
const DstType& dst, const SrcType& src,
|
||||
@ -1741,134 +1841,43 @@ inline void deep_copy(
|
||||
typename DstType::traits::non_const_value_type>::value,
|
||||
"deep_copy requires non-const destination type");
|
||||
|
||||
using dst_type = DstType;
|
||||
using src_type = SrcType;
|
||||
|
||||
using dst_execution_space = typename dst_type::execution_space;
|
||||
using src_execution_space = typename src_type::execution_space;
|
||||
using dst_memory_space = typename dst_type::memory_space;
|
||||
using src_memory_space = typename src_type::memory_space;
|
||||
|
||||
enum {
|
||||
DstExecCanAccessSrc =
|
||||
Kokkos::SpaceAccessibility<dst_execution_space,
|
||||
src_memory_space>::accessible
|
||||
};
|
||||
|
||||
enum {
|
||||
SrcExecCanAccessDst =
|
||||
Kokkos::SpaceAccessibility<src_execution_space,
|
||||
dst_memory_space>::accessible
|
||||
};
|
||||
|
||||
if ((void*)dst.data() != (void*)src.data()) {
|
||||
// Concern: If overlapping views then a parallel copy will be erroneous.
|
||||
// ...
|
||||
|
||||
// If same type, equal layout, equal dimensions, equal span, and contiguous
|
||||
// memory then can byte-wise copy
|
||||
if (rank(src) == 0 && rank(dst) == 0) {
|
||||
using value_type = typename dst_type::value_type;
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence before "
|
||||
"copying rank-0 views");
|
||||
Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
|
||||
dst.data(), src.data(), sizeof(value_type));
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence after "
|
||||
"copying rank-0 views");
|
||||
} else if (std::is_same<
|
||||
typename DstType::traits::value_type,
|
||||
typename SrcType::traits::non_const_value_type>::value &&
|
||||
((std::is_same<typename DstType::traits::array_layout,
|
||||
typename SrcType::traits::array_layout>::value &&
|
||||
(std::is_same<typename DstType::traits::array_layout,
|
||||
typename Kokkos::LayoutLeft>::value ||
|
||||
std::is_same<typename DstType::traits::array_layout,
|
||||
typename Kokkos::LayoutRight>::value)) ||
|
||||
(rank(dst) == 1 && rank(src) == 1)) &&
|
||||
dst.span_is_contiguous() && src.span_is_contiguous() &&
|
||||
dst.span() == src.span() && dst.extent(0) == src.extent(0) &&
|
||||
|
||||
dst.extent(1) == src.extent(1) &&
|
||||
dst.extent(2) == src.extent(2) &&
|
||||
dst.extent(3) == src.extent(3) &&
|
||||
dst.extent(4) == src.extent(4) &&
|
||||
dst.extent(5) == src.extent(5) &&
|
||||
dst.extent(6) == src.extent(6) &&
|
||||
dst.extent(7) == src.extent(7)) {
|
||||
const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence before "
|
||||
"copying rank-1 views");
|
||||
Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
|
||||
dst.data(), src.data(), nbytes);
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence after "
|
||||
"copying rank-1 views");
|
||||
} else if (std::is_same<
|
||||
typename DstType::traits::value_type,
|
||||
typename SrcType::traits::non_const_value_type>::value &&
|
||||
((std::is_same<typename DstType::traits::array_layout,
|
||||
typename SrcType::traits::array_layout>::value &&
|
||||
std::is_same<typename DstType::traits::array_layout,
|
||||
typename Kokkos::LayoutStride>::value) ||
|
||||
(rank(dst) == 1 && rank(src) == 1)) &&
|
||||
dst.span_is_contiguous() && src.span_is_contiguous() &&
|
||||
dst.span() == src.span() && dst.extent(0) == src.extent(0) &&
|
||||
dst.extent(1) == src.extent(1) &&
|
||||
dst.extent(2) == src.extent(2) &&
|
||||
dst.extent(3) == src.extent(3) &&
|
||||
dst.extent(4) == src.extent(4) &&
|
||||
dst.extent(5) == src.extent(5) &&
|
||||
dst.extent(6) == src.extent(6) &&
|
||||
dst.extent(7) == src.extent(7) &&
|
||||
dst.stride_0() == src.stride_0() &&
|
||||
dst.stride_1() == src.stride_1() &&
|
||||
dst.stride_2() == src.stride_2() &&
|
||||
dst.stride_3() == src.stride_3() &&
|
||||
dst.stride_4() == src.stride_4() &&
|
||||
dst.stride_5() == src.stride_5() &&
|
||||
dst.stride_6() == src.stride_6() &&
|
||||
dst.stride_7() == src.stride_7()) {
|
||||
const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence before "
|
||||
"copying rank-1 views");
|
||||
Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
|
||||
dst.data(), src.data(), nbytes);
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence after "
|
||||
"copying rank-1 views");
|
||||
} else if (DstExecCanAccessSrc) {
|
||||
// Copying data between views in accessible memory spaces and either
|
||||
// non-contiguous or incompatible shape.
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence before "
|
||||
"remapping views of incompatible shape");
|
||||
Kokkos::Impl::DynRankViewRemap<dst_type, src_type>(dst, src);
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence after "
|
||||
"remapping views of incompatible shape");
|
||||
} else if (SrcExecCanAccessDst) {
|
||||
// Copying data between views in accessible memory spaces and either
|
||||
// non-contiguous or incompatible shape.
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence before "
|
||||
"remapping views of incompatible shape");
|
||||
Kokkos::Impl::DynRankViewRemap<dst_type, src_type, src_execution_space>(
|
||||
dst, src);
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence after "
|
||||
"remapping views of incompatible shape");
|
||||
} else {
|
||||
switch (rank(dst)) {
|
||||
case 0:
|
||||
deep_copy(Impl::as_view_of_rank_n<0>(dst),
|
||||
Impl::as_view_of_rank_n<0>(src));
|
||||
break;
|
||||
case 1:
|
||||
deep_copy(Impl::as_view_of_rank_n<1>(dst),
|
||||
Impl::as_view_of_rank_n<1>(src));
|
||||
break;
|
||||
case 2:
|
||||
deep_copy(Impl::as_view_of_rank_n<2>(dst),
|
||||
Impl::as_view_of_rank_n<2>(src));
|
||||
break;
|
||||
case 3:
|
||||
deep_copy(Impl::as_view_of_rank_n<3>(dst),
|
||||
Impl::as_view_of_rank_n<3>(src));
|
||||
break;
|
||||
case 4:
|
||||
deep_copy(Impl::as_view_of_rank_n<4>(dst),
|
||||
Impl::as_view_of_rank_n<4>(src));
|
||||
break;
|
||||
case 5:
|
||||
deep_copy(Impl::as_view_of_rank_n<5>(dst),
|
||||
Impl::as_view_of_rank_n<5>(src));
|
||||
break;
|
||||
case 6:
|
||||
deep_copy(Impl::as_view_of_rank_n<6>(dst),
|
||||
Impl::as_view_of_rank_n<6>(src));
|
||||
break;
|
||||
case 7:
|
||||
deep_copy(Impl::as_view_of_rank_n<7>(dst),
|
||||
Impl::as_view_of_rank_n<7>(src));
|
||||
break;
|
||||
default:
|
||||
Kokkos::Impl::throw_runtime_exception(
|
||||
"deep_copy given views that would require a temporary allocation");
|
||||
}
|
||||
} else {
|
||||
Kokkos::fence(
|
||||
"Kokkos::Impl::DeepCopy(DynRankView, DynRankView): fence due to same "
|
||||
"src and dst");
|
||||
"Calling DynRankView deep_copy with a view of unexpected rank " +
|
||||
std::to_string(rank(dst)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2053,6 +2062,24 @@ create_mirror_view_and_copy(
|
||||
namespace Kokkos {
|
||||
/** \brief Resize a view with copying old data to new data at the corresponding
|
||||
* indices. */
|
||||
template <class... I, class T, class... P>
|
||||
inline void impl_resize(DynRankView<T, P...>& v, const size_t n0,
|
||||
const size_t n1, const size_t n2, const size_t n3,
|
||||
const size_t n4, const size_t n5, const size_t n6,
|
||||
const size_t n7, const I&... arg_prop) {
|
||||
using drview_type = DynRankView<T, P...>;
|
||||
|
||||
static_assert(Kokkos::ViewTraits<T, P...>::is_managed,
|
||||
"Can only resize managed views");
|
||||
|
||||
drview_type v_resized(view_alloc(v.label(), arg_prop...), n0, n1, n2, n3, n4,
|
||||
n5, n6, n7);
|
||||
|
||||
Kokkos::Impl::DynRankViewRemap<drview_type, drview_type>(v_resized, v);
|
||||
|
||||
v = v_resized;
|
||||
}
|
||||
|
||||
template <class T, class... P>
|
||||
inline void resize(DynRankView<T, P...>& v,
|
||||
const size_t n0 = KOKKOS_INVALID_INDEX,
|
||||
@ -2063,20 +2090,42 @@ inline void resize(DynRankView<T, P...>& v,
|
||||
const size_t n5 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n6 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n7 = KOKKOS_INVALID_INDEX) {
|
||||
using drview_type = DynRankView<T, P...>;
|
||||
impl_resize(v, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
static_assert(Kokkos::ViewTraits<T, P...>::is_managed,
|
||||
"Can only resize managed views");
|
||||
|
||||
drview_type v_resized(v.label(), n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
|
||||
Kokkos::Impl::DynRankViewRemap<drview_type, drview_type>(v_resized, v);
|
||||
|
||||
v = v_resized;
|
||||
template <class I, class T, class... P>
|
||||
inline std::enable_if_t<Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop, DynRankView<T, P...>& v,
|
||||
const size_t n0 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n1 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n2 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n3 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n4 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n5 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n6 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n7 = KOKKOS_INVALID_INDEX) {
|
||||
impl_resize(v, n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
|
||||
}
|
||||
|
||||
/** \brief Resize a view with copying old data to new data at the corresponding
|
||||
* indices. */
|
||||
template <class... I, class T, class... P>
|
||||
inline void impl_realloc(DynRankView<T, P...>& v, const size_t n0,
|
||||
const size_t n1, const size_t n2, const size_t n3,
|
||||
const size_t n4, const size_t n5, const size_t n6,
|
||||
const size_t n7, const I&... arg_prop) {
|
||||
using drview_type = DynRankView<T, P...>;
|
||||
|
||||
static_assert(Kokkos::ViewTraits<T, P...>::is_managed,
|
||||
"Can only realloc managed views");
|
||||
|
||||
const std::string label = v.label();
|
||||
|
||||
v = drview_type(); // Deallocate first, if the only view to allocation
|
||||
v = drview_type(view_alloc(label, arg_prop...), n0, n1, n2, n3, n4, n5, n6,
|
||||
n7);
|
||||
}
|
||||
|
||||
template <class T, class... P>
|
||||
inline void realloc(DynRankView<T, P...>& v,
|
||||
const size_t n0 = KOKKOS_INVALID_INDEX,
|
||||
@ -2087,15 +2136,21 @@ inline void realloc(DynRankView<T, P...>& v,
|
||||
const size_t n5 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n6 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n7 = KOKKOS_INVALID_INDEX) {
|
||||
using drview_type = DynRankView<T, P...>;
|
||||
impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
static_assert(Kokkos::ViewTraits<T, P...>::is_managed,
|
||||
"Can only realloc managed views");
|
||||
|
||||
const std::string label = v.label();
|
||||
|
||||
v = drview_type(); // Deallocate first, if the only view to allocation
|
||||
v = drview_type(label, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
template <class I, class T, class... P>
|
||||
inline std::enable_if_t<Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop, DynRankView<T, P...>& v,
|
||||
const size_t n0 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n1 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n2 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n3 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n4 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n5 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n6 = KOKKOS_INVALID_INDEX,
|
||||
const size_t n7 = KOKKOS_INVALID_INDEX) {
|
||||
impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
|
||||
}
|
||||
|
||||
} // namespace Kokkos
|
||||
|
||||
@ -281,21 +281,6 @@ class DynamicView : public Kokkos::ViewTraits<DataType, P...> {
|
||||
static_assert(std::is_same<typename traits::specialize, void>::value,
|
||||
"DynamicView only implemented for non-specialized View type");
|
||||
|
||||
template <class Space, bool = Kokkos::Impl::MemorySpaceAccess<
|
||||
Space, device_space>::accessible>
|
||||
struct verify_space {
|
||||
KOKKOS_FORCEINLINE_FUNCTION static void check() {}
|
||||
};
|
||||
|
||||
template <class Space>
|
||||
struct verify_space<Space, false> {
|
||||
KOKKOS_FORCEINLINE_FUNCTION static void check() {
|
||||
Kokkos::abort(
|
||||
"Kokkos::DynamicView ERROR: attempt to access inaccessible memory "
|
||||
"space");
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
device_accessor m_chunks;
|
||||
host_accessor m_chunks_host;
|
||||
@ -420,8 +405,10 @@ class DynamicView : public Kokkos::ViewTraits<DataType, P...> {
|
||||
static_assert(Kokkos::Impl::are_integral<I0, Args...>::value,
|
||||
"Indices must be integral type");
|
||||
|
||||
DynamicView::template verify_space<
|
||||
Kokkos::Impl::ActiveExecutionMemorySpace>::check();
|
||||
Kokkos::Impl::runtime_check_memory_access_violation<
|
||||
typename traits::memory_space>(
|
||||
"Kokkos::DynamicView ERROR: attempt to access inaccessible memory "
|
||||
"space");
|
||||
|
||||
// Which chunk is being indexed.
|
||||
const uintptr_t ic = uintptr_t(i0 >> m_chunk_shift);
|
||||
|
||||
@ -103,13 +103,13 @@ class ErrorReporter {
|
||||
}
|
||||
|
||||
private:
|
||||
using reports_view_t = Kokkos::View<report_type *, execution_space>;
|
||||
using reports_dualview_t = Kokkos::DualView<report_type *, execution_space>;
|
||||
using reports_view_t = Kokkos::View<report_type *, device_type>;
|
||||
using reports_dualview_t = Kokkos::DualView<report_type *, device_type>;
|
||||
|
||||
using host_mirror_space = typename reports_dualview_t::host_mirror_space;
|
||||
Kokkos::View<int, execution_space> m_numReportsAttempted;
|
||||
Kokkos::View<int, device_type> m_numReportsAttempted;
|
||||
reports_dualview_t m_reports;
|
||||
Kokkos::DualView<int *, execution_space> m_reporters;
|
||||
Kokkos::DualView<int *, device_type> m_reporters;
|
||||
};
|
||||
|
||||
template <typename ReportType, typename DeviceType>
|
||||
@ -157,12 +157,10 @@ void ErrorReporter<ReportType, DeviceType>::getReports(
|
||||
typename DeviceType::execution_space>::HostMirror
|
||||
&reports_out) {
|
||||
int num_reports = getNumReports();
|
||||
reporters_out =
|
||||
typename Kokkos::View<int *, typename DeviceType::execution_space>::
|
||||
HostMirror("ErrorReport::reporters_out", num_reports);
|
||||
reports_out = typename Kokkos::
|
||||
View<report_type *, typename DeviceType::execution_space>::HostMirror(
|
||||
"ErrorReport::reports_out", num_reports);
|
||||
reporters_out = typename Kokkos::View<int *, DeviceType>::HostMirror(
|
||||
"ErrorReport::reporters_out", num_reports);
|
||||
reports_out = typename Kokkos::View<report_type *, DeviceType>::HostMirror(
|
||||
"ErrorReport::reports_out", num_reports);
|
||||
|
||||
if (num_reports > 0) {
|
||||
m_reports.template sync<host_mirror_space>();
|
||||
|
||||
@ -99,36 +99,32 @@ KOKKOS_INLINE_FUNCTION void offsetview_verify_operator_bounds(
|
||||
Kokkos::Impl::SharedAllocationTracker const& tracker, const MapType& map,
|
||||
const BeginsType& begins, Args... args) {
|
||||
if (!offsetview_verify_operator_bounds<0>(map, begins, args...)) {
|
||||
#if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
|
||||
enum { LEN = 1024 };
|
||||
char buffer[LEN];
|
||||
const std::string label = tracker.template get_label<MemorySpace>();
|
||||
int n =
|
||||
snprintf(buffer, LEN, "OffsetView bounds error of view labeled %s (",
|
||||
label.c_str());
|
||||
offsetview_error_operator_bounds<0>(buffer + n, LEN - n, map, begins,
|
||||
args...);
|
||||
Kokkos::Impl::throw_runtime_exception(std::string(buffer));
|
||||
#else
|
||||
/* Check #1: is there a SharedAllocationRecord?
|
||||
(we won't use it, but if its not there then there isn't
|
||||
a corresponding SharedAllocationHeader containing a label).
|
||||
This check should cover the case of Views that don't
|
||||
have the Unmanaged trait but were initialized by pointer. */
|
||||
if (tracker.has_record()) {
|
||||
Kokkos::Impl::operator_bounds_error_on_device(map);
|
||||
} else {
|
||||
Kokkos::abort("OffsetView bounds error");
|
||||
}
|
||||
#endif
|
||||
KOKKOS_IF_ON_HOST(
|
||||
(enum {LEN = 1024}; char buffer[LEN];
|
||||
const std::string label = tracker.template get_label<MemorySpace>();
|
||||
int n = snprintf(buffer, LEN,
|
||||
"OffsetView bounds error of view labeled %s (",
|
||||
label.c_str());
|
||||
offsetview_error_operator_bounds<0>(buffer + n, LEN - n, map, begins,
|
||||
args...);
|
||||
Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
|
||||
|
||||
KOKKOS_IF_ON_DEVICE((
|
||||
/* Check #1: is there a SharedAllocationRecord?
|
||||
(we won't use it, but if it is not there then there isn't
|
||||
a corresponding SharedAllocationHeader containing a label).
|
||||
This check should cover the case of Views that don't
|
||||
have the Unmanaged trait but were initialized by pointer. */
|
||||
if (tracker.has_record()) {
|
||||
Kokkos::Impl::operator_bounds_error_on_device(map);
|
||||
} else { Kokkos::abort("OffsetView bounds error"); }))
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void runtime_check_rank_host(const size_t rank_dynamic, const size_t rank,
|
||||
const index_list_type minIndices,
|
||||
const std::string& label) {
|
||||
inline void runtime_check_rank_host(const size_t rank_dynamic,
|
||||
const size_t rank,
|
||||
const index_list_type minIndices,
|
||||
const std::string& label) {
|
||||
bool isBad = false;
|
||||
std::string message =
|
||||
"Kokkos::Experimental::OffsetView ERROR: for OffsetView labeled '" +
|
||||
@ -155,7 +151,6 @@ void runtime_check_rank_host(const size_t rank_dynamic, const size_t rank,
|
||||
|
||||
if (isBad) Kokkos::abort(message.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void runtime_check_rank_device(const size_t rank_dynamic, const size_t rank,
|
||||
@ -378,18 +373,22 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
|
||||
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
|
||||
|
||||
#define KOKKOS_IMPL_OFFSETVIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
|
||||
typename traits::memory_space>::check(); \
|
||||
Kokkos::Experimental::Impl::offsetview_verify_operator_bounds< \
|
||||
typename traits::memory_space> \
|
||||
#define KOKKOS_IMPL_OFFSETVIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::runtime_check_memory_access_violation< \
|
||||
typename traits::memory_space>( \
|
||||
"Kokkos::OffsetView ERROR: attempt to access inaccessible memory " \
|
||||
"space"); \
|
||||
Kokkos::Experimental::Impl::offsetview_verify_operator_bounds< \
|
||||
typename traits::memory_space> \
|
||||
ARG;
|
||||
|
||||
#else
|
||||
|
||||
#define KOKKOS_IMPL_OFFSETVIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
|
||||
typename traits::memory_space>::check();
|
||||
#define KOKKOS_IMPL_OFFSETVIEW_OPERATOR_VERIFY(ARG) \
|
||||
Kokkos::Impl::runtime_check_memory_access_violation< \
|
||||
typename traits::memory_space>( \
|
||||
"Kokkos::OffsetView ERROR: attempt to access inaccessible memory " \
|
||||
"space");
|
||||
|
||||
#endif
|
||||
public:
|
||||
@ -863,14 +862,11 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
"Incompatible OffsetView copy construction");
|
||||
Mapping::assign(m_map, aview.impl_map(), m_track);
|
||||
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
Kokkos::Experimental::Impl::runtime_check_rank_host(
|
||||
traits::rank_dynamic, Rank, minIndices, label());
|
||||
#else
|
||||
Kokkos::Experimental::Impl::runtime_check_rank_device(traits::rank_dynamic,
|
||||
Rank, minIndices);
|
||||
KOKKOS_IF_ON_HOST((Kokkos::Experimental::Impl::runtime_check_rank_host(
|
||||
traits::rank_dynamic, Rank, minIndices, label());))
|
||||
|
||||
#endif
|
||||
KOKKOS_IF_ON_DEVICE((Kokkos::Experimental::Impl::runtime_check_rank_device(
|
||||
traits::rank_dynamic, Rank, minIndices);))
|
||||
|
||||
for (size_t i = 0; i < minIndices.size(); ++i) {
|
||||
m_begins[i] = minIndices.begin()[i];
|
||||
@ -885,15 +881,6 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
static_assert(Mapping::is_assignable,
|
||||
"Incompatible OffsetView copy construction");
|
||||
Mapping::assign(m_map, aview.impl_map(), m_track);
|
||||
|
||||
//#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
// Kokkos::Experimental::Impl::runtime_check_rank_host(traits::rank_dynamic,
|
||||
// Rank, minIndices, label());
|
||||
//#else
|
||||
// Kokkos::Experimental::Impl::runtime_check_rank_device(traits::rank_dynamic,
|
||||
// Rank, minIndices);
|
||||
//
|
||||
//#endif
|
||||
}
|
||||
|
||||
// may assign unmanaged from managed.
|
||||
@ -941,12 +928,11 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
return *(a.begin() + pos);
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
// Check that begins < ends for all elements
|
||||
// B, E can be begins_type and/or index_list_type
|
||||
template <typename B, typename E>
|
||||
KOKKOS_INLINE_FUNCTION static subtraction_failure
|
||||
runtime_check_begins_ends_host(const B& begins, const E& ends) {
|
||||
static subtraction_failure runtime_check_begins_ends_host(const B& begins,
|
||||
const E& ends) {
|
||||
std::string message;
|
||||
if (begins.size() != Rank)
|
||||
message +=
|
||||
@ -1015,7 +1001,6 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
|
||||
return subtraction_failure::none;
|
||||
}
|
||||
#endif // KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
|
||||
// Check the begins < ends for all elements
|
||||
template <typename B, typename E>
|
||||
@ -1049,6 +1034,14 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
return subtraction_failure::none;
|
||||
}
|
||||
|
||||
template <typename B, typename E>
|
||||
KOKKOS_INLINE_FUNCTION static subtraction_failure runtime_check_begins_ends(
|
||||
const B& begins, const E& ends) {
|
||||
KOKKOS_IF_ON_HOST((return runtime_check_begins_ends_host(begins, ends);))
|
||||
KOKKOS_IF_ON_DEVICE(
|
||||
(return runtime_check_begins_ends_device(begins, ends);))
|
||||
}
|
||||
|
||||
// Constructor around unmanaged data after checking begins < ends for all
|
||||
// elements
|
||||
// Each of B, E can be begins_type and/or index_list_type
|
||||
@ -1081,54 +1074,26 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OffsetView(const pointer_type& p, const begins_type& begins_,
|
||||
const begins_type& ends_)
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_host(begins_, ends_))
|
||||
#else
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_device(begins_, ends_))
|
||||
#endif
|
||||
{
|
||||
}
|
||||
runtime_check_begins_ends(begins_, ends_)) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OffsetView(const pointer_type& p, const begins_type& begins_,
|
||||
index_list_type ends_)
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_host(begins_, ends_))
|
||||
#else
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_device(begins_, ends_))
|
||||
#endif
|
||||
{
|
||||
}
|
||||
runtime_check_begins_ends(begins_, ends_)) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OffsetView(const pointer_type& p, index_list_type begins_,
|
||||
const begins_type& ends_)
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_host(begins_, ends_))
|
||||
#else
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_device(begins_, ends_))
|
||||
#endif
|
||||
{
|
||||
}
|
||||
runtime_check_begins_ends(begins_, ends_)) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OffsetView(const pointer_type& p, index_list_type begins_,
|
||||
index_list_type ends_)
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_host(begins_, ends_))
|
||||
#else
|
||||
: OffsetView(p, begins_, ends_,
|
||||
runtime_check_begins_ends_device(begins_, ends_))
|
||||
#endif
|
||||
{
|
||||
}
|
||||
runtime_check_begins_ends(begins_, ends_)) {}
|
||||
|
||||
//----------------------------------------
|
||||
// Allocation tracking properties
|
||||
@ -1265,14 +1230,11 @@ class OffsetView : public ViewTraits<DataType, Properties...> {
|
||||
// Setup and initialization complete, start tracking
|
||||
m_track.assign_allocated_record_to_uninitialized(record);
|
||||
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
Kokkos::Experimental::Impl::runtime_check_rank_host(
|
||||
traits::rank_dynamic, Rank, minIndices, label());
|
||||
#else
|
||||
Kokkos::Experimental::Impl::runtime_check_rank_device(traits::rank_dynamic,
|
||||
Rank, minIndices);
|
||||
KOKKOS_IF_ON_HOST((Kokkos::Experimental::Impl::runtime_check_rank_host(
|
||||
traits::rank_dynamic, Rank, minIndices, label());))
|
||||
|
||||
#endif
|
||||
KOKKOS_IF_ON_DEVICE((Kokkos::Experimental::Impl::runtime_check_rank_device(
|
||||
traits::rank_dynamic, Rank, minIndices);))
|
||||
}
|
||||
};
|
||||
|
||||
@ -1887,12 +1849,12 @@ struct MirrorOffsetViewType {
|
||||
// The array_layout
|
||||
using array_layout = typename src_view_type::array_layout;
|
||||
// The data type (we probably want it non-const since otherwise we can't even
|
||||
// deep_copy to it.
|
||||
// deep_copy to it.)
|
||||
using data_type = typename src_view_type::non_const_data_type;
|
||||
// The destination view type if it is not the same memory space
|
||||
using dest_view_type =
|
||||
Kokkos::Experimental::OffsetView<data_type, array_layout, Space>;
|
||||
// If it is the same memory_space return the existsing view_type
|
||||
// If it is the same memory_space return the existing view_type
|
||||
// This will also keep the unmanaged trait if necessary
|
||||
using view_type = typename std::conditional<is_same_memspace, src_view_type,
|
||||
dest_view_type>::type;
|
||||
@ -1912,7 +1874,7 @@ struct MirrorOffsetType {
|
||||
// The array_layout
|
||||
using array_layout = typename src_view_type::array_layout;
|
||||
// The data type (we probably want it non-const since otherwise we can't even
|
||||
// deep_copy to it.
|
||||
// deep_copy to it.)
|
||||
using data_type = typename src_view_type::non_const_data_type;
|
||||
// The destination view type if it is not the same memory space
|
||||
using view_type =
|
||||
|
||||
@ -861,18 +861,54 @@ class ScatterView<DataType, Layout, DeviceType, Op, ScatterNonDuplicated,
|
||||
if (view.data() != internal_view.data()) reset(exec_space);
|
||||
}
|
||||
|
||||
void resize(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0, const size_t n7 = 0) {
|
||||
void resize(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::resize(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0, const size_t n7 = 0) {
|
||||
template <class I>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::resize(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::realloc(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
template <class I>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::realloc(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename... Args>
|
||||
KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(Args... args) const {
|
||||
@ -1097,20 +1133,54 @@ class ScatterView<DataType, Kokkos::LayoutRight, DeviceType, Op,
|
||||
internal_view.size() - view.size(), internal_view.label());
|
||||
}
|
||||
|
||||
void resize(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0) {
|
||||
void resize(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::resize(internal_view, unique_token.size(), n0, n1, n2, n3, n4, n5,
|
||||
n6);
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0) {
|
||||
template <class I>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::resize(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
|
||||
n3, n4, n5, n6);
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::realloc(internal_view, unique_token.size(), n0, n1, n2, n3, n4,
|
||||
n5, n6);
|
||||
}
|
||||
|
||||
template <class I>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
::Kokkos::realloc(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
|
||||
n3, n4, n5, n6);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename... Args>
|
||||
KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(int rank,
|
||||
@ -1328,9 +1398,13 @@ class ScatterView<DataType, Kokkos::LayoutLeft, DeviceType, Op,
|
||||
internal_view.size() - view.size(), internal_view.label());
|
||||
}
|
||||
|
||||
void resize(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0) {
|
||||
void resize(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
size_t arg_N[8] = {n0, n1, n2, n3, n4, n5, n6, 0};
|
||||
const int i = internal_view.rank - 1;
|
||||
arg_N[i] = unique_token.size();
|
||||
@ -1339,9 +1413,13 @@ class ScatterView<DataType, Kokkos::LayoutLeft, DeviceType, Op,
|
||||
arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
|
||||
}
|
||||
|
||||
void realloc(const size_t n0 = 0, const size_t n1 = 0, const size_t n2 = 0,
|
||||
const size_t n3 = 0, const size_t n4 = 0, const size_t n5 = 0,
|
||||
const size_t n6 = 0) {
|
||||
void realloc(const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
|
||||
size_t arg_N[8] = {n0, n1, n2, n3, n4, n5, n6, 0};
|
||||
const int i = internal_view.rank - 1;
|
||||
arg_N[i] = unique_token.size();
|
||||
@ -1518,6 +1596,15 @@ void realloc(
|
||||
scatter_view.realloc(is...);
|
||||
}
|
||||
|
||||
template <typename I, typename DT, typename LY, typename ES, typename OP,
|
||||
typename CT, typename DP, typename... IS>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
|
||||
const I& arg_prop,
|
||||
Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
|
||||
IS... is) {
|
||||
scatter_view.realloc(arg_prop, is...);
|
||||
}
|
||||
|
||||
template <typename DT, typename LY, typename ES, typename OP, typename CT,
|
||||
typename DP, typename... IS>
|
||||
void resize(
|
||||
@ -1526,6 +1613,15 @@ void resize(
|
||||
scatter_view.resize(is...);
|
||||
}
|
||||
|
||||
template <typename I, typename DT, typename LY, typename ES, typename OP,
|
||||
typename CT, typename DP, typename... IS>
|
||||
std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
|
||||
const I& arg_prop,
|
||||
Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
|
||||
IS... is) {
|
||||
scatter_view.resize(arg_prop, is...);
|
||||
}
|
||||
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
|
||||
@ -203,7 +203,7 @@ template <typename Key, typename Value,
|
||||
typename Device = Kokkos::DefaultExecutionSpace,
|
||||
typename Hasher = pod_hash<typename std::remove_const<Key>::type>,
|
||||
typename EqualTo =
|
||||
pod_equal_to<typename std::remove_const<Key>::type> >
|
||||
pod_equal_to<typename std::remove_const<Key>::type>>
|
||||
class UnorderedMap {
|
||||
private:
|
||||
using host_mirror_space =
|
||||
@ -268,20 +268,19 @@ class UnorderedMap {
|
||||
|
||||
using key_type_view = std::conditional_t<
|
||||
is_insertable_map, View<key_type *, device_type>,
|
||||
View<const key_type *, device_type, MemoryTraits<RandomAccess> > >;
|
||||
View<const key_type *, device_type, MemoryTraits<RandomAccess>>>;
|
||||
|
||||
using value_type_view = std::conditional_t<
|
||||
is_insertable_map || is_modifiable_map,
|
||||
View<impl_value_type *, device_type>,
|
||||
View<const impl_value_type *, device_type, MemoryTraits<RandomAccess> > >;
|
||||
View<const impl_value_type *, device_type, MemoryTraits<RandomAccess>>>;
|
||||
|
||||
using size_type_view = std::conditional_t<
|
||||
is_insertable_map, View<size_type *, device_type>,
|
||||
View<const size_type *, device_type, MemoryTraits<RandomAccess> > >;
|
||||
View<const size_type *, device_type, MemoryTraits<RandomAccess>>>;
|
||||
|
||||
using bitset_type =
|
||||
std::conditional_t<is_insertable_map, Bitset<execution_space>,
|
||||
ConstBitset<execution_space> >;
|
||||
using bitset_type = std::conditional_t<is_insertable_map, Bitset<Device>,
|
||||
ConstBitset<Device>>;
|
||||
|
||||
enum { modified_idx = 0, erasable_idx = 1, failed_insert_idx = 2 };
|
||||
enum { num_scalars = 3 };
|
||||
@ -310,8 +309,13 @@ class UnorderedMap {
|
||||
capacity() + 1) // +1 so that the *_at functions can
|
||||
// always return a valid reference
|
||||
,
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
m_keys("UnorderedMap keys", capacity() + 1),
|
||||
m_values("UnorderedMap values", (is_set ? 1 : capacity() + 1)),
|
||||
#else
|
||||
m_keys("UnorderedMap keys", capacity()),
|
||||
m_values("UnorderedMap values", (is_set ? 0 : capacity())),
|
||||
#endif
|
||||
m_scalars("UnorderedMap scalars") {
|
||||
if (!is_insertable_map) {
|
||||
throw std::runtime_error(
|
||||
@ -341,17 +345,24 @@ class UnorderedMap {
|
||||
const key_type tmp = key_type();
|
||||
Kokkos::deep_copy(m_keys, tmp);
|
||||
}
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
if (is_set) {
|
||||
const impl_value_type tmp = impl_value_type();
|
||||
Kokkos::deep_copy(m_values, tmp);
|
||||
}
|
||||
#endif
|
||||
Kokkos::deep_copy(m_scalars, 0);
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION constexpr bool is_allocated() const {
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
return (m_keys.is_allocated() && m_values.is_allocated() &&
|
||||
m_scalars.is_allocated());
|
||||
#else
|
||||
return (m_keys.is_allocated() && (is_set || m_values.is_allocated()) &&
|
||||
m_scalars.is_allocated());
|
||||
#endif
|
||||
}
|
||||
|
||||
/// \brief Change the capacity of the the map
|
||||
@ -424,9 +435,6 @@ class UnorderedMap {
|
||||
"Kokkos::UnorderedMap::begin_erase: fence before setting erasable "
|
||||
"flag");
|
||||
set_flag(erasable_idx);
|
||||
execution_space().fence(
|
||||
"Kokkos::UnorderedMap::begin_erase: fence after setting erasable "
|
||||
"flag");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -520,19 +528,35 @@ class UnorderedMap {
|
||||
// Continue searching the unordered list for this key,
|
||||
// list will only be appended during insert phase.
|
||||
// Need volatile_load as other threads may be appending.
|
||||
|
||||
// FIXME_SYCL replacement for memory_fence
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
size_type curr = Kokkos::atomic_load(curr_ptr);
|
||||
#else
|
||||
size_type curr = volatile_load(curr_ptr);
|
||||
#endif
|
||||
|
||||
KOKKOS_NONTEMPORAL_PREFETCH_LOAD(
|
||||
&m_keys[curr != invalid_index ? curr : 0]);
|
||||
#if defined(__MIC__)
|
||||
#pragma noprefetch
|
||||
#endif
|
||||
while (curr != invalid_index &&
|
||||
!m_equal_to(volatile_load(&m_keys[curr]), k)) {
|
||||
while (curr != invalid_index && !m_equal_to(
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
Kokkos::atomic_load(&m_keys[curr])
|
||||
#else
|
||||
volatile_load(&m_keys[curr])
|
||||
#endif
|
||||
,
|
||||
k)) {
|
||||
result.increment_list_position();
|
||||
index_hint = curr;
|
||||
curr_ptr = &m_next_index[curr];
|
||||
curr = volatile_load(curr_ptr);
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
curr = Kokkos::atomic_load(curr_ptr);
|
||||
#else
|
||||
curr = volatile_load(curr_ptr);
|
||||
#endif
|
||||
KOKKOS_NONTEMPORAL_PREFETCH_LOAD(
|
||||
&m_keys[curr != invalid_index ? curr : 0]);
|
||||
}
|
||||
@ -572,15 +596,26 @@ class UnorderedMap {
|
||||
new_index = index_hint;
|
||||
// Set key and value
|
||||
KOKKOS_NONTEMPORAL_PREFETCH_STORE(&m_keys[new_index]);
|
||||
// FIXME_SYCL replacement for memory_fence
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
Kokkos::atomic_store(&m_keys[new_index], k);
|
||||
#else
|
||||
m_keys[new_index] = k;
|
||||
#endif
|
||||
|
||||
if (!is_set) {
|
||||
KOKKOS_NONTEMPORAL_PREFETCH_STORE(&m_values[new_index]);
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
Kokkos::atomic_store(&m_values[new_index], v);
|
||||
#else
|
||||
m_values[new_index] = v;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef KOKKOS_ENABLE_SYCL
|
||||
// Do not proceed until key and value are updated in global memory
|
||||
memory_fence();
|
||||
#endif
|
||||
}
|
||||
} else if (failed_insert_ref) {
|
||||
not_done = false;
|
||||
@ -660,13 +695,31 @@ class UnorderedMap {
|
||||
/// kernel.
|
||||
///
|
||||
/// 'const value_type' via Cuda texture fetch must return by value.
|
||||
KOKKOS_FORCEINLINE_FUNCTION
|
||||
std::conditional_t<(is_set || has_const_value), impl_value_type,
|
||||
impl_value_type &>
|
||||
template <typename Dummy = value_type>
|
||||
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
|
||||
!std::is_void<Dummy>::value, // !is_set
|
||||
std::conditional_t<has_const_value, impl_value_type, impl_value_type &>>
|
||||
value_at(size_type i) const {
|
||||
return m_values[is_set ? 0 : (i < capacity() ? i : capacity())];
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
return m_values[i < capacity() ? i : capacity()];
|
||||
#else
|
||||
KOKKOS_EXPECTS(i < capacity());
|
||||
return m_values[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
template <typename Dummy = value_type>
|
||||
KOKKOS_DEPRECATED_WITH_COMMENT(
|
||||
"Calling value_at for value_type==void is deprecated!")
|
||||
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
|
||||
std::is_void<Dummy>::value, // is_set
|
||||
std::conditional_t<has_const_value, impl_value_type,
|
||||
impl_value_type &>> value_at(size_type /*i*/) const {
|
||||
return m_values[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
/// \brief Get the key with \c i as its direct index.
|
||||
///
|
||||
/// \param i [in] Index directly into the array of entries.
|
||||
@ -675,7 +728,12 @@ class UnorderedMap {
|
||||
/// kernel.
|
||||
KOKKOS_FORCEINLINE_FUNCTION
|
||||
key_type key_at(size_type i) const {
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
return m_keys[i < capacity() ? i : capacity()];
|
||||
#else
|
||||
KOKKOS_EXPECTS(i < capacity());
|
||||
return m_keys[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
KOKKOS_FORCEINLINE_FUNCTION
|
||||
@ -766,6 +824,9 @@ class UnorderedMap {
|
||||
raw_deep_copy(tmp.m_scalars.data(), src.m_scalars.data(),
|
||||
sizeof(int) * num_scalars);
|
||||
|
||||
Kokkos::fence(
|
||||
"Kokkos::UnorderedMap::create_copy_view: fence after copy to tmp");
|
||||
|
||||
*this = tmp;
|
||||
}
|
||||
}
|
||||
@ -780,6 +841,9 @@ class UnorderedMap {
|
||||
Kokkos::HostSpace>;
|
||||
const int true_ = true;
|
||||
raw_deep_copy(m_scalars.data() + flag, &true_, sizeof(int));
|
||||
Kokkos::fence(
|
||||
"Kokkos::UnorderedMap::set_flag: fence after copying flag from "
|
||||
"HostSpace");
|
||||
}
|
||||
|
||||
void reset_flag(int flag) const {
|
||||
@ -788,6 +852,9 @@ class UnorderedMap {
|
||||
Kokkos::HostSpace>;
|
||||
const int false_ = false;
|
||||
raw_deep_copy(m_scalars.data() + flag, &false_, sizeof(int));
|
||||
Kokkos::fence(
|
||||
"Kokkos::UnorderedMap::reset_flag: fence after copying flag from "
|
||||
"HostSpace");
|
||||
}
|
||||
|
||||
bool get_flag(int flag) const {
|
||||
@ -796,6 +863,9 @@ class UnorderedMap {
|
||||
typename device_type::memory_space>;
|
||||
int result = false;
|
||||
raw_deep_copy(&result, m_scalars.data() + flag, sizeof(int));
|
||||
Kokkos::fence(
|
||||
"Kokkos::UnorderedMap::get_flag: fence after copy to return value in "
|
||||
"HostSpace");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -106,8 +106,8 @@ uint32_t MurmurHash3_x86_32(const void* key, int len, uint32_t seed) {
|
||||
uint32_t k1 = 0;
|
||||
|
||||
switch (len & 3) {
|
||||
case 3: k1 ^= tail[2] << 16;
|
||||
case 2: k1 ^= tail[1] << 8;
|
||||
case 3: k1 ^= tail[2] << 16; KOKKOS_IMPL_FALLTHROUGH
|
||||
case 2: k1 ^= tail[1] << 8; KOKKOS_IMPL_FALLTHROUGH
|
||||
case 1:
|
||||
k1 ^= tail[0];
|
||||
k1 *= c1;
|
||||
|
||||
@ -47,6 +47,8 @@
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <Kokkos_StaticCrsGraph.hpp>
|
||||
|
||||
namespace Kokkos {
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
#ifndef KOKKOS_UNORDERED_MAP_IMPL_HPP
|
||||
#define KOKKOS_UNORDERED_MAP_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core_fwd.hpp>
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
#include <cstdio>
|
||||
@ -144,7 +144,7 @@ struct UnorderedMapHistogram {
|
||||
using execution_space = typename map_type::execution_space;
|
||||
using size_type = typename map_type::size_type;
|
||||
|
||||
using histogram_view = View<int[100], execution_space>;
|
||||
using histogram_view = View<int[100], typename map_type::device_type>;
|
||||
using host_histogram_view = typename histogram_view::HostMirror;
|
||||
|
||||
map_type m_map;
|
||||
@ -170,8 +170,8 @@ struct UnorderedMapHistogram {
|
||||
}
|
||||
|
||||
void print_length(std::ostream& out) {
|
||||
host_histogram_view host_copy = create_mirror_view(m_length);
|
||||
Kokkos::deep_copy(host_copy, m_length);
|
||||
host_histogram_view host_copy =
|
||||
create_mirror_view_and_copy(Kokkos::HostSpace{}, m_length);
|
||||
|
||||
for (int i = 0, size = host_copy.extent(0); i < size; ++i) {
|
||||
out << host_copy[i] << " , ";
|
||||
@ -180,8 +180,8 @@ struct UnorderedMapHistogram {
|
||||
}
|
||||
|
||||
void print_distance(std::ostream& out) {
|
||||
host_histogram_view host_copy = create_mirror_view(m_distance);
|
||||
Kokkos::deep_copy(host_copy, m_distance);
|
||||
host_histogram_view host_copy =
|
||||
create_mirror_view_and_copy(Kokkos::HostSpace{}, m_distance);
|
||||
|
||||
for (int i = 0, size = host_copy.extent(0); i < size; ++i) {
|
||||
out << host_copy[i] << " , ";
|
||||
@ -190,8 +190,8 @@ struct UnorderedMapHistogram {
|
||||
}
|
||||
|
||||
void print_block_distance(std::ostream& out) {
|
||||
host_histogram_view host_copy = create_mirror_view(m_block_distance);
|
||||
Kokkos::deep_copy(host_copy, m_block_distance);
|
||||
host_histogram_view host_copy =
|
||||
create_mirror_view_and_copy(Kokkos::HostSpace{}, m_block_distance);
|
||||
|
||||
for (int i = 0, size = host_copy.extent(0); i < size; ++i) {
|
||||
out << host_copy[i] << " , ";
|
||||
|
||||
@ -5,15 +5,10 @@ KOKKOS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../src )
|
||||
KOKKOS_INCLUDE_DIRECTORIES(${KOKKOS_SOURCE_DIR}/core/unit_test/category_files)
|
||||
|
||||
foreach(Tag Threads;Serial;OpenMP;HPX;Cuda;HIP;SYCL)
|
||||
# Because there is always an exception to the rule
|
||||
if(Tag STREQUAL "Threads")
|
||||
set(DEVICE "PTHREAD")
|
||||
else()
|
||||
string(TOUPPER ${Tag} DEVICE)
|
||||
endif()
|
||||
string(TOUPPER ${Tag} DEVICE)
|
||||
string(TOLOWER ${Tag} dir)
|
||||
# Add test for that backend if it is enabled
|
||||
if(Kokkos_ENABLE_${DEVICE})
|
||||
if(KOKKOS_ENABLE_${DEVICE})
|
||||
set(UnitTestSources UnitTestMain.cpp)
|
||||
set(dir ${CMAKE_CURRENT_BINARY_DIR}/${dir})
|
||||
file(MAKE_DIRECTORY ${dir})
|
||||
@ -28,6 +23,7 @@ foreach(Tag Threads;Serial;OpenMP;HPX;Cuda;HIP;SYCL)
|
||||
OffsetView
|
||||
ScatterView
|
||||
StaticCrsGraph
|
||||
WithoutInitializing
|
||||
UnorderedMap
|
||||
Vector
|
||||
ViewCtorPropEmbeddedDim
|
||||
@ -42,6 +38,11 @@ foreach(Tag Threads;Serial;OpenMP;HPX;Cuda;HIP;SYCL)
|
||||
configure_file(${dir}/dummy.cpp ${file})
|
||||
list(APPEND UnitTestSources ${file})
|
||||
endforeach()
|
||||
#fatal error C1128: number of sections exceeded object file format limit: compile with /bigobj
|
||||
if(KOKKOS_ENABLE_CUDA AND WIN32)
|
||||
LIST(REMOVE_ITEM UnitTestSources ${dir}/TestCuda_DynViewAPI_generic.cpp)
|
||||
endif()
|
||||
|
||||
KOKKOS_ADD_EXECUTABLE_AND_TEST(UnitTest_${Tag} SOURCES ${UnitTestSources})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@ -60,7 +60,7 @@ ifeq ($(KOKKOS_INTERNAL_USE_CUDA), 1)
|
||||
TEST_TARGETS += test-cuda
|
||||
endif
|
||||
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_PTHREADS), 1)
|
||||
ifeq ($(KOKKOS_INTERNAL_USE_THREADS), 1)
|
||||
OBJ_THREADS = UnitTestMain.o gtest-all.o
|
||||
OBJ_THREADS += TestThreads_Bitset.o
|
||||
OBJ_THREADS += TestThreads_DualView.o
|
||||
|
||||
@ -258,7 +258,7 @@ struct test_dual_view_deep_copy {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
template <typename Scalar, class Device, bool Initialize>
|
||||
struct test_dualview_resize {
|
||||
using scalar_type = Scalar;
|
||||
using execution_space = Device;
|
||||
@ -274,7 +274,10 @@ struct test_dualview_resize {
|
||||
|
||||
/* Covers case "Resize on Device" */
|
||||
a.modify_device();
|
||||
Kokkos::resize(a, factor * n, factor * m);
|
||||
if (Initialize)
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, a, factor * n, factor * m);
|
||||
else
|
||||
Kokkos::resize(a, factor * n, factor * m);
|
||||
ASSERT_EQ(a.extent(0), n * factor);
|
||||
ASSERT_EQ(a.extent(1), m * factor);
|
||||
|
||||
@ -300,12 +303,15 @@ struct test_dualview_resize {
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
ASSERT_EQ(a_h_sum, scalar_type(a.extent(0) * a.extent(1)));
|
||||
|
||||
/* Covers case "Resize on Host" */
|
||||
a.modify_host();
|
||||
|
||||
Kokkos::resize(a, n / factor, m / factor);
|
||||
if (Initialize)
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, a, n / factor, m / factor);
|
||||
else
|
||||
Kokkos::resize(a, n / factor, m / factor);
|
||||
ASSERT_EQ(a.extent(0), n / factor);
|
||||
ASSERT_EQ(a.extent(1), m / factor);
|
||||
|
||||
@ -330,7 +336,7 @@ struct test_dualview_resize {
|
||||
}
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
ASSERT_EQ(a_h_sum, scalar_type(a.extent(0) * a.extent(1)));
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
|
||||
} // end run_me
|
||||
@ -340,7 +346,7 @@ struct test_dualview_resize {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
template <typename Scalar, class Device, bool Initialize>
|
||||
struct test_dualview_realloc {
|
||||
using scalar_type = Scalar;
|
||||
using execution_space = Device;
|
||||
@ -351,7 +357,10 @@ struct test_dualview_realloc {
|
||||
const unsigned int m = 5;
|
||||
|
||||
ViewType a("A", n, m);
|
||||
Kokkos::realloc(a, n, m);
|
||||
if (Initialize)
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, a, n, m);
|
||||
else
|
||||
Kokkos::realloc(a, n, m);
|
||||
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
a.modify_device();
|
||||
@ -375,7 +384,7 @@ struct test_dualview_realloc {
|
||||
}
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
ASSERT_EQ(a_h_sum, scalar_type(a.extent(0) * a.extent(1)));
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
} // end run_me
|
||||
|
||||
@ -405,12 +414,14 @@ void test_dualview_deep_copy() {
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_realloc() {
|
||||
Impl::test_dualview_realloc<Scalar, Device>();
|
||||
Impl::test_dualview_realloc<Scalar, Device, false>();
|
||||
Impl::test_dualview_realloc<Scalar, Device, true>();
|
||||
}
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_resize() {
|
||||
Impl::test_dualview_resize<Scalar, Device>();
|
||||
Impl::test_dualview_resize<Scalar, Device, false>();
|
||||
Impl::test_dualview_resize<Scalar, Device, true>();
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_combination) {
|
||||
|
||||
@ -712,7 +712,8 @@ class TestDynViewAPI {
|
||||
using host_view_space = typename View0::host_mirror_space;
|
||||
|
||||
static void run_tests() {
|
||||
run_test_resize_realloc();
|
||||
run_test_resize_realloc<false>();
|
||||
run_test_resize_realloc<true>();
|
||||
run_test_mirror();
|
||||
run_test_mirror_and_copy();
|
||||
run_test_scalar();
|
||||
@ -722,6 +723,7 @@ class TestDynViewAPI {
|
||||
run_test_subview();
|
||||
run_test_subview_strided();
|
||||
run_test_vector();
|
||||
run_test_as_view_of_rank_n();
|
||||
}
|
||||
|
||||
static void run_operator_test_rank12345() {
|
||||
@ -738,21 +740,28 @@ class TestDynViewAPI {
|
||||
TestViewOperator_LeftAndRight<int, device, 6>::testit(2, 3, 4, 2, 3, 4);
|
||||
}
|
||||
|
||||
template <bool Initialize>
|
||||
static void run_test_resize_realloc() {
|
||||
dView0 drv0("drv0", 10, 20, 30);
|
||||
ASSERT_EQ(drv0.rank(), 3);
|
||||
ASSERT_EQ(drv0.rank(), 3u);
|
||||
|
||||
Kokkos::resize(drv0, 5, 10);
|
||||
ASSERT_EQ(drv0.rank(), 2);
|
||||
ASSERT_EQ(drv0.extent(0), 5);
|
||||
ASSERT_EQ(drv0.extent(1), 10);
|
||||
ASSERT_EQ(drv0.extent(2), 1);
|
||||
if (Initialize)
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, drv0, 5, 10);
|
||||
else
|
||||
Kokkos::resize(drv0, 5, 10);
|
||||
ASSERT_EQ(drv0.rank(), 2u);
|
||||
ASSERT_EQ(drv0.extent(0), 5u);
|
||||
ASSERT_EQ(drv0.extent(1), 10u);
|
||||
ASSERT_EQ(drv0.extent(2), 1u);
|
||||
|
||||
Kokkos::realloc(drv0, 10, 20);
|
||||
ASSERT_EQ(drv0.rank(), 2);
|
||||
ASSERT_EQ(drv0.extent(0), 10);
|
||||
ASSERT_EQ(drv0.extent(1), 20);
|
||||
ASSERT_EQ(drv0.extent(2), 1);
|
||||
if (Initialize)
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, drv0, 10, 20);
|
||||
else
|
||||
Kokkos::realloc(drv0, 10, 20);
|
||||
ASSERT_EQ(drv0.rank(), 2u);
|
||||
ASSERT_EQ(drv0.extent(0), 10u);
|
||||
ASSERT_EQ(drv0.extent(1), 20u);
|
||||
ASSERT_EQ(drv0.extent(2), 1u);
|
||||
}
|
||||
|
||||
static void run_test_mirror() {
|
||||
@ -961,6 +970,199 @@ class TestDynViewAPI {
|
||||
}
|
||||
}
|
||||
|
||||
static void run_test_as_view_of_rank_n() {
|
||||
Kokkos::View<int, Kokkos::HostSpace> error_flag_host("error_flag");
|
||||
error_flag_host() = 0;
|
||||
auto error_flag =
|
||||
Kokkos::create_mirror_view_and_copy(DeviceType(), error_flag_host);
|
||||
|
||||
dView0 d("d");
|
||||
|
||||
#if defined(KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA)
|
||||
|
||||
// Rank 0
|
||||
Kokkos::resize(d);
|
||||
|
||||
auto policy0 = Kokkos::RangePolicy<DeviceType>(DeviceType(), 0, 1);
|
||||
|
||||
View0 v0 = Kokkos::Impl::as_view_of_rank_n<0>(d);
|
||||
// Assign values after calling as_view_of_rank_n() function under
|
||||
// test to ensure aliasing
|
||||
Kokkos::parallel_for(
|
||||
policy0, KOKKOS_LAMBDA(int) { d() = 13; });
|
||||
ASSERT_EQ(v0.size(), d.size());
|
||||
ASSERT_EQ(v0.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy0, KOKKOS_LAMBDA(int) {
|
||||
if (d() != v0()) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 1
|
||||
Kokkos::resize(d, 1);
|
||||
|
||||
auto policy1 =
|
||||
Kokkos::RangePolicy<DeviceType>(DeviceType(), 0, d.extent(0));
|
||||
|
||||
View1 v1 = Kokkos::Impl::as_view_of_rank_n<1>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy1, KOKKOS_LAMBDA(int i0) { d(i0) = i0; });
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v1.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v1.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy1, KOKKOS_LAMBDA(int i0) {
|
||||
if (d(i0) != v1(i0)) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 2
|
||||
Kokkos::resize(d, 1, 2);
|
||||
|
||||
auto policy2 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<2>>(
|
||||
{0, 0}, {d.extent(0), d.extent(1)});
|
||||
|
||||
View2 v2 = Kokkos::Impl::as_view_of_rank_n<2>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy2, KOKKOS_LAMBDA(int i0, int i1) { d(i0, i1) = i0 + 10 * i1; });
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v2.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v2.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy2, KOKKOS_LAMBDA(int i0, int i1) {
|
||||
if (d(i0, i1) != v2(i0, i1)) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 3
|
||||
Kokkos::resize(d, 1, 2, 3);
|
||||
|
||||
auto policy3 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<3>>(
|
||||
{0, 0, 0}, {d.extent(0), d.extent(1), d.extent(2)});
|
||||
|
||||
View3 v3 = Kokkos::Impl::as_view_of_rank_n<3>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy3, KOKKOS_LAMBDA(int i0, int i1, int i2) {
|
||||
d(i0, i1, i2) = i0 + 10 * i1 + 100 * i2;
|
||||
});
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v3.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v3.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy3, KOKKOS_LAMBDA(int i0, int i1, int i2) {
|
||||
if (d(i0, i1, i2) != v3(i0, i1, i2)) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 4
|
||||
Kokkos::resize(d, 1, 2, 3, 4);
|
||||
|
||||
auto policy4 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<4>>(
|
||||
{0, 0, 0, 0}, {d.extent(0), d.extent(1), d.extent(2), d.extent(3)});
|
||||
|
||||
View4 v4 = Kokkos::Impl::as_view_of_rank_n<4>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy4, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3) {
|
||||
d(i0, i1, i2, i3) = i0 + 10 * i1 + 100 * i2 + 1000 * i3;
|
||||
});
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v4.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v4.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy4, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3) {
|
||||
if (d(i0, i1, i2, i3) != v4(i0, i1, i2, i3)) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 5
|
||||
Kokkos::resize(d, 1, 2, 3, 4, 5);
|
||||
|
||||
auto policy5 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<5>>(
|
||||
{0, 0, 0, 0, 0},
|
||||
{d.extent(0), d.extent(1), d.extent(2), d.extent(3), d.extent(4)});
|
||||
|
||||
View5 v5 = Kokkos::Impl::as_view_of_rank_n<5>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy5, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4) {
|
||||
d(i0, i1, i2, i3, i4) =
|
||||
i0 + 10 * i1 + 100 * i2 + 1000 * i3 + 10000 * i4;
|
||||
});
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v5.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v5.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy5, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4) {
|
||||
if (d(i0, i1, i2, i3, i4) != v5(i0, i1, i2, i3, i4)) error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 6
|
||||
Kokkos::resize(d, 1, 2, 3, 4, 5, 6);
|
||||
|
||||
auto policy6 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<6>>(
|
||||
{0, 0, 0, 0, 0, 0}, {d.extent(0), d.extent(1), d.extent(2), d.extent(3),
|
||||
d.extent(4), d.extent(5)});
|
||||
|
||||
View6 v6 = Kokkos::Impl::as_view_of_rank_n<6>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy6, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5) {
|
||||
d(i0, i1, i2, i3, i4, i5) =
|
||||
i0 + 10 * i1 + 100 * i2 + 1000 * i3 + 10000 * i4 + 100000 * i5;
|
||||
});
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v6.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v6.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy6, KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5) {
|
||||
if (d(i0, i1, i2, i3, i4, i5) != v6(i0, i1, i2, i3, i4, i5))
|
||||
error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
|
||||
// Rank 7
|
||||
Kokkos::resize(d, 1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
// MDRangePolicy only accepts Rank < 7
|
||||
#if 0
|
||||
auto policy7 = Kokkos::MDRangePolicy<DeviceType, Kokkos::Rank<7>>(
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
{d.extent(0), d.extent(1), d.extent(2), d.extent(3), d.extent(4),
|
||||
d.extent(5), d.extent(6)});
|
||||
|
||||
View7 v7 = Kokkos::Impl::as_view_of_rank_n<7>(d);
|
||||
Kokkos::parallel_for(
|
||||
policy7,
|
||||
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5, int i6) {
|
||||
d(i0, i1, i2, i3, i4, i5, i6) = i0 + 10 * i1 + 100 * i2 + 1000 * i3 +
|
||||
10000 * i4 + 100000 * i5 +
|
||||
1000000 * i6;
|
||||
});
|
||||
for (unsigned int rank = 0; rank < d.rank(); ++rank)
|
||||
ASSERT_EQ(v7.extent(rank), d.extent(rank));
|
||||
ASSERT_EQ(v7.data(), d.data());
|
||||
Kokkos::parallel_for(
|
||||
policy7,
|
||||
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5, int i6) {
|
||||
if (d(i0, i1, i2, i3, i4, i5, i6) != v7(i0, i1, i2, i3, i4, i5, i6))
|
||||
error_flag() = 1;
|
||||
});
|
||||
Kokkos::deep_copy(error_flag_host, error_flag);
|
||||
ASSERT_EQ(error_flag_host(), 0);
|
||||
#endif // MDRangePolict Rank < 7
|
||||
|
||||
#endif // defined(KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA)
|
||||
|
||||
// Error checking test
|
||||
EXPECT_ANY_THROW({ auto v_copy = Kokkos::Impl::as_view_of_rank_n<2>(d); });
|
||||
}
|
||||
|
||||
static void run_test_scalar() {
|
||||
using hView0 = typename dView0::HostMirror; // HostMirror of DynRankView is
|
||||
// a DynRankView
|
||||
@ -1071,10 +1273,10 @@ class TestDynViewAPI {
|
||||
dView0 d_uninitialized(
|
||||
Kokkos::view_alloc(Kokkos::WithoutInitializing, "uninit"), 10, 20);
|
||||
ASSERT_NE(d_uninitialized.data(), nullptr);
|
||||
ASSERT_EQ(d_uninitialized.rank(), 2);
|
||||
ASSERT_EQ(d_uninitialized.extent(0), 10);
|
||||
ASSERT_EQ(d_uninitialized.extent(1), 20);
|
||||
ASSERT_EQ(d_uninitialized.extent(2), 1);
|
||||
ASSERT_EQ(d_uninitialized.rank(), 2u);
|
||||
ASSERT_EQ(d_uninitialized.extent(0), 10u);
|
||||
ASSERT_EQ(d_uninitialized.extent(1), 20u);
|
||||
ASSERT_EQ(d_uninitialized.extent(2), 1u);
|
||||
|
||||
dView0 dx, dy, dz;
|
||||
hView0 hx, hy, hz;
|
||||
@ -1107,8 +1309,8 @@ class TestDynViewAPI {
|
||||
ASSERT_EQ(dy.extent(0), unsigned(N1)); // Okay with UVM
|
||||
ASSERT_EQ(hx.extent(0), unsigned(N1));
|
||||
ASSERT_EQ(hy.extent(0), unsigned(N1));
|
||||
ASSERT_EQ(dx.rank(), 3); // Okay with UVM
|
||||
ASSERT_EQ(hx.rank(), 3);
|
||||
ASSERT_EQ(dx.rank(), 3u); // Okay with UVM
|
||||
ASSERT_EQ(hx.rank(), 3u);
|
||||
|
||||
dx = dView0("dx", N0, N1, N2, N3);
|
||||
dy = dView0("dy", N0, N1, N2, N3);
|
||||
@ -1119,15 +1321,15 @@ class TestDynViewAPI {
|
||||
ASSERT_EQ(dy.extent(0), unsigned(N0));
|
||||
ASSERT_EQ(hx.extent(0), unsigned(N0));
|
||||
ASSERT_EQ(hy.extent(0), unsigned(N0));
|
||||
ASSERT_EQ(dx.rank(), 4);
|
||||
ASSERT_EQ(dy.rank(), 4);
|
||||
ASSERT_EQ(hx.rank(), 4);
|
||||
ASSERT_EQ(hy.rank(), 4);
|
||||
ASSERT_EQ(dx.rank(), 4u);
|
||||
ASSERT_EQ(dy.rank(), 4u);
|
||||
ASSERT_EQ(hx.rank(), 4u);
|
||||
ASSERT_EQ(hy.rank(), 4u);
|
||||
|
||||
ASSERT_EQ(dx.use_count(), size_t(1));
|
||||
ASSERT_EQ(dx.use_count(), 1);
|
||||
|
||||
dView0_unmanaged unmanaged_dx = dx;
|
||||
ASSERT_EQ(dx.use_count(), size_t(1));
|
||||
ASSERT_EQ(dx.use_count(), 1);
|
||||
|
||||
dView0_unmanaged unmanaged_from_ptr_dx = dView0_unmanaged(
|
||||
dx.data(), dx.extent(0), dx.extent(1), dx.extent(2), dx.extent(3));
|
||||
@ -1139,24 +1341,24 @@ class TestDynViewAPI {
|
||||
}
|
||||
|
||||
const_dView0 const_dx = dx;
|
||||
ASSERT_EQ(dx.use_count(), size_t(2));
|
||||
ASSERT_EQ(dx.use_count(), 2);
|
||||
|
||||
{
|
||||
const_dView0 const_dx2;
|
||||
const_dx2 = const_dx;
|
||||
ASSERT_EQ(dx.use_count(), size_t(3));
|
||||
ASSERT_EQ(dx.use_count(), 3);
|
||||
|
||||
const_dx2 = dy;
|
||||
ASSERT_EQ(dx.use_count(), size_t(2));
|
||||
ASSERT_EQ(dx.use_count(), 2);
|
||||
|
||||
const_dView0 const_dx3(dx);
|
||||
ASSERT_EQ(dx.use_count(), size_t(3));
|
||||
ASSERT_EQ(dx.use_count(), 3);
|
||||
|
||||
dView0_unmanaged dx4_unmanaged(dx);
|
||||
ASSERT_EQ(dx.use_count(), size_t(3));
|
||||
ASSERT_EQ(dx.use_count(), 3);
|
||||
}
|
||||
|
||||
ASSERT_EQ(dx.use_count(), size_t(2));
|
||||
ASSERT_EQ(dx.use_count(), 2);
|
||||
|
||||
ASSERT_NE(dx.data(), nullptr);
|
||||
ASSERT_NE(const_dx.data(), nullptr);
|
||||
@ -1336,18 +1538,18 @@ class TestDynViewAPI {
|
||||
|
||||
// View - DynRankView Interoperability tests
|
||||
// deep_copy from view to dynrankview
|
||||
const int testdim = 4;
|
||||
constexpr size_t testdim = 4;
|
||||
dView0 dxx("dxx", testdim);
|
||||
View1 vxx("vxx", testdim);
|
||||
auto hvxx = Kokkos::create_mirror_view(vxx);
|
||||
for (int i = 0; i < testdim; ++i) {
|
||||
for (size_t i = 0; i < testdim; ++i) {
|
||||
hvxx(i) = i;
|
||||
}
|
||||
Kokkos::deep_copy(vxx, hvxx);
|
||||
Kokkos::deep_copy(dxx, vxx);
|
||||
auto hdxx = Kokkos::create_mirror_view(dxx);
|
||||
Kokkos::deep_copy(hdxx, dxx);
|
||||
for (int i = 0; i < testdim; ++i) {
|
||||
for (size_t i = 0; i < testdim; ++i) {
|
||||
ASSERT_EQ(hvxx(i), hdxx(i));
|
||||
}
|
||||
|
||||
@ -1362,7 +1564,7 @@ class TestDynViewAPI {
|
||||
ASSERT_EQ(rank(hdxx), rank(hvdxx));
|
||||
ASSERT_EQ(hvdxx.extent(0), testdim);
|
||||
ASSERT_EQ(hdxx.extent(0), hvdxx.extent(0));
|
||||
for (int i = 0; i < testdim; ++i) {
|
||||
for (size_t i = 0; i < testdim; ++i) {
|
||||
ASSERT_EQ(hvxx(i), hvdxx(i));
|
||||
}
|
||||
}
|
||||
@ -1432,51 +1634,51 @@ class TestDynViewAPI {
|
||||
unsigned order[] = {6, 5, 4, 3, 2, 1, 0},
|
||||
dimen[] = {N0, N1, N2, 2, 2, 2, 2}; // LayoutRight equivalent
|
||||
sdView d7("d7", Kokkos::LayoutStride::order_dimensions(7, order, dimen));
|
||||
ASSERT_EQ(d7.rank(), 7);
|
||||
ASSERT_EQ(d7.rank(), 7u);
|
||||
|
||||
sdView ds0 = Kokkos::subdynrankview(d7, 1, 1, 1, 1, 1, 1, 1);
|
||||
ASSERT_EQ(ds0.rank(), 0);
|
||||
ASSERT_EQ(ds0.rank(), 0u);
|
||||
|
||||
// Basic test - ALL
|
||||
sdView dsALL = Kokkos::subdynrankview(
|
||||
d7, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL());
|
||||
ASSERT_EQ(dsALL.rank(), 7);
|
||||
ASSERT_EQ(dsALL.rank(), 7u);
|
||||
|
||||
// Send a value to final rank returning rank 6 subview
|
||||
sdView dsm1 =
|
||||
Kokkos::subdynrankview(d7, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), 1);
|
||||
ASSERT_EQ(dsm1.rank(), 6);
|
||||
ASSERT_EQ(dsm1.rank(), 6u);
|
||||
|
||||
// Send a std::pair as argument to a rank
|
||||
sdView dssp = Kokkos::subdynrankview(
|
||||
d7, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(), std::pair<unsigned, unsigned>(1, 2));
|
||||
ASSERT_EQ(dssp.rank(), 7);
|
||||
ASSERT_EQ(dssp.rank(), 7u);
|
||||
|
||||
// Send a kokkos::pair as argument to a rank; take default layout as input
|
||||
dView0 dd0("dd0", N0, N1, N2, 2, 2, 2, 2); // default layout
|
||||
ASSERT_EQ(dd0.rank(), 7);
|
||||
ASSERT_EQ(dd0.rank(), 7u);
|
||||
sdView dtkp = Kokkos::subdynrankview(
|
||||
dd0, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(), Kokkos::pair<unsigned, unsigned>(0, 1));
|
||||
ASSERT_EQ(dtkp.rank(), 7);
|
||||
ASSERT_EQ(dtkp.rank(), 7u);
|
||||
|
||||
// Return rank 7 subview, taking a pair as one argument, layout stride input
|
||||
sdView ds7 = Kokkos::subdynrankview(
|
||||
d7, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(), Kokkos::pair<unsigned, unsigned>(0, 1));
|
||||
ASSERT_EQ(ds7.rank(), 7);
|
||||
ASSERT_EQ(ds7.rank(), 7u);
|
||||
|
||||
// Default Layout DynRankView
|
||||
dView dv6("dv6", N0, N1, N2, N3, 2, 2);
|
||||
ASSERT_EQ(dv6.rank(), 6);
|
||||
ASSERT_EQ(dv6.rank(), 6u);
|
||||
|
||||
// DynRankView with LayoutRight
|
||||
using drView = Kokkos::DynRankView<T, Kokkos::LayoutRight, device>;
|
||||
drView dr5("dr5", N0, N1, N2, 2, 2);
|
||||
ASSERT_EQ(dr5.rank(), 5);
|
||||
ASSERT_EQ(dr5.rank(), 5u);
|
||||
|
||||
// LayoutStride but arranged as LayoutRight
|
||||
// NOTE: unused arg_layout dimensions must be set toKOKKOS_INVALID_INDEX so
|
||||
@ -1489,7 +1691,7 @@ class TestDynViewAPI {
|
||||
ls.dimension[6] = KOKKOS_INVALID_INDEX;
|
||||
ls.dimension[7] = KOKKOS_INVALID_INDEX;
|
||||
sdView d5("d5", ls);
|
||||
ASSERT_EQ(d5.rank(), 5);
|
||||
ASSERT_EQ(d5.rank(), 5u);
|
||||
|
||||
// LayoutStride arranged as LayoutRight - commented out as example that
|
||||
// fails unit test
|
||||
@ -1522,7 +1724,7 @@ class TestDynViewAPI {
|
||||
sdView ds5 = Kokkos::subdynrankview(d5, Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::ALL(), Kokkos::ALL(),
|
||||
Kokkos::pair<unsigned, unsigned>(0, 1));
|
||||
ASSERT_EQ(ds5.rank(), 5);
|
||||
ASSERT_EQ(ds5.rank(), 5u);
|
||||
|
||||
// Pass in extra ALL arguments beyond the rank of the DynRank View.
|
||||
// This behavior is allowed - ignore the extra ALL arguments when
|
||||
@ -1554,7 +1756,7 @@ class TestDynViewAPI {
|
||||
Kokkos::ALL(), 0, Kokkos::ALL());
|
||||
|
||||
ASSERT_EQ(ds4.rank(), ds4plus.rank());
|
||||
ASSERT_EQ(ds4.rank(), 4);
|
||||
ASSERT_EQ(ds4.rank(), 4u);
|
||||
ASSERT_EQ(ds4.extent(0), ds4plus.extent(0));
|
||||
ASSERT_EQ(ds4.extent(4), ds4plus.extent(4));
|
||||
ASSERT_EQ(ds4.extent(5), ds4plus.extent(5));
|
||||
@ -1601,8 +1803,8 @@ class TestDynViewAPI {
|
||||
ASSERT_EQ(yl4.extent(1), xl4.extent(3));
|
||||
ASSERT_EQ(yr4.extent(0), xr4.extent(1));
|
||||
ASSERT_EQ(yr4.extent(1), xr4.extent(3));
|
||||
ASSERT_EQ(yl4.rank(), 2);
|
||||
ASSERT_EQ(yr4.rank(), 2);
|
||||
ASSERT_EQ(yl4.rank(), 2u);
|
||||
ASSERT_EQ(yr4.rank(), 2u);
|
||||
|
||||
ASSERT_EQ(&yl4(4, 4) - &xl4(1, 4, 2, 4), 0);
|
||||
ASSERT_EQ(&yr4(4, 4) - &xr4(1, 4, 2, 4), 0);
|
||||
|
||||
@ -93,7 +93,7 @@ struct TestDynamicView {
|
||||
ASSERT_TRUE(d3.is_allocated());
|
||||
}
|
||||
view_type da("da", 1024, arg_total_size);
|
||||
ASSERT_EQ(da.size(), 0);
|
||||
ASSERT_EQ(da.size(), 0u);
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 8;
|
||||
da.resize_serial(da_size);
|
||||
@ -145,7 +145,7 @@ struct TestDynamicView {
|
||||
// Case 2: min_chunk_size is NOT a power of 2
|
||||
{
|
||||
view_type da("da", 1023, arg_total_size);
|
||||
ASSERT_EQ(da.size(), 0);
|
||||
ASSERT_EQ(da.size(), 0u);
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 8;
|
||||
da.resize_serial(da_size);
|
||||
@ -197,7 +197,7 @@ struct TestDynamicView {
|
||||
// Case 3: resize reduces the size
|
||||
{
|
||||
view_type da("da", 1023, arg_total_size);
|
||||
ASSERT_EQ(da.size(), 0);
|
||||
ASSERT_EQ(da.size(), 0u);
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 2;
|
||||
da.resize_serial(da_size);
|
||||
|
||||
@ -50,10 +50,6 @@
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <Kokkos_ErrorReporter.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace Test {
|
||||
|
||||
// Just save the data in the report. Informative text goes in the
|
||||
@ -174,7 +170,8 @@ struct ErrorReporterDriver : public ErrorReporterDriverBase<DeviceType> {
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(const int work_idx) const {
|
||||
if (driver_base::error_condition(work_idx)) {
|
||||
double val = M_PI * static_cast<double>(work_idx);
|
||||
double val =
|
||||
Kokkos::Experimental::pi_v<double> * static_cast<double>(work_idx);
|
||||
typename driver_base::report_type report = {work_idx, -2 * work_idx, val};
|
||||
driver_base::m_errorReporter.add_report(work_idx, report);
|
||||
}
|
||||
@ -200,7 +197,8 @@ struct ErrorReporterDriverUseLambda
|
||||
Kokkos::RangePolicy<execution_space>(0, test_size),
|
||||
KOKKOS_CLASS_LAMBDA(const int work_idx) {
|
||||
if (driver_base::error_condition(work_idx)) {
|
||||
double val = M_PI * static_cast<double>(work_idx);
|
||||
double val = Kokkos::Experimental::pi_v<double> *
|
||||
static_cast<double>(work_idx);
|
||||
typename driver_base::report_type report = {work_idx, -2 * work_idx,
|
||||
val};
|
||||
driver_base::m_errorReporter.add_report(work_idx, report);
|
||||
@ -224,7 +222,8 @@ struct ErrorReporterDriverNativeOpenMP
|
||||
#pragma omp parallel for
|
||||
for (int work_idx = 0; work_idx < test_size; ++work_idx) {
|
||||
if (driver_base::error_condition(work_idx)) {
|
||||
double val = M_PI * static_cast<double>(work_idx);
|
||||
double val =
|
||||
Kokkos::Experimental::pi_v<double> * static_cast<double>(work_idx);
|
||||
typename driver_base::report_type report = {work_idx, -2 * work_idx,
|
||||
val};
|
||||
driver_base::m_errorReporter.add_report(work_idx, report);
|
||||
|
||||
@ -91,8 +91,8 @@ void test_offsetview_construction() {
|
||||
ASSERT_EQ(ov.begin(1), -2);
|
||||
ASSERT_EQ(ov.end(1), 3);
|
||||
|
||||
ASSERT_EQ(ov.extent(0), 5);
|
||||
ASSERT_EQ(ov.extent(1), 5);
|
||||
ASSERT_EQ(ov.extent(0), 5u);
|
||||
ASSERT_EQ(ov.extent(1), 5u);
|
||||
|
||||
#if defined(KOKKOS_ENABLE_CUDA_LAMBDA) || !defined(KOKKOS_ENABLE_CUDA)
|
||||
{
|
||||
@ -357,7 +357,6 @@ void test_offsetview_unmanaged_construction() {
|
||||
ASSERT_EQ(bb, ii);
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
{
|
||||
using offset_view_type = Kokkos::Experimental::OffsetView<Scalar*, Device>;
|
||||
|
||||
@ -397,7 +396,6 @@ void test_offsetview_unmanaged_construction() {
|
||||
ASSERT_THROW(offset_view_type(&s, {0, 0, 0}, {1, 1, 1}),
|
||||
std::runtime_error);
|
||||
}
|
||||
#endif // KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
|
||||
}
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
|
||||
@ -67,6 +67,8 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
|
||||
using orig_view_type = Kokkos::View<NumberType * [12], Layout, DeviceType>;
|
||||
|
||||
using size_type = typename Kokkos::HostSpace::size_type;
|
||||
|
||||
scatter_view_type scatter_view;
|
||||
int scatterSize;
|
||||
|
||||
@ -79,21 +81,7 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
host_view(i, 0) = 0.0;
|
||||
host_view(i, 1) = 0.0;
|
||||
host_view(i, 2) = 0.0;
|
||||
host_view(i, 3) = 0.0;
|
||||
host_view(i, 4) = 0.0;
|
||||
host_view(i, 5) = 0.0;
|
||||
host_view(i, 6) = 0.0;
|
||||
host_view(i, 7) = 0.0;
|
||||
host_view(i, 8) = 0.0;
|
||||
host_view(i, 9) = 0.0;
|
||||
host_view(i, 10) = 0.0;
|
||||
host_view(i, 11) = 0.0;
|
||||
}
|
||||
Kokkos::deep_copy(host_view, 0);
|
||||
Kokkos::fence();
|
||||
Kokkos::deep_copy(orig, host_view);
|
||||
}
|
||||
@ -171,34 +159,40 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
auto val3 = host_view(i, 3);
|
||||
auto val4 = host_view(i, 4);
|
||||
auto val5 = host_view(i, 5);
|
||||
auto val6 = host_view(i, 6);
|
||||
auto val7 = host_view(i, 7);
|
||||
auto val8 = host_view(i, 8);
|
||||
auto val9 = host_view(i, 9);
|
||||
auto val10 = host_view(i, 10);
|
||||
auto val11 = host_view(i, 11);
|
||||
EXPECT_NEAR(val0, NumberType(80), 1e-14);
|
||||
EXPECT_NEAR(val1, NumberType(20), 1e-14);
|
||||
EXPECT_NEAR(val2, NumberType(-20), 1e-14);
|
||||
EXPECT_NEAR(val3, NumberType(20), 1e-14);
|
||||
EXPECT_NEAR(val4, NumberType(-20), 1e-14);
|
||||
EXPECT_NEAR(val5, NumberType(-100), 1e-14);
|
||||
EXPECT_NEAR(val6, NumberType(40), 1e-14);
|
||||
EXPECT_NEAR(val7, NumberType(20), 1e-14);
|
||||
EXPECT_NEAR(val8, NumberType(-20), 1e-14);
|
||||
EXPECT_NEAR(val9, NumberType(-20), 1e-14);
|
||||
EXPECT_NEAR(val10, NumberType(20), 1e-14);
|
||||
EXPECT_NEAR(val11, NumberType(-60), 1e-14);
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
for (size_type j = 0; j < host_view.extent(1); ++j) {
|
||||
EXPECT_NEAR(host_view(i, j), NumberType(ref[j]), 1e-14)
|
||||
<< "Data differs at indices " << i << ", " << j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for correct padding
|
||||
void validateResultsForSubview(
|
||||
orig_view_type orig, std::pair<size_type, size_type>& subRangeDim0,
|
||||
std::pair<size_type, size_type>& subRangeDim1) {
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
for (size_type j = 0; j < host_view.extent(1); ++j) {
|
||||
auto val = host_view(i, j);
|
||||
if ((i >= std::get<0>(subRangeDim0) && i < std::get<1>(subRangeDim0)) &&
|
||||
(j >= std::get<0>(subRangeDim1) && j < std::get<1>(subRangeDim1))) {
|
||||
// is in subview
|
||||
EXPECT_NEAR(val, NumberType(ref[j]), 1e-14)
|
||||
<< "Data differs at indices " << i << ", " << j;
|
||||
} else {
|
||||
// is outside of subview
|
||||
EXPECT_NEAR(val, NumberType(0), 1e-14)
|
||||
<< "Data differs at indices " << i << ", " << j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
NumberType ref[12] = {80, 20, -20, 20, -20, -100, 40, 20, -20, -20, 20, -60};
|
||||
};
|
||||
|
||||
template <typename DeviceType, typename Layout, typename Duplication,
|
||||
@ -214,6 +208,8 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
|
||||
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
|
||||
|
||||
using size_type = typename Kokkos::HostSpace::size_type;
|
||||
|
||||
scatter_view_type scatter_view;
|
||||
int scatterSize;
|
||||
|
||||
@ -226,8 +222,7 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
host_view(i, 0) = 1.0;
|
||||
host_view(i, 1) = 1.0;
|
||||
host_view(i, 2) = 1.0;
|
||||
@ -260,14 +255,45 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
EXPECT_TRUE(std::fabs((val0 - 65536.0) / 65536.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val1 - 256.0) / 256.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val0 - 65536.0) / 65536.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val1 - 256.0) / 256.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
|
||||
// check for correct padding
|
||||
void validateResultsForSubview(
|
||||
orig_view_type orig, std::pair<size_type, size_type>& subRangeDim0,
|
||||
std::pair<size_type, size_type>& subRangeDim1) {
|
||||
(void)subRangeDim1;
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
if (i >= std::get<0>(subRangeDim0) && i < std::get<1>(subRangeDim0)) {
|
||||
// is in subview
|
||||
EXPECT_TRUE(std::fabs((val0 - 65536.0) / 65536.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val1 - 256.0) / 256.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14);
|
||||
} else {
|
||||
// is outside of subview
|
||||
EXPECT_NEAR(val0, NumberType(1), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val1, NumberType(1), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val2, NumberType(1), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -285,6 +311,8 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
|
||||
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
|
||||
|
||||
using size_type = typename Kokkos::HostSpace::size_type;
|
||||
|
||||
scatter_view_type scatter_view;
|
||||
int scatterSize;
|
||||
|
||||
@ -297,8 +325,7 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
host_view(i, 0) = 999999.0;
|
||||
host_view(i, 1) = 999999.0;
|
||||
host_view(i, 2) = 999999.0;
|
||||
@ -331,14 +358,48 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
EXPECT_TRUE(std::fabs((val0 - 4.0) / 4.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val1 - 2.0) / 2.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val0 - 4.0) / 4.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val1 - 2.0) / 2.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
|
||||
// check for correct padding
|
||||
void validateResultsForSubview(
|
||||
orig_view_type orig, std::pair<size_type, size_type>& subRangeDim0,
|
||||
std::pair<size_type, size_type>& subRangeDim1) {
|
||||
(void)subRangeDim1;
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
if (i >= std::get<0>(subRangeDim0) && i < std::get<1>(subRangeDim0)) {
|
||||
// is in subview
|
||||
EXPECT_TRUE(std::fabs((val0 - 4.0) / 4.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val1 - 2.0) / 2.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val2 - 1.0) / 1.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
} else {
|
||||
// is outside of subview
|
||||
EXPECT_NEAR(val0, NumberType(999999), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val1, NumberType(999999), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val2, NumberType(999999), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -356,6 +417,8 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
|
||||
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
|
||||
|
||||
using size_type = typename Kokkos::HostSpace::size_type;
|
||||
|
||||
scatter_view_type scatter_view;
|
||||
int scatterSize;
|
||||
|
||||
@ -368,8 +431,7 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
host_view(i, 0) = 0.0;
|
||||
host_view(i, 1) = 0.0;
|
||||
host_view(i, 2) = 0.0;
|
||||
@ -401,14 +463,104 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
|
||||
++i) {
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
EXPECT_TRUE(std::fabs((val0 - 16.0) / 16.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val1 - 8.0) / 8.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val2 - 4.0) / 4.0) < 1e-14);
|
||||
EXPECT_TRUE(std::fabs((val0 - 16.0) / 16.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val1 - 8.0) / 8.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val2 - 4.0) / 4.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
|
||||
// check for correct padding
|
||||
void validateResultsForSubview(
|
||||
orig_view_type orig, std::pair<size_type, size_type>& subRangeDim0,
|
||||
std::pair<size_type, size_type>& subRangeDim1) {
|
||||
(void)subRangeDim1;
|
||||
auto host_view =
|
||||
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), orig);
|
||||
Kokkos::fence();
|
||||
for (size_type i = 0; i < host_view.extent(0); ++i) {
|
||||
auto val0 = host_view(i, 0);
|
||||
auto val1 = host_view(i, 1);
|
||||
auto val2 = host_view(i, 2);
|
||||
if (i >= std::get<0>(subRangeDim0) && i < std::get<1>(subRangeDim0)) {
|
||||
// is in subview
|
||||
EXPECT_TRUE(std::fabs((val0 - 16.0) / 16.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val1 - 8.0) / 8.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_TRUE(std::fabs((val2 - 4.0) / 4.0) < 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
} else {
|
||||
// is outside of subview
|
||||
EXPECT_NEAR(val0, NumberType(0), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val1, NumberType(0), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
EXPECT_NEAR(val2, NumberType(0), 1e-14)
|
||||
<< "Data differs at index " << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Test ScatterView on subview
|
||||
template <typename DeviceType, typename Layout, typename Op,
|
||||
typename NumberType>
|
||||
struct test_default_scatter_sub_view {
|
||||
public:
|
||||
using default_duplication = Kokkos::Impl::Experimental::DefaultDuplication<
|
||||
typename DeviceType::execution_space>;
|
||||
using Duplication = typename default_duplication::type;
|
||||
using Contribution = typename Kokkos::Impl::Experimental::DefaultContribution<
|
||||
typename DeviceType::execution_space, Duplication>::type;
|
||||
using scatter_view_def =
|
||||
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
|
||||
Contribution, Op,
|
||||
NumberType>::scatter_view_type;
|
||||
using orig_view_def =
|
||||
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
|
||||
Contribution, Op,
|
||||
NumberType>::orig_view_type;
|
||||
|
||||
using size_type = typename Kokkos::HostSpace::size_type;
|
||||
|
||||
void run_test(int n) {
|
||||
// Test creation via create_scatter_view overload 1
|
||||
{
|
||||
orig_view_def original_view("original_view", n);
|
||||
|
||||
auto rangeDim0 = std::pair<size_type, size_type>(0 + 1, n - 1);
|
||||
auto rangeDim1 =
|
||||
std::pair<size_type, size_type>(0, original_view.extent(1));
|
||||
|
||||
auto original_sub_view =
|
||||
Kokkos::subview(original_view, rangeDim0, rangeDim1);
|
||||
|
||||
scatter_view_def scatter_view =
|
||||
Kokkos::Experimental::create_scatter_view(Op{}, original_sub_view);
|
||||
|
||||
test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
|
||||
Op, NumberType>
|
||||
scatter_view_test_impl(scatter_view);
|
||||
scatter_view_test_impl.initialize(original_view);
|
||||
scatter_view_test_impl.run_parallel(original_sub_view.extent(0));
|
||||
|
||||
Kokkos::Experimental::contribute(original_sub_view, scatter_view);
|
||||
scatter_view.reset_except(original_sub_view);
|
||||
|
||||
scatter_view_test_impl.run_parallel(original_sub_view.extent(0));
|
||||
|
||||
Kokkos::Experimental::contribute(original_sub_view, scatter_view);
|
||||
Kokkos::fence();
|
||||
|
||||
scatter_view_test_impl.validateResultsForSubview(original_view, rangeDim0,
|
||||
rangeDim1);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -674,14 +826,24 @@ void test_scatter_view(int64_t n) {
|
||||
test_default_sv;
|
||||
test_default_sv.run_test(n);
|
||||
}
|
||||
|
||||
// run same test but on a subview (this covers support for padded
|
||||
// ScatterViews)
|
||||
{
|
||||
test_default_scatter_sub_view<DeviceType, Kokkos::LayoutRight, ScatterType,
|
||||
NumberType>
|
||||
test_default_scatter_view_subview;
|
||||
test_default_scatter_view_subview.run_test(n);
|
||||
}
|
||||
|
||||
TestDuplicatedScatterView<DeviceType, ScatterType, NumberType> duptest(n);
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, scatterview) {
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, double>(
|
||||
10);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum,
|
||||
unsigned int>(10);
|
||||
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, int>(10);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterProd>(10);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMin>(10);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMax>(10);
|
||||
@ -698,10 +860,11 @@ TEST(TEST_CATEGORY, scatterview) {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, double>(
|
||||
big_n);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum,
|
||||
unsigned int>(big_n);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, int>(
|
||||
big_n);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterProd>(big_n);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMin>(big_n);
|
||||
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMax>(big_n);
|
||||
@ -712,8 +875,7 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
|
||||
Kokkos::Device<TEST_EXECSPACE, typename TEST_EXECSPACE::memory_space>;
|
||||
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum, double>(10);
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum,
|
||||
unsigned int>(10);
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum, int>(10);
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterProd>(10);
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterMin>(10);
|
||||
test_scatter_view<device_type, Kokkos::Experimental::ScatterMax>(10);
|
||||
@ -734,7 +896,7 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
|
||||
test_scatter_view<device_device_type, Kokkos::Experimental::ScatterSum,
|
||||
double>(10);
|
||||
test_scatter_view<device_device_type, Kokkos::Experimental::ScatterSum,
|
||||
unsigned int>(10);
|
||||
int>(10);
|
||||
test_scatter_view<device_device_type, Kokkos::Experimental::ScatterProd>(
|
||||
10);
|
||||
test_scatter_view<device_device_type, Kokkos::Experimental::ScatterMin>(10);
|
||||
@ -743,8 +905,8 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
|
||||
Kokkos::Device<device_execution_space, host_accessible_space>;
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterSum,
|
||||
double>(10);
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterSum,
|
||||
unsigned int>(10);
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterSum, int>(
|
||||
10);
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterProd>(10);
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterMin>(10);
|
||||
test_scatter_view<host_device_type, Kokkos::Experimental::ScatterMax>(10);
|
||||
|
||||
@ -105,8 +105,8 @@ void run_test_graph() {
|
||||
auto rowView = hx.rowConst(i);
|
||||
ASSERT_EQ(rowView.length, graph[i].size());
|
||||
for (size_t j = 0; j < rowView.length; ++j) {
|
||||
ASSERT_EQ(rowView.colidx(j), graph[i][j]);
|
||||
ASSERT_EQ(rowView(j), graph[i][j]);
|
||||
ASSERT_EQ(rowView.colidx(j), (size_t)graph[i][j]);
|
||||
ASSERT_EQ(rowView(j), (size_t)graph[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,9 +294,7 @@ void test_deep_copy(uint32_t num_nodes) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME_SYCL wrong results on Nvidia GPUs but correct on Host and Intel GPUs
|
||||
// WORKAROUND MSVC
|
||||
#if !defined(_WIN32) && !defined(KOKKOS_ENABLE_SYCL)
|
||||
#if !defined(_WIN32)
|
||||
TEST(TEST_CATEGORY, UnorderedMap_insert) {
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
test_insert<TEST_EXECSPACE>(100000, 90000, 100, true);
|
||||
|
||||
@ -60,7 +60,7 @@ struct test_vector_insert {
|
||||
|
||||
template <typename Vector>
|
||||
void run_test(Vector& a) {
|
||||
int n = a.size();
|
||||
auto n = a.size();
|
||||
|
||||
auto it = a.begin();
|
||||
if (n > 0) {
|
||||
@ -97,7 +97,7 @@ struct test_vector_insert {
|
||||
#endif
|
||||
|
||||
ASSERT_EQ(a.size(), n + 1 + n + 5);
|
||||
ASSERT_EQ(std::distance(it_return, a.begin() + 17), 0);
|
||||
ASSERT_EQ(std::distance(it_return, a.begin() + 17), 0u);
|
||||
|
||||
Vector b;
|
||||
|
||||
@ -109,7 +109,7 @@ struct test_vector_insert {
|
||||
#else
|
||||
b.insert(b.begin(), 7, 9);
|
||||
#endif
|
||||
ASSERT_EQ(b.size(), 7);
|
||||
ASSERT_EQ(b.size(), 7u);
|
||||
ASSERT_EQ(b[0], scalar_type(9));
|
||||
|
||||
it = a.begin();
|
||||
@ -121,7 +121,7 @@ struct test_vector_insert {
|
||||
it_return = a.insert(it, b.begin(), b.end());
|
||||
#endif
|
||||
ASSERT_EQ(a.size(), n + 1 + n + 5 + 7);
|
||||
ASSERT_EQ(std::distance(it_return, a.begin() + 27 + n), 0);
|
||||
ASSERT_EQ(std::distance(it_return, a.begin() + 27 + n), 0u);
|
||||
|
||||
// Testing insert at end via all three function interfaces
|
||||
a.insert(a.end(), 11);
|
||||
|
||||
183
lib/kokkos/containers/unit_tests/TestWithoutInitializing.hpp
Normal file
183
lib/kokkos/containers/unit_tests/TestWithoutInitializing.hpp
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 3.0
|
||||
// Copyright (2020) National Technology & Engineering
|
||||
// Solutions of Sandia, LLC (NTESS).
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// 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 NTESS "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 NTESS 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 Christian R. Trott (crtrott@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <Kokkos_DualView.hpp>
|
||||
#include <Kokkos_DynRankView.hpp>
|
||||
#include <Kokkos_ScatterView.hpp>
|
||||
|
||||
#include <../../core/unit_test/tools/include/ToolTestingUtilities.hpp>
|
||||
|
||||
TEST(TEST_CATEGORY, resize_realloc_no_init_dualview) {
|
||||
using namespace Kokkos::Test::Tools;
|
||||
listen_tool_events(Config::DisableAll(), Config::EnableKernels());
|
||||
Kokkos::DualView<int*** * [1][2][3][4], TEST_EXECSPACE> bla("bla", 5, 6, 7,
|
||||
8);
|
||||
|
||||
auto success = validate_absence(
|
||||
[&]() {
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, bla, 5, 6, 7, 9);
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 8, 8, 8);
|
||||
},
|
||||
[&](BeginParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found begin event"}};
|
||||
return MatchDiagnostic{false};
|
||||
},
|
||||
[&](EndParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found end event"}};
|
||||
return MatchDiagnostic{false};
|
||||
});
|
||||
ASSERT_TRUE(success);
|
||||
listen_tool_events(Config::DisableAll());
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, resize_realloc_no_alloc_dualview) {
|
||||
using namespace Kokkos::Test::Tools;
|
||||
listen_tool_events(Config::DisableAll(), Config::EnableKernels(),
|
||||
Config::EnableAllocs());
|
||||
Kokkos::DualView<int*** * [1][2][3][4], TEST_EXECSPACE> bla("bla", 8, 7, 6,
|
||||
5);
|
||||
|
||||
auto success = validate_absence(
|
||||
[&]() {
|
||||
Kokkos::resize(bla, 8, 7, 6, 5);
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 7, 6, 5);
|
||||
},
|
||||
[&](BeginParallelForEvent) {
|
||||
return MatchDiagnostic{true, {"Found begin event"}};
|
||||
},
|
||||
[&](EndParallelForEvent) {
|
||||
return MatchDiagnostic{true, {"Found end event"}};
|
||||
},
|
||||
[&](AllocateDataEvent) {
|
||||
return MatchDiagnostic{true, {"Found alloc event"}};
|
||||
},
|
||||
[&](DeallocateDataEvent) {
|
||||
return MatchDiagnostic{true, {"Found dealloc event"}};
|
||||
});
|
||||
ASSERT_TRUE(success);
|
||||
listen_tool_events(Config::DisableAll());
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, resize_realloc_no_init_dynrankview) {
|
||||
using namespace Kokkos::Test::Tools;
|
||||
listen_tool_events(Config::DisableAll(), Config::EnableKernels());
|
||||
Kokkos::DynRankView<int, TEST_EXECSPACE> bla("bla", 5, 6, 7, 8);
|
||||
|
||||
auto success = validate_absence(
|
||||
[&]() {
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, bla, 5, 6, 7, 9);
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 8, 8, 8);
|
||||
},
|
||||
[&](BeginParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found begin event"}};
|
||||
return MatchDiagnostic{false};
|
||||
},
|
||||
[&](EndParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found end event"}};
|
||||
return MatchDiagnostic{false};
|
||||
});
|
||||
ASSERT_TRUE(success);
|
||||
listen_tool_events(Config::DisableAll());
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, resize_realloc_no_init_scatterview) {
|
||||
using namespace Kokkos::Test::Tools;
|
||||
listen_tool_events(Config::DisableAll(), Config::EnableKernels());
|
||||
Kokkos::Experimental::ScatterView<
|
||||
int*** * [1][2][3], typename TEST_EXECSPACE::array_layout, TEST_EXECSPACE>
|
||||
bla("bla", 4, 5, 6, 7);
|
||||
|
||||
auto success = validate_absence(
|
||||
[&]() {
|
||||
Kokkos::resize(Kokkos::WithoutInitializing, bla, 4, 5, 6, 8);
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 8, 8, 8);
|
||||
},
|
||||
[&](BeginParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found begin event"}};
|
||||
return MatchDiagnostic{false};
|
||||
},
|
||||
[&](EndParallelForEvent event) {
|
||||
if (event.descriptor().find("initialization") != std::string::npos)
|
||||
return MatchDiagnostic{true, {"Found end event"}};
|
||||
return MatchDiagnostic{false};
|
||||
});
|
||||
ASSERT_TRUE(success);
|
||||
listen_tool_events(Config::DisableAll());
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, resize_realloc_no_alloc_scatterview) {
|
||||
using namespace Kokkos::Test::Tools;
|
||||
listen_tool_events(Config::DisableAll(), Config::EnableKernels(),
|
||||
Config::EnableAllocs());
|
||||
Kokkos::Experimental::ScatterView<
|
||||
int*** * [1][2][3], typename TEST_EXECSPACE::array_layout, TEST_EXECSPACE>
|
||||
bla("bla", 7, 6, 5, 4);
|
||||
|
||||
auto success = validate_absence(
|
||||
[&]() {
|
||||
Kokkos::resize(bla, 7, 6, 5, 4);
|
||||
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 7, 6, 5, 4);
|
||||
},
|
||||
[&](BeginParallelForEvent) {
|
||||
return MatchDiagnostic{true, {"Found begin event"}};
|
||||
},
|
||||
[&](EndParallelForEvent) {
|
||||
return MatchDiagnostic{true, {"Found end event"}};
|
||||
},
|
||||
[&](AllocateDataEvent) {
|
||||
return MatchDiagnostic{true, {"Found alloc event"}};
|
||||
},
|
||||
[&](DeallocateDataEvent) {
|
||||
return MatchDiagnostic{true, {"Found dealloc event"}};
|
||||
});
|
||||
ASSERT_TRUE(success);
|
||||
listen_tool_events(Config::DisableAll());
|
||||
}
|
||||
Reference in New Issue
Block a user