Update Kokkos library in LAMMPS to v3.7.0
This commit is contained in:
@ -11,6 +11,7 @@ FILE(GLOB ALGO_HEADERS *.hpp)
|
||||
FILE(GLOB ALGO_SOURCES *.cpp)
|
||||
LIST(APPEND ALGO_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_config.h)
|
||||
APPEND_GLOB(ALGO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/std_algorithms/*.hpp)
|
||||
APPEND_GLOB(ALGO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/std_algorithms/impl/*.hpp)
|
||||
|
||||
INSTALL (
|
||||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||
|
||||
@ -44,6 +44,10 @@
|
||||
|
||||
#ifndef KOKKOS_RANDOM_HPP
|
||||
#define KOKKOS_RANDOM_HPP
|
||||
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_RANDOM
|
||||
#endif
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <Kokkos_Complex.hpp>
|
||||
@ -648,63 +652,44 @@ struct Random_UniqueIndex {
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef KOKKOS_ENABLE_CUDA
|
||||
template <class MemorySpace>
|
||||
struct Random_UniqueIndex<Kokkos::Device<Kokkos::Cuda, MemorySpace>> {
|
||||
using locks_view_type =
|
||||
View<int**, Kokkos::Device<Kokkos::Cuda, MemorySpace>>;
|
||||
KOKKOS_FUNCTION
|
||||
static int get_state_idx(const locks_view_type& locks_) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
const int i_offset =
|
||||
(threadIdx.x * blockDim.y + threadIdx.y) * blockDim.z + threadIdx.z;
|
||||
int i = (((blockIdx.x * gridDim.y + blockIdx.y) * gridDim.z + blockIdx.z) *
|
||||
blockDim.x * blockDim.y * blockDim.z +
|
||||
i_offset) %
|
||||
locks_.extent(0);
|
||||
while (Kokkos::atomic_compare_exchange(&locks_(i, 0), 0, 1)) {
|
||||
i += blockDim.x * blockDim.y * blockDim.z;
|
||||
if (i >= static_cast<int>(locks_.extent(0))) {
|
||||
i = i_offset;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
#else
|
||||
(void)locks_;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)
|
||||
|
||||
#if defined(KOKKOS_ENABLE_CUDA)
|
||||
#define KOKKOS_IMPL_EXECUTION_SPACE_CUDA_OR_HIP Kokkos::Cuda
|
||||
#elif defined(KOKKOS_ENABLE_HIP)
|
||||
#define KOKKOS_IMPL_EXECUTION_SPACE_CUDA_OR_HIP Kokkos::Experimental::HIP
|
||||
#endif
|
||||
|
||||
#ifdef KOKKOS_ENABLE_HIP
|
||||
template <class MemorySpace>
|
||||
struct Random_UniqueIndex<
|
||||
Kokkos::Device<Kokkos::Experimental::HIP, MemorySpace>> {
|
||||
Kokkos::Device<KOKKOS_IMPL_EXECUTION_SPACE_CUDA_OR_HIP, MemorySpace>> {
|
||||
using locks_view_type =
|
||||
View<int**, Kokkos::Device<Kokkos::Experimental::HIP, MemorySpace>>;
|
||||
View<int**, Kokkos::Device<KOKKOS_IMPL_EXECUTION_SPACE_CUDA_OR_HIP,
|
||||
MemorySpace>>;
|
||||
KOKKOS_FUNCTION
|
||||
static int get_state_idx(const locks_view_type& locks_) {
|
||||
#ifdef __HIP_DEVICE_COMPILE__
|
||||
const int i_offset =
|
||||
(threadIdx.x * blockDim.y + threadIdx.y) * blockDim.z + threadIdx.z;
|
||||
int i = (((blockIdx.x * gridDim.y + blockIdx.y) * gridDim.z + blockIdx.z) *
|
||||
KOKKOS_IF_ON_DEVICE((
|
||||
const int i_offset =
|
||||
(threadIdx.x * blockDim.y + threadIdx.y) * blockDim.z + threadIdx.z;
|
||||
int i =
|
||||
(((blockIdx.x * gridDim.y + blockIdx.y) * gridDim.z + blockIdx.z) *
|
||||
blockDim.x * blockDim.y * blockDim.z +
|
||||
i_offset) %
|
||||
locks_.extent(0);
|
||||
while (Kokkos::atomic_compare_exchange(&locks_(i, 0), 0, 1)) {
|
||||
i += blockDim.x * blockDim.y * blockDim.z;
|
||||
if (i >= static_cast<int>(locks_.extent(0))) {
|
||||
i = i_offset;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
#else
|
||||
(void)locks_;
|
||||
return 0;
|
||||
#endif
|
||||
while (Kokkos::atomic_compare_exchange(&locks_(i, 0), 0, 1)) {
|
||||
i += blockDim.x * blockDim.y * blockDim.z;
|
||||
if (i >= static_cast<int>(locks_.extent(0))) {
|
||||
i = i_offset;
|
||||
}
|
||||
}
|
||||
|
||||
return i;))
|
||||
KOKKOS_IF_ON_HOST(((void)locks_; return 0;))
|
||||
}
|
||||
};
|
||||
|
||||
#undef KOKKOS_IMPL_EXECUTION_SPACE_CUDA_OR_HIP
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef KOKKOS_ENABLE_SYCL
|
||||
@ -1279,7 +1264,6 @@ struct fill_random_functor_begin_end;
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 0,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1303,7 +1287,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 0,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 1,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1331,7 +1314,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 1,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 2,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1361,7 +1343,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 2,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 3,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1392,7 +1373,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 3,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 4,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1424,7 +1404,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 4,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 5,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1458,7 +1437,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 5,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 6,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1494,7 +1472,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 6,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 7,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1532,7 +1509,6 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 7,
|
||||
template <class ViewType, class RandomPool, int loops, class IndexType>
|
||||
struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 8,
|
||||
IndexType> {
|
||||
using execution_space = typename ViewType::execution_space;
|
||||
ViewType a;
|
||||
RandomPool rand_pool;
|
||||
typename ViewType::const_value_type begin, end;
|
||||
@ -1569,34 +1545,57 @@ struct fill_random_functor_begin_end<ViewType, RandomPool, loops, 8,
|
||||
}
|
||||
};
|
||||
|
||||
template <class ViewType, class RandomPool, class IndexType = int64_t>
|
||||
void fill_random(ViewType a, RandomPool g,
|
||||
template <class ExecutionSpace, class ViewType, class RandomPool,
|
||||
class IndexType = int64_t>
|
||||
void fill_random(const ExecutionSpace& exec, ViewType a, RandomPool g,
|
||||
typename ViewType::const_value_type begin,
|
||||
typename ViewType::const_value_type end) {
|
||||
int64_t LDA = a.extent(0);
|
||||
if (LDA > 0)
|
||||
parallel_for("Kokkos::fill_random", (LDA + 127) / 128,
|
||||
Impl::fill_random_functor_begin_end<ViewType, RandomPool, 128,
|
||||
ViewType::Rank, IndexType>(
|
||||
a, g, begin, end));
|
||||
parallel_for(
|
||||
"Kokkos::fill_random",
|
||||
Kokkos::RangePolicy<ExecutionSpace>(exec, 0, (LDA + 127) / 128),
|
||||
Impl::fill_random_functor_begin_end<ViewType, RandomPool, 128,
|
||||
ViewType::Rank, IndexType>(
|
||||
a, g, begin, end));
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
template <class ExecutionSpace, class ViewType, class RandomPool,
|
||||
class IndexType = int64_t>
|
||||
void fill_random(const ExecutionSpace& exec, ViewType a, RandomPool g,
|
||||
typename ViewType::const_value_type begin,
|
||||
typename ViewType::const_value_type end) {
|
||||
Impl::apply_to_view_of_static_rank(
|
||||
[&](auto dst) { Kokkos::Impl::fill_random(exec, dst, g, begin, end); },
|
||||
a);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class ViewType, class RandomPool,
|
||||
class IndexType = int64_t>
|
||||
void fill_random(const ExecutionSpace& exec, ViewType a, RandomPool g,
|
||||
typename ViewType::const_value_type range) {
|
||||
fill_random(exec, a, g, 0, range);
|
||||
}
|
||||
|
||||
template <class ViewType, class RandomPool, class IndexType = int64_t>
|
||||
void fill_random(ViewType a, RandomPool g,
|
||||
typename ViewType::const_value_type begin,
|
||||
typename ViewType::const_value_type end) {
|
||||
Impl::apply_to_view_of_static_rank(
|
||||
[&](auto dst) { Kokkos::Impl::fill_random(dst, g, begin, end); }, a);
|
||||
fill_random(typename ViewType::execution_space{}, a, g, begin, end);
|
||||
}
|
||||
|
||||
template <class ViewType, class RandomPool, class IndexType = int64_t>
|
||||
void fill_random(ViewType a, RandomPool g,
|
||||
typename ViewType::const_value_type range) {
|
||||
fill_random(a, g, 0, range);
|
||||
fill_random(typename ViewType::execution_space{}, a, g, 0, range);
|
||||
}
|
||||
|
||||
} // namespace Kokkos
|
||||
|
||||
#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_RANDOM
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_RANDOM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -44,6 +44,10 @@
|
||||
|
||||
#ifndef KOKKOS_SORT_HPP_
|
||||
#define KOKKOS_SORT_HPP_
|
||||
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SORT
|
||||
#endif
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
@ -120,13 +124,13 @@ class BinSort {
|
||||
// If a Kokkos::View then can generate constant random access
|
||||
// otherwise can only use the constant type.
|
||||
|
||||
using src_view_type = typename std::conditional<
|
||||
using src_view_type = std::conditional_t<
|
||||
Kokkos::is_view<SrcViewType>::value,
|
||||
Kokkos::View<typename SrcViewType::const_data_type,
|
||||
typename SrcViewType::array_layout,
|
||||
typename SrcViewType::device_type,
|
||||
Kokkos::MemoryTraits<Kokkos::RandomAccess> >,
|
||||
typename SrcViewType::const_type>::type;
|
||||
typename SrcViewType::const_type>;
|
||||
|
||||
using perm_view_type = typename PermuteViewType::const_type;
|
||||
|
||||
@ -151,8 +155,11 @@ class BinSort {
|
||||
}
|
||||
};
|
||||
|
||||
using execution_space = typename Space::execution_space;
|
||||
using bin_op_type = BinSortOp;
|
||||
// Naming this alias "execution_space" would be problematic since it would be
|
||||
// considered as execution space for the various functors which might use
|
||||
// another execution space through sort() or create_permute_vector().
|
||||
using exec_space = typename Space::execution_space;
|
||||
using bin_op_type = BinSortOp;
|
||||
|
||||
struct bin_count_tag {};
|
||||
struct bin_offset_tag {};
|
||||
@ -171,13 +178,13 @@ class BinSort {
|
||||
// If a Kokkos::View then can generate constant random access
|
||||
// otherwise can only use the constant type.
|
||||
|
||||
using const_rnd_key_view_type = typename std::conditional<
|
||||
using const_rnd_key_view_type = std::conditional_t<
|
||||
Kokkos::is_view<KeyViewType>::value,
|
||||
Kokkos::View<typename KeyViewType::const_data_type,
|
||||
typename KeyViewType::array_layout,
|
||||
typename KeyViewType::device_type,
|
||||
Kokkos::MemoryTraits<Kokkos::RandomAccess> >,
|
||||
const_key_view_type>::type;
|
||||
const_key_view_type>;
|
||||
|
||||
using non_const_key_scalar = typename KeyViewType::non_const_value_type;
|
||||
using const_key_scalar = typename KeyViewType::const_value_type;
|
||||
@ -220,6 +227,14 @@ class BinSort {
|
||||
range_begin(range_begin_),
|
||||
range_end(range_end_),
|
||||
sort_within_bins(sort_within_bins_) {
|
||||
static_assert(
|
||||
Kokkos::SpaceAccessibility<ExecutionSpace,
|
||||
typename Space::memory_space>::accessible,
|
||||
"The provided execution space must be able to access the memory space "
|
||||
"BinSort was initialized with!");
|
||||
if (bin_op.max_bins() <= 0)
|
||||
Kokkos::abort(
|
||||
"The number of bins in the BinSortOp object must be greater than 0!");
|
||||
bin_count_atomic = Kokkos::View<int*, Space>(
|
||||
"Kokkos::SortImpl::BinSortFunctor::bin_count", bin_op.max_bins());
|
||||
bin_count_const = bin_count_atomic;
|
||||
@ -235,7 +250,7 @@ class BinSort {
|
||||
|
||||
BinSort(const_key_view_type keys_, int range_begin_, int range_end_,
|
||||
BinSortOp bin_op_, bool sort_within_bins_ = false)
|
||||
: BinSort(execution_space{}, keys_, range_begin_, range_end_, bin_op_,
|
||||
: BinSort(exec_space{}, keys_, range_begin_, range_end_, bin_op_,
|
||||
sort_within_bins_) {}
|
||||
|
||||
template <typename ExecutionSpace>
|
||||
@ -245,13 +260,19 @@ class BinSort {
|
||||
|
||||
BinSort(const_key_view_type keys_, BinSortOp bin_op_,
|
||||
bool sort_within_bins_ = false)
|
||||
: BinSort(execution_space{}, keys_, bin_op_, sort_within_bins_) {}
|
||||
: BinSort(exec_space{}, keys_, bin_op_, sort_within_bins_) {}
|
||||
|
||||
//----------------------------------------
|
||||
// Create the permutation vector, the bin_offset array and the bin_count
|
||||
// array. Can be called again if keys changed
|
||||
template <class ExecutionSpace = execution_space>
|
||||
void create_permute_vector(const ExecutionSpace& exec = execution_space{}) {
|
||||
template <class ExecutionSpace = exec_space>
|
||||
void create_permute_vector(const ExecutionSpace& exec = exec_space{}) {
|
||||
static_assert(
|
||||
Kokkos::SpaceAccessibility<ExecutionSpace,
|
||||
typename Space::memory_space>::accessible,
|
||||
"The provided execution space must be able to access the memory space "
|
||||
"BinSort was initialized with!");
|
||||
|
||||
const size_t len = range_end - range_begin;
|
||||
Kokkos::parallel_for(
|
||||
"Kokkos::Sort::BinCount",
|
||||
@ -281,6 +302,17 @@ class BinSort {
|
||||
template <class ExecutionSpace, class ValuesViewType>
|
||||
void sort(const ExecutionSpace& exec, ValuesViewType const& values,
|
||||
int values_range_begin, int values_range_end) const {
|
||||
static_assert(
|
||||
Kokkos::SpaceAccessibility<ExecutionSpace,
|
||||
typename Space::memory_space>::accessible,
|
||||
"The provided execution space must be able to access the memory space "
|
||||
"BinSort was initialized with!");
|
||||
static_assert(
|
||||
Kokkos::SpaceAccessibility<
|
||||
ExecutionSpace, typename ValuesViewType::memory_space>::accessible,
|
||||
"The provided execution space must be able to access the memory space "
|
||||
"of the View argument!");
|
||||
|
||||
using scratch_view_type =
|
||||
Kokkos::View<typename ValuesViewType::data_type,
|
||||
typename ValuesViewType::array_layout,
|
||||
@ -340,7 +372,7 @@ class BinSort {
|
||||
template <class ValuesViewType>
|
||||
void sort(ValuesViewType const& values, int values_range_begin,
|
||||
int values_range_end) const {
|
||||
execution_space exec;
|
||||
exec_space exec;
|
||||
sort(exec, values, values_range_begin, values_range_end);
|
||||
exec.fence("Kokkos::Sort: fence after sorting");
|
||||
}
|
||||
@ -428,7 +460,7 @@ struct BinOp1D {
|
||||
|
||||
BinOp1D() = default;
|
||||
|
||||
// Construct BinOp with number of bins, minimum value and maxuimum value
|
||||
// Construct BinOp with number of bins, minimum value and maximum value
|
||||
BinOp1D(int max_bins__, typename KeyViewType::const_value_type min,
|
||||
typename KeyViewType::const_value_type max)
|
||||
: max_bins_(max_bins__ + 1),
|
||||
@ -554,11 +586,7 @@ struct min_max_functor {
|
||||
|
||||
template <class ExecutionSpace, class ViewType>
|
||||
std::enable_if_t<Kokkos::is_execution_space<ExecutionSpace>::value> sort(
|
||||
const ExecutionSpace& exec, ViewType const& view,
|
||||
bool const always_use_kokkos_sort = false) {
|
||||
if (!always_use_kokkos_sort) {
|
||||
if (Impl::try_std_sort(view, exec)) return;
|
||||
}
|
||||
const ExecutionSpace& exec, ViewType const& view) {
|
||||
using CompType = BinOp1D<ViewType>;
|
||||
|
||||
Kokkos::MinMaxScalar<typename ViewType::non_const_value_type> result;
|
||||
@ -596,12 +624,38 @@ std::enable_if_t<Kokkos::is_execution_space<ExecutionSpace>::value> sort(
|
||||
bin_sort.sort(exec, view);
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
template <class ExecutionSpace, class ViewType>
|
||||
KOKKOS_DEPRECATED_WITH_COMMENT(
|
||||
"Use the overload not taking bool always_use_kokkos_sort")
|
||||
std::enable_if_t<Kokkos::is_execution_space<ExecutionSpace>::value> sort(
|
||||
const ExecutionSpace& exec, ViewType const& view,
|
||||
bool const always_use_kokkos_sort) {
|
||||
if (!always_use_kokkos_sort && Impl::try_std_sort(view, exec)) {
|
||||
return;
|
||||
} else {
|
||||
sort(exec, view);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class ViewType>
|
||||
void sort(ViewType const& view, bool const always_use_kokkos_sort = false) {
|
||||
void sort(ViewType const& view) {
|
||||
typename ViewType::execution_space exec;
|
||||
sort(exec, view);
|
||||
exec.fence("Kokkos::Sort: fence after sorting");
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
|
||||
template <class ViewType>
|
||||
KOKKOS_DEPRECATED_WITH_COMMENT(
|
||||
"Use the overload not taking bool always_use_kokkos_sort")
|
||||
void sort(ViewType const& view, bool const always_use_kokkos_sort) {
|
||||
typename ViewType::execution_space exec;
|
||||
sort(exec, view, always_use_kokkos_sort);
|
||||
exec.fence("Kokkos::Sort: fence after sorting");
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class ExecutionSpace, class ViewType>
|
||||
std::enable_if_t<Kokkos::is_execution_space<ExecutionSpace>::value> sort(
|
||||
@ -635,4 +689,8 @@ void sort(ViewType view, size_t const begin, size_t const end) {
|
||||
|
||||
} // namespace Kokkos
|
||||
|
||||
#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SORT
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -44,59 +44,103 @@
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_HPP
|
||||
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_STD_ALGORITHMS
|
||||
#endif
|
||||
|
||||
/// \file Kokkos_StdAlgorithms.hpp
|
||||
/// \brief Kokkos counterparts for Standard C++ Library algorithms
|
||||
|
||||
#include <std_algorithms/Kokkos_Constraints.hpp>
|
||||
#include <std_algorithms/Kokkos_RandomAccessIterator.hpp>
|
||||
#include <std_algorithms/Kokkos_BeginEnd.hpp>
|
||||
#include "std_algorithms/impl/Kokkos_Constraints.hpp"
|
||||
#include "std_algorithms/impl/Kokkos_RandomAccessIterator.hpp"
|
||||
#include "std_algorithms/Kokkos_BeginEnd.hpp"
|
||||
|
||||
// distance
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include "std_algorithms/Kokkos_Distance.hpp"
|
||||
|
||||
// move, swap, iter_swap
|
||||
#include "std_algorithms/Kokkos_ModifyingOperations.hpp"
|
||||
// note that we categorize below the headers
|
||||
// following the std classification.
|
||||
|
||||
// find, find_if, find_if_not
|
||||
// for_each, for_each_n
|
||||
// mismatch
|
||||
// equal
|
||||
// count_if, count
|
||||
// all_of, any_of, none_of
|
||||
// adjacent_find
|
||||
// lexicographical_compare
|
||||
// search, search_n
|
||||
// find_first_of, find_end
|
||||
#include <std_algorithms/Kokkos_NonModifyingSequenceOperations.hpp>
|
||||
// modifying ops
|
||||
#include "std_algorithms/Kokkos_Swap.hpp"
|
||||
#include "std_algorithms/Kokkos_IterSwap.hpp"
|
||||
|
||||
// replace, replace_copy_if, replace_copy, replace_if
|
||||
// copy, copy_n, copy_backward, copy_if
|
||||
// fill, fill_n
|
||||
// transform
|
||||
// generate, generate_n
|
||||
// reverse, reverse_copy
|
||||
// move, move_backward
|
||||
// swap_ranges
|
||||
// unique, unique_copy
|
||||
// rotate, rotate_copy
|
||||
// remove, remove_if, remove_copy, remove_copy_if
|
||||
// shift_left, shift_right
|
||||
#include <std_algorithms/Kokkos_ModifyingSequenceOperations.hpp>
|
||||
// non-modifying sequence
|
||||
#include "std_algorithms/Kokkos_AdjacentFind.hpp"
|
||||
#include "std_algorithms/Kokkos_Count.hpp"
|
||||
#include "std_algorithms/Kokkos_CountIf.hpp"
|
||||
#include "std_algorithms/Kokkos_AllOf.hpp"
|
||||
#include "std_algorithms/Kokkos_AnyOf.hpp"
|
||||
#include "std_algorithms/Kokkos_NoneOf.hpp"
|
||||
#include "std_algorithms/Kokkos_Equal.hpp"
|
||||
#include "std_algorithms/Kokkos_Find.hpp"
|
||||
#include "std_algorithms/Kokkos_FindIf.hpp"
|
||||
#include "std_algorithms/Kokkos_FindIfNot.hpp"
|
||||
#include "std_algorithms/Kokkos_FindEnd.hpp"
|
||||
#include "std_algorithms/Kokkos_FindFirstOf.hpp"
|
||||
#include "std_algorithms/Kokkos_ForEach.hpp"
|
||||
#include "std_algorithms/Kokkos_ForEachN.hpp"
|
||||
#include "std_algorithms/Kokkos_LexicographicalCompare.hpp"
|
||||
#include "std_algorithms/Kokkos_Mismatch.hpp"
|
||||
#include "std_algorithms/Kokkos_Search.hpp"
|
||||
#include "std_algorithms/Kokkos_SearchN.hpp"
|
||||
|
||||
// is_sorted_until, is_sorted
|
||||
#include <std_algorithms/Kokkos_SortingOperations.hpp>
|
||||
// modifying sequence
|
||||
#include "std_algorithms/Kokkos_Fill.hpp"
|
||||
#include "std_algorithms/Kokkos_FillN.hpp"
|
||||
#include "std_algorithms/Kokkos_Replace.hpp"
|
||||
#include "std_algorithms/Kokkos_ReplaceIf.hpp"
|
||||
#include "std_algorithms/Kokkos_ReplaceCopyIf.hpp"
|
||||
#include "std_algorithms/Kokkos_ReplaceCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_Copy.hpp"
|
||||
#include "std_algorithms/Kokkos_CopyN.hpp"
|
||||
#include "std_algorithms/Kokkos_CopyBackward.hpp"
|
||||
#include "std_algorithms/Kokkos_CopyIf.hpp"
|
||||
#include "std_algorithms/Kokkos_Transform.hpp"
|
||||
#include "std_algorithms/Kokkos_Generate.hpp"
|
||||
#include "std_algorithms/Kokkos_GenerateN.hpp"
|
||||
#include "std_algorithms/Kokkos_Reverse.hpp"
|
||||
#include "std_algorithms/Kokkos_ReverseCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_Move.hpp"
|
||||
#include "std_algorithms/Kokkos_MoveBackward.hpp"
|
||||
#include "std_algorithms/Kokkos_SwapRanges.hpp"
|
||||
#include "std_algorithms/Kokkos_Unique.hpp"
|
||||
#include "std_algorithms/Kokkos_UniqueCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_Rotate.hpp"
|
||||
#include "std_algorithms/Kokkos_RotateCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_Remove.hpp"
|
||||
#include "std_algorithms/Kokkos_RemoveIf.hpp"
|
||||
#include "std_algorithms/Kokkos_RemoveCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_RemoveCopyIf.hpp"
|
||||
#include "std_algorithms/Kokkos_ShiftLeft.hpp"
|
||||
#include "std_algorithms/Kokkos_ShiftRight.hpp"
|
||||
|
||||
// min_element, max_element, minmax_element
|
||||
#include <std_algorithms/Kokkos_MinMaxElementOperations.hpp>
|
||||
// sorting
|
||||
#include "std_algorithms/Kokkos_IsSortedUntil.hpp"
|
||||
#include "std_algorithms/Kokkos_IsSorted.hpp"
|
||||
|
||||
// is_partitioned, partition_copy, partition_point
|
||||
#include <std_algorithms/Kokkos_PartitioningOperations.hpp>
|
||||
// min/max element
|
||||
#include "std_algorithms/Kokkos_MinElement.hpp"
|
||||
#include "std_algorithms/Kokkos_MaxElement.hpp"
|
||||
#include "std_algorithms/Kokkos_MinMaxElement.hpp"
|
||||
|
||||
// adjacent_difference
|
||||
// reduce, transform_reduce
|
||||
// exclusive_scan, transform_exclusive_scan
|
||||
// inclusive_scan, transform_inclusive_scan
|
||||
#include <std_algorithms/Kokkos_Numeric.hpp>
|
||||
// partitioning
|
||||
#include "std_algorithms/Kokkos_IsPartitioned.hpp"
|
||||
#include "std_algorithms/Kokkos_PartitionCopy.hpp"
|
||||
#include "std_algorithms/Kokkos_PartitionPoint.hpp"
|
||||
|
||||
// numeric
|
||||
#include "std_algorithms/Kokkos_AdjacentDifference.hpp"
|
||||
#include "std_algorithms/Kokkos_Reduce.hpp"
|
||||
#include "std_algorithms/Kokkos_TransformReduce.hpp"
|
||||
#include "std_algorithms/Kokkos_ExclusiveScan.hpp"
|
||||
#include "std_algorithms/Kokkos_TransformExclusiveScan.hpp"
|
||||
#include "std_algorithms/Kokkos_InclusiveScan.hpp"
|
||||
#include "std_algorithms/Kokkos_TransformInclusiveScan.hpp"
|
||||
|
||||
#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_STD_ALGORITHMS
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE
|
||||
#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_STD_ALGORITHMS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -42,106 +42,15 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_NUMERICS_ADJACENT_DIFFERENCE_HPP
|
||||
#define KOKKOS_STD_NUMERICS_ADJACENT_DIFFERENCE_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ADJACENT_DIFFERENCE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ADJACENT_DIFFERENCE_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "../Kokkos_BeginEnd.hpp"
|
||||
#include "../Kokkos_Constraints.hpp"
|
||||
#include "../Kokkos_Distance.hpp"
|
||||
#include "impl/Kokkos_AdjacentDifference.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// functors
|
||||
//
|
||||
// ------------------------
|
||||
template <class ValueType1, class ValueType2, class RetType = ValueType2>
|
||||
struct StdAdjacentDifferenceDefaultBinaryOpFunctor {
|
||||
KOKKOS_FUNCTION
|
||||
constexpr RetType operator()(const ValueType1& a, const ValueType2& b) const {
|
||||
return a - b;
|
||||
}
|
||||
};
|
||||
|
||||
template <class InputIteratorType, class OutputIteratorType,
|
||||
class BinaryOperator>
|
||||
struct StdAdjacentDiffFunctor {
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
|
||||
const InputIteratorType m_first_from;
|
||||
const OutputIteratorType m_first_dest;
|
||||
BinaryOperator m_op;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i) const {
|
||||
const auto& my_value = m_first_from[i];
|
||||
if (i == 0) {
|
||||
m_first_dest[i] = my_value;
|
||||
} else {
|
||||
const auto& left_value = m_first_from[i - 1];
|
||||
m_first_dest[i] = m_op(my_value, left_value);
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdAdjacentDiffFunctor(InputIteratorType first_from,
|
||||
OutputIteratorType first_dest, BinaryOperator op)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)),
|
||||
m_op(std::move(op)) {}
|
||||
};
|
||||
|
||||
// ------------------------------------------
|
||||
// adjacent_difference_impl
|
||||
// ------------------------------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp>
|
||||
OutputIteratorType adjacent_difference_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
InputIteratorType first_from,
|
||||
InputIteratorType last_from,
|
||||
OutputIteratorType first_dest,
|
||||
BinaryOp bin_op) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
if (first_from == last_from) {
|
||||
return first_dest;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using value_type = typename OutputIteratorType::value_type;
|
||||
using aux_view_type = ::Kokkos::View<value_type*, ExecutionSpace>;
|
||||
using functor_t =
|
||||
StdAdjacentDiffFunctor<InputIteratorType, OutputIteratorType, BinaryOp>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
aux_view_type aux_view("aux_view", num_elements);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
functor_t(first_from, first_dest, bin_op));
|
||||
ex.fence("Kokkos::adjacent_difference: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
} // end namespace Impl
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// public API
|
||||
//
|
||||
// ------------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType>
|
||||
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value,
|
||||
124
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AdjacentFind.hpp
Normal file
124
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AdjacentFind.hpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ADJACENT_FIND_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ADJACENT_FIND_HPP
|
||||
|
||||
#include "impl/Kokkos_AdjacentFind.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set1
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType adjacent_find(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::adjacent_find_impl("Kokkos::adjacent_find_iterator_api_default",
|
||||
ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType adjacent_find(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::adjacent_find_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto adjacent_find(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::adjacent_find_impl("Kokkos::adjacent_find_view_api_default", ex,
|
||||
KE::begin(v), KE::end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto adjacent_find(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::adjacent_find_impl(label, ex, KE::begin(v), KE::end(v));
|
||||
}
|
||||
|
||||
// overload set2
|
||||
template <class ExecutionSpace, class IteratorType, class BinaryPredicateType>
|
||||
IteratorType adjacent_find(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, BinaryPredicateType pred) {
|
||||
return Impl::adjacent_find_impl("Kokkos::adjacent_find_iterator_api_default",
|
||||
ex, first, last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class BinaryPredicateType>
|
||||
IteratorType adjacent_find(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
BinaryPredicateType pred) {
|
||||
return Impl::adjacent_find_impl(label, ex, first, last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class BinaryPredicateType>
|
||||
auto adjacent_find(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
BinaryPredicateType pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::adjacent_find_impl("Kokkos::adjacent_find_view_api_default", ex,
|
||||
KE::begin(v), KE::end(v), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class BinaryPredicateType>
|
||||
auto adjacent_find(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
BinaryPredicateType pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::adjacent_find_impl(label, ex, KE::begin(v), KE::end(v), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AllOf.hpp
Normal file
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AllOf.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ALL_OF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ALL_OF_HPP
|
||||
|
||||
#include "impl/Kokkos_AllOfAnyOfNoneOf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool all_of(const ExecutionSpace& ex, InputIterator first, InputIterator last,
|
||||
Predicate predicate) {
|
||||
return Impl::all_of_impl("Kokkos::all_of_iterator_api_default", ex, first,
|
||||
last, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool all_of(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, Predicate predicate) {
|
||||
return Impl::all_of_impl(label, ex, first, last, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool all_of(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::all_of_impl("Kokkos::all_of_view_api_default", ex, KE::cbegin(v),
|
||||
KE::cend(v), std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool all_of(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::all_of_impl(label, ex, KE::cbegin(v), KE::cend(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AnyOf.hpp
Normal file
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_AnyOf.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ANY_OF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ANY_OF_HPP
|
||||
|
||||
#include "impl/Kokkos_AllOfAnyOfNoneOf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool any_of(const ExecutionSpace& ex, InputIterator first, InputIterator last,
|
||||
Predicate predicate) {
|
||||
return Impl::any_of_impl("Kokkos::any_of_view_api_default", ex, first, last,
|
||||
predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool any_of(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, Predicate predicate) {
|
||||
return Impl::any_of_impl(label, ex, first, last, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool any_of(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::any_of_impl("Kokkos::any_of_view_api_default", ex, KE::cbegin(v),
|
||||
KE::cend(v), std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool any_of(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::any_of_impl(label, ex, KE::cbegin(v), KE::cend(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -46,8 +46,8 @@
|
||||
#define KOKKOS_BEGIN_END_HPP
|
||||
|
||||
#include <Kokkos_View.hpp>
|
||||
#include "Kokkos_RandomAccessIterator.hpp"
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "impl/Kokkos_RandomAccessIterator.hpp"
|
||||
#include "impl/Kokkos_Constraints.hpp"
|
||||
|
||||
/// \file Kokkos_BeginEnd.hpp
|
||||
/// \brief Kokkos begin, end, cbegin, cend
|
||||
|
||||
97
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Copy.hpp
Normal file
97
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Copy.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_CopyCopyN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator copy(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, OutputIterator d_first) {
|
||||
return Impl::copy_impl("Kokkos::copy_iterator_api_default", ex, first, last,
|
||||
d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
return Impl::copy_impl(label, ex, first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::copy_impl("Kokkos::copy_view_api_default", ex,
|
||||
KE::cbegin(source), KE::cend(source), KE::begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::copy_impl(label, ex, KE::cbegin(source), KE::cend(source),
|
||||
KE::begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,95 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_BACKWARD_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_BACKWARD_HPP
|
||||
|
||||
#include "impl/Kokkos_CopyBackward.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 copy_backward(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 d_last) {
|
||||
return Impl::copy_backward_impl("Kokkos::copy_backward_iterator_api_default",
|
||||
ex, first, last, d_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 copy_backward(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 d_last) {
|
||||
return Impl::copy_backward_impl(label, ex, first, last, d_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto copy_backward(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::copy_backward_impl("Kokkos::copy_backward_view_api_default", ex,
|
||||
cbegin(source), cend(source), end(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto copy_backward(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::copy_backward_impl(label, ex, cbegin(source), cend(source),
|
||||
end(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
99
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CopyIf.hpp
Normal file
99
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CopyIf.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_CopyIf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class Predicate>
|
||||
OutputIterator copy_if(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, OutputIterator d_first,
|
||||
Predicate pred) {
|
||||
return Impl::copy_if_impl("Kokkos::copy_if_iterator_api_default", ex, first,
|
||||
last, d_first, std::move(pred));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class Predicate>
|
||||
OutputIterator copy_if(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first, Predicate pred) {
|
||||
return Impl::copy_if_impl(label, ex, first, last, d_first, std::move(pred));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class Predicate>
|
||||
auto copy_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest, Predicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::copy_if_impl("Kokkos::copy_if_view_api_default", ex,
|
||||
cbegin(source), cend(source), begin(dest),
|
||||
std::move(pred));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class Predicate>
|
||||
auto copy_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest, Predicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::copy_if_impl(label, ex, cbegin(source), cend(source),
|
||||
begin(dest), std::move(pred));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
98
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CopyN.hpp
Normal file
98
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CopyN.hpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_N_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_N_HPP
|
||||
|
||||
#include "impl/Kokkos_CopyCopyN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Size,
|
||||
class OutputIterator>
|
||||
OutputIterator copy_n(const ExecutionSpace& ex, InputIterator first, Size count,
|
||||
OutputIterator result) {
|
||||
return Impl::copy_n_impl("Kokkos::copy_n_iterator_api_default", ex, first,
|
||||
count, result);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Size,
|
||||
class OutputIterator>
|
||||
OutputIterator copy_n(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, Size count, OutputIterator result) {
|
||||
return Impl::copy_n_impl(label, ex, first, count, result);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class Size, class DataType2, class... Properties2>
|
||||
auto copy_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source, Size count,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::copy_n_impl("Kokkos::copy_n_view_api_default", ex,
|
||||
KE::cbegin(source), count, KE::begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class Size, class DataType2, class... Properties2>
|
||||
auto copy_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source, Size count,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::copy_n_impl(label, ex, KE::cbegin(source), count,
|
||||
KE::begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Count.hpp
Normal file
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Count.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COUNT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COUNT_HPP
|
||||
|
||||
#include "impl/Kokkos_CountCountIf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
typename IteratorType::difference_type count(const ExecutionSpace& ex,
|
||||
IteratorType first,
|
||||
IteratorType last,
|
||||
const T& value) {
|
||||
return Impl::count_impl("Kokkos::count_iterator_api_default", ex, first, last,
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
typename IteratorType::difference_type count(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first,
|
||||
IteratorType last,
|
||||
const T& value) {
|
||||
return Impl::count_impl(label, ex, first, last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
auto count(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::count_impl("Kokkos::count_view_api_default", ex, KE::cbegin(v),
|
||||
KE::cend(v), value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
auto count(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::count_impl(label, ex, KE::cbegin(v), KE::cend(v), value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
99
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CountIf.hpp
Normal file
99
lib/kokkos/algorithms/src/std_algorithms/Kokkos_CountIf.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COUNT_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COUNT_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_CountCountIf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
typename IteratorType::difference_type count_if(const ExecutionSpace& ex,
|
||||
IteratorType first,
|
||||
IteratorType last,
|
||||
Predicate predicate) {
|
||||
return Impl::count_if_impl("Kokkos::count_if_iterator_api_default", ex, first,
|
||||
last, std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
typename IteratorType::difference_type count_if(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first,
|
||||
IteratorType last,
|
||||
Predicate predicate) {
|
||||
return Impl::count_if_impl(label, ex, first, last, std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto count_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::count_if_impl("Kokkos::count_if_view_api_default", ex,
|
||||
KE::cbegin(v), KE::cend(v), std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto count_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::count_if_impl(label, ex, KE::cbegin(v), KE::cend(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -45,8 +45,8 @@
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_DISTANCE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_DISTANCE_HPP
|
||||
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_RandomAccessIterator.hpp"
|
||||
#include "impl/Kokkos_Constraints.hpp"
|
||||
#include "impl/Kokkos_RandomAccessIterator.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
198
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Equal.hpp
Normal file
198
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Equal.hpp
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_EQUAL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_EQUAL_HPP
|
||||
|
||||
#include "impl/Kokkos_Equal.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const ExecutionSpace& ex, IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2) {
|
||||
return Impl::equal_impl("Kokkos::equal_iterator_api_default", ex, first1,
|
||||
last1, first2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2) {
|
||||
return Impl::equal_impl(label, ex, first1, last1, first2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const ExecutionSpace& ex, IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, BinaryPredicateType predicate) {
|
||||
return Impl::equal_impl("Kokkos::equal_iterator_api_default", ex, first1,
|
||||
last1, first2, std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2,
|
||||
BinaryPredicateType predicate) {
|
||||
return Impl::equal_impl(label, ex, first1, last1, first2,
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
bool equal(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::equal_impl("Kokkos::equal_view_api_default", ex,
|
||||
KE::cbegin(view1), KE::cend(view1),
|
||||
KE::cbegin(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
bool equal(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::equal_impl(label, ex, KE::cbegin(view1), KE::cend(view1),
|
||||
KE::cbegin(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
bool equal(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2,
|
||||
BinaryPredicateType predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::equal_impl("Kokkos::equal_view_api_default", ex,
|
||||
KE::cbegin(view1), KE::cend(view1), KE::cbegin(view2),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
bool equal(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2,
|
||||
BinaryPredicateType predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::equal_impl(label, ex, KE::cbegin(view1), KE::cend(view1),
|
||||
KE::cbegin(view2), std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const ExecutionSpace& ex, IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2) {
|
||||
return Impl::equal_impl("Kokkos::equal_iterator_api_default", ex, first1,
|
||||
last1, first2, last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2) {
|
||||
return Impl::equal_impl(label, ex, first1, last1, first2, last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const ExecutionSpace& ex, IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2,
|
||||
BinaryPredicateType predicate) {
|
||||
return Impl::equal_impl("Kokkos::equal_iterator_api_default", ex, first1,
|
||||
last1, first2, last2, std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
IteratorType1, IteratorType2>::value,
|
||||
bool>
|
||||
equal(const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2,
|
||||
BinaryPredicateType predicate) {
|
||||
return Impl::equal_impl(label, ex, first1, last1, first2, last2,
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,190 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_EXCLUSIVE_SCAN_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_EXCLUSIVE_SCAN_HPP
|
||||
|
||||
#include "impl/Kokkos_ExclusiveScan.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
exclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
ValueType init_value) {
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::exclusive_scan_default_op_impl(
|
||||
"Kokkos::exclusive_scan_default_functors_iterator_api", ex, first, last,
|
||||
first_dest, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
exclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, ValueType init_value) {
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::exclusive_scan_default_op_impl(label, ex, first, last,
|
||||
first_dest, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto exclusive_scan(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::exclusive_scan_default_op_impl(
|
||||
"Kokkos::exclusive_scan_default_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto exclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::exclusive_scan_default_op_impl(label, ex, KE::cbegin(view_from),
|
||||
KE::cend(view_from),
|
||||
KE::begin(view_dest), init_value);
|
||||
}
|
||||
|
||||
// overload set 2
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType, class BinaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
exclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
ValueType init_value, BinaryOpType bop) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::exclusive_scan_custom_op_impl(
|
||||
"Kokkos::exclusive_scan_custom_functors_iterator_api", ex, first, last,
|
||||
first_dest, init_value, bop);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType, class BinaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
exclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, ValueType init_value,
|
||||
BinaryOpType bop) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::exclusive_scan_custom_op_impl(label, ex, first, last, first_dest,
|
||||
init_value, bop);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType,
|
||||
class BinaryOpType>
|
||||
auto exclusive_scan(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value, BinaryOpType bop) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::exclusive_scan_custom_op_impl(
|
||||
"Kokkos::exclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
init_value, bop);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType,
|
||||
class BinaryOpType>
|
||||
auto exclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value, BinaryOpType bop) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::exclusive_scan_custom_op_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), init_value, bop);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
86
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Fill.hpp
Normal file
86
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Fill.hpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FILL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FILL_HPP
|
||||
|
||||
#include "impl/Kokkos_FillFillN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
void fill(const ExecutionSpace& ex, IteratorType first, IteratorType last,
|
||||
const T& value) {
|
||||
Impl::fill_impl("Kokkos::fill_iterator_api_default", ex, first, last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
void fill(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, const T& value) {
|
||||
Impl::fill_impl(label, ex, first, last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
void fill(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
Impl::fill_impl("Kokkos::fill_view_api_default", ex, begin(view), end(view),
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
void fill(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
Impl::fill_impl(label, ex, begin(view), end(view), value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FillN.hpp
Normal file
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FillN.hpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FILL_N_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FILL_N_HPP
|
||||
|
||||
#include "impl/Kokkos_FillFillN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType, class T>
|
||||
IteratorType fill_n(const ExecutionSpace& ex, IteratorType first, SizeType n,
|
||||
const T& value) {
|
||||
return Impl::fill_n_impl("Kokkos::fill_n_iterator_api_default", ex, first, n,
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType, class T>
|
||||
IteratorType fill_n(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, SizeType n, const T& value) {
|
||||
return Impl::fill_n_impl(label, ex, first, n, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class T>
|
||||
auto fill_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, SizeType n,
|
||||
const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
return Impl::fill_n_impl("Kokkos::fill_n_view_api_default", ex, begin(view),
|
||||
n, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class T>
|
||||
auto fill_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, SizeType n,
|
||||
const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
return Impl::fill_n_impl(label, ex, begin(view), n, value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
89
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Find.hpp
Normal file
89
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Find.hpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_HPP
|
||||
|
||||
#include "impl/Kokkos_FindIfOrNot.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class T>
|
||||
InputIterator find(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, const T& value) {
|
||||
return Impl::find_impl("Kokkos::find_iterator_api_default", ex, first, last,
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class T>
|
||||
InputIterator find(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, const T& value) {
|
||||
return Impl::find_impl(label, ex, first, last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
auto find(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_impl("Kokkos::find_view_api_default", ex, KE::begin(view),
|
||||
KE::end(view), value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class T>
|
||||
auto find(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, const T& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_impl(label, ex, KE::begin(view), KE::end(view), value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
149
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindEnd.hpp
Normal file
149
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindEnd.hpp
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_END_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_END_HPP
|
||||
|
||||
#include "impl/Kokkos_FindEnd.hpp"
|
||||
#include "Kokkos_Equal.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1: no binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_end(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last) {
|
||||
return Impl::find_end_impl("Kokkos::find_end_iterator_api_default", ex, first,
|
||||
last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_end(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last) {
|
||||
return Impl::find_end_impl(label, ex, first, last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto find_end(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_end_impl("Kokkos::find_end_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), KE::begin(s_view),
|
||||
KE::end(s_view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto find_end(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_end_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view));
|
||||
}
|
||||
|
||||
// overload set 2: binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_end(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last, const BinaryPredicateType& pred) {
|
||||
return Impl::find_end_impl("Kokkos::find_end_iterator_api_default", ex, first,
|
||||
last, s_first, s_last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_end(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
return Impl::find_end_impl(label, ex, first, last, s_first, s_last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto find_end(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_end_impl("Kokkos::find_end_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), KE::begin(s_view),
|
||||
KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto find_end(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_end_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
150
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindFirstOf.hpp
Normal file
150
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindFirstOf.hpp
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_FIRST_OF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_FIRST_OF_HPP
|
||||
|
||||
#include "impl/Kokkos_FindFirstOf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1: no binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_first_of(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last) {
|
||||
return Impl::find_first_of_impl("Kokkos::find_first_of_iterator_api_default",
|
||||
ex, first, last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_first_of(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last) {
|
||||
return Impl::find_first_of_impl(label, ex, first, last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto find_first_of(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_first_of_impl("Kokkos::find_first_of_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto find_first_of(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_first_of_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view));
|
||||
}
|
||||
|
||||
// overload set 2: binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_first_of(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
return Impl::find_first_of_impl("Kokkos::find_first_of_iterator_api_default",
|
||||
ex, first, last, s_first, s_last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_first_of(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
return Impl::find_first_of_impl(label, ex, first, last, s_first, s_last,
|
||||
pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto find_first_of(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_first_of_impl("Kokkos::find_first_of_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto find_first_of(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_first_of_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
95
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindIf.hpp
Normal file
95
lib/kokkos/algorithms/src/std_algorithms/Kokkos_FindIf.hpp
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_FindIfOrNot.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
IteratorType find_if(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType predicate) {
|
||||
return Impl::find_if_or_not_impl<true>("Kokkos::find_if_iterator_api_default",
|
||||
ex, first, last, std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
IteratorType find_if(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
PredicateType predicate) {
|
||||
return Impl::find_if_or_not_impl<true>(label, ex, first, last,
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto find_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_if_or_not_impl<true>("Kokkos::find_if_view_api_default", ex,
|
||||
KE::begin(v), KE::end(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto find_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_if_or_not_impl<true>(label, ex, KE::begin(v), KE::end(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_IF_NOT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_IF_NOT_HPP
|
||||
|
||||
#include "impl/Kokkos_FindIfOrNot.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
IteratorType find_if_not(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, Predicate predicate) {
|
||||
return Impl::find_if_or_not_impl<false>(
|
||||
"Kokkos::find_if_not_iterator_api_default", ex, first, last,
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
IteratorType find_if_not(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
Predicate predicate) {
|
||||
return Impl::find_if_or_not_impl<false>(label, ex, first, last,
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto find_if_not(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_if_or_not_impl<false>(
|
||||
"Kokkos::find_if_not_view_api_default", ex, KE::begin(v), KE::end(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
auto find_if_not(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::find_if_or_not_impl<false>(label, ex, KE::begin(v), KE::end(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
95
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ForEach.hpp
Normal file
95
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ForEach.hpp
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FOR_EACH_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FOR_EACH_HPP
|
||||
|
||||
#include "impl/Kokkos_ForEachForEachN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryFunctorType>
|
||||
UnaryFunctorType for_each(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
UnaryFunctorType functor) {
|
||||
return Impl::for_each_impl(label, ex, first, last, std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryFunctorType>
|
||||
UnaryFunctorType for_each(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, UnaryFunctorType functor) {
|
||||
return Impl::for_each_impl("Kokkos::for_each_iterator_api_default", ex, first,
|
||||
last, std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class UnaryFunctorType>
|
||||
UnaryFunctorType for_each(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryFunctorType functor) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::for_each_impl(label, ex, KE::begin(v), KE::end(v),
|
||||
std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class UnaryFunctorType>
|
||||
UnaryFunctorType for_each(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryFunctorType functor) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::for_each_impl("Kokkos::for_each_view_api_default", ex,
|
||||
KE::begin(v), KE::end(v), std::move(functor));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
96
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ForEachN.hpp
Normal file
96
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ForEachN.hpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FOR_EACH_N_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FOR_EACH_N_HPP
|
||||
|
||||
#include "impl/Kokkos_ForEachForEachN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class UnaryFunctorType>
|
||||
IteratorType for_each_n(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, SizeType n,
|
||||
UnaryFunctorType functor) {
|
||||
return Impl::for_each_n_impl(label, ex, first, n, std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class UnaryFunctorType>
|
||||
IteratorType for_each_n(const ExecutionSpace& ex, IteratorType first,
|
||||
SizeType n, UnaryFunctorType functor) {
|
||||
return Impl::for_each_n_impl("Kokkos::for_each_n_iterator_api_default", ex,
|
||||
first, n, std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class UnaryFunctorType>
|
||||
auto for_each_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v, SizeType n,
|
||||
UnaryFunctorType functor) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::for_each_n_impl(label, ex, KE::begin(v), n, std::move(functor));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class UnaryFunctorType>
|
||||
auto for_each_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v, SizeType n,
|
||||
UnaryFunctorType functor) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::for_each_n_impl("Kokkos::for_each_n_view_api_default", ex,
|
||||
KE::begin(v), n, std::move(functor));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Generate.hpp
Normal file
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Generate.hpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_GENERATE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_GENERATE_HPP
|
||||
|
||||
#include "impl/Kokkos_GenerateGenerateN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Generator>
|
||||
void generate(const ExecutionSpace& ex, IteratorType first, IteratorType last,
|
||||
Generator g) {
|
||||
Impl::generate_impl("Kokkos::generate_iterator_api_default", ex, first, last,
|
||||
std::move(g));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Generator>
|
||||
void generate(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, Generator g) {
|
||||
Impl::generate_impl(label, ex, first, last, std::move(g));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Generator>
|
||||
void generate(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
Generator g) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
Impl::generate_impl("Kokkos::generate_view_api_default", ex, begin(view),
|
||||
end(view), std::move(g));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Generator>
|
||||
void generate(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
Generator g) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
Impl::generate_impl(label, ex, begin(view), end(view), std::move(g));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_GENERATE_N_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_GENERATE_N_HPP
|
||||
|
||||
#include "impl/Kokkos_GenerateGenerateN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Size, class Generator>
|
||||
IteratorType generate_n(const ExecutionSpace& ex, IteratorType first,
|
||||
Size count, Generator g) {
|
||||
Impl::generate_n_impl("Kokkos::generate_n_iterator_api_default", ex, first,
|
||||
count, std::move(g));
|
||||
return first + count;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Size, class Generator>
|
||||
IteratorType generate_n(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, Size count, Generator g) {
|
||||
Impl::generate_n_impl(label, ex, first, count, std::move(g));
|
||||
return first + count;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class Size,
|
||||
class Generator>
|
||||
auto generate_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, Size count,
|
||||
Generator g) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
return Impl::generate_n_impl("Kokkos::generate_n_view_api_default", ex,
|
||||
begin(view), count, std::move(g));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties, class Size,
|
||||
class Generator>
|
||||
auto generate_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view, Size count,
|
||||
Generator g) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
return Impl::generate_n_impl(label, ex, begin(view), count, std::move(g));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,223 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_INCLUSIVE_SCAN_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_INCLUSIVE_SCAN_HPP
|
||||
|
||||
#include "impl/Kokkos_InclusiveScan.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest) {
|
||||
return Impl::inclusive_scan_default_op_impl(
|
||||
"Kokkos::inclusive_scan_default_functors_iterator_api", ex, first, last,
|
||||
first_dest);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest) {
|
||||
return Impl::inclusive_scan_default_op_impl(label, ex, first, last,
|
||||
first_dest);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto inclusive_scan(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_default_op_impl(
|
||||
"Kokkos::inclusive_scan_default_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto inclusive_scan(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_default_op_impl(label, ex, KE::cbegin(view_from),
|
||||
KE::cend(view_from),
|
||||
KE::begin(view_dest));
|
||||
}
|
||||
|
||||
// overload set 2 (accepting custom binary op)
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
BinaryOp binary_op) {
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
"Kokkos::inclusive_scan_custom_functors_iterator_api", ex, first, last,
|
||||
first_dest, binary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, BinaryOp binary_op) {
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(label, ex, first, last,
|
||||
first_dest, binary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOp>
|
||||
auto inclusive_scan(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOp binary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
"Kokkos::inclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
binary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOp>
|
||||
auto inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOp binary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), binary_op);
|
||||
}
|
||||
|
||||
// overload set 3
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp, class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
BinaryOp binary_op, ValueType init_value) {
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
"Kokkos::inclusive_scan_custom_functors_iterator_api", ex, first, last,
|
||||
first_dest, binary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp, class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, BinaryOp binary_op,
|
||||
ValueType init_value) {
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
label, ex, first, last, first_dest, binary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOp,
|
||||
class ValueType>
|
||||
auto inclusive_scan(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOp binary_op, ValueType init_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
"Kokkos::inclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
binary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOp,
|
||||
class ValueType>
|
||||
auto inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOp binary_op, ValueType init_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::inclusive_scan_custom_binary_op_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), binary_op, init_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,92 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_PARTITIONED_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_PARTITIONED_HPP
|
||||
|
||||
#include "impl/Kokkos_IsPartitioned.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType p) {
|
||||
return Impl::is_partitioned_impl(
|
||||
"Kokkos::is_partitioned_iterator_api_default", ex, first, last,
|
||||
std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, PredicateType p) {
|
||||
return Impl::is_partitioned_impl(label, ex, first, last, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class PredicateType, class DataType,
|
||||
class... Properties>
|
||||
bool is_partitioned(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
PredicateType p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::is_partitioned_impl("Kokkos::is_partitioned_view_api_default",
|
||||
ex, cbegin(v), cend(v), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class PredicateType, class DataType,
|
||||
class... Properties>
|
||||
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
PredicateType p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::is_partitioned_impl(label, ex, cbegin(v), cend(v), std::move(p));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
131
lib/kokkos/algorithms/src/std_algorithms/Kokkos_IsSorted.hpp
Normal file
131
lib/kokkos/algorithms/src/std_algorithms/Kokkos_IsSorted.hpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_SORTED_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_SORTED_HPP
|
||||
|
||||
#include "impl/Kokkos_IsSorted.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
|
||||
first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::is_sorted_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
bool is_sorted(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
|
||||
KE::cbegin(view), KE::cend(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted(const ExecutionSpace& ex, IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
|
||||
first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_impl(label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
bool is_sorted(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
|
||||
KE::cbegin(view), KE::cend(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,134 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_SORTED_UNTIL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_SORTED_UNTIL_HPP
|
||||
|
||||
#include "impl/Kokkos_IsSortedUntil.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::is_sorted_until_impl(
|
||||
"Kokkos::is_sorted_until_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::is_sorted_until_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto is_sorted_until(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl("Kokkos::is_sorted_until_view_api_default",
|
||||
ex, KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl(label, ex, KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_until_impl(
|
||||
"Kokkos::is_sorted_until_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::is_sorted_until_impl(label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
auto is_sorted_until(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl("Kokkos::is_sorted_until_view_api_default",
|
||||
ex, KE::begin(view), KE::end(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
auto is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,38 +42,17 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_MODIFYING_OPERATIONS_HPP
|
||||
#define KOKKOS_MODIFYING_OPERATIONS_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ITER_SWAP_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ITER_SWAP_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "impl/Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_Swap.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// move
|
||||
template <typename T>
|
||||
KOKKOS_INLINE_FUNCTION std::remove_reference_t<T>&& move(T&& t) {
|
||||
return static_cast<std::remove_reference_t<T>&&>(t);
|
||||
}
|
||||
|
||||
// swap
|
||||
template <class T>
|
||||
KOKKOS_INLINE_FUNCTION void swap(T& a, T& b) noexcept {
|
||||
static_assert(
|
||||
std::is_move_assignable<T>::value && std::is_move_constructible<T>::value,
|
||||
"Kokkos::Experimental::swap arguments must be move assignable "
|
||||
"and move constructible");
|
||||
|
||||
T tmp = std::move(a);
|
||||
a = std::move(b);
|
||||
b = std::move(tmp);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// this is here because we use the swap function above
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType1, class IteratorType2>
|
||||
struct StdIterSwapFunctor {
|
||||
IteratorType1 m_a;
|
||||
@ -0,0 +1,154 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_LEXICOGRAPHICAL_COMPARE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_LEXICOGRAPHICAL_COMPARE_HPP
|
||||
|
||||
#include "impl/Kokkos_LexicographicalCompare.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
bool lexicographical_compare(const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2,
|
||||
IteratorType2 last2) {
|
||||
return Impl::lexicographical_compare_impl(
|
||||
"Kokkos::lexicographical_compare_iterator_api_default", ex, first1, last1,
|
||||
first2, last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
bool lexicographical_compare(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2) {
|
||||
return Impl::lexicographical_compare_impl(label, ex, first1, last1, first2,
|
||||
last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
bool lexicographical_compare(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::lexicographical_compare_impl(
|
||||
"Kokkos::lexicographical_compare_view_api_default", ex, KE::cbegin(view1),
|
||||
KE::cend(view1), KE::cbegin(view2), KE::cend(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
bool lexicographical_compare(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::lexicographical_compare_impl(label, ex, KE::cbegin(view1),
|
||||
KE::cend(view1), KE::cbegin(view2),
|
||||
KE::cend(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class ComparatorType>
|
||||
bool lexicographical_compare(const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2,
|
||||
IteratorType2 last2, ComparatorType comp) {
|
||||
return Impl::lexicographical_compare_impl(
|
||||
"Kokkos::lexicographical_compare_iterator_api_default", ex, first1, last1,
|
||||
first2, last2, comp);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class ComparatorType>
|
||||
bool lexicographical_compare(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2,
|
||||
ComparatorType comp) {
|
||||
return Impl::lexicographical_compare_impl(label, ex, first1, last1, first2,
|
||||
last2, comp);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ComparatorType>
|
||||
bool lexicographical_compare(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2, ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::lexicographical_compare_impl(
|
||||
"Kokkos::lexicographical_compare_view_api_default", ex, KE::cbegin(view1),
|
||||
KE::cend(view1), KE::cbegin(view2), KE::cend(view2), comp);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ComparatorType>
|
||||
bool lexicographical_compare(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
::Kokkos::View<DataType2, Properties2...>& view2, ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::lexicographical_compare_impl(label, ex, KE::cbegin(view1),
|
||||
KE::cend(view1), KE::cbegin(view2),
|
||||
KE::cend(view2), comp);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
132
lib/kokkos/algorithms/src/std_algorithms/Kokkos_MaxElement.hpp
Normal file
132
lib/kokkos/algorithms/src/std_algorithms/Kokkos_MaxElement.hpp
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MAX_ELEMENT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MAX_ELEMENT_HPP
|
||||
|
||||
#include "impl/Kokkos_MinMaxMinmaxElement.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto max_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(
|
||||
"Kokkos::max_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto max_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
"Kokkos::max_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto max_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(
|
||||
"Kokkos::max_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto max_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
"Kokkos::max_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
132
lib/kokkos/algorithms/src/std_algorithms/Kokkos_MinElement.hpp
Normal file
132
lib/kokkos/algorithms/src/std_algorithms/Kokkos_MinElement.hpp
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MIN_ELEMENT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MIN_ELEMENT_HPP
|
||||
|
||||
#include "impl/Kokkos_MinMaxMinmaxElement.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto min_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(
|
||||
"Kokkos::min_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto min_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
"Kokkos::min_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto min_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(
|
||||
"Kokkos::min_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto min_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
"Kokkos::min_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,133 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MINMAX_ELEMENT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MINMAX_ELEMENT_HPP
|
||||
|
||||
#include "impl/Kokkos_MinMaxMinmaxElement.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto minmax_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(
|
||||
"Kokkos::minmax_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto minmax_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
"Kokkos::minmax_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto minmax_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(
|
||||
"Kokkos::minmax_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto minmax_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
"Kokkos::minmax_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -1,409 +0,0 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_MIN_MAX_ELEMENT_OPERATIONS_HPP
|
||||
#define KOKKOS_STD_MIN_MAX_ELEMENT_OPERATIONS_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_Distance.hpp"
|
||||
#include "Kokkos_ModifyingOperations.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class ReducerType>
|
||||
struct StdMinOrMaxElemFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
m_reducer.join(red_value, red_value_type{m_first[i], i});
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdMinOrMaxElemFunctor(IteratorType first, ReducerType reducer)
|
||||
: m_first(std::move(first)), m_reducer(std::move(reducer)) {}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ReducerType>
|
||||
struct StdMinMaxElemFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
const auto& my_value = m_first[i];
|
||||
m_reducer.join(red_value, red_value_type{my_value, my_value, i, i});
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdMinMaxElemFunctor(IteratorType first, ReducerType reducer)
|
||||
: m_first(std::move(first)), m_reducer(std::move(reducer)) {}
|
||||
};
|
||||
|
||||
// ------------------------------------------
|
||||
// min_or_max_element_impl
|
||||
// ------------------------------------------
|
||||
template <template <class... Args> class ReducerType, class ExecutionSpace,
|
||||
class IteratorType, class... Args>
|
||||
IteratorType min_or_max_element_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
Args&&... args) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using reducer_type = ReducerType<value_type, index_type, Args...>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdMinOrMaxElemFunctor<IteratorType, reducer_type>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result, std::forward<Args>(args)...);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// return
|
||||
return first + red_result.loc;
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// minmax_element_impl
|
||||
// ------------------------------------------
|
||||
template <template <class... Args> class ReducerType, class ExecutionSpace,
|
||||
class IteratorType, class... Args>
|
||||
::Kokkos::pair<IteratorType, IteratorType> minmax_element_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, Args&&... args) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return {first, first};
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using reducer_type = ReducerType<value_type, index_type, Args...>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdMinMaxElemFunctor<IteratorType, reducer_type>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result, std::forward<Args>(args)...);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// return
|
||||
return {first + red_result.min_loc, first + red_result.max_loc};
|
||||
}
|
||||
|
||||
} // end namespace Impl
|
||||
|
||||
// ----------------------
|
||||
// min_element public API
|
||||
// ----------------------
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto min_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(
|
||||
"Kokkos::min_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto min_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
"Kokkos::min_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto min_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(
|
||||
"Kokkos::min_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto min_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
"Kokkos::min_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto min_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MinFirstLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// max_element public API
|
||||
// ----------------------
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto max_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(
|
||||
"Kokkos::max_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto max_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
"Kokkos::max_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto max_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(
|
||||
"Kokkos::max_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto max_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
"Kokkos::max_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto max_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::min_or_max_element_impl<MaxFirstLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// minmax_element public API
|
||||
// -------------------------
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto minmax_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(
|
||||
"Kokkos::minmax_element_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto minmax_element(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
"Kokkos::minmax_element_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto minmax_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(
|
||||
"Kokkos::minmax_element_view_api_default", ex, begin(v), end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLoc>(label, ex, begin(v),
|
||||
end(v));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto minmax_element(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
"Kokkos::minmax_element_view_api_default", ex, begin(v), end(v),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class ComparatorType,
|
||||
class... Properties>
|
||||
auto minmax_element(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::minmax_element_impl<MinMaxFirstLastLocCustomComparator>(
|
||||
label, ex, begin(v), end(v), std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
160
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Mismatch.hpp
Normal file
160
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Mismatch.hpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MISMATCH_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MISMATCH_HPP
|
||||
|
||||
#include "impl/Kokkos_Mismatch.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// FIXME: add mismatch overloads accepting 3 iterators.
|
||||
// An overload consistent with other algorithms:
|
||||
//
|
||||
// auto mismatch(const ExecSpace& ex, It1 first1, It1 last1, It2 first2) {...}
|
||||
//
|
||||
// makes API ambiguous (with the overload accepting views).
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch(const ExecutionSpace& ex,
|
||||
IteratorType1 first1,
|
||||
IteratorType1 last1,
|
||||
IteratorType2 first2,
|
||||
IteratorType2 last2) {
|
||||
return Impl::mismatch_impl("Kokkos::mismatch_iterator_api_default", ex,
|
||||
first1, last1, first2, last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch(
|
||||
const ExecutionSpace& ex, IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2,
|
||||
BinaryPredicateType&& predicate) {
|
||||
return Impl::mismatch_impl("Kokkos::mismatch_iterator_api_default", ex,
|
||||
first1, last1, first2, last2,
|
||||
std::forward<BinaryPredicateType>(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2) {
|
||||
return Impl::mismatch_impl(label, ex, first1, last1, first2, last2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2,
|
||||
BinaryPredicateType&& predicate) {
|
||||
return Impl::mismatch_impl(label, ex, first1, last1, first2, last2,
|
||||
std::forward<BinaryPredicateType>(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto mismatch(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::mismatch_impl("Kokkos::mismatch_view_api_default", ex,
|
||||
KE::begin(view1), KE::end(view1), KE::begin(view2),
|
||||
KE::end(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto mismatch(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view2,
|
||||
BinaryPredicateType&& predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::mismatch_impl("Kokkos::mismatch_view_api_default", ex,
|
||||
KE::begin(view1), KE::end(view1), KE::begin(view2),
|
||||
KE::end(view2),
|
||||
std::forward<BinaryPredicateType>(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto mismatch(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view2) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::mismatch_impl(label, ex, KE::begin(view1), KE::end(view1),
|
||||
KE::begin(view2), KE::end(view2));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto mismatch(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view2,
|
||||
BinaryPredicateType&& predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view2);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::mismatch_impl(label, ex, KE::begin(view1), KE::end(view1),
|
||||
KE::begin(view2), KE::end(view2),
|
||||
std::forward<BinaryPredicateType>(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Move.hpp
Normal file
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Move.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MOVE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MOVE_HPP
|
||||
|
||||
#include "impl/Kokkos_Move.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator move(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, OutputIterator d_first) {
|
||||
return Impl::move_impl("Kokkos::move_iterator_api_default", ex, first, last,
|
||||
d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator move(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
return Impl::move_impl(label, ex, first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto move(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::move_impl("Kokkos::move_view_api_default", ex, begin(source),
|
||||
end(source), begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto move(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::move_impl(label, ex, begin(source), end(source), begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,95 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MOVE_BACKWARD_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MOVE_BACKWARD_HPP
|
||||
|
||||
#include "impl/Kokkos_MoveBackward.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 move_backward(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 d_last) {
|
||||
return Impl::move_backward_impl("Kokkos::move_backward_iterator_api_default",
|
||||
ex, first, last, d_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto move_backward(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::move_backward_impl("Kokkos::move_backward_view_api_default", ex,
|
||||
begin(source), end(source), end(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 move_backward(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 d_last) {
|
||||
return Impl::move_backward_impl(label, ex, first, last, d_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto move_backward(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::move_backward_impl(label, ex, begin(source), end(source),
|
||||
end(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_NoneOf.hpp
Normal file
94
lib/kokkos/algorithms/src/std_algorithms/Kokkos_NoneOf.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_NONE_OF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_NONE_OF_HPP
|
||||
|
||||
#include "impl/Kokkos_AllOfAnyOfNoneOf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
bool none_of(const ExecutionSpace& ex, IteratorType first, IteratorType last,
|
||||
Predicate predicate) {
|
||||
return Impl::none_of_impl("Kokkos::none_of_iterator_api_default", ex, first,
|
||||
last, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
bool none_of(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, Predicate predicate) {
|
||||
return Impl::none_of_impl(label, ex, first, last, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool none_of(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::none_of_impl("Kokkos::none_of_view_api_default", ex,
|
||||
KE::cbegin(v), KE::cend(v), std::move(predicate));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class Predicate>
|
||||
bool none_of(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
Predicate predicate) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::none_of_impl(label, ex, KE::cbegin(v), KE::cend(v),
|
||||
std::move(predicate));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,110 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_PARTITION_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_PARTITION_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_PartitionCopy.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorTrueType, class OutputIteratorFalseType,
|
||||
class PredicateType>
|
||||
::Kokkos::pair<OutputIteratorTrueType, OutputIteratorFalseType> partition_copy(
|
||||
const ExecutionSpace& ex, InputIteratorType from_first,
|
||||
InputIteratorType from_last, OutputIteratorTrueType to_first_true,
|
||||
OutputIteratorFalseType to_first_false, PredicateType p) {
|
||||
return Impl::partition_copy_impl(
|
||||
"Kokkos::partition_copy_iterator_api_default", ex, from_first, from_last,
|
||||
to_first_true, to_first_false, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorTrueType, class OutputIteratorFalseType,
|
||||
class PredicateType>
|
||||
::Kokkos::pair<OutputIteratorTrueType, OutputIteratorFalseType> partition_copy(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType from_first, InputIteratorType from_last,
|
||||
OutputIteratorTrueType to_first_true,
|
||||
OutputIteratorFalseType to_first_false, PredicateType p) {
|
||||
return Impl::partition_copy_impl(label, ex, from_first, from_last,
|
||||
to_first_true, to_first_false, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class PredicateType>
|
||||
auto partition_copy(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest_true,
|
||||
const ::Kokkos::View<DataType3, Properties3...>& view_dest_false,
|
||||
PredicateType p) {
|
||||
return Impl::partition_copy_impl("Kokkos::partition_copy_view_api_default",
|
||||
ex, cbegin(view_from), cend(view_from),
|
||||
begin(view_dest_true),
|
||||
begin(view_dest_false), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class PredicateType>
|
||||
auto partition_copy(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest_true,
|
||||
const ::Kokkos::View<DataType3, Properties3...>& view_dest_false,
|
||||
PredicateType p) {
|
||||
return Impl::partition_copy_impl(label, ex, cbegin(view_from),
|
||||
cend(view_from), begin(view_dest_true),
|
||||
begin(view_dest_false), std::move(p));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_PARTITION_POINT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_PARTITION_POINT_HPP
|
||||
|
||||
#include "impl/Kokkos_PartitionPoint.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryPredicate>
|
||||
IteratorType partition_point(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, UnaryPredicate p) {
|
||||
return Impl::partition_point_impl(
|
||||
"Kokkos::partitioned_point_iterator_api_default", ex, first, last,
|
||||
std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryPredicate>
|
||||
IteratorType partition_point(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
UnaryPredicate p) {
|
||||
return Impl::partition_point_impl(label, ex, first, last, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class UnaryPredicate, class DataType,
|
||||
class... Properties>
|
||||
auto partition_point(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryPredicate p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
return Impl::partition_point_impl(label, ex, begin(v), end(v), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class UnaryPredicate, class DataType,
|
||||
class... Properties>
|
||||
auto partition_point(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryPredicate p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
return Impl::partition_point_impl("Kokkos::partition_point_view_api_default",
|
||||
ex, begin(v), end(v), std::move(p));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -1,491 +0,0 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_PARTITIONING_OPERATIONS_HPP
|
||||
#define KOKKOS_STD_PARTITIONING_OPERATIONS_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_ModifyingOperations.hpp"
|
||||
#include "Kokkos_NonModifyingSequenceOperations.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
// -------------------------
|
||||
//
|
||||
// functors
|
||||
//
|
||||
// -------------------------
|
||||
|
||||
template <class IteratorType, class ReducerType, class PredicateType>
|
||||
struct StdIsPartitionedFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& redValue) const {
|
||||
const auto predicate_value = m_p(m_first[i]);
|
||||
constexpr index_type m_red_id_min =
|
||||
::Kokkos::reduction_identity<index_type>::min();
|
||||
constexpr index_type m_red_id_max =
|
||||
::Kokkos::reduction_identity<index_type>::max();
|
||||
auto rv = predicate_value ? red_value_type{i, m_red_id_min}
|
||||
: red_value_type{m_red_id_max, i};
|
||||
|
||||
m_reducer.join(redValue, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsPartitionedFunctor(IteratorType first, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ReducerType, class PredicateType>
|
||||
struct StdPartitionPointFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& redValue) const {
|
||||
const auto predicate_value = m_p(m_first[i]);
|
||||
auto rv =
|
||||
predicate_value
|
||||
? red_value_type{::Kokkos::reduction_identity<index_type>::min()}
|
||||
: red_value_type{i};
|
||||
m_reducer.join(redValue, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdPartitionPointFunctor(IteratorType first, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct StdPartitionCopyScalar {
|
||||
ValueType true_count_;
|
||||
ValueType false_count_;
|
||||
|
||||
// Here we implement the copy assignment operators explicitly for consistency
|
||||
// with how the Scalar structs are implemented inside
|
||||
// Kokkos_Parallel_Reduce.hpp.
|
||||
KOKKOS_FUNCTION
|
||||
void operator=(const StdPartitionCopyScalar& other) {
|
||||
true_count_ = other.true_count_;
|
||||
false_count_ = other.false_count_;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator=(const volatile StdPartitionCopyScalar& other) volatile {
|
||||
true_count_ = other.true_count_;
|
||||
false_count_ = other.false_count_;
|
||||
}
|
||||
|
||||
// this is needed for
|
||||
// OpenMPTarget/Kokkos_OpenMPTarget_Parallel.hpp:699:21: error: no viable
|
||||
// overloaded '=' m_returnvalue = 0;
|
||||
//
|
||||
KOKKOS_FUNCTION
|
||||
void operator=(const ValueType value) {
|
||||
true_count_ = value;
|
||||
false_count_ = value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class IndexType, class FirstFrom, class FirstDestTrue,
|
||||
class FirstDestFalse, class PredType>
|
||||
struct StdPartitionCopyFunctor {
|
||||
using value_type = StdPartitionCopyScalar<IndexType>;
|
||||
|
||||
FirstFrom m_first_from;
|
||||
FirstDestTrue m_first_dest_true;
|
||||
FirstDestFalse m_first_dest_false;
|
||||
PredType m_pred;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdPartitionCopyFunctor(FirstFrom first_from, FirstDestTrue first_dest_true,
|
||||
FirstDestFalse first_dest_false, PredType pred)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest_true(std::move(first_dest_true)),
|
||||
m_first_dest_false(std::move(first_dest_false)),
|
||||
m_pred(std::move(pred)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, value_type& update,
|
||||
const bool final_pass) const {
|
||||
const auto& myval = m_first_from[i];
|
||||
if (final_pass) {
|
||||
if (m_pred(myval)) {
|
||||
m_first_dest_true[update.true_count_] = myval;
|
||||
} else {
|
||||
m_first_dest_false[update.false_count_] = myval;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pred(myval)) {
|
||||
update.true_count_ += 1;
|
||||
} else {
|
||||
update.false_count_ += 1;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void init(value_type& update) const {
|
||||
update.true_count_ = 0;
|
||||
update.false_count_ = 0;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void join(volatile value_type& update,
|
||||
volatile const value_type& input) const {
|
||||
update.true_count_ += input.true_count_;
|
||||
update.false_count_ += input.false_count_;
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------
|
||||
// is_partitioned_impl
|
||||
// ------------------------------------------
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
PredicateType pred) {
|
||||
// true if all elements in the range [first, last) that satisfy
|
||||
// the predicate "pred" appear before all elements that don't.
|
||||
// Also returns true if [first, last) is empty.
|
||||
// also true if all elements satisfy the predicate.
|
||||
|
||||
// we implement it by finding:
|
||||
// - the max location where predicate is true (max_loc_true)
|
||||
// - the min location where predicate is false (min_loc_false)
|
||||
// so the range is partitioned if max_loc_true < (min_loc_false)
|
||||
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// trivial case
|
||||
if (first == last) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using reducer_type = StdIsPartitioned<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t =
|
||||
StdIsPartitionedFunctor<IteratorType, reducer_type, PredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
constexpr index_type red_id_min =
|
||||
::Kokkos::reduction_identity<index_type>::min();
|
||||
constexpr index_type red_id_max =
|
||||
::Kokkos::reduction_identity<index_type>::max();
|
||||
|
||||
if (red_result.max_loc_true != red_id_max &&
|
||||
red_result.min_loc_false != red_id_min) {
|
||||
return red_result.max_loc_true < red_result.min_loc_false;
|
||||
} else if (first + red_result.max_loc_true == --last) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// partition_point_impl
|
||||
// ------------------------------------------
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
IteratorType partition_point_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType pred) {
|
||||
// locates the end of the first partition, that is, the first
|
||||
// element that does not satisfy p or last if all elements satisfy p.
|
||||
// Implementation below finds the first location where p is false.
|
||||
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return first;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using reducer_type = StdPartitionPoint<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t =
|
||||
StdPartitionPointFunctor<IteratorType, reducer_type, PredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
if (red_result.min_loc_false ==
|
||||
::Kokkos::reduction_identity<index_type>::min()) {
|
||||
// if all elements are true, return last
|
||||
return last;
|
||||
} else {
|
||||
return first + red_result.min_loc_false;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// partition_copy_impl
|
||||
// ------------------------------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorTrueType, class OutputIteratorFalseType,
|
||||
class PredicateType>
|
||||
::Kokkos::pair<OutputIteratorTrueType, OutputIteratorFalseType>
|
||||
partition_copy_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType from_first, InputIteratorType from_last,
|
||||
OutputIteratorTrueType to_first_true,
|
||||
OutputIteratorFalseType to_first_false,
|
||||
PredicateType pred) {
|
||||
// impl uses a scan, this is similar how we implemented copy_if
|
||||
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(
|
||||
ex, from_first, to_first_true, to_first_false);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(
|
||||
from_first, to_first_true, to_first_false);
|
||||
Impl::expect_valid_range(from_first, from_last);
|
||||
|
||||
if (from_first == from_last) {
|
||||
return {to_first_true, to_first_false};
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using func_type =
|
||||
StdPartitionCopyFunctor<index_type, InputIteratorType,
|
||||
OutputIteratorTrueType, OutputIteratorFalseType,
|
||||
PredicateType>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(from_first, from_last);
|
||||
typename func_type::value_type counts{0, 0};
|
||||
::Kokkos::parallel_scan(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(from_first, to_first_true, to_first_false, pred), counts);
|
||||
|
||||
// fence not needed here because of the scan into counts
|
||||
|
||||
return {to_first_true + counts.true_count_,
|
||||
to_first_false + counts.false_count_};
|
||||
}
|
||||
|
||||
} // end namespace Impl
|
||||
|
||||
// ----------------------
|
||||
// is_partitioned public API
|
||||
// ----------------------
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType p) {
|
||||
return Impl::is_partitioned_impl(
|
||||
"Kokkos::is_partitioned_iterator_api_default", ex, first, last,
|
||||
std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, PredicateType p) {
|
||||
return Impl::is_partitioned_impl(label, ex, first, last, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class PredicateType, class DataType,
|
||||
class... Properties>
|
||||
bool is_partitioned(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
PredicateType p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::is_partitioned_impl("Kokkos::is_partitioned_view_api_default",
|
||||
ex, cbegin(v), cend(v), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class PredicateType, class DataType,
|
||||
class... Properties>
|
||||
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
PredicateType p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
|
||||
return Impl::is_partitioned_impl(label, ex, cbegin(v), cend(v), std::move(p));
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// partition_copy
|
||||
// ----------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorTrueType, class OutputIteratorFalseType,
|
||||
class PredicateType>
|
||||
::Kokkos::pair<OutputIteratorTrueType, OutputIteratorFalseType> partition_copy(
|
||||
const ExecutionSpace& ex, InputIteratorType from_first,
|
||||
InputIteratorType from_last, OutputIteratorTrueType to_first_true,
|
||||
OutputIteratorFalseType to_first_false, PredicateType p) {
|
||||
return Impl::partition_copy_impl(
|
||||
"Kokkos::partition_copy_iterator_api_default", ex, from_first, from_last,
|
||||
to_first_true, to_first_false, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorTrueType, class OutputIteratorFalseType,
|
||||
class PredicateType>
|
||||
::Kokkos::pair<OutputIteratorTrueType, OutputIteratorFalseType> partition_copy(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType from_first, InputIteratorType from_last,
|
||||
OutputIteratorTrueType to_first_true,
|
||||
OutputIteratorFalseType to_first_false, PredicateType p) {
|
||||
return Impl::partition_copy_impl(label, ex, from_first, from_last,
|
||||
to_first_true, to_first_false, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class PredicateType>
|
||||
auto partition_copy(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest_true,
|
||||
const ::Kokkos::View<DataType3, Properties3...>& view_dest_false,
|
||||
PredicateType p) {
|
||||
return Impl::partition_copy_impl("Kokkos::partition_copy_view_api_default",
|
||||
ex, cbegin(view_from), cend(view_from),
|
||||
begin(view_dest_true),
|
||||
begin(view_dest_false), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class PredicateType>
|
||||
auto partition_copy(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest_true,
|
||||
const ::Kokkos::View<DataType3, Properties3...>& view_dest_false,
|
||||
PredicateType p) {
|
||||
return Impl::partition_copy_impl(label, ex, cbegin(view_from),
|
||||
cend(view_from), begin(view_dest_true),
|
||||
begin(view_dest_false), std::move(p));
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// partition_point
|
||||
// ----------------------
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryPredicate>
|
||||
IteratorType partition_point(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, UnaryPredicate p) {
|
||||
return Impl::partition_point_impl(
|
||||
"Kokkos::partitioned_point_iterator_api_default", ex, first, last,
|
||||
std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryPredicate>
|
||||
IteratorType partition_point(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
UnaryPredicate p) {
|
||||
return Impl::partition_point_impl(label, ex, first, last, std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class UnaryPredicate, class DataType,
|
||||
class... Properties>
|
||||
auto partition_point(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryPredicate p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
return Impl::partition_point_impl(label, ex, begin(v), end(v), std::move(p));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class UnaryPredicate, class DataType,
|
||||
class... Properties>
|
||||
auto partition_point(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& v,
|
||||
UnaryPredicate p) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
|
||||
return Impl::partition_point_impl("Kokkos::partition_point_view_api_default",
|
||||
ex, begin(v), end(v), std::move(p));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,119 +42,14 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_NUMERICS_REDUCE_HPP
|
||||
#define KOKKOS_STD_NUMERICS_REDUCE_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REDUCE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REDUCE_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "../Kokkos_BeginEnd.hpp"
|
||||
#include "../Kokkos_Constraints.hpp"
|
||||
#include "../Kokkos_Distance.hpp"
|
||||
#include "../Kokkos_ModifyingOperations.hpp"
|
||||
#include "../Kokkos_ReducerWithArbitraryJoinerNoNeutralElement.hpp"
|
||||
#include "impl/Kokkos_Reduce.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class ValueType>
|
||||
struct StdReduceDefaultJoinFunctor {
|
||||
KOKKOS_FUNCTION
|
||||
constexpr ValueType operator()(const ValueType& a, const ValueType& b) const {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
constexpr ValueType operator()(const volatile ValueType& a,
|
||||
const volatile ValueType& b) const {
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ReducerType>
|
||||
struct StdReduceFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
|
||||
const IteratorType m_first;
|
||||
const ReducerType m_reducer;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
auto tmp_wrapped_value = red_value_type{m_first[i], false};
|
||||
|
||||
if (red_value.is_initial) {
|
||||
red_value = tmp_wrapped_value;
|
||||
} else {
|
||||
m_reducer.join(red_value, tmp_wrapped_value);
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdReduceFunctor(IteratorType first, ReducerType reducer)
|
||||
: m_first(std::move(first)), m_reducer(std::move(reducer)) {}
|
||||
};
|
||||
|
||||
//------------------------------
|
||||
// reduce_custom_functors_impl
|
||||
//------------------------------
|
||||
template <class ExecutionSpace, class IteratorType, class ValueType,
|
||||
class JoinerType>
|
||||
ValueType reduce_custom_functors_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ValueType init_reduction_value,
|
||||
JoinerType joiner) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
// init is returned, unmodified
|
||||
return init_reduction_value;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using reducer_type =
|
||||
ReducerWithArbitraryJoinerNoNeutralElement<ValueType, JoinerType>;
|
||||
using functor_type = StdReduceFunctor<IteratorType, reducer_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
|
||||
// run
|
||||
reduction_value_type result;
|
||||
reducer_type reducer(result, joiner);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
functor_type(first, reducer), reducer);
|
||||
|
||||
// fence not needed since reducing into scalar
|
||||
return joiner(result.val, init_reduction_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ValueType>
|
||||
ValueType reduce_default_functors_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ValueType init_reduction_value) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
using value_type = Kokkos::Impl::remove_cvref_t<ValueType>;
|
||||
using joiner_type = Impl::StdReduceDefaultJoinFunctor<value_type>;
|
||||
return reduce_custom_functors_impl(
|
||||
label, ex, first, last, std::move(init_reduction_value), joiner_type());
|
||||
}
|
||||
|
||||
} // end namespace Impl
|
||||
|
||||
///////////////////////////////
|
||||
//
|
||||
// reduce public API
|
||||
//
|
||||
///////////////////////////////
|
||||
|
||||
//
|
||||
// overload set 1
|
||||
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Remove.hpp
Normal file
91
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Remove.hpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REMOVE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REMOVE_HPP
|
||||
|
||||
#include "impl/Kokkos_RemoveAllVariants.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class ValueType>
|
||||
Iterator remove(const ExecutionSpace& ex, Iterator first, Iterator last,
|
||||
const ValueType& value) {
|
||||
return Impl::remove_impl("Kokkos::remove_iterator_api_default", ex, first,
|
||||
last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class ValueType>
|
||||
Iterator remove(const std::string& label, const ExecutionSpace& ex,
|
||||
Iterator first, Iterator last, const ValueType& value) {
|
||||
return Impl::remove_impl(label, ex, first, last, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ValueType>
|
||||
auto remove(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::remove_impl("Kokkos::remove_iterator_api_default", ex,
|
||||
::Kokkos::Experimental::begin(view),
|
||||
::Kokkos::Experimental::end(view), value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ValueType>
|
||||
auto remove(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::remove_impl(label, ex, ::Kokkos::Experimental::begin(view),
|
||||
::Kokkos::Experimental::end(view), value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
106
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveCopy.hpp
Normal file
106
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveCopy.hpp
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REMOVE_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REMOVE_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_RemoveAllVariants.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class ValueType>
|
||||
OutputIterator remove_copy(const ExecutionSpace& ex, InputIterator first_from,
|
||||
InputIterator last_from, OutputIterator first_dest,
|
||||
const ValueType& value) {
|
||||
return Impl::remove_copy_impl("Kokkos::remove_copy_iterator_api_default", ex,
|
||||
first_from, last_from, first_dest, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class ValueType>
|
||||
OutputIterator remove_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first_from, InputIterator last_from,
|
||||
OutputIterator first_dest, const ValueType& value) {
|
||||
return Impl::remove_copy_impl(label, ex, first_from, last_from, first_dest,
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto remove_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
|
||||
return Impl::remove_copy_impl("Kokkos::remove_copy_iterator_api_default", ex,
|
||||
::Kokkos::Experimental::cbegin(view_from),
|
||||
::Kokkos::Experimental::cend(view_from),
|
||||
::Kokkos::Experimental::begin(view_dest),
|
||||
value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto remove_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
|
||||
return Impl::remove_copy_impl(
|
||||
label, ex, ::Kokkos::Experimental::cbegin(view_from),
|
||||
::Kokkos::Experimental::cend(view_from),
|
||||
::Kokkos::Experimental::begin(view_dest), value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
110
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveCopyIf.hpp
Normal file
110
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveCopyIf.hpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REMOVE_COPY_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REMOVE_COPY_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_RemoveAllVariants.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class UnaryPredicate>
|
||||
OutputIterator remove_copy_if(const ExecutionSpace& ex,
|
||||
InputIterator first_from, InputIterator last_from,
|
||||
OutputIterator first_dest,
|
||||
const UnaryPredicate& pred) {
|
||||
return Impl::remove_copy_if_impl(
|
||||
"Kokkos::remove_copy_if_iterator_api_default", ex, first_from, last_from,
|
||||
first_dest, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class UnaryPredicate>
|
||||
OutputIterator remove_copy_if(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
InputIterator first_from, InputIterator last_from,
|
||||
OutputIterator first_dest,
|
||||
const UnaryPredicate& pred) {
|
||||
return Impl::remove_copy_if_impl(label, ex, first_from, last_from, first_dest,
|
||||
pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class UnaryPredicate>
|
||||
auto remove_copy_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const UnaryPredicate& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
|
||||
return Impl::remove_copy_if_impl(
|
||||
"Kokkos::remove_copy_if_iterator_api_default", ex,
|
||||
::Kokkos::Experimental::cbegin(view_from),
|
||||
::Kokkos::Experimental::cend(view_from),
|
||||
::Kokkos::Experimental::begin(view_dest), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class UnaryPredicate>
|
||||
auto remove_copy_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const UnaryPredicate& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
|
||||
return Impl::remove_copy_if_impl(
|
||||
label, ex, ::Kokkos::Experimental::cbegin(view_from),
|
||||
::Kokkos::Experimental::cend(view_from),
|
||||
::Kokkos::Experimental::begin(view_dest), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
92
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveIf.hpp
Normal file
92
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RemoveIf.hpp
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REMOVE_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REMOVE_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_RemoveAllVariants.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class UnaryPredicate>
|
||||
Iterator remove_if(const ExecutionSpace& ex, Iterator first, Iterator last,
|
||||
UnaryPredicate pred) {
|
||||
return Impl::remove_if_impl("Kokkos::remove_if_iterator_api_default", ex,
|
||||
first, last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class UnaryPredicate>
|
||||
Iterator remove_if(const std::string& label, const ExecutionSpace& ex,
|
||||
Iterator first, Iterator last, UnaryPredicate pred) {
|
||||
return Impl::remove_if_impl(label, ex, first, last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class UnaryPredicate>
|
||||
auto remove_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
UnaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
return Impl::remove_if_impl("Kokkos::remove_if_iterator_api_default", ex,
|
||||
::Kokkos::Experimental::begin(view),
|
||||
::Kokkos::Experimental::end(view), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class UnaryPredicate>
|
||||
auto remove_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
UnaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::remove_if_impl(label, ex, ::Kokkos::Experimental::begin(view),
|
||||
::Kokkos::Experimental::end(view), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
93
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Replace.hpp
Normal file
93
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Replace.hpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REPLACE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REPLACE_HPP
|
||||
|
||||
#include "impl/Kokkos_Replace.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class ValueType>
|
||||
void replace(const ExecutionSpace& ex, Iterator first, Iterator last,
|
||||
const ValueType& old_value, const ValueType& new_value) {
|
||||
return Impl::replace_impl("Kokkos::replace_iterator_api", ex, first, last,
|
||||
old_value, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class Iterator, class ValueType>
|
||||
void replace(const std::string& label, const ExecutionSpace& ex, Iterator first,
|
||||
Iterator last, const ValueType& old_value,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_impl(label, ex, first, last, old_value, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class ValueType>
|
||||
void replace(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ValueType& old_value, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_impl("Kokkos::replace_view_api", ex, KE::begin(view),
|
||||
KE::end(view), old_value, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class ValueType>
|
||||
void replace(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ValueType& old_value, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
old_value, new_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
107
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ReplaceCopy.hpp
Normal file
107
lib/kokkos/algorithms/src/std_algorithms/Kokkos_ReplaceCopy.hpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REPLACE_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REPLACE_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_ReplaceCopy.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class ValueType>
|
||||
OutputIterator replace_copy(const ExecutionSpace& ex, InputIterator first_from,
|
||||
InputIterator last_from, OutputIterator first_dest,
|
||||
const ValueType& old_value,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_copy_impl("Kokkos::replace_copy_iterator_api", ex,
|
||||
first_from, last_from, first_dest, old_value,
|
||||
new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class ValueType>
|
||||
OutputIterator replace_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first_from, InputIterator last_from,
|
||||
OutputIterator first_dest,
|
||||
const ValueType& old_value,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_copy_impl(label, ex, first_from, last_from, first_dest,
|
||||
old_value, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto replace_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const ValueType& old_value, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_copy_impl("Kokkos::replace_copy_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), old_value, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType>
|
||||
auto replace_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
const ValueType& old_value, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_copy_impl(label, ex, KE::cbegin(view_from),
|
||||
KE::cend(view_from), KE::begin(view_dest),
|
||||
old_value, new_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,111 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REPLACE_COPY_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REPLACE_COPY_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_ReplaceCopyIf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class PredicateType, class ValueType>
|
||||
OutputIterator replace_copy_if(const ExecutionSpace& ex,
|
||||
InputIterator first_from,
|
||||
InputIterator last_from,
|
||||
OutputIterator first_dest, PredicateType pred,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_copy_if_impl("Kokkos::replace_copy_if_iterator_api", ex,
|
||||
first_from, last_from, first_dest, pred,
|
||||
new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class PredicateType, class ValueType>
|
||||
OutputIterator replace_copy_if(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
InputIterator first_from,
|
||||
InputIterator last_from,
|
||||
OutputIterator first_dest, PredicateType pred,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_copy_if_impl(label, ex, first_from, last_from,
|
||||
first_dest, pred, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class PredicateType,
|
||||
class ValueType>
|
||||
auto replace_copy_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
PredicateType pred, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_copy_if_impl("Kokkos::replace_copy_if_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), pred, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class PredicateType,
|
||||
class ValueType>
|
||||
auto replace_copy_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
PredicateType pred, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_copy_if_impl(label, ex, KE::cbegin(view_from),
|
||||
KE::cend(view_from), KE::begin(view_dest),
|
||||
pred, new_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,96 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REPLACE_IF_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REPLACE_IF_HPP
|
||||
|
||||
#include "impl/Kokkos_ReplaceIf.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate,
|
||||
class ValueType>
|
||||
void replace_if(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, Predicate pred,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_if_impl("Kokkos::replace_if_iterator_api", ex, first,
|
||||
last, pred, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate,
|
||||
class ValueType>
|
||||
void replace_if(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
const ValueType& new_value) {
|
||||
return Impl::replace_if_impl(label, ex, first, last, pred, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class Predicate, class ValueType>
|
||||
void replace_if(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
Predicate pred, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_if_impl("Kokkos::replace_if_view_api", ex,
|
||||
KE::begin(view), KE::end(view), pred, new_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class Predicate, class ValueType>
|
||||
void replace_if(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
Predicate pred, const ValueType& new_value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::replace_if_impl(label, ex, KE::begin(view), KE::end(view), pred,
|
||||
new_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
87
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Reverse.hpp
Normal file
87
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Reverse.hpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REVERSE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REVERSE_HPP
|
||||
|
||||
#include "impl/Kokkos_Reverse.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator>
|
||||
void reverse(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last) {
|
||||
return Impl::reverse_impl("Kokkos::reverse_iterator_api_default", ex, first,
|
||||
last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator>
|
||||
void reverse(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last) {
|
||||
return Impl::reverse_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
void reverse(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::reverse_impl("Kokkos::reverse_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
void reverse(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::reverse_impl(label, ex, KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,95 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_REVERSE_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_REVERSE_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_ReverseCopy.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator reverse_copy(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, OutputIterator d_first) {
|
||||
return Impl::reverse_copy_impl("Kokkos::reverse_copy_iterator_api_default",
|
||||
ex, first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator reverse_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
return Impl::reverse_copy_impl(label, ex, first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto reverse_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::reverse_copy_impl("Kokkos::reverse_copy_view_api_default", ex,
|
||||
cbegin(source), cend(source), begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto reverse_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::reverse_copy_impl(label, ex, cbegin(source), cend(source),
|
||||
begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
89
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Rotate.hpp
Normal file
89
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Rotate.hpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ROTATE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ROTATE_HPP
|
||||
|
||||
#include "impl/Kokkos_Rotate.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType rotate(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType n_first, IteratorType last) {
|
||||
return Impl::rotate_impl("Kokkos::rotate_iterator_api_default", ex, first,
|
||||
n_first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType rotate(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType n_first,
|
||||
IteratorType last) {
|
||||
return Impl::rotate_impl(label, ex, first, n_first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto rotate(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
std::size_t n_location) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::rotate_impl("Kokkos::rotate_view_api_default", ex, begin(view),
|
||||
begin(view) + n_location, end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto rotate(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
std::size_t n_location) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::rotate_impl(label, ex, begin(view), begin(view) + n_location,
|
||||
end(view));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
100
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RotateCopy.hpp
Normal file
100
lib/kokkos/algorithms/src/std_algorithms/Kokkos_RotateCopy.hpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ROTATE_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ROTATE_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_RotateCopy.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator rotate_copy(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator n_first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
return Impl::rotate_copy_impl("Kokkos::rotate_copy_iterator_api_default", ex,
|
||||
first, n_first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator rotate_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator n_first,
|
||||
InputIterator last, OutputIterator d_first) {
|
||||
return Impl::rotate_copy_impl(label, ex, first, n_first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto rotate_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
std::size_t n_location,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::rotate_copy_impl("Kokkos::rotate_copy_view_api_default", ex,
|
||||
cbegin(source), cbegin(source) + n_location,
|
||||
cend(source), begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto rotate_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
std::size_t n_location,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::rotate_copy_impl(label, ex, cbegin(source),
|
||||
cbegin(source) + n_location, cend(source),
|
||||
begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
148
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Search.hpp
Normal file
148
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Search.hpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SEARCH_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SEARCH_HPP
|
||||
|
||||
#include "impl/Kokkos_Search.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1: no binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 search(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last) {
|
||||
return Impl::search_impl("Kokkos::search_iterator_api_default", ex, first,
|
||||
last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 search(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last) {
|
||||
return Impl::search_impl(label, ex, first, last, s_first, s_last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto search(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_impl("Kokkos::search_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), KE::begin(s_view),
|
||||
KE::end(s_view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto search(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view));
|
||||
}
|
||||
|
||||
// overload set 2: binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 search(const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last, const BinaryPredicateType& pred) {
|
||||
return Impl::search_impl("Kokkos::search_iterator_api_default", ex, first,
|
||||
last, s_first, s_last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 search(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
return Impl::search_impl(label, ex, first, last, s_first, s_last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto search(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_impl("Kokkos::search_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), KE::begin(s_view),
|
||||
KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicateType>
|
||||
auto search(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& s_view,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(s_view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
KE::begin(s_view), KE::end(s_view), pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
144
lib/kokkos/algorithms/src/std_algorithms/Kokkos_SearchN.hpp
Normal file
144
lib/kokkos/algorithms/src/std_algorithms/Kokkos_SearchN.hpp
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SEARCH_N_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SEARCH_N_HPP
|
||||
|
||||
#include "impl/Kokkos_SearchN.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1: no binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class ValueType>
|
||||
IteratorType search_n(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, SizeType count,
|
||||
const ValueType& value) {
|
||||
return Impl::search_n_impl("Kokkos::search_n_iterator_api_default", ex, first,
|
||||
last, count, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class ValueType>
|
||||
IteratorType search_n(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, SizeType count,
|
||||
const ValueType& value) {
|
||||
return Impl::search_n_impl(label, ex, first, last, count, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class ValueType>
|
||||
auto search_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
SizeType count, const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_n_impl("Kokkos::search_n_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), count, value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class ValueType>
|
||||
auto search_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
SizeType count, const ValueType& value) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_n_impl(label, ex, KE::begin(view), KE::end(view), count,
|
||||
value);
|
||||
}
|
||||
|
||||
// overload set 2: binary predicate passed
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class ValueType, class BinaryPredicateType>
|
||||
IteratorType search_n(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, SizeType count, const ValueType& value,
|
||||
const BinaryPredicateType& pred) {
|
||||
return Impl::search_n_impl("Kokkos::search_n_iterator_api_default", ex, first,
|
||||
last, count, value, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class ValueType, class BinaryPredicateType>
|
||||
IteratorType search_n(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, SizeType count,
|
||||
const ValueType& value, const BinaryPredicateType& pred) {
|
||||
return Impl::search_n_impl(label, ex, first, last, count, value, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class ValueType, class BinaryPredicateType>
|
||||
auto search_n(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
SizeType count, const ValueType& value,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_n_impl("Kokkos::search_n_view_api_default", ex,
|
||||
KE::begin(view), KE::end(view), count, value,
|
||||
pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class SizeType, class ValueType, class BinaryPredicateType>
|
||||
auto search_n(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
SizeType count, const ValueType& value,
|
||||
const BinaryPredicateType& pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::search_n_impl(label, ex, KE::begin(view), KE::end(view), count,
|
||||
value, pred);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SHIFT_LEFT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SHIFT_LEFT_HPP
|
||||
|
||||
#include "impl/Kokkos_ShiftLeft.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType shift_left(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last,
|
||||
typename IteratorType::difference_type n) {
|
||||
return Impl::shift_left_impl("Kokkos::shift_left_iterator_api_default", ex,
|
||||
first, last, n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType shift_left(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
typename IteratorType::difference_type n) {
|
||||
return Impl::shift_left_impl(label, ex, first, last, n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto shift_left(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
typename decltype(begin(view))::difference_type n) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::shift_left_impl("Kokkos::shift_left_view_api_default", ex,
|
||||
begin(view), end(view), n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto shift_left(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
typename decltype(begin(view))::difference_type n) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::shift_left_impl(label, ex, begin(view), end(view), n);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SHIFT_RIGHT_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SHIFT_RIGHT_HPP
|
||||
|
||||
#include "impl/Kokkos_ShiftRight.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType shift_right(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last,
|
||||
typename IteratorType::difference_type n) {
|
||||
return Impl::shift_right_impl("Kokkos::shift_right_iterator_api_default", ex,
|
||||
first, last, n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType shift_right(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
typename IteratorType::difference_type n) {
|
||||
return Impl::shift_right_impl(label, ex, first, last, n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto shift_right(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
typename decltype(begin(view))::difference_type n) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::shift_right_impl("Kokkos::shift_right_view_api_default", ex,
|
||||
begin(view), end(view), n);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto shift_right(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
typename decltype(begin(view))::difference_type n) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::shift_right_impl(label, ex, begin(view), end(view), n);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -1,378 +0,0 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_SORTING_OPERATIONS_HPP
|
||||
#define KOKKOS_STD_SORTING_OPERATIONS_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_NonModifyingSequenceOperations.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
// ------------------
|
||||
//
|
||||
// functors
|
||||
//
|
||||
// ------------------
|
||||
|
||||
template <class IteratorType, class IndicatorViewType, class ComparatorType>
|
||||
struct StdIsSortedUntilFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
IndicatorViewType m_indicator;
|
||||
ComparatorType m_comparator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, int& update, const bool final) const {
|
||||
const auto& val_i = m_first[i];
|
||||
const auto& val_ip1 = m_first[i + 1];
|
||||
|
||||
if (m_comparator(val_ip1, val_i)) {
|
||||
++update;
|
||||
}
|
||||
|
||||
if (final) {
|
||||
m_indicator(i) = update;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsSortedUntilFunctor(IteratorType _first1, IndicatorViewType indicator,
|
||||
ComparatorType comparator)
|
||||
: m_first(std::move(_first1)),
|
||||
m_indicator(std::move(indicator)),
|
||||
m_comparator(std::move(comparator)) {}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ComparatorType>
|
||||
struct StdIsSortedFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
ComparatorType m_comparator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, std::size_t& update) const {
|
||||
const auto& val_i = m_first[i];
|
||||
const auto& val_ip1 = m_first[i + 1];
|
||||
|
||||
if (m_comparator(val_ip1, val_i)) {
|
||||
++update;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsSortedFunctor(IteratorType _first1, ComparatorType comparator)
|
||||
: m_first(std::move(_first1)), m_comparator(std::move(comparator)) {}
|
||||
};
|
||||
|
||||
// ------------------------------------------
|
||||
// is_sorted_until_impl
|
||||
// ------------------------------------------
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
|
||||
// trivial case
|
||||
if (num_elements <= 1) {
|
||||
return last;
|
||||
}
|
||||
|
||||
/*
|
||||
use scan and a helper "indicator" view
|
||||
such that we scan the data and fill the indicator with
|
||||
partial sum that is always 0 unless we find a pair that
|
||||
breaks the sorting, so in that case the indicator will
|
||||
have a 1 starting at the location where the sorting breaks.
|
||||
So finding that 1 means finding the location we want.
|
||||
*/
|
||||
|
||||
// aliases
|
||||
using indicator_value_type = std::size_t;
|
||||
using indicator_view_type =
|
||||
::Kokkos::View<indicator_value_type*, ExecutionSpace>;
|
||||
using functor_type =
|
||||
StdIsSortedUntilFunctor<IteratorType, indicator_view_type,
|
||||
ComparatorType>;
|
||||
|
||||
// do scan
|
||||
// use num_elements-1 because each index handles i and i+1
|
||||
const auto num_elements_minus_one = num_elements - 1;
|
||||
indicator_view_type indicator("is_sorted_until_indicator_helper",
|
||||
num_elements_minus_one);
|
||||
::Kokkos::parallel_scan(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements_minus_one),
|
||||
functor_type(first, indicator, std::move(comp)));
|
||||
|
||||
// try to find the first sentinel value, which indicates
|
||||
// where the sorting condition breaks
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
constexpr indicator_value_type sentinel_value = 1;
|
||||
auto r =
|
||||
KE::find(ex, KE::cbegin(indicator), KE::cend(indicator), sentinel_value);
|
||||
const auto shift = r - ::Kokkos::Experimental::cbegin(indicator);
|
||||
|
||||
return first + (shift + 1);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using pred_t = Impl::StdAlgoLessThanBinaryPredicate<value_type>;
|
||||
return is_sorted_until_impl(label, ex, first, last, pred_t());
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// is_sorted_impl
|
||||
// ------------------------------------------
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
if (num_elements <= 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// use num_elements-1 because each index handles i and i+1
|
||||
const auto num_elements_minus_one = num_elements - 1;
|
||||
using functor_type = StdIsSortedFunctor<IteratorType, ComparatorType>;
|
||||
|
||||
// result is incremented by one if sorting breaks at index i
|
||||
std::size_t result = 0;
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements_minus_one),
|
||||
functor_type(first, std::move(comp)), result);
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using pred_t = Impl::StdAlgoLessThanBinaryPredicate<value_type>;
|
||||
return is_sorted_impl(label, ex, first, last, pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
// ----------------------------------
|
||||
// is_sorted_until public API
|
||||
// ----------------------------------
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::is_sorted_until_impl(
|
||||
"Kokkos::is_sorted_until_iterator_api_default", ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::is_sorted_until_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto is_sorted_until(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl("Kokkos::is_sorted_until_view_api_default",
|
||||
ex, KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl(label, ex, KE::begin(view), KE::end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_until_impl(
|
||||
"Kokkos::is_sorted_until_iterator_api_default", ex, first, last,
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::is_sorted_until_impl(label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
auto is_sorted_until(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl("Kokkos::is_sorted_until_view_api_default",
|
||||
ex, KE::begin(view), KE::end(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
auto is_sorted_until(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_until_impl(label, ex, KE::begin(view), KE::end(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// is_sorted public API
|
||||
// ----------------------------------
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
|
||||
first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
return Impl::is_sorted_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
bool is_sorted(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
|
||||
KE::cbegin(view), KE::cend(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted(const ExecutionSpace& ex, IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
|
||||
first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, ComparatorType comp) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::is_sorted_impl(label, ex, first, last, std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
bool is_sorted(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
|
||||
KE::cbegin(view), KE::cend(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class ComparatorType>
|
||||
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
ComparatorType comp) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view),
|
||||
std::move(comp));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,18 +42,28 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_NUMERIC_ALL_HPP
|
||||
#define KOKKOS_STD_NUMERIC_ALL_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SWAP_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SWAP_HPP
|
||||
|
||||
#include "./numeric/Kokkos_AdjacentDifference.hpp"
|
||||
#include <Kokkos_Core.hpp>
|
||||
|
||||
// contains exclusive_scan, transform_exclusive_scan
|
||||
#include "./numeric/Kokkos_ExclusiveScan.hpp"
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// contains inclusive_scan, transform_inclusive_scan
|
||||
#include "./numeric/Kokkos_InclusiveScan.hpp"
|
||||
// swap
|
||||
template <class T>
|
||||
KOKKOS_INLINE_FUNCTION void swap(T& a, T& b) noexcept {
|
||||
static_assert(
|
||||
std::is_move_assignable<T>::value && std::is_move_constructible<T>::value,
|
||||
"Kokkos::Experimental::swap arguments must be move assignable "
|
||||
"and move constructible");
|
||||
|
||||
#include "./numeric/Kokkos_Reduce.hpp"
|
||||
#include "./numeric/Kokkos_TransformReduce.hpp"
|
||||
T tmp = std::move(a);
|
||||
a = std::move(b);
|
||||
b = std::move(tmp);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_SWAP_RANGES_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_SWAP_RANGES_HPP
|
||||
|
||||
#include "impl/Kokkos_SwapRanges.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 swap_ranges(const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2) {
|
||||
return Impl::swap_ranges_impl("Kokkos::swap_ranges_iterator_api_default", ex,
|
||||
first1, last1, first2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto swap_ranges(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
assert(source.extent(0) == dest.extent(0));
|
||||
return Impl::swap_ranges_impl("Kokkos::swap_ranges_view_api_default", ex,
|
||||
begin(source), end(source), begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 swap_ranges(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2) {
|
||||
return Impl::swap_ranges_impl(label, ex, first1, last1, first2);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto swap_ranges(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
assert(source.extent(0) == dest.extent(0));
|
||||
return Impl::swap_ranges_impl(label, ex, begin(source), end(source),
|
||||
begin(dest));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
166
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Transform.hpp
Normal file
166
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Transform.hpp
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_TRANSFORM_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_TRANSFORM_HPP
|
||||
|
||||
#include "impl/Kokkos_Transform.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class UnaryOperation>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIterator, OutputIterator>::value,
|
||||
OutputIterator>
|
||||
transform(const ExecutionSpace& ex, InputIterator first1, InputIterator last1,
|
||||
OutputIterator d_first, UnaryOperation unary_op) {
|
||||
return Impl::transform_impl("Kokkos::transform_iterator_api_default", ex,
|
||||
first1, last1, d_first, std::move(unary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class UnaryOperation>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIterator, OutputIterator>::value,
|
||||
OutputIterator>
|
||||
transform(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first1, InputIterator last1, OutputIterator d_first,
|
||||
UnaryOperation unary_op) {
|
||||
return Impl::transform_impl(label, ex, first1, last1, d_first,
|
||||
std::move(unary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class UnaryOperation>
|
||||
auto transform(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest,
|
||||
UnaryOperation unary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::transform_impl("Kokkos::transform_view_api_default", ex,
|
||||
begin(source), end(source), begin(dest),
|
||||
std::move(unary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class UnaryOperation>
|
||||
auto transform(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
::Kokkos::View<DataType2, Properties2...>& dest,
|
||||
UnaryOperation unary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::transform_impl(label, ex, begin(source), end(source),
|
||||
begin(dest), std::move(unary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator1, class InputIterator2,
|
||||
class OutputIterator, class BinaryOperation>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIterator1, InputIterator2, OutputIterator>::value,
|
||||
OutputIterator>
|
||||
transform(const ExecutionSpace& ex, InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, OutputIterator d_first,
|
||||
BinaryOperation binary_op) {
|
||||
return Impl::transform_impl("Kokkos::transform_iterator_api_default", ex,
|
||||
first1, last1, first2, d_first,
|
||||
std::move(binary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator1, class InputIterator2,
|
||||
class OutputIterator, class BinaryOperation>
|
||||
std::enable_if_t< ::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIterator1, InputIterator2, OutputIterator>::value,
|
||||
OutputIterator>
|
||||
transform(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
|
||||
OutputIterator d_first, BinaryOperation binary_op) {
|
||||
return Impl::transform_impl(label, ex, first1, last1, first2, d_first,
|
||||
std::move(binary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class BinaryOperation>
|
||||
auto transform(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& source2,
|
||||
::Kokkos::View<DataType3, Properties3...>& dest,
|
||||
BinaryOperation binary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source2);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::transform_impl("Kokkos::transform_view_api_default", ex,
|
||||
begin(source1), end(source1), begin(source2),
|
||||
begin(dest), std::move(binary_op));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class DataType3,
|
||||
class... Properties3, class BinaryOperation>
|
||||
auto transform(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source1,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& source2,
|
||||
::Kokkos::View<DataType3, Properties3...>& dest,
|
||||
BinaryOperation binary_op) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source1);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source2);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::transform_impl(label, ex, begin(source1), end(source1),
|
||||
begin(source2), begin(dest),
|
||||
std::move(binary_op));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,131 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_TRASFORM_EXCLUSIVE_SCAN_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_TRASFORM_EXCLUSIVE_SCAN_HPP
|
||||
|
||||
#include "impl/Kokkos_TransformExclusiveScan.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType, class BinaryOpType,
|
||||
class UnaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_exclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
ValueType init_value, BinaryOpType binary_op,
|
||||
UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::transform_exclusive_scan_impl(
|
||||
"Kokkos::transform_exclusive_scan_custom_functors_iterator_api", ex,
|
||||
first, last, first_dest, init_value, binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType, class BinaryOpType,
|
||||
class UnaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_exclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, ValueType init_value,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
return Impl::transform_exclusive_scan_impl(label, ex, first, last, first_dest,
|
||||
init_value, binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType,
|
||||
class BinaryOpType, class UnaryOpType>
|
||||
auto transform_exclusive_scan(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value, BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_exclusive_scan_impl(
|
||||
"Kokkos::transform_exclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
init_value, binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class ValueType,
|
||||
class BinaryOpType, class UnaryOpType>
|
||||
auto transform_exclusive_scan(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
ValueType init_value, BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
static_assert(std::is_move_constructible<ValueType>::value,
|
||||
"ValueType must be move constructible.");
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_exclusive_scan_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), init_value, binary_op, unary_op);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,190 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_TRANSFORM_INCLUSIVE_SCAN_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_TRANSFORM_INCLUSIVE_SCAN_HPP
|
||||
|
||||
#include "impl/Kokkos_TransformInclusiveScan.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set 1 (no init value)
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType, class UnaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_inclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
"Kokkos::transform_inclusive_scan_custom_functors_iterator_api", ex,
|
||||
first, last, first_dest, binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType, class UnaryOpType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, BinaryOpType binary_op,
|
||||
UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
|
||||
return Impl::transform_inclusive_scan_impl(label, ex, first, last, first_dest,
|
||||
binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOpType,
|
||||
class UnaryOpType>
|
||||
auto transform_inclusive_scan(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
"Kokkos::transform_inclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
binary_op, unary_op);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOpType,
|
||||
class UnaryOpType>
|
||||
auto transform_inclusive_scan(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), binary_op, unary_op);
|
||||
}
|
||||
|
||||
// overload set 2 (init value)
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType, class UnaryOpType,
|
||||
class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_inclusive_scan(const ExecutionSpace& ex, InputIteratorType first,
|
||||
InputIteratorType last, OutputIteratorType first_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op,
|
||||
ValueType init_value) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
"Kokkos::transform_inclusive_scan_custom_functors_iterator_api", ex,
|
||||
first, last, first_dest, binary_op, unary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType, class UnaryOpType,
|
||||
class ValueType>
|
||||
std::enable_if_t<::Kokkos::Experimental::Impl::are_iterators<
|
||||
InputIteratorType, OutputIteratorType>::value,
|
||||
OutputIteratorType>
|
||||
transform_inclusive_scan(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first, InputIteratorType last,
|
||||
OutputIteratorType first_dest, BinaryOpType binary_op,
|
||||
UnaryOpType unary_op, ValueType init_value) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
return Impl::transform_inclusive_scan_impl(label, ex, first, last, first_dest,
|
||||
binary_op, unary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOpType,
|
||||
class UnaryOpType, class ValueType>
|
||||
auto transform_inclusive_scan(
|
||||
const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op, ValueType init_value) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
"Kokkos::transform_inclusive_scan_custom_functors_view_api", ex,
|
||||
KE::cbegin(view_from), KE::cend(view_from), KE::begin(view_dest),
|
||||
binary_op, unary_op, init_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryOpType,
|
||||
class UnaryOpType, class ValueType>
|
||||
auto transform_inclusive_scan(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& view_from,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
|
||||
BinaryOpType binary_op, UnaryOpType unary_op, ValueType init_value) {
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
return Impl::transform_inclusive_scan_impl(
|
||||
label, ex, KE::cbegin(view_from), KE::cend(view_from),
|
||||
KE::begin(view_dest), binary_op, unary_op, init_value);
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,219 +42,14 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_NUMERICS_TRANSFORM_REDUCE_HPP
|
||||
#define KOKKOS_STD_NUMERICS_TRANSFORM_REDUCE_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_TRANSFORM_REDUCE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_TRANSFORM_REDUCE_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "../Kokkos_Constraints.hpp"
|
||||
#include "../Kokkos_Distance.hpp"
|
||||
#include "../Kokkos_ModifyingOperations.hpp"
|
||||
#include "../Kokkos_BeginEnd.hpp"
|
||||
#include "../Kokkos_ReducerWithArbitraryJoinerNoNeutralElement.hpp"
|
||||
#include "impl/Kokkos_TransformReduce.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
//
|
||||
// helper functors
|
||||
//
|
||||
template <class ValueType>
|
||||
struct StdTranformReduceDefaultBinaryTransformFunctor {
|
||||
KOKKOS_FUNCTION
|
||||
constexpr ValueType operator()(const ValueType& a, const ValueType& b) const {
|
||||
return (a * b);
|
||||
}
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct StdTranformReduceDefaultJoinFunctor {
|
||||
KOKKOS_FUNCTION
|
||||
constexpr ValueType operator()(const ValueType& a, const ValueType& b) const {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
constexpr ValueType operator()(const volatile ValueType& a,
|
||||
const volatile ValueType& b) const {
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ReducerType, class TransformType>
|
||||
struct StdTransformReduceSingleIntervalFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
|
||||
const IteratorType m_first;
|
||||
const ReducerType m_reducer;
|
||||
const TransformType m_transform;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
auto tmp_wrapped_value = red_value_type{m_transform(m_first[i]), false};
|
||||
if (red_value.is_initial) {
|
||||
red_value = tmp_wrapped_value;
|
||||
} else {
|
||||
m_reducer.join(red_value, tmp_wrapped_value);
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdTransformReduceSingleIntervalFunctor(IteratorType first,
|
||||
ReducerType reducer,
|
||||
TransformType transform)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_transform(std::move(transform)) {}
|
||||
};
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ReducerType, class TransformType>
|
||||
struct StdTransformReduceTwoIntervalsFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
const IteratorType1 m_first1;
|
||||
const IteratorType2 m_first2;
|
||||
const ReducerType m_reducer;
|
||||
const TransformType m_transform;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
auto tmp_wrapped_value =
|
||||
red_value_type{m_transform(m_first1[i], m_first2[i]), false};
|
||||
|
||||
if (red_value.is_initial) {
|
||||
red_value = tmp_wrapped_value;
|
||||
} else {
|
||||
m_reducer.join(red_value, tmp_wrapped_value);
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdTransformReduceTwoIntervalsFunctor(IteratorType1 first1,
|
||||
IteratorType2 first2,
|
||||
ReducerType reducer,
|
||||
TransformType transform)
|
||||
: m_first1(std::move(first1)),
|
||||
m_first2(std::move(first2)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_transform(std::move(transform)) {}
|
||||
};
|
||||
|
||||
//------------------------------
|
||||
//
|
||||
// impl functions
|
||||
//
|
||||
//------------------------------
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ValueType,
|
||||
class JoinerType, class UnaryTransformerType>
|
||||
ValueType transform_reduce_custom_functors_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ValueType init_reduction_value, JoinerType joiner,
|
||||
UnaryTransformerType transformer) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
// init is returned, unmodified
|
||||
return init_reduction_value;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using reducer_type =
|
||||
ReducerWithArbitraryJoinerNoNeutralElement<ValueType, JoinerType>;
|
||||
using functor_type =
|
||||
StdTransformReduceSingleIntervalFunctor<IteratorType, reducer_type,
|
||||
UnaryTransformerType>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
|
||||
// run
|
||||
reduction_value_type result;
|
||||
reducer_type reducer(result, joiner);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
functor_type(first, reducer, transformer), reducer);
|
||||
|
||||
// fence not needed since reducing into scalar
|
||||
|
||||
// as per standard, transform is not applied to the init value
|
||||
// https://en.cppreference.com/w/cpp/algorithm/transform_reduce
|
||||
return joiner(result.val, init_reduction_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class ValueType, class JoinerType, class BinaryTransformerType>
|
||||
ValueType transform_reduce_custom_functors_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, ValueType init_reduction_value,
|
||||
JoinerType joiner, BinaryTransformerType transformer) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first1, first2);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first1, first2);
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
|
||||
if (first1 == last1) {
|
||||
// init is returned, unmodified
|
||||
return init_reduction_value;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using reducer_type =
|
||||
ReducerWithArbitraryJoinerNoNeutralElement<ValueType, JoinerType>;
|
||||
using functor_type =
|
||||
StdTransformReduceTwoIntervalsFunctor<index_type, IteratorType1,
|
||||
IteratorType2, reducer_type,
|
||||
BinaryTransformerType>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
|
||||
// run
|
||||
reduction_value_type result;
|
||||
reducer_type reducer(result, joiner);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first1, last1);
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
functor_type(first1, first2, reducer, transformer), reducer);
|
||||
|
||||
// fence not needed since reducing into scalar
|
||||
return joiner(result.val, init_reduction_value);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class ValueType>
|
||||
ValueType transform_reduce_default_functors_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, ValueType init_reduction_value) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first1, first2);
|
||||
Impl::static_assert_is_not_openmptarget(ex);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first1, first2);
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
|
||||
// aliases
|
||||
using transformer_type =
|
||||
Impl::StdTranformReduceDefaultBinaryTransformFunctor<ValueType>;
|
||||
using joiner_type = Impl::StdTranformReduceDefaultJoinFunctor<ValueType>;
|
||||
|
||||
return transform_reduce_custom_functors_impl(
|
||||
label, ex, first1, last1, first2, std::move(init_reduction_value),
|
||||
joiner_type(), transformer_type());
|
||||
}
|
||||
|
||||
} // end namespace Impl
|
||||
|
||||
///////////////////////////////
|
||||
//
|
||||
// transform_reduce public API
|
||||
//
|
||||
///////////////////////////////
|
||||
|
||||
// ----------------------------
|
||||
// overload set1:
|
||||
124
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Unique.hpp
Normal file
124
lib/kokkos/algorithms/src/std_algorithms/Kokkos_Unique.hpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_UNIQUE_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_UNIQUE_HPP
|
||||
|
||||
#include "impl/Kokkos_Unique.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// note: the enable_if below is to avoid "call to ... is ambiguous"
|
||||
// for example in the unit test when using a variadic function
|
||||
|
||||
// overload set1
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
std::enable_if_t<!::Kokkos::is_view<IteratorType>::value, IteratorType> unique(
|
||||
const ExecutionSpace& ex, IteratorType first, IteratorType last) {
|
||||
return Impl::unique_impl("Kokkos::unique_iterator_api_default", ex, first,
|
||||
last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
std::enable_if_t<!::Kokkos::is_view<IteratorType>::value, IteratorType> unique(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
return Impl::unique_impl(label, ex, first, last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto unique(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return ::Kokkos::Experimental::unique("Kokkos::unique_view_api_default", ex,
|
||||
begin(view), end(view));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties>
|
||||
auto unique(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return ::Kokkos::Experimental::unique(label, ex, begin(view), end(view));
|
||||
}
|
||||
|
||||
// overload set2
|
||||
template <class ExecutionSpace, class IteratorType, class BinaryPredicate>
|
||||
IteratorType unique(const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, BinaryPredicate pred) {
|
||||
return Impl::unique_impl("Kokkos::unique_iterator_api_default", ex, first,
|
||||
last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class BinaryPredicate>
|
||||
IteratorType unique(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
BinaryPredicate pred) {
|
||||
return Impl::unique_impl(label, ex, first, last, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class BinaryPredicate>
|
||||
auto unique(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
BinaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::unique_impl("Kokkos::unique_view_api_default", ex, begin(view),
|
||||
end(view), std::move(pred));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType, class... Properties,
|
||||
class BinaryPredicate>
|
||||
auto unique(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType, Properties...>& view,
|
||||
BinaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
|
||||
return Impl::unique_impl(label, ex, begin(view), end(view), std::move(pred));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
143
lib/kokkos/algorithms/src/std_algorithms/Kokkos_UniqueCopy.hpp
Normal file
143
lib/kokkos/algorithms/src/std_algorithms/Kokkos_UniqueCopy.hpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_UNIQUE_COPY_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_UNIQUE_COPY_HPP
|
||||
|
||||
#include "impl/Kokkos_UniqueCopy.hpp"
|
||||
#include "Kokkos_BeginEnd.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
|
||||
// overload set1
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
std::enable_if_t<!::Kokkos::is_view<InputIterator>::value, OutputIterator>
|
||||
unique_copy(const ExecutionSpace& ex, InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
return Impl::unique_copy_impl("Kokkos::unique_copy_iterator_api_default", ex,
|
||||
first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
std::enable_if_t<!::Kokkos::is_view<InputIterator>::value, OutputIterator>
|
||||
unique_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, OutputIterator d_first) {
|
||||
return Impl::unique_copy_impl(label, ex, first, last, d_first);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto unique_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return ::Kokkos::Experimental::unique_copy(
|
||||
"Kokkos::unique_copy_view_api_default", ex, cbegin(source), cend(source),
|
||||
begin(dest));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2>
|
||||
auto unique_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return ::Kokkos::Experimental::unique_copy(label, ex, cbegin(source),
|
||||
cend(source), begin(dest));
|
||||
}
|
||||
|
||||
// overload set2
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class BinaryPredicate>
|
||||
OutputIterator unique_copy(const ExecutionSpace& ex, InputIterator first,
|
||||
InputIterator last, OutputIterator d_first,
|
||||
BinaryPredicate pred) {
|
||||
return Impl::unique_copy_impl("Kokkos::unique_copy_iterator_api_default", ex,
|
||||
first, last, d_first, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class BinaryPredicate>
|
||||
OutputIterator unique_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first, BinaryPredicate pred) {
|
||||
return Impl::unique_copy_impl(label, ex, first, last, d_first, pred);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicate>
|
||||
auto unique_copy(const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest,
|
||||
BinaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::unique_copy_impl("Kokkos::unique_copy_view_api_default", ex,
|
||||
cbegin(source), cend(source), begin(dest),
|
||||
std::move(pred));
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class DataType1, class... Properties1,
|
||||
class DataType2, class... Properties2, class BinaryPredicate>
|
||||
auto unique_copy(const std::string& label, const ExecutionSpace& ex,
|
||||
const ::Kokkos::View<DataType1, Properties1...>& source,
|
||||
const ::Kokkos::View<DataType2, Properties2...>& dest,
|
||||
BinaryPredicate pred) {
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
|
||||
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);
|
||||
|
||||
return Impl::unique_copy_impl(label, ex, cbegin(source), cend(source),
|
||||
begin(dest), std::move(pred));
|
||||
}
|
||||
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,135 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ADJACENT_DIFFERENCE_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ADJACENT_DIFFERENCE_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class ValueType1, class ValueType2, class RetType = ValueType2>
|
||||
struct StdAdjacentDifferenceDefaultBinaryOpFunctor {
|
||||
KOKKOS_FUNCTION
|
||||
constexpr RetType operator()(const ValueType1& a, const ValueType2& b) const {
|
||||
return a - b;
|
||||
}
|
||||
};
|
||||
|
||||
template <class InputIteratorType, class OutputIteratorType,
|
||||
class BinaryOperator>
|
||||
struct StdAdjacentDiffFunctor {
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
|
||||
const InputIteratorType m_first_from;
|
||||
const OutputIteratorType m_first_dest;
|
||||
BinaryOperator m_op;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i) const {
|
||||
const auto& my_value = m_first_from[i];
|
||||
if (i == 0) {
|
||||
m_first_dest[i] = my_value;
|
||||
} else {
|
||||
const auto& left_value = m_first_from[i - 1];
|
||||
m_first_dest[i] = m_op(my_value, left_value);
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdAdjacentDiffFunctor(InputIteratorType first_from,
|
||||
OutputIteratorType first_dest, BinaryOperator op)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)),
|
||||
m_op(std::move(op)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOp>
|
||||
OutputIteratorType adjacent_difference_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
InputIteratorType first_from,
|
||||
InputIteratorType last_from,
|
||||
OutputIteratorType first_dest,
|
||||
BinaryOp bin_op) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
if (first_from == last_from) {
|
||||
return first_dest;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using value_type = typename OutputIteratorType::value_type;
|
||||
using aux_view_type = ::Kokkos::View<value_type*, ExecutionSpace>;
|
||||
using functor_t =
|
||||
StdAdjacentDiffFunctor<InputIteratorType, OutputIteratorType, BinaryOp>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
aux_view_type aux_view("aux_view", num_elements);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
functor_t(first_from, first_dest, bin_op));
|
||||
ex.fence("Kokkos::adjacent_difference: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,140 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ADJACENT_FIND_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ADJACENT_FIND_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType, class ReducerType,
|
||||
class PredicateType>
|
||||
struct StdAdjacentFindFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
const auto& my_value = m_first[i];
|
||||
const auto& next_value = m_first[i + 1];
|
||||
const bool are_equal = m_p(my_value, next_value);
|
||||
|
||||
auto rv =
|
||||
are_equal
|
||||
? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdAdjacentFindFunctor(IteratorType first, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
IteratorType adjacent_find_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType pred) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
|
||||
if (num_elements <= 1) {
|
||||
return last;
|
||||
}
|
||||
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using reducer_type = FirstLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdAdjacentFindFunctor<index_type, IteratorType, reducer_type,
|
||||
PredicateType>;
|
||||
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
|
||||
// note that we use below num_elements-1 because
|
||||
// each index i in the reduction checks i and (i+1).
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements - 1),
|
||||
func_t(first, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
if (red_result.min_loc_true ==
|
||||
::Kokkos::reduction_identity<index_type>::min()) {
|
||||
return last;
|
||||
} else {
|
||||
return first + red_result.min_loc_true;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType adjacent_find_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using default_pred_t = StdAlgoEqualBinaryPredicate<value_type>;
|
||||
return adjacent_find_impl(label, ex, first, last, default_pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,10 +42,36 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_MOD_SEQ_OPS_INC_ALL_HPP
|
||||
#define KOKKOS_STD_MOD_SEQ_OPS_INC_ALL_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_ALL_OF_ANY_OF_NONE_OF_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_ALL_OF_ANY_OF_NONE_OF_IMPL_HPP
|
||||
|
||||
#include "./modifying_sequence_ops/Kokkos_ModifyingSequenceOperationsSet1.hpp"
|
||||
#include "./modifying_sequence_ops/Kokkos_ModifyingSequenceOperationsSet2.hpp"
|
||||
#include "Kokkos_FindIfOrNot.hpp"
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool all_of_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, Predicate predicate) {
|
||||
return (find_if_or_not_impl<false>(label, ex, first, last, predicate) ==
|
||||
last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Predicate>
|
||||
bool any_of_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last, Predicate predicate) {
|
||||
return (find_if_or_not_impl<true>(label, ex, first, last, predicate) != last);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
bool none_of_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, Predicate predicate) {
|
||||
return (find_if_or_not_impl<true>(label, ex, first, last, predicate) == last);
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,103 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_BACKWARD_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_BACKWARD_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2>
|
||||
struct StdCopyBackwardFunctor {
|
||||
static_assert(std::is_signed<IndexType>::value,
|
||||
"Kokkos: StdCopyBackwardFunctor requires signed index type");
|
||||
|
||||
IteratorType1 m_last;
|
||||
IteratorType2 m_dest_last;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType i) const { m_dest_last[-i - 1] = m_last[-i - 1]; }
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdCopyBackwardFunctor(IteratorType1 _last, IteratorType2 _dest_last)
|
||||
: m_last(std::move(_last)), m_dest_last(std::move(_dest_last)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 copy_backward_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 d_last) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, d_last);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, d_last);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using func_t =
|
||||
StdCopyBackwardFunctor<index_type, IteratorType1, IteratorType2>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(last, d_last));
|
||||
ex.fence("Kokkos::copy_backward: fence after operation");
|
||||
|
||||
// return
|
||||
return d_last - num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,116 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class InputIterator, class OutputIterator>
|
||||
struct StdCopyFunctor {
|
||||
InputIterator m_first;
|
||||
OutputIterator m_dest_first;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType i) const { m_dest_first[i] = m_first[i]; }
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdCopyFunctor(InputIterator _first, OutputIterator _dest_first)
|
||||
: m_first(std::move(_first)), m_dest_first(std::move(_dest_first)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator copy_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, d_first);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, d_first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIterator::difference_type;
|
||||
using func_t = StdCopyFunctor<index_type, InputIterator, OutputIterator>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, d_first));
|
||||
ex.fence("Kokkos::copy: fence after operation");
|
||||
|
||||
// return
|
||||
return d_first + num_elements;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class Size,
|
||||
class OutputIterator>
|
||||
OutputIterator copy_n_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first_from, Size count,
|
||||
OutputIterator first_dest) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
|
||||
if (count > 0) {
|
||||
return copy_impl(label, ex, first_from, first_from + count, first_dest);
|
||||
} else {
|
||||
return first_dest;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
142
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp
Normal file
142
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COPY_IF_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COPY_IF_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class FirstFrom, class FirstDest, class PredType>
|
||||
struct StdCopyIfFunctor {
|
||||
FirstFrom m_first_from;
|
||||
FirstDest m_first_dest;
|
||||
PredType m_pred;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdCopyIfFunctor(FirstFrom first_from, FirstDest first_dest, PredType pred)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)),
|
||||
m_pred(std::move(pred)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, IndexType& update,
|
||||
const bool final_pass) const {
|
||||
const auto& myval = m_first_from[i];
|
||||
if (final_pass) {
|
||||
if (m_pred(myval)) {
|
||||
m_first_dest[update] = myval;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pred(myval)) {
|
||||
update += 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator,
|
||||
class PredicateType>
|
||||
OutputIterator copy_if_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first, PredicateType pred) {
|
||||
/*
|
||||
To explain the impl, suppose that our data is:
|
||||
|
||||
| 1 | 1 | 2 | 2 | 3 | -2 | 4 | 4 | 4 | 5 | 7 | -10 |
|
||||
|
||||
and we want to copy only the even entries,
|
||||
We can use an exclusive scan where the "update"
|
||||
is incremented only for the elements that satisfy the predicate.
|
||||
This way, the update allows us to track where in the destination
|
||||
we need to copy the elements:
|
||||
|
||||
In this case, counting only the even entries, the exlusive scan
|
||||
during the final pass would yield:
|
||||
|
||||
| 0 | 0 | 0 | 1 | 2 | 2 | 3 | 4 | 5 | 6 | 6 | 6 |
|
||||
* * * * * * *
|
||||
|
||||
which provides the indexing in the destination where
|
||||
each starred (*) element needs to be copied to since
|
||||
the starred elements are those that satisfy the predicate.
|
||||
*/
|
||||
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, d_first);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, d_first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return d_first;
|
||||
} else {
|
||||
// aliases
|
||||
using index_type = typename InputIterator::difference_type;
|
||||
using func_type = StdCopyIfFunctor<index_type, InputIterator,
|
||||
OutputIterator, PredicateType>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
index_type count = 0;
|
||||
::Kokkos::parallel_scan(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(first, d_first, pred), count);
|
||||
|
||||
// fence not needed because of the scan accumulating into count
|
||||
return d_first + count;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,112 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_COUNT_IF_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_COUNT_IF_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class Predicate>
|
||||
struct StdCountIfFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
Predicate m_predicate;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(index_type i, index_type& lsum) const {
|
||||
if (m_predicate(m_first[i])) {
|
||||
lsum++;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdCountIfFunctor(IteratorType _first, Predicate _predicate)
|
||||
: m_first(std::move(_first)), m_predicate(std::move(_predicate)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Predicate>
|
||||
typename IteratorType::difference_type count_if_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first,
|
||||
IteratorType last,
|
||||
Predicate predicate) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using func_t = StdCountIfFunctor<IteratorType, Predicate>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
typename IteratorType::difference_type count = 0;
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, predicate), count);
|
||||
ex.fence("Kokkos::count_if: fence after operation");
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
auto count_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, const T& value) {
|
||||
return count_if_impl(
|
||||
label, ex, first, last,
|
||||
::Kokkos::Experimental::Impl::StdAlgoEqualsValUnaryPredicate<T>(value));
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
147
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Equal.hpp
Normal file
147
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Equal.hpp
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_EQUAL_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_EQUAL_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
struct StdEqualFunctor {
|
||||
IteratorType1 m_first1;
|
||||
IteratorType2 m_first2;
|
||||
BinaryPredicateType m_predicate;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType i, std::size_t& lsum) const {
|
||||
if (!m_predicate(m_first1[i], m_first2[i])) {
|
||||
lsum = 1;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdEqualFunctor(IteratorType1 _first1, IteratorType2 _first2,
|
||||
BinaryPredicateType _predicate)
|
||||
: m_first1(std::move(_first1)),
|
||||
m_first2(std::move(_first2)),
|
||||
m_predicate(std::move(_predicate)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
bool equal_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1, IteratorType2 first2,
|
||||
BinaryPredicateType predicate) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first1, first2);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first1, first2);
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using func_t = StdEqualFunctor<index_type, IteratorType1, IteratorType2,
|
||||
BinaryPredicateType>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first1, last1);
|
||||
std::size_t different = 0;
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first1, first2, predicate), different);
|
||||
ex.fence("Kokkos::equal: fence after operation");
|
||||
|
||||
return !different;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
bool equal_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2) {
|
||||
using value_type1 = typename IteratorType1::value_type;
|
||||
using value_type2 = typename IteratorType2::value_type;
|
||||
using pred_t = StdAlgoEqualBinaryPredicate<value_type1, value_type2>;
|
||||
return equal_impl(label, ex, first1, last1, first2, pred_t());
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
bool equal_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1, IteratorType2 first2,
|
||||
IteratorType2 last2, BinaryPredicateType predicate) {
|
||||
const auto d1 = ::Kokkos::Experimental::distance(first1, last1);
|
||||
const auto d2 = ::Kokkos::Experimental::distance(first2, last2);
|
||||
if (d1 != d2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return equal_impl(label, ex, first1, last1, first2, predicate);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
bool equal_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1, IteratorType2 first2,
|
||||
IteratorType2 last2) {
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
Impl::expect_valid_range(first2, last2);
|
||||
|
||||
using value_type1 = typename IteratorType1::value_type;
|
||||
using value_type2 = typename IteratorType2::value_type;
|
||||
using pred_t = StdAlgoEqualBinaryPredicate<value_type1, value_type2>;
|
||||
return equal_impl(label, ex, first1, last1, first2, last2, pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,232 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_EXCLUSIVE_SCAN_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_EXCLUSIVE_SCAN_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include "Kokkos_ValueWrapperForNoNeutralElement.hpp"
|
||||
#include "Kokkos_IdentityReferenceUnaryFunctor.hpp"
|
||||
#include <std_algorithms/Kokkos_TransformExclusiveScan.hpp>
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class ExeSpace, class IndexType, class ValueType, class FirstFrom,
|
||||
class FirstDest>
|
||||
struct ExclusiveScanDefaultFunctorForKnownNeutralElement {
|
||||
using execution_space = ExeSpace;
|
||||
|
||||
ValueType m_init_value;
|
||||
FirstFrom m_first_from;
|
||||
FirstDest m_first_dest;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
ExclusiveScanDefaultFunctorForKnownNeutralElement(ValueType init,
|
||||
FirstFrom first_from,
|
||||
FirstDest first_dest)
|
||||
: m_init_value(std::move(init)),
|
||||
m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, ValueType& update,
|
||||
const bool final_pass) const {
|
||||
if (final_pass) m_first_dest[i] = update + m_init_value;
|
||||
update += m_first_from[i];
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExeSpace, class IndexType, class ValueType, class FirstFrom,
|
||||
class FirstDest>
|
||||
struct ExclusiveScanDefaultFunctor {
|
||||
using execution_space = ExeSpace;
|
||||
using value_type =
|
||||
::Kokkos::Experimental::Impl::ValueWrapperForNoNeutralElement<ValueType>;
|
||||
|
||||
ValueType m_init_value;
|
||||
FirstFrom m_first_from;
|
||||
FirstDest m_first_dest;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
ExclusiveScanDefaultFunctor(ValueType init, FirstFrom first_from,
|
||||
FirstDest first_dest)
|
||||
: m_init_value(std::move(init)),
|
||||
m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, value_type& update,
|
||||
const bool final_pass) const {
|
||||
if (final_pass) {
|
||||
if (i == 0) {
|
||||
m_first_dest[i] = m_init_value;
|
||||
} else {
|
||||
m_first_dest[i] = update.val + m_init_value;
|
||||
}
|
||||
}
|
||||
|
||||
const auto tmp = value_type{m_first_from[i], false};
|
||||
this->join(update, tmp);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void init(value_type& update) const {
|
||||
update.val = {};
|
||||
update.is_initial = true;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void join(value_type& update, const value_type& input) const {
|
||||
if (update.is_initial) {
|
||||
update.val = input.val;
|
||||
update.is_initial = false;
|
||||
} else {
|
||||
update.val = update.val + input.val;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType, class BinaryOpType>
|
||||
OutputIteratorType exclusive_scan_custom_op_impl(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first_from, InputIteratorType last_from,
|
||||
OutputIteratorType first_dest, ValueType init_value, BinaryOpType bop) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor<ValueType>;
|
||||
using func_type =
|
||||
TransformExclusiveScanFunctor<ExecutionSpace, index_type, ValueType,
|
||||
InputIteratorType, OutputIteratorType,
|
||||
BinaryOpType, unary_op_type>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
::Kokkos::parallel_scan(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(init_value, first_from, first_dest, bop, unary_op_type()));
|
||||
ex.fence("Kokkos::exclusive_scan_custom_op: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
using ex_scan_has_reduction_identity_sum_t =
|
||||
decltype(Kokkos::reduction_identity<ValueType>::sum());
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class ValueType>
|
||||
OutputIteratorType exclusive_scan_default_op_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
InputIteratorType first_from,
|
||||
InputIteratorType last_from,
|
||||
OutputIteratorType first_dest,
|
||||
ValueType init_value) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
// does it make sense to do this static_assert too?
|
||||
// using input_iterator_value_type = typename InputIteratorType::value_type;
|
||||
// static_assert
|
||||
// (std::is_convertible<std::remove_cv_t<input_iterator_value_type>,
|
||||
// ValueType>::value,
|
||||
// "exclusive_scan: InputIteratorType::value_type not convertible to
|
||||
// ValueType");
|
||||
|
||||
// we are unnecessarily duplicating code, but this is on purpose
|
||||
// so that we can use the default_op for OpenMPTarget.
|
||||
// Originally, I had this implemented as:
|
||||
// '''
|
||||
// using bop_type = StdExclusiveScanDefaultJoinFunctor<ValueType>;
|
||||
// call exclusive_scan_custom_op_impl(..., bop_type());
|
||||
// '''
|
||||
// which avoids duplicating the functors, but for OpenMPTarget
|
||||
// I cannot use a custom binary op.
|
||||
// This is the same problem that occurs for reductions.
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using func_type = std::conditional_t<
|
||||
::Kokkos::is_detected<ex_scan_has_reduction_identity_sum_t,
|
||||
ValueType>::value,
|
||||
ExclusiveScanDefaultFunctorForKnownNeutralElement<
|
||||
ExecutionSpace, index_type, ValueType, InputIteratorType,
|
||||
OutputIteratorType>,
|
||||
ExclusiveScanDefaultFunctor<ExecutionSpace, index_type, ValueType,
|
||||
InputIteratorType, OutputIteratorType>>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
::Kokkos::parallel_scan(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(init_value, first_from, first_dest));
|
||||
|
||||
ex.fence("Kokkos::exclusive_scan_default_op: fence after operation");
|
||||
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,106 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FILL_AND_FILL_N_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FILL_AND_FILL_N_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class InputIterator, class T>
|
||||
struct StdFillFunctor {
|
||||
using index_type = typename InputIterator::difference_type;
|
||||
InputIterator m_first;
|
||||
T m_value;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(index_type i) const { m_first[i] = m_value; }
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdFillFunctor(InputIterator _first, T _value)
|
||||
: m_first(std::move(_first)), m_value(std::move(_value)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class T>
|
||||
void fill_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, const T& value) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
StdFillFunctor<IteratorType, T>(first, value));
|
||||
ex.fence("Kokkos::fill: fence after operation");
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType, class T>
|
||||
IteratorType fill_n_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, SizeType n, const T& value) {
|
||||
auto last = first + n;
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (n <= 0) {
|
||||
return first;
|
||||
}
|
||||
|
||||
fill_impl(label, ex, first, last, value);
|
||||
return last;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
191
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp
Normal file
191
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_END_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_END_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ReducerType, class PredicateType>
|
||||
struct StdFindEndFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType1 m_first;
|
||||
IteratorType1 m_last;
|
||||
IteratorType2 m_s_first;
|
||||
IteratorType2 m_s_last;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
auto myit = m_first + i;
|
||||
bool found = true;
|
||||
|
||||
const auto search_count = KE::distance(m_s_first, m_s_last);
|
||||
for (IndexType k = 0; k < search_count; ++k) {
|
||||
// note that we add this EXPECT to check if we are in a valid range
|
||||
// but I think we can remvoe this beceause the guarantee we don't go
|
||||
// out of bounds is taken care of at the calling site
|
||||
// where we launch the par-reduce.
|
||||
KOKKOS_EXPECTS((myit + k) < m_last);
|
||||
|
||||
if (!m_p(myit[k], m_s_first[k])) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const auto rv =
|
||||
found ? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::max()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdFindEndFunctor(IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last,
|
||||
ReducerType reducer, PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_last(std::move(last)),
|
||||
m_s_first(std::move(s_first)),
|
||||
m_s_last(std::move(s_last)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_end_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, s_first);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, s_first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
Impl::expect_valid_range(s_first, s_last);
|
||||
|
||||
// the target sequence should not be larger than the range [first, last)
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
const auto num_elements = KE::distance(first, last);
|
||||
const auto s_count = KE::distance(s_first, s_last);
|
||||
KOKKOS_EXPECTS(num_elements >= s_count);
|
||||
(void)s_count; // needed when macro above is a no-op
|
||||
|
||||
if (s_first == s_last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
// special case where the two ranges have equal size
|
||||
if (num_elements == s_count) {
|
||||
const auto equal_result = equal_impl(label, ex, first, last, s_first, pred);
|
||||
return (equal_result) ? first : last;
|
||||
} else {
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using reducer_type = LastLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdFindEndFunctor<index_type, IteratorType1, IteratorType2,
|
||||
reducer_type, BinaryPredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
|
||||
// decide the size of the range policy of the par_red:
|
||||
// note that the last feasible index to start looking is the index
|
||||
// whose distance from the "last" is equal to the sequence count.
|
||||
// the +1 is because we need to include that location too.
|
||||
const auto range_size = num_elements - s_count + 1;
|
||||
|
||||
// run par reduce
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, range_size),
|
||||
func_t(first, last, s_first, s_last, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
if (red_result.max_loc_true ==
|
||||
::Kokkos::reduction_identity<index_type>::max()) {
|
||||
// if here, a subrange has not been found
|
||||
return last;
|
||||
} else {
|
||||
// a location has been found
|
||||
return first + red_result.max_loc_true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_end_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType1 first, IteratorType1 last,
|
||||
IteratorType2 s_first, IteratorType2 s_last) {
|
||||
using value_type1 = typename IteratorType1::value_type;
|
||||
using value_type2 = typename IteratorType2::value_type;
|
||||
using predicate_type = StdAlgoEqualBinaryPredicate<value_type1, value_type2>;
|
||||
return find_end_impl(label, ex, first, last, s_first, s_last,
|
||||
predicate_type());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,161 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_FIRST_OF_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_FIRST_OF_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ReducerType, class PredicateType>
|
||||
struct StdFindFirstOfFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType1 m_first;
|
||||
IteratorType2 m_s_first;
|
||||
IteratorType2 m_s_last;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
const auto& myvalue = m_first[i];
|
||||
bool found = false;
|
||||
|
||||
const auto search_count = KE::distance(m_s_first, m_s_last);
|
||||
for (IndexType k = 0; k < search_count; ++k) {
|
||||
if (m_p(myvalue, m_s_first[k])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const auto rv =
|
||||
found ? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdFindFirstOfFunctor(IteratorType1 first, IteratorType2 s_first,
|
||||
IteratorType2 s_last, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_s_first(std::move(s_first)),
|
||||
m_s_last(std::move(s_last)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
IteratorType1 find_first_of_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last,
|
||||
const BinaryPredicateType& pred) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, s_first);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, s_first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
Impl::expect_valid_range(s_first, s_last);
|
||||
|
||||
if ((s_first == s_last) || (first == last)) {
|
||||
return last;
|
||||
}
|
||||
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using reducer_type = FirstLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdFindFirstOfFunctor<index_type, IteratorType1, IteratorType2,
|
||||
reducer_type, BinaryPredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, s_first, s_last, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
if (red_result.min_loc_true ==
|
||||
::Kokkos::reduction_identity<index_type>::min()) {
|
||||
// if here, nothing found
|
||||
return last;
|
||||
} else {
|
||||
// a location has been found
|
||||
return first + red_result.min_loc_true;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType1 find_first_of_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 s_first,
|
||||
IteratorType2 s_last) {
|
||||
using value_type1 = typename IteratorType1::value_type;
|
||||
using value_type2 = typename IteratorType2::value_type;
|
||||
using predicate_type = StdAlgoEqualBinaryPredicate<value_type1, value_type2>;
|
||||
return find_first_of_impl(label, ex, first, last, s_first, s_last,
|
||||
predicate_type());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,146 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FIND_IF_AND_FIND_IF_NOT_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FIND_IF_AND_FIND_IF_NOT_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <bool is_find_if, class IndexType, class IteratorType,
|
||||
class ReducerType, class PredicateType>
|
||||
struct StdFindIfOrNotFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
const auto& my_value = m_first[i];
|
||||
|
||||
// if doing find_if, look for when predicate is true
|
||||
// if doing find_if_not, look for when predicate is false
|
||||
const bool found_condition = is_find_if ? m_p(my_value) : !m_p(my_value);
|
||||
|
||||
auto rv =
|
||||
found_condition
|
||||
? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdFindIfOrNotFunctor(IteratorType first, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <bool is_find_if, class ExecutionSpace, class IteratorType,
|
||||
class PredicateType>
|
||||
IteratorType find_if_or_not_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, PredicateType pred) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(
|
||||
ex, first); // only need one It per type
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using reducer_type = FirstLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdFindIfOrNotFunctor<is_find_if, index_type, IteratorType,
|
||||
reducer_type, PredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
if (red_result.min_loc_true ==
|
||||
::Kokkos::reduction_identity<index_type>::min()) {
|
||||
// here, it means a valid loc has not been found,
|
||||
return last;
|
||||
} else {
|
||||
// a location has been found
|
||||
return first + red_result.min_loc_true;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class T>
|
||||
InputIterator find_impl(const std::string& label, ExecutionSpace ex,
|
||||
InputIterator first, InputIterator last,
|
||||
const T& value) {
|
||||
return find_if_or_not_impl<true>(
|
||||
label, ex, first, last,
|
||||
::Kokkos::Experimental::Impl::StdAlgoEqualsValUnaryPredicate<T>(value));
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,113 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_FOR_EACH_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_FOR_EACH_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class UnaryFunctorType>
|
||||
struct StdForEachFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
UnaryFunctorType m_functor;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(index_type i) const { m_functor(m_first[i]); }
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdForEachFunctor(IteratorType _first, UnaryFunctorType _functor)
|
||||
: m_first(std::move(_first)), m_functor(std::move(_functor)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class UnaryFunctorType>
|
||||
UnaryFunctorType for_each_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, UnaryFunctorType functor) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
StdForEachFunctor<IteratorType, UnaryFunctorType>(first, functor));
|
||||
ex.fence("Kokkos::for_each: fence after operation");
|
||||
|
||||
return functor;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class SizeType,
|
||||
class UnaryFunctorType>
|
||||
IteratorType for_each_n_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, SizeType n,
|
||||
UnaryFunctorType functor) {
|
||||
auto last = first + n;
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, last);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (n == 0) {
|
||||
return first;
|
||||
}
|
||||
|
||||
for_each_impl(label, ex, first, last, std::move(functor));
|
||||
// no neeed to fence since for_each_impl fences already
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,105 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_GENERATE_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_GENERATE_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class Generator>
|
||||
struct StdGenerateFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
Generator m_generator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(index_type i) const { m_first[i] = m_generator(); }
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdGenerateFunctor(IteratorType _first, Generator _g)
|
||||
: m_first(std::move(_first)), m_generator(std::move(_g)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Generator>
|
||||
void generate_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last, Generator g) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using func_t = StdGenerateFunctor<IteratorType, Generator>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, g));
|
||||
ex.fence("Kokkos::generate: fence after operation");
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class Size, class Generator>
|
||||
IteratorType generate_n_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, Size count, Generator g) {
|
||||
if (count <= 0) {
|
||||
return first;
|
||||
}
|
||||
|
||||
generate_impl(label, ex, first, first + count, g);
|
||||
return first + count;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -42,8 +42,8 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_HELPER_PREDICATES_HPP
|
||||
#define KOKKOS_STD_HELPER_PREDICATES_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_HELPER_PREDICATES_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_HELPER_PREDICATES_HPP
|
||||
|
||||
#include <Kokkos_Macros.hpp>
|
||||
|
||||
@ -42,8 +42,8 @@
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_NUMERIC_IDENTITY_REFERENCE_UNARY_FUNCTOR_HPP
|
||||
#define KOKKOS_STD_NUMERIC_IDENTITY_REFERENCE_UNARY_FUNCTOR_HPP
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_NUMERIC_IDENTITY_REFERENCE_UNARY_FUNCTOR_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_NUMERIC_IDENTITY_REFERENCE_UNARY_FUNCTOR_HPP
|
||||
|
||||
#include <Kokkos_Macros.hpp>
|
||||
|
||||
@ -0,0 +1,243 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_INCLUSIVE_SCAN_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_INCLUSIVE_SCAN_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_TransformInclusiveScan.hpp>
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <typename ValueType>
|
||||
using in_scan_has_reduction_identity_sum_t =
|
||||
decltype(Kokkos::reduction_identity<ValueType>::sum());
|
||||
|
||||
template <class ExeSpace, class IndexType, class ValueType, class FirstFrom,
|
||||
class FirstDest>
|
||||
struct InclusiveScanDefaultFunctorForKnownIdentityElement {
|
||||
using execution_space = ExeSpace;
|
||||
|
||||
FirstFrom m_first_from;
|
||||
FirstDest m_first_dest;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
InclusiveScanDefaultFunctorForKnownIdentityElement(FirstFrom first_from,
|
||||
FirstDest first_dest)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, ValueType& update,
|
||||
const bool final_pass) const {
|
||||
update += m_first_from[i];
|
||||
|
||||
if (final_pass) {
|
||||
m_first_dest[i] = update;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExeSpace, class IndexType, class ValueType, class FirstFrom,
|
||||
class FirstDest>
|
||||
struct InclusiveScanDefaultFunctor {
|
||||
using execution_space = ExeSpace;
|
||||
using value_type = ValueWrapperForNoNeutralElement<ValueType>;
|
||||
|
||||
FirstFrom m_first_from;
|
||||
FirstDest m_first_dest;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
InclusiveScanDefaultFunctor(FirstFrom first_from, FirstDest first_dest)
|
||||
: m_first_from(std::move(first_from)),
|
||||
m_first_dest(std::move(first_dest)) {}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, value_type& update,
|
||||
const bool final_pass) const {
|
||||
const auto tmp = value_type{m_first_from[i], false};
|
||||
this->join(update, tmp);
|
||||
|
||||
if (final_pass) {
|
||||
m_first_dest[i] = update.val;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void init(value_type& update) const {
|
||||
update.val = {};
|
||||
update.is_initial = true;
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void join(value_type& update, const value_type& input) const {
|
||||
if (update.is_initial) {
|
||||
update.val = input.val;
|
||||
} else {
|
||||
update.val = update.val + input.val;
|
||||
}
|
||||
update.is_initial = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType>
|
||||
OutputIteratorType inclusive_scan_default_op_impl(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first_from, InputIteratorType last_from,
|
||||
OutputIteratorType first_dest) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using value_type =
|
||||
std::remove_const_t<typename InputIteratorType::value_type>;
|
||||
using func_type = std::conditional_t<
|
||||
::Kokkos::is_detected<in_scan_has_reduction_identity_sum_t,
|
||||
value_type>::value,
|
||||
InclusiveScanDefaultFunctorForKnownIdentityElement<
|
||||
ExecutionSpace, index_type, value_type, InputIteratorType,
|
||||
OutputIteratorType>,
|
||||
InclusiveScanDefaultFunctor<ExecutionSpace, index_type, value_type,
|
||||
InputIteratorType, OutputIteratorType>>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
::Kokkos::parallel_scan(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(first_from, first_dest));
|
||||
ex.fence("Kokkos::inclusive_scan_default_op: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// inclusive_scan_custom_binary_op_impl
|
||||
// -------------------------------------------------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType>
|
||||
OutputIteratorType inclusive_scan_custom_binary_op_impl(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first_from, InputIteratorType last_from,
|
||||
OutputIteratorType first_dest, BinaryOpType binary_op) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using value_type =
|
||||
std::remove_const_t<typename InputIteratorType::value_type>;
|
||||
using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor<value_type>;
|
||||
using func_type = TransformInclusiveScanNoInitValueFunctor<
|
||||
ExecutionSpace, index_type, value_type, InputIteratorType,
|
||||
OutputIteratorType, BinaryOpType, unary_op_type>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
::Kokkos::parallel_scan(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(first_from, first_dest, binary_op, unary_op_type()));
|
||||
ex.fence("Kokkos::inclusive_scan_custom_binary_op: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// inclusive_scan_custom_binary_op_impl with init_value
|
||||
// -------------------------------------------------------------
|
||||
template <class ExecutionSpace, class InputIteratorType,
|
||||
class OutputIteratorType, class BinaryOpType, class ValueType>
|
||||
OutputIteratorType inclusive_scan_custom_binary_op_impl(
|
||||
const std::string& label, const ExecutionSpace& ex,
|
||||
InputIteratorType first_from, InputIteratorType last_from,
|
||||
OutputIteratorType first_dest, BinaryOpType binary_op,
|
||||
ValueType init_value) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first_from, first_dest);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first_from,
|
||||
first_dest);
|
||||
Impl::expect_valid_range(first_from, last_from);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIteratorType::difference_type;
|
||||
using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor<ValueType>;
|
||||
using func_type = TransformInclusiveScanWithInitValueFunctor<
|
||||
ExecutionSpace, index_type, ValueType, InputIteratorType,
|
||||
OutputIteratorType, BinaryOpType, unary_op_type>;
|
||||
|
||||
// run
|
||||
const auto num_elements =
|
||||
Kokkos::Experimental::distance(first_from, last_from);
|
||||
::Kokkos::parallel_scan(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_type(first_from, first_dest, binary_op,
|
||||
unary_op_type(), init_value));
|
||||
ex.fence("Kokkos::inclusive_scan_custom_binary_op: fence after operation");
|
||||
|
||||
// return
|
||||
return first_dest + num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,148 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_PARTITIONED_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_PARTITIONED_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class ReducerType, class PredicateType>
|
||||
struct StdIsPartitionedFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
PredicateType m_p;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& redValue) const {
|
||||
const auto predicate_value = m_p(m_first[i]);
|
||||
constexpr index_type m_red_id_min =
|
||||
::Kokkos::reduction_identity<index_type>::min();
|
||||
constexpr index_type m_red_id_max =
|
||||
::Kokkos::reduction_identity<index_type>::max();
|
||||
auto rv = predicate_value ? red_value_type{i, m_red_id_min}
|
||||
: red_value_type{m_red_id_max, i};
|
||||
|
||||
m_reducer.join(redValue, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsPartitionedFunctor(IteratorType first, ReducerType reducer,
|
||||
PredicateType p)
|
||||
: m_first(std::move(first)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_p(std::move(p)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class PredicateType>
|
||||
bool is_partitioned_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
PredicateType pred) {
|
||||
// true if all elements in the range [first, last) that satisfy
|
||||
// the predicate "pred" appear before all elements that don't.
|
||||
// Also returns true if [first, last) is empty.
|
||||
// also true if all elements satisfy the predicate.
|
||||
|
||||
// we implement it by finding:
|
||||
// - the max location where predicate is true (max_loc_true)
|
||||
// - the min location where predicate is false (min_loc_false)
|
||||
// so the range is partitioned if max_loc_true < (min_loc_false)
|
||||
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// trivial case
|
||||
if (first == last) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using reducer_type = StdIsPartitioned<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t =
|
||||
StdIsPartitionedFunctor<IteratorType, reducer_type, PredicateType>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer, pred), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
constexpr index_type red_id_min =
|
||||
::Kokkos::reduction_identity<index_type>::min();
|
||||
constexpr index_type red_id_max =
|
||||
::Kokkos::reduction_identity<index_type>::max();
|
||||
|
||||
if (red_result.max_loc_true != red_id_max &&
|
||||
red_result.min_loc_false != red_id_min) {
|
||||
return red_result.max_loc_true < red_result.min_loc_false;
|
||||
} else if (first + red_result.max_loc_true == --last) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,117 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_SORTED_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_SORTED_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class ComparatorType>
|
||||
struct StdIsSortedFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
ComparatorType m_comparator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, std::size_t& update) const {
|
||||
const auto& val_i = m_first[i];
|
||||
const auto& val_ip1 = m_first[i + 1];
|
||||
|
||||
if (m_comparator(val_ip1, val_i)) {
|
||||
++update;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsSortedFunctor(IteratorType _first1, ComparatorType comparator)
|
||||
: m_first(std::move(_first1)), m_comparator(std::move(comparator)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
bool is_sorted_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
ComparatorType comp) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
if (num_elements <= 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// use num_elements-1 because each index handles i and i+1
|
||||
const auto num_elements_minus_one = num_elements - 1;
|
||||
using functor_type = StdIsSortedFunctor<IteratorType, ComparatorType>;
|
||||
|
||||
// result is incremented by one if sorting breaks at index i
|
||||
std::size_t result = 0;
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements_minus_one),
|
||||
functor_type(first, std::move(comp)), result);
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
bool is_sorted_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last) {
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using pred_t = Impl::StdAlgoLessThanBinaryPredicate<value_type>;
|
||||
return is_sorted_impl(label, ex, first, last, pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,153 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_IS_SORTED_UNTIL_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_IS_SORTED_UNTIL_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <std_algorithms/Kokkos_Find.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class IndicatorViewType, class ComparatorType>
|
||||
struct StdIsSortedUntilFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
IteratorType m_first;
|
||||
IndicatorViewType m_indicator;
|
||||
ComparatorType m_comparator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, int& update, const bool final) const {
|
||||
const auto& val_i = m_first[i];
|
||||
const auto& val_ip1 = m_first[i + 1];
|
||||
|
||||
if (m_comparator(val_ip1, val_i)) {
|
||||
++update;
|
||||
}
|
||||
|
||||
if (final) {
|
||||
m_indicator(i) = update;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdIsSortedUntilFunctor(IteratorType _first1, IndicatorViewType indicator,
|
||||
ComparatorType comparator)
|
||||
: m_first(std::move(_first1)),
|
||||
m_indicator(std::move(indicator)),
|
||||
m_comparator(std::move(comparator)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType, class ComparatorType>
|
||||
IteratorType is_sorted_until_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, ComparatorType comp) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
|
||||
// trivial case
|
||||
if (num_elements <= 1) {
|
||||
return last;
|
||||
}
|
||||
|
||||
/*
|
||||
use scan and a helper "indicator" view
|
||||
such that we scan the data and fill the indicator with
|
||||
partial sum that is always 0 unless we find a pair that
|
||||
breaks the sorting, so in that case the indicator will
|
||||
have a 1 starting at the location where the sorting breaks.
|
||||
So finding that 1 means finding the location we want.
|
||||
*/
|
||||
|
||||
// aliases
|
||||
using indicator_value_type = std::size_t;
|
||||
using indicator_view_type =
|
||||
::Kokkos::View<indicator_value_type*, ExecutionSpace>;
|
||||
using functor_type =
|
||||
StdIsSortedUntilFunctor<IteratorType, indicator_view_type,
|
||||
ComparatorType>;
|
||||
|
||||
// do scan
|
||||
// use num_elements-1 because each index handles i and i+1
|
||||
const auto num_elements_minus_one = num_elements - 1;
|
||||
indicator_view_type indicator("is_sorted_until_indicator_helper",
|
||||
num_elements_minus_one);
|
||||
::Kokkos::parallel_scan(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elements_minus_one),
|
||||
functor_type(first, indicator, std::move(comp)));
|
||||
|
||||
// try to find the first sentinel value, which indicates
|
||||
// where the sorting condition breaks
|
||||
namespace KE = ::Kokkos::Experimental;
|
||||
constexpr indicator_value_type sentinel_value = 1;
|
||||
auto r =
|
||||
KE::find(ex, KE::cbegin(indicator), KE::cend(indicator), sentinel_value);
|
||||
const auto shift = r - ::Kokkos::Experimental::cbegin(indicator);
|
||||
|
||||
return first + (shift + 1);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType>
|
||||
IteratorType is_sorted_until_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last) {
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using pred_t = Impl::StdAlgoLessThanBinaryPredicate<value_type>;
|
||||
return is_sorted_until_impl(label, ex, first, last, pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,184 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_LEXICOGRAPHICAL_COMPARE_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_LEXICOGRAPHICAL_COMPARE_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ComparatorType>
|
||||
struct StdCompareFunctor {
|
||||
IteratorType1 m_it1;
|
||||
IteratorType2 m_it2;
|
||||
ComparatorType m_predicate;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType /* i is unused */, int& lsum) const {
|
||||
if (m_predicate(*m_it1, *m_it2)) {
|
||||
lsum = 1;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdCompareFunctor(IteratorType1 _it1, IteratorType2 _it2,
|
||||
ComparatorType _predicate)
|
||||
: m_it1(std::move(_it1)),
|
||||
m_it2(std::move(_it2)),
|
||||
m_predicate(std::move(_predicate)) {}
|
||||
};
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ReducerType, class ComparatorType>
|
||||
struct StdLexicographicalCompareFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
IteratorType1 m_first1;
|
||||
IteratorType2 m_first2;
|
||||
ReducerType m_reducer;
|
||||
ComparatorType m_comparator;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
const auto& my_value1 = m_first1[i];
|
||||
const auto& my_value2 = m_first2[i];
|
||||
|
||||
bool different = m_comparator(my_value1, my_value2) ||
|
||||
m_comparator(my_value2, my_value1);
|
||||
auto rv =
|
||||
different
|
||||
? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdLexicographicalCompareFunctor(IteratorType1 _first1, IteratorType2 _first2,
|
||||
ReducerType _reducer, ComparatorType _comp)
|
||||
: m_first1(std::move(_first1)),
|
||||
m_first2(std::move(_first2)),
|
||||
m_reducer(std::move(_reducer)),
|
||||
m_comparator(std::move(_comp)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class ComparatorType>
|
||||
bool lexicographical_compare_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2,
|
||||
ComparatorType comp) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first1, first2);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first1, first2);
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
Impl::expect_valid_range(first2, last2);
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using reducer_type = FirstLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
|
||||
// run
|
||||
const auto d1 = Kokkos::Experimental::distance(first1, last1);
|
||||
const auto d2 = Kokkos::Experimental::distance(first2, last2);
|
||||
const auto range = Kokkos::min(d1, d2);
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
using func1_t =
|
||||
StdLexicographicalCompareFunctor<index_type, IteratorType1, IteratorType2,
|
||||
reducer_type, ComparatorType>;
|
||||
|
||||
::Kokkos::parallel_reduce(label, RangePolicy<ExecutionSpace>(ex, 0, range),
|
||||
func1_t(first1, first2, reducer, comp), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
// no mismatch
|
||||
if (red_result.min_loc_true ==
|
||||
::Kokkos::reduction_identity<index_type>::min()) {
|
||||
auto new_last1 = first1 + range;
|
||||
auto new_last2 = first2 + range;
|
||||
bool is_prefix = (new_last1 == last1) && (new_last2 != last2);
|
||||
return is_prefix;
|
||||
}
|
||||
|
||||
// check mismatched
|
||||
int less = 0;
|
||||
auto it1 = first1 + red_result.min_loc_true;
|
||||
auto it2 = first2 + red_result.min_loc_true;
|
||||
using func2_t = StdCompareFunctor<index_type, IteratorType1, IteratorType2,
|
||||
ComparatorType>;
|
||||
::Kokkos::parallel_reduce(label, RangePolicy<ExecutionSpace>(ex, 0, 1),
|
||||
func2_t(it1, it2, comp), less);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
return static_cast<bool>(less);
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
bool lexicographical_compare_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType1 first1, IteratorType1 last1,
|
||||
IteratorType2 first2, IteratorType2 last2) {
|
||||
using value_type_1 = typename IteratorType1::value_type;
|
||||
using value_type_2 = typename IteratorType2::value_type;
|
||||
using predicate_t =
|
||||
Impl::StdAlgoLessThanBinaryPredicate<value_type_1, value_type_2>;
|
||||
return lexicographical_compare_impl(label, ex, first1, last1, first2, last2,
|
||||
predicate_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,167 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MIN_MAX_MINMAX_ELEMENT_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MIN_MAX_MINMAX_ELEMENT_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IteratorType, class ReducerType>
|
||||
struct StdMinOrMaxElemFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
m_reducer.join(red_value, red_value_type{m_first[i], i});
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdMinOrMaxElemFunctor(IteratorType first, ReducerType reducer)
|
||||
: m_first(std::move(first)), m_reducer(std::move(reducer)) {}
|
||||
};
|
||||
|
||||
template <class IteratorType, class ReducerType>
|
||||
struct StdMinMaxElemFunctor {
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
IteratorType m_first;
|
||||
ReducerType m_reducer;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const index_type i, red_value_type& red_value) const {
|
||||
const auto& my_value = m_first[i];
|
||||
m_reducer.join(red_value, red_value_type{my_value, my_value, i, i});
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdMinMaxElemFunctor(IteratorType first, ReducerType reducer)
|
||||
: m_first(std::move(first)), m_reducer(std::move(reducer)) {}
|
||||
};
|
||||
|
||||
template <template <class... Args> class ReducerType, class ExecutionSpace,
|
||||
class IteratorType, class... Args>
|
||||
IteratorType min_or_max_element_impl(const std::string& label,
|
||||
const ExecutionSpace& ex,
|
||||
IteratorType first, IteratorType last,
|
||||
Args&&... args) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using reducer_type = ReducerType<value_type, index_type, Args...>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdMinOrMaxElemFunctor<IteratorType, reducer_type>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result, std::forward<Args>(args)...);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// return
|
||||
return first + red_result.loc;
|
||||
}
|
||||
|
||||
template <template <class... Args> class ReducerType, class ExecutionSpace,
|
||||
class IteratorType, class... Args>
|
||||
::Kokkos::pair<IteratorType, IteratorType> minmax_element_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType first,
|
||||
IteratorType last, Args&&... args) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
if (first == last) {
|
||||
return {first, first};
|
||||
}
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType::difference_type;
|
||||
using value_type = typename IteratorType::value_type;
|
||||
using reducer_type = ReducerType<value_type, index_type, Args...>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using func_t = StdMinMaxElemFunctor<IteratorType, reducer_type>;
|
||||
|
||||
// run
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result, std::forward<Args>(args)...);
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_reduce(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, reducer), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// return
|
||||
return {first + red_result.min_loc, first + red_result.max_loc};
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,162 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MISMATCH_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MISMATCH_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2,
|
||||
class ReducerType, class BinaryPredicateType>
|
||||
struct StdMismatchRedFunctor {
|
||||
using red_value_type = typename ReducerType::value_type;
|
||||
|
||||
IteratorType1 m_first1;
|
||||
IteratorType2 m_first2;
|
||||
ReducerType m_reducer;
|
||||
BinaryPredicateType m_predicate;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const IndexType i, red_value_type& red_value) const {
|
||||
const auto& my_value1 = m_first1[i];
|
||||
const auto& my_value2 = m_first2[i];
|
||||
|
||||
auto rv =
|
||||
!m_predicate(my_value1, my_value2)
|
||||
? red_value_type{i}
|
||||
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
|
||||
|
||||
m_reducer.join(red_value, rv);
|
||||
}
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
StdMismatchRedFunctor(IteratorType1 first1, IteratorType2 first2,
|
||||
ReducerType reducer, BinaryPredicateType predicate)
|
||||
: m_first1(std::move(first1)),
|
||||
m_first2(std::move(first2)),
|
||||
m_reducer(std::move(reducer)),
|
||||
m_predicate(std::move(predicate)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2,
|
||||
class BinaryPredicateType>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2,
|
||||
BinaryPredicateType predicate) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first1, first2);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first1, first2);
|
||||
Impl::expect_valid_range(first1, last1);
|
||||
Impl::expect_valid_range(first2, last2);
|
||||
|
||||
// aliases
|
||||
using return_type = ::Kokkos::pair<IteratorType1, IteratorType2>;
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using reducer_type = FirstLoc<index_type>;
|
||||
using reduction_value_type = typename reducer_type::value_type;
|
||||
using functor_type =
|
||||
StdMismatchRedFunctor<index_type, IteratorType1, IteratorType2,
|
||||
reducer_type, BinaryPredicateType>;
|
||||
|
||||
// trivial case: note that this is important,
|
||||
// for OpenMPTarget, omitting special handling of
|
||||
// the trivial case was giving all sorts of strange stuff.
|
||||
const auto num_e1 = last1 - first1;
|
||||
const auto num_e2 = last2 - first2;
|
||||
if (num_e1 == 0 || num_e2 == 0) {
|
||||
return return_type(first1, first2);
|
||||
}
|
||||
|
||||
// run
|
||||
const auto num_elemen_par_reduce = (num_e1 <= num_e2) ? num_e1 : num_e2;
|
||||
reduction_value_type red_result;
|
||||
reducer_type reducer(red_result);
|
||||
::Kokkos::parallel_reduce(
|
||||
label, RangePolicy<ExecutionSpace>(ex, 0, num_elemen_par_reduce),
|
||||
functor_type(first1, first2, reducer, std::move(predicate)), reducer);
|
||||
|
||||
// fence not needed because reducing into scalar
|
||||
|
||||
// decide and return
|
||||
constexpr auto red_min = ::Kokkos::reduction_identity<index_type>::min();
|
||||
if (red_result.min_loc_true == red_min) {
|
||||
// in here means mismatch has not been found
|
||||
if (num_e1 == num_e2) {
|
||||
return return_type(last1, last2);
|
||||
} else if (num_e1 < num_e2) {
|
||||
return return_type(last1, first2 + num_e1);
|
||||
} else {
|
||||
return return_type(first1 + num_e2, last2);
|
||||
}
|
||||
} else {
|
||||
// in here means mismatch has been found
|
||||
return return_type(first1 + red_result.min_loc_true,
|
||||
first2 + red_result.min_loc_true);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
::Kokkos::pair<IteratorType1, IteratorType2> mismatch_impl(
|
||||
const std::string& label, const ExecutionSpace& ex, IteratorType1 first1,
|
||||
IteratorType1 last1, IteratorType2 first2, IteratorType2 last2) {
|
||||
using value_type1 = typename IteratorType1::value_type;
|
||||
using value_type2 = typename IteratorType2::value_type;
|
||||
using pred_t = StdAlgoEqualBinaryPredicate<value_type1, value_type2>;
|
||||
return mismatch_impl(label, ex, first1, last1, first2, last2, pred_t());
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
100
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Move.hpp
Normal file
100
lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Move.hpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MOVE_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MOVE_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class InputIterator, class OutputIterator>
|
||||
struct StdMoveFunctor {
|
||||
InputIterator m_first;
|
||||
OutputIterator m_dest_first;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType i) const {
|
||||
m_dest_first[i] = std::move(m_first[i]);
|
||||
}
|
||||
|
||||
StdMoveFunctor(InputIterator _first, OutputIterator _dest_first)
|
||||
: m_first(std::move(_first)), m_dest_first(std::move(_dest_first)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class InputIterator, class OutputIterator>
|
||||
OutputIterator move_impl(const std::string& label, const ExecutionSpace& ex,
|
||||
InputIterator first, InputIterator last,
|
||||
OutputIterator d_first) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, d_first);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, d_first);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using index_type = typename InputIterator::difference_type;
|
||||
using func_t = StdMoveFunctor<index_type, InputIterator, OutputIterator>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(first, d_first));
|
||||
ex.fence("Kokkos::move: fence after operation");
|
||||
|
||||
// return
|
||||
return d_first + num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,104 @@
|
||||
/*
|
||||
//@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
|
||||
*/
|
||||
|
||||
#ifndef KOKKOS_STD_ALGORITHMS_MOVE_BACKWARD_IMPL_HPP
|
||||
#define KOKKOS_STD_ALGORITHMS_MOVE_BACKWARD_IMPL_HPP
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include "Kokkos_Constraints.hpp"
|
||||
#include "Kokkos_HelperPredicates.hpp"
|
||||
#include <std_algorithms/Kokkos_Distance.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Kokkos {
|
||||
namespace Experimental {
|
||||
namespace Impl {
|
||||
|
||||
template <class IndexType, class IteratorType1, class IteratorType2>
|
||||
struct StdMoveBackwardFunctor {
|
||||
static_assert(std::is_signed<IndexType>::value,
|
||||
"Kokkos: StdMoveBackwardFunctor requires signed index type");
|
||||
|
||||
IteratorType1 m_last;
|
||||
IteratorType2 m_dest_last;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(IndexType i) const {
|
||||
m_dest_last[-i - 1] = std::move(m_last[-i - 1]);
|
||||
}
|
||||
|
||||
StdMoveBackwardFunctor(IteratorType1 _last, IteratorType2 _dest_last)
|
||||
: m_last(std::move(_last)), m_dest_last(std::move(_dest_last)) {}
|
||||
};
|
||||
|
||||
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
|
||||
IteratorType2 move_backward_impl(const std::string& label,
|
||||
const ExecutionSpace& ex, IteratorType1 first,
|
||||
IteratorType1 last, IteratorType2 d_last) {
|
||||
// checks
|
||||
Impl::static_assert_random_access_and_accessible(ex, first, d_last);
|
||||
Impl::static_assert_iterators_have_matching_difference_type(first, d_last);
|
||||
Impl::expect_valid_range(first, last);
|
||||
|
||||
// aliases
|
||||
using index_type = typename IteratorType1::difference_type;
|
||||
using func_t =
|
||||
StdMoveBackwardFunctor<index_type, IteratorType1, IteratorType2>;
|
||||
|
||||
// run
|
||||
const auto num_elements = Kokkos::Experimental::distance(first, last);
|
||||
::Kokkos::parallel_for(label,
|
||||
RangePolicy<ExecutionSpace>(ex, 0, num_elements),
|
||||
func_t(last, d_last));
|
||||
ex.fence("Kokkos::move_backward: fence after operation");
|
||||
|
||||
// return
|
||||
return d_last - num_elements;
|
||||
}
|
||||
|
||||
} // namespace Impl
|
||||
} // namespace Experimental
|
||||
} // namespace Kokkos
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user