21 #ifndef __ViewAlgorithms_hpp__
22 #define __ViewAlgorithms_hpp__
34 template<
typename T,
typename... properties>
43 using ExecutionSpace =
44 typename ViewType1D<T, properties...>::execution_space;
46 uint32 numElems = end - start;
48 return pFlow::algorithms::KOKKOS::count<T, ExecutionSpace>(
49 view.data() + start, numElems, val
53 template<
typename T,
typename... properties>
57 using exe_space =
typename ViewType1D<T, properties...>::execution_space;
58 auto subV = Kokkos::subview(view,
span.getPair());
59 if constexpr (std::is_trivially_copyable_v<T>)
61 Kokkos::deep_copy(subV, val);
63 else if constexpr (isHostAccessible<exe_space>())
72 static_assert(
"fill is not valid for non-trivially-copyable data type");
76 template<
typename T,
typename... properties>
83 template<
typename T,
typename... properties>
93 static_assert(std::is_trivially_copyable_v<T>,
"Not valid type for fill");
94 auto subV = Kokkos::subview(view, range1, range2, range3);
95 Kokkos::deep_copy(subV, val);
98 template<
typename T,
typename... properties>
102 static_assert(std::is_trivially_copyable_v<T>,
"Not valid type for fill");
103 Kokkos::deep_copy(view, val);
106 template<
typename Type,
typename... properties>
116 std::is_trivially_copyable_v<Type>,
"Not valid type for fill"
118 using ExecutionSpace =
119 typename ViewType1D<Type, properties...>::execution_space;
120 uint32 numElems = end - start;
122 pFlow::algorithms::KOKKOS::fillSequence<Type, ExecutionSpace>(
123 view.data() + start, numElems, startVal
131 typename... properties,
133 typename... indexProperties>
143 std::is_trivially_copyable_v<Type>,
"Not valid type for fillSelected"
149 "In fillSelected, arguments view and indices must have similar spaces"
152 using ExSpace =
typename ViewType1D<Type, properties...>::execution_space;
153 using policy = Kokkos::RangePolicy<ExSpace, Kokkos::IndexType<uint32>>;
155 Kokkos::parallel_for(
156 "ViewAlgorithms::fillSelected",
169 typename... properties,
171 typename... indexProperties>
181 std::is_trivially_copyable_v<Type>,
"Not valid type for fillSelected"
187 "In fillSelected arguments view and indices must have similar spaces"
190 using ExecutionSpace =
191 typename ViewType1D<Type, properties...>::execution_space;
193 pFlow::algorithms::KOKKOS::fillSelected<Type, indexType, ExecutionSpace>(
194 view.data(), indices.data(), vals.data(), numElems
200 template<
typename T,
typename... properties>
204 using ExecutionSpace =
205 typename ViewType1D<T, properties...>::execution_space;
207 uint32 numElems = end - start;
209 return pFlow::algorithms::KOKKOS::min<T, ExecutionSpace>(
210 view.data() + start, numElems
214 template<
typename T,
typename... properties>
218 using ExecutionSpace =
219 typename ViewType1D<T, properties...>::execution_space;
221 uint32 numElems = end - start;
223 return pFlow::algorithms::KOKKOS::max<T, ExecutionSpace>(
224 view.data() + start, numElems
230 typename... dProperties,
232 typename... sProperties>
239 Kokkos::deep_copy(dst, src);
244 typename... dProperties,
246 typename... sProperties>
257 auto srcSub = Kokkos::subview(
259 Kokkos::make_pair(sStart, sEnd));
261 auto dstSub = Kokkos::subview(
263 Kokkos::make_pair(dStart, dStart + (sEnd - sStart)));
265 Kokkos::deep_copy(dstSub, srcSub);
268 template<
typename Type,
typename... sProperties>
272 auto subV = Kokkos::subview(src, Kokkos::make_pair(
n,
n + 1));
275 Kokkos::deep_copy(dstView, subV);
276 dst = *dstView.data();
279 template<
typename T,
typename... properties>
283 using ExecutionSpace =
284 typename ViewType1D<T, properties...>::execution_space;
286 uint32 numElems = end - start;
288 if constexpr (isHostAccessible<ExecutionSpace>())
290 pFlow::algorithms::STD::sort<T, true>(view.data() + start, numElems);
296 pFlow::algorithms::CUDA::sort<T>(view.data() + start, numElems);
298 static_assert(
"sort on device is not defined!");
305 template<
typename T,
typename... properties,
typename CompareFunc>
314 using ExecutionSpace =
315 typename ViewType1D<T, properties...>::execution_space;
317 uint32 numElems = end - start;
319 if constexpr (isHostAccessible<ExecutionSpace>())
321 pFlow::algorithms::STD::sort<T, CompareFunc, true>(
322 view.data() + start, numElems, compare
329 pFlow::algorithms::CUDA::sort<T, CompareFunc>(
330 view.data() + start, numElems, compare
333 static_assert(
"sort on device is not defined!");
342 typename... properties,
344 typename... permProperties>
358 "In permuteSort, view and permuteView should have the same space"
361 using ExecutionSpace =
362 typename ViewType1D<Type, properties...>::execution_space;
364 uint32 numElems = end - start;
366 pFlow::algorithms::STD::permuteSort<Type, permType, true>(
367 view.data() + start, permuteView.data() + permStart, numElems
374 view.data() + start, permuteView.data() + permStart, numElems
377 static_assert(
"sort on device is not defined!");
394 int mid = low + (high - low) / 2;
396 if (array[mid] > val)
400 else if (array[mid] < val)
414 template<
typename Type,
typename... properties>
424 return static_cast<uint32>(-1);
426 if (
auto res =
binarySearch_(view.data() + start, end - start, val);
427 res !=
static_cast<uint32>(-1))
437 template<
typename Type,
typename... properties,
typename... dProperties>
451 "In exclusiveScan, view and dView should have the same space"
455 using ExecutionSpace =
456 typename ViewType1D<Type, properties...>::execution_space;
458 uint32 numElems = end - start;
460 pFlow::algorithms::KOKKOS::exclusiveScan<Type, ExecutionSpace>(
461 view.data() + start, dView.data() + dStart, numElems
465 template<
typename Type,
typename... properties,
typename... dProperties>
475 using ExecutionSpace =
476 typename ViewType1D<Type, properties...>::execution_space;
482 "In exclusiveScan, view and dView should have the same space"
485 uint32 numElems = end - start;
487 pFlow::algorithms::KOKKOS::inclusiveScan<Type, ExecutionSpace>(
488 view.data() + start, dView.data() + dStart, numElems
494 #endif // __ViewAlgorithms_hpp__