VTK-m  2.2
DeviceAdapterAlgorithmKokkos.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_kokkos_internal_DeviceAdapterAlgorithmKokkos_h
11 #define vtk_m_cont_kokkos_internal_DeviceAdapterAlgorithmKokkos_h
12 
20 
23 
25 
26 #include <vtkmstd/void_t.h>
27 
29 #include <Kokkos_Core.hpp>
30 #include <Kokkos_DualView.hpp>
31 #include <Kokkos_Sort.hpp>
33 
34 #include <type_traits>
35 
36 #if KOKKOS_VERSION_MAJOR > 3 || (KOKKOS_VERSION_MAJOR == 3 && KOKKOS_VERSION_MINOR >= 7)
37 #define VTKM_VOLATILE
38 #else
39 #define VTKM_VOLATILE volatile
40 #endif
41 
42 #if defined(VTKM_ENABLE_KOKKOS_THRUST) && (defined(__HIP__) || defined(__CUDA__))
43 #define VTKM_USE_KOKKOS_THRUST
44 #endif
45 
46 #if defined(VTKM_USE_KOKKOS_THRUST)
47 #include <thrust/device_ptr.h>
48 #include <thrust/iterator/constant_iterator.h>
49 #include <thrust/sort.h>
50 #endif
51 
52 namespace vtkm
53 {
54 namespace internal
55 {
56 
57 template <typename, typename = void>
58 struct is_type_complete : public std::false_type
59 {
60 };
61 
62 template <typename T>
63 struct is_type_complete<T, vtkmstd::void_t<decltype(sizeof(T))>> : public std::true_type
64 {
65 };
66 } // internal
67 
68 namespace cont
69 {
70 
71 namespace kokkos
72 {
73 namespace internal
74 {
75 
76 //----------------------------------------------------------------------------
77 template <typename BitsPortal>
78 struct BitFieldToBoolField : public vtkm::exec::FunctorBase
79 {
80  VTKM_EXEC_CONT BitFieldToBoolField() {}
81 
82  VTKM_CONT
83  explicit BitFieldToBoolField(const BitsPortal& bp)
84  : Bits(bp)
85  {
86  }
87 
88  VTKM_EXEC bool operator()(vtkm::Id bitIdx) const { return this->Bits.GetBit(bitIdx); }
89 
90 private:
91  BitsPortal Bits;
92 };
93 
94 template <typename BitsPortal>
95 struct BitFieldCountSetBitsWord : public vtkm::exec::FunctorBase
96 {
97  VTKM_EXEC_CONT BitFieldCountSetBitsWord() {}
98 
99  VTKM_CONT
100  explicit BitFieldCountSetBitsWord(const BitsPortal& bp)
101  : Bits(bp)
102  {
103  }
104 
105  VTKM_EXEC vtkm::Id operator()(vtkm::Id wordIdx) const
106  {
107  auto word = this->Bits.GetWord(wordIdx);
108  if (wordIdx == (this->Bits.GetNumberOfWords() - 1))
109  {
110  word &= this->Bits.GetFinalWordMask();
111  }
112 
113  return vtkm::CountSetBits(word);
114  }
115 
116 private:
117  BitsPortal Bits;
118 };
119 
120 //----------------------------------------------------------------------------
121 template <typename Operator, typename ResultType>
122 struct ReductionIdentity;
123 
124 template <typename ResultType>
125 struct ReductionIdentity<vtkm::Sum, ResultType>
126 {
127  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::sum();
128 };
129 
130 template <typename ResultType>
131 struct ReductionIdentity<vtkm::Add, ResultType>
132 {
133  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::sum();
134 };
135 
136 template <typename ResultType>
137 struct ReductionIdentity<vtkm::Product, ResultType>
138 {
139  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::prod();
140 };
141 
142 template <typename ResultType>
143 struct ReductionIdentity<vtkm::Multiply, ResultType>
144 {
145  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::prod();
146 };
147 
148 template <typename ResultType>
149 struct ReductionIdentity<vtkm::Minimum, ResultType>
150 {
151  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::min();
152 };
153 
154 template <typename ResultType>
155 struct ReductionIdentity<vtkm::Maximum, ResultType>
156 {
157  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::max();
158 };
159 
160 template <typename ResultType>
161 struct ReductionIdentity<vtkm::MinAndMax<ResultType>, vtkm::Vec<ResultType, 2>>
162 {
163  static constexpr vtkm::Vec<ResultType, 2> value =
164  vtkm::Vec<ResultType, 2>(Kokkos::reduction_identity<ResultType>::min(),
165  Kokkos::reduction_identity<ResultType>::max());
166 };
167 
168 template <typename ResultType>
169 struct ReductionIdentity<vtkm::BitwiseAnd, ResultType>
170 {
171  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::band();
172 };
173 
174 template <typename ResultType>
175 struct ReductionIdentity<vtkm::BitwiseOr, ResultType>
176 {
177  static constexpr ResultType value = Kokkos::reduction_identity<ResultType>::bor();
178 };
179 }
180 } // kokkos::internal
181 
182 //=============================================================================
183 template <>
185  : vtkm::cont::internal::DeviceAdapterAlgorithmGeneral<
186  DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagKokkos>,
187  vtkm::cont::DeviceAdapterTagKokkos>
188 {
189 private:
190  using Superclass = vtkm::cont::internal::DeviceAdapterAlgorithmGeneral<
193 
194  VTKM_CONT_EXPORT static vtkm::exec::internal::ErrorMessageBuffer GetErrorMessageBufferInstance();
195  VTKM_CONT_EXPORT static void CheckForErrors();
196 
197 public:
198  template <typename IndicesStorage>
200  const vtkm::cont::BitField& bits,
202  {
203  vtkm::cont::Token token;
204  auto bitsPortal = bits.PrepareForInput(DeviceAdapterTagKokkos{}, token);
205  auto bits2bools = kokkos::internal::BitFieldToBoolField<decltype(bitsPortal)>(bitsPortal);
206 
210  indices);
211 
212  return indices.GetNumberOfValues();
213  }
214 
216  {
217  vtkm::cont::Token token;
218  auto bitsPortal = bits.PrepareForInput(DeviceAdapterTagKokkos{}, token);
219  auto countPerWord =
220  kokkos::internal::BitFieldCountSetBitsWord<decltype(bitsPortal)>(bitsPortal);
221 
223  vtkm::cont::make_ArrayHandleImplicit(countPerWord, bitsPortal.GetNumberOfWords()),
224  vtkm::Id{ 0 });
225  }
226 
227  //----------------------------------------------------------------------------
228  using Superclass::Copy;
229 
230  template <typename T>
231  VTKM_CONT static void Copy(const vtkm::cont::ArrayHandle<T>& input,
233  {
234  const vtkm::Id inSize = input.GetNumberOfValues();
235 
236  vtkm::cont::Token token;
237 
238  auto portalIn = input.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
239  auto portalOut = output.PrepareForOutput(inSize, vtkm::cont::DeviceAdapterTagKokkos{}, token);
240 
241 
242  kokkos::internal::KokkosViewConstExec<T> viewIn(portalIn.GetArray(), inSize);
243  kokkos::internal::KokkosViewExec<T> viewOut(portalOut.GetArray(), inSize);
244  Kokkos::deep_copy(vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), viewOut, viewIn);
245  }
246 
247  //----------------------------------------------------------------------------
248 #ifndef VTKM_CUDA
249  // nvcc doesn't like the private class declaration so disable under CUDA
250 private:
251 #endif
252  template <typename ArrayHandle, typename BinaryOperator, typename ResultType>
253  VTKM_CONT static ResultType ReduceImpl(const ArrayHandle& input,
254  BinaryOperator binaryOperator,
255  ResultType initialValue,
256  std::false_type)
257  {
258  return Superclass::Reduce(input, initialValue, binaryOperator);
259  }
260 
261  template <typename BinaryOperator, typename FunctorOperator, typename ResultType>
262  class KokkosReduceFunctor
263  {
264  public:
266  using value_type = ResultType;
267 
268  KOKKOS_INLINE_FUNCTION
270 
271  template <typename... Args>
272  KOKKOS_INLINE_FUNCTION explicit KokkosReduceFunctor(const BinaryOperator& op, Args... args)
273  : Operator(op)
274  , Functor(std::forward<Args>(args)...)
275  {
276  }
277 
278  KOKKOS_INLINE_FUNCTION
279  void join(VTKM_VOLATILE value_type& dst, const VTKM_VOLATILE value_type& src) const
280  {
281  dst = this->Operator(dst, src);
282  }
283 
284  KOKKOS_INLINE_FUNCTION
285  void init(value_type& dst) const
286  {
287  dst = kokkos::internal::ReductionIdentity<BinaryOperator, value_type>::value;
288  }
289 
290  // Reduce operator
291  KOKKOS_INLINE_FUNCTION
292  void operator()(vtkm::Id i, ResultType& update) const
293  {
294  this->Functor(this->Operator, i, update);
295  }
296 
297  // Scan operator
298  KOKKOS_INLINE_FUNCTION
299  void operator()(vtkm::Id i, ResultType& update, const bool final) const
300  {
301  this->Functor(this->Operator, i, update, final);
302  }
303 
304  private:
305  BinaryOperator Operator;
306  FunctorOperator Functor;
307  };
308 
309  template <typename ArrayPortal, typename BinaryOperator, typename ResultType>
310  class ReduceOperator
311  {
312  public:
313  KOKKOS_INLINE_FUNCTION
315 
316  KOKKOS_INLINE_FUNCTION
317  explicit ReduceOperator(const ArrayPortal& portal)
318  : Portal(portal)
319  {
320  }
321 
322  KOKKOS_INLINE_FUNCTION
323  void operator()(const BinaryOperator& op, vtkm::Id i, ResultType& update) const
324  {
325  update = op(update, this->Portal.Get(i));
326  }
327 
328  private:
330  };
331 
332  template <typename BinaryOperator, typename ArrayPortal, typename ResultType>
333  using ReduceFunctor = KokkosReduceFunctor<BinaryOperator,
334  ReduceOperator<ArrayPortal, BinaryOperator, ResultType>,
335  ResultType>;
336 
337  template <typename ArrayHandle, typename BinaryOperator, typename ResultType>
338  VTKM_CONT static ResultType ReduceImpl(const ArrayHandle& input,
339  BinaryOperator binaryOperator,
340  ResultType initialValue,
341  std::true_type)
342  {
343  vtkm::cont::Token token;
344  auto inputPortal = input.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
345 
346  ReduceFunctor<BinaryOperator, decltype(inputPortal), ResultType> functor(binaryOperator,
347  inputPortal);
348 
349  ResultType result;
350 
351  Kokkos::RangePolicy<vtkm::cont::kokkos::internal::ExecutionSpace, vtkm::Id> policy(
352  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), 0, input.GetNumberOfValues());
353  Kokkos::parallel_reduce(policy, functor, result);
354 
355  return binaryOperator(initialValue, result);
356  }
357 
358  template <bool P1, typename BinaryOperator, typename ResultType>
359  struct UseKokkosReduceP1 : std::false_type
360  {
361  };
362 
363  template <typename BinaryOperator, typename ResultType>
364  struct UseKokkosReduceP1<true, BinaryOperator, ResultType>
365  : vtkm::internal::is_type_complete<
366  kokkos::internal::ReductionIdentity<BinaryOperator, ResultType>>
367  {
368  };
369 
370  template <typename BinaryOperator, typename ResultType>
371  struct UseKokkosReduce
372  : UseKokkosReduceP1<
373  vtkm::internal::is_type_complete<Kokkos::reduction_identity<ResultType>>::value,
374  BinaryOperator,
375  ResultType>
376  {
377  };
378 
379 public:
380  template <typename T, typename U, class CIn, class BinaryOperator>
382  U initialValue,
383  BinaryOperator binaryOperator)
384  {
386 
387  if (input.GetNumberOfValues() == 0)
388  {
389  return initialValue;
390  }
391  if (input.GetNumberOfValues() == 1)
392  {
393  return binaryOperator(initialValue, input.ReadPortal().Get(0));
394  }
395 
396 #if defined(VTKM_KOKKOS_CUDA)
397  // Kokkos reduce is having some issues with the cuda backend. Please refer to issue #586.
398  // Following is a work around where we use the Superclass reduce implementation when using
399  // Cuda execution space.
400  std::integral_constant<
401  bool,
402  !std::is_same<vtkm::cont::kokkos::internal::ExecutionSpace, Kokkos::Cuda>::value &&
403  UseKokkosReduce<BinaryOperator, U>::value>
404  use_kokkos_reduce;
405 #else
406  typename UseKokkosReduce<BinaryOperator, U>::type use_kokkos_reduce;
407 #endif
408  return ReduceImpl(input, binaryOperator, initialValue, use_kokkos_reduce);
409  }
410 
411  template <typename T, typename U, class CIn>
412  VTKM_CONT static U Reduce(const vtkm::cont::ArrayHandle<T, CIn>& input, U initialValue)
413  {
415 
416  return Reduce(input, initialValue, vtkm::Add());
417  }
418 
419  //----------------------------------------------------------------------------
420 #ifndef VTKM_CUDA
421  // nvcc doesn't like the private class declaration so disable under CUDA
422 private:
423 #endif
424  // Scan and Reduce have the same conditions
425  template <typename BinaryOperator, typename ResultType>
426  using UseKokkosScan = UseKokkosReduce<BinaryOperator, ResultType>;
427 
428  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
431  BinaryOperator binaryOperator,
432  const T& initialValue,
433  std::false_type)
434  {
435  return Superclass::ScanExclusive(input, output, binaryOperator, initialValue);
436  }
437 
438  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
439  class ScanExclusiveOperator
440  {
441  private:
444 
445  public:
446  KOKKOS_INLINE_FUNCTION
448 
449  KOKKOS_INLINE_FUNCTION
450  explicit ScanExclusiveOperator(const ArrayPortalIn& portalIn,
451  const ArrayPortalOut& portalOut,
452  const T& initialValue)
453  : PortalIn(portalIn)
454  , PortalOut(portalOut)
455  , InitialValue(initialValue)
456  {
457  }
458 
459  KOKKOS_INLINE_FUNCTION
460  void operator()(const BinaryOperator& op, const vtkm::Id i, T& update, const bool final) const
461  {
462  auto val = this->PortalIn.Get(i);
463  if (i == 0)
464  {
465  update = InitialValue;
466  }
467  if (final)
468  {
469  this->PortalOut.Set(i, update);
470  }
471  update = op(update, val);
472  }
473 
474  private:
478  };
479 
480  template <typename BinaryOperator, typename T, typename StorageIn, typename StorageOut>
481  using ScanExclusiveFunctor =
482  KokkosReduceFunctor<BinaryOperator,
483  ScanExclusiveOperator<T, StorageIn, StorageOut, BinaryOperator>,
484  T>;
485 
486  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
489  BinaryOperator binaryOperator,
490  const T& initialValue,
491  std::true_type)
492  {
493  vtkm::Id length = input.GetNumberOfValues();
494 
495  vtkm::cont::Token token;
496  auto inputPortal = input.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
497  auto outputPortal =
498  output.PrepareForOutput(length, vtkm::cont::DeviceAdapterTagKokkos{}, token);
499 
501  binaryOperator, inputPortal, outputPortal, initialValue);
502 
504  Kokkos::RangePolicy<vtkm::cont::kokkos::internal::ExecutionSpace, vtkm::Id> policy(
505  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), 0, length);
506  Kokkos::parallel_scan(policy, functor, result);
507 
508  return result;
509  }
510 
511 public:
512  template <typename T, class CIn, class COut, class BinaryOperator>
515  BinaryOperator binaryOperator,
516  const T& initialValue)
517  {
519 
520  vtkm::Id length = input.GetNumberOfValues();
521  if (length == 0)
522  {
523  output.ReleaseResources();
524  return initialValue;
525  }
526  if (length == 1)
527  {
528  auto v0 = input.ReadPortal().Get(0);
529  Fill(output, initialValue, 1);
530  return binaryOperator(initialValue, v0);
531  }
532 
533 #if defined(VTKM_KOKKOS_CUDA)
534  // Kokkos scan for the cuda backend is not working correctly for int/uint types of 8 and 16 bits.
535  std::integral_constant<bool,
536  !(std::is_integral<T>::value && sizeof(T) < 4) &&
538  use_kokkos_scan;
539 #else
540  typename UseKokkosScan<BinaryOperator, T>::type use_kokkos_scan;
541 #endif
542  return ScanExclusiveImpl(input, output, binaryOperator, initialValue, use_kokkos_scan);
543  }
544 
545  template <typename T, class CIn, class COut>
548  {
550 
552  }
553 
554  //----------------------------------------------------------------------------
555 #ifndef VTKM_CUDA
556  // nvcc doesn't like the private class declaration so disable under CUDA
557 private:
558 #endif
559  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
562  BinaryOperator binaryOperator,
563  std::false_type)
564  {
565  return Superclass::ScanInclusive(input, output, binaryOperator);
566  }
567 
568  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
569  class ScanInclusiveOperator
570  {
571  private:
574 
575  public:
576  KOKKOS_INLINE_FUNCTION
578 
579  KOKKOS_INLINE_FUNCTION
580  explicit ScanInclusiveOperator(const ArrayPortalIn& portalIn, const ArrayPortalOut& portalOut)
581  : PortalIn(portalIn)
582  , PortalOut(portalOut)
583  {
584  }
585 
586  KOKKOS_INLINE_FUNCTION
587  void operator()(const BinaryOperator& op, const vtkm::Id i, T& update, const bool final) const
588  {
589  update = op(update, this->PortalIn.Get(i));
590  if (final)
591  {
592  this->PortalOut.Set(i, update);
593  }
594  }
595 
596  private:
599  };
600 
601  template <typename BinaryOperator, typename T, typename StorageIn, typename StorageOut>
602  using ScanInclusiveFunctor =
603  KokkosReduceFunctor<BinaryOperator,
604  ScanInclusiveOperator<T, StorageIn, StorageOut, BinaryOperator>,
605  T>;
606 
607  template <typename T, typename StorageIn, typename StorageOut, typename BinaryOperator>
610  BinaryOperator binaryOperator,
611  std::true_type)
612  {
613  vtkm::Id length = input.GetNumberOfValues();
614 
615  vtkm::cont::Token token;
616  auto inputPortal = input.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
617  auto outputPortal =
618  output.PrepareForOutput(length, vtkm::cont::DeviceAdapterTagKokkos{}, token);
619 
621  binaryOperator, inputPortal, outputPortal);
622 
624  Kokkos::RangePolicy<vtkm::cont::kokkos::internal::ExecutionSpace, vtkm::Id> policy(
625  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), 0, length);
626  Kokkos::parallel_scan(policy, functor, result);
627 
628  return result;
629  }
630 
631 public:
632  template <typename T, class CIn, class COut, class BinaryOperator>
635  BinaryOperator binaryOperator)
636  {
638 
639  vtkm::Id length = input.GetNumberOfValues();
640  if (length == 0)
641  {
643  }
644  if (length == 1)
645  {
646  auto result = input.ReadPortal().Get(0);
647  Fill(output, result, 1);
648  return result;
649  }
650 
651 #if defined(VTKM_KOKKOS_CUDA)
652  // Kokkos scan for the cuda backend is not working correctly for int/uint types of 8 and 16 bits.
653  std::integral_constant<bool,
654  !(std::is_integral<T>::value && sizeof(T) < 4) &&
656  use_kokkos_scan;
657 #else
658  typename UseKokkosScan<BinaryOperator, T>::type use_kokkos_scan;
659 #endif
660  return ScanInclusiveImpl(input, output, binaryOperator, use_kokkos_scan);
661  }
662 
663  template <typename T, class CIn, class COut>
666  {
668 
669  return ScanInclusive(input, output, vtkm::Add());
670  }
671 
672  //----------------------------------------------------------------------------
673  template <typename WType, typename IType, typename Hints>
674  VTKM_CONT static void ScheduleTask(
675  vtkm::exec::kokkos::internal::TaskBasic1D<WType, IType, Hints>& functor,
676  vtkm::Id numInstances)
677  {
679 
680  if (numInstances < 1)
681  {
682  // No instances means nothing to run. Just return.
683  return;
684  }
685 
686  functor.SetErrorMessageBuffer(GetErrorMessageBufferInstance());
687 
688  constexpr vtkm::IdComponent maxThreadsPerBlock =
689  vtkm::cont::internal::HintFind<Hints,
690  vtkm::cont::internal::HintThreadsPerBlock<0>,
692 
693  Kokkos::RangePolicy<vtkm::cont::kokkos::internal::ExecutionSpace,
694  Kokkos::LaunchBounds<maxThreadsPerBlock, 0>,
695  Kokkos::IndexType<vtkm::Id>>
696  policy(vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), 0, numInstances);
697  Kokkos::parallel_for(policy, functor);
698  CheckForErrors(); // synchronizes
699  }
700 
701  template <typename WType, typename IType, typename Hints>
702  VTKM_CONT static void ScheduleTask(
703  vtkm::exec::kokkos::internal::TaskBasic3D<WType, IType, Hints>& functor,
704  vtkm::Id3 rangeMax)
705  {
707 
708  if ((rangeMax[0] < 1) || (rangeMax[1] < 1) || (rangeMax[2] < 1))
709  {
710  // No instances means nothing to run. Just return.
711  return;
712  }
713 
714  functor.SetErrorMessageBuffer(GetErrorMessageBufferInstance());
715 
716  constexpr vtkm::IdComponent maxThreadsPerBlock =
717  vtkm::cont::internal::HintFind<Hints,
718  vtkm::cont::internal::HintThreadsPerBlock<0>,
720 
721  Kokkos::MDRangePolicy<vtkm::cont::kokkos::internal::ExecutionSpace,
722  Kokkos::LaunchBounds<maxThreadsPerBlock, 0>,
723  Kokkos::Rank<3>,
724  Kokkos::IndexType<vtkm::Id>>
725  policy(vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(),
726  { 0, 0, 0 },
727  { rangeMax[0], rangeMax[1], rangeMax[2] });
728 
729  // Calling rangeMax[X] inside KOKKOS_LAMBDA confuses some compilers since
730  // at first it tries to use the non-const inline vec_base::operator[0]
731  // method, however, KOKKOS_LAMBDA DOES converts rangeMax to a const
732  // vec_base. This convertion is somehow catched by the compiler making it
733  // complain that we are using a non-const method for a const object.
734  const auto rMax_0 = rangeMax[0];
735  const auto rMax_1 = rangeMax[1];
736 
737  Kokkos::parallel_for(
738  policy, KOKKOS_LAMBDA(vtkm::Id i, vtkm::Id j, vtkm::Id k) {
739  auto flatIdx = i + (j * rMax_0) + (k * rMax_0 * rMax_1);
740  functor(vtkm::Id3(i, j, k), flatIdx);
741  });
742  CheckForErrors(); // synchronizes
743  }
744 
745  template <typename Hints, typename Functor>
746  VTKM_CONT static void Schedule(Hints, Functor functor, vtkm::Id numInstances)
747  {
749 
750  vtkm::exec::kokkos::internal::TaskBasic1D<Functor, vtkm::internal::NullType, Hints> kernel(
751  functor);
752  ScheduleTask(kernel, numInstances);
753  }
754 
755  template <typename FunctorType>
756  VTKM_CONT static inline void Schedule(FunctorType&& functor, vtkm::Id numInstances)
757  {
758  Schedule(vtkm::cont::internal::HintList<>{}, functor, numInstances);
759  }
760 
761  template <typename Hints, typename Functor>
762  VTKM_CONT static void Schedule(Hints, Functor functor, const vtkm::Id3& rangeMax)
763  {
765 
766  vtkm::exec::kokkos::internal::TaskBasic3D<Functor, vtkm::internal::NullType, Hints> kernel(
767  functor);
768  ScheduleTask(kernel, rangeMax);
769  }
770 
771  template <typename FunctorType>
772  VTKM_CONT static inline void Schedule(FunctorType&& functor, vtkm::Id3 rangeMax)
773  {
774  Schedule(vtkm::cont::internal::HintList<>{}, functor, rangeMax);
775  }
776 
777  //----------------------------------------------------------------------------
778 private:
779  template <typename T>
780  VTKM_CONT static void SortImpl(vtkm::cont::ArrayHandle<T>& values, vtkm::SortLess, std::true_type)
781  {
782  // In Kokkos 3.7, we have noticed some errors when sorting with zero-length arrays (which
783  // should do nothing). There is no check, and the bin size computation gets messed up.
784  if (values.GetNumberOfValues() <= 1)
785  {
786  return;
787  }
788 
789  vtkm::cont::Token token;
790  auto portal = values.PrepareForInPlace(vtkm::cont::DeviceAdapterTagKokkos{}, token);
791  kokkos::internal::KokkosViewExec<T> view(portal.GetArray(), portal.GetNumberOfValues());
792 
793  // We use per-thread execution spaces so that the threads can execute independently without
794  // requiring global synchronizations.
795  // Currently, there is no way to specify the execution space for sort and therefore it
796  // executes in the default execution space.
797  // Therefore, we need explicit syncs here.
798  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance().fence();
799  Kokkos::sort(view);
800  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance().fence();
801  }
802 
803  template <typename T>
805  vtkm::SortLess comp,
806  std::false_type)
807  {
808  Superclass::Sort(values, comp);
809  }
810 
811 public:
812  using Superclass::Sort;
813 
814  template <typename T>
816  {
817  SortImpl(values, comp, typename std::is_scalar<T>::type{});
818  }
819 
820 protected:
821  // Kokkos currently (11/10/2022) does not support a sort_by_key operator
822  // so instead we are using thrust if and only if HIP or CUDA are the backends for Kokkos
823 #if defined(VTKM_USE_KOKKOS_THRUST)
824 
825  template <typename T, typename U, typename BinaryCompare>
826  VTKM_CONT static std::enable_if_t<(std::is_same<BinaryCompare, vtkm::SortLess>::value ||
827  std::is_same<BinaryCompare, vtkm::SortGreater>::value)>
828  SortByKeyImpl(vtkm::cont::ArrayHandle<T>& keys,
830  BinaryCompare,
831  std::true_type,
832  std::true_type)
833  {
834  vtkm::cont::Token token;
835  auto keys_portal = keys.PrepareForInPlace(vtkm::cont::DeviceAdapterTagKokkos{}, token);
836  auto values_portal = values.PrepareForInPlace(vtkm::cont::DeviceAdapterTagKokkos{}, token);
837 
838  kokkos::internal::KokkosViewExec<T> keys_view(keys_portal.GetArray(),
839  keys_portal.GetNumberOfValues());
840  kokkos::internal::KokkosViewExec<U> values_view(values_portal.GetArray(),
841  values_portal.GetNumberOfValues());
842 
843  thrust::device_ptr<T> keys_begin(keys_view.data());
844  thrust::device_ptr<T> keys_end(keys_view.data() + keys_view.size());
845  thrust::device_ptr<U> values_begin(values_view.data());
846 
847  if (std::is_same<BinaryCompare, vtkm::SortLess>::value)
848  {
849  thrust::sort_by_key(keys_begin, keys_end, values_begin, thrust::less<T>());
850  }
851  else
852  {
853  thrust::sort_by_key(keys_begin, keys_end, values_begin, thrust::greater<T>());
854  }
855  }
856 
857 #endif
858 
859  template <typename T,
860  typename U,
861  class StorageT,
862  class StorageU,
863  class BinaryCompare,
864  typename ValidKeys,
865  typename ValidValues>
868  BinaryCompare binary_compare,
869  ValidKeys,
870  ValidValues)
871  {
872  // Default to general algorithm
873  Superclass::SortByKey(keys, values, binary_compare);
874  }
875 
876 public:
877  template <typename T, typename U, class StorageT, class StorageU>
880  {
881  // Make sure not to use the general algorithm here since
882  // it will use Sort algorithm instead of SortByKey
884  }
885 
886  template <typename T, typename U, class StorageT, class StorageU, class BinaryCompare>
889  BinaryCompare binary_compare)
890  {
891  // If T or U are not scalar types, or the BinaryCompare is not supported
892  // then the general algorithm is called, otherwise we will run thrust
893  SortByKeyImpl(keys,
894  values,
895  binary_compare,
896  typename std::is_scalar<T>::type{},
897  typename std::is_scalar<U>::type{});
898  }
899 
900  //----------------------------------------------------------------------------
901  // Reduce By Key
902 
903 #ifdef VTKM_USE_KOKKOS_THRUST
904 
905 protected:
906  template <typename K, typename V, class BinaryFunctor>
907  VTKM_CONT static void ReduceByKeyImpl(const vtkm::cont::ArrayHandle<K>& keys,
908  const vtkm::cont::ArrayHandle<V>& values,
909  vtkm::cont::ArrayHandle<K>& keys_output,
910  vtkm::cont::ArrayHandle<V>& values_output,
911  BinaryFunctor binary_functor)
912  {
914 
915  const vtkm::Id numberOfKeys = keys.GetNumberOfValues();
916 
917  vtkm::Id num_unique_keys;
918  {
919  vtkm::cont::Token token;
920 
921  auto keys_portal = keys.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
922  auto values_portal = values.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
923 
924  auto keys_output_portal =
925  keys_output.PrepareForOutput(numberOfKeys, vtkm::cont::DeviceAdapterTagKokkos{}, token);
926  auto values_output_portal =
927  values_output.PrepareForOutput(numberOfKeys, vtkm::cont::DeviceAdapterTagKokkos{}, token);
928 
929  thrust::device_ptr<const K> keys_begin(keys_portal.GetArray());
930  thrust::device_ptr<const K> keys_end(keys_portal.GetArray() + numberOfKeys);
931  thrust::device_ptr<const V> values_begin(values_portal.GetArray());
932  thrust::device_ptr<K> keys_output_begin(keys_output_portal.GetArray());
933  thrust::device_ptr<V> values_output_begin(values_output_portal.GetArray());
934 
935  auto ends = thrust::reduce_by_key(keys_begin,
936  keys_end,
937  values_begin,
938  keys_output_begin,
939  values_output_begin,
940  thrust::equal_to<K>(),
941  binary_functor);
942 
943  num_unique_keys = ends.first - keys_output_begin;
944  }
945 
946  // Resize output (reduce allocation)
947  keys_output.Allocate(num_unique_keys, CopyFlag::On);
948  values_output.Allocate(num_unique_keys, CopyFlag::On);
949  }
950 
951 
952  template <typename K, typename V, class BinaryFunctor>
953  VTKM_CONT static void ReduceByKeyImpl(
954  const vtkm::cont::ArrayHandle<K>& keys,
956  vtkm::cont::ArrayHandle<K>& keys_output,
957  vtkm::cont::ArrayHandle<V>& values_output,
958  BinaryFunctor binary_functor)
959  {
961 
962  const vtkm::Id numberOfKeys = keys.GetNumberOfValues();
963 
964  vtkm::Id num_unique_keys;
965  {
966  vtkm::cont::Token token;
967 
968  auto keys_portal = keys.PrepareForInput(vtkm::cont::DeviceAdapterTagKokkos{}, token);
969  auto value = values.ReadPortal().Get(0);
970 
971  auto keys_output_portal =
972  keys_output.PrepareForOutput(numberOfKeys, vtkm::cont::DeviceAdapterTagKokkos{}, token);
973  auto values_output_portal =
974  values_output.PrepareForOutput(numberOfKeys, vtkm::cont::DeviceAdapterTagKokkos{}, token);
975 
976  thrust::device_ptr<const K> keys_begin(keys_portal.GetArray());
977  thrust::device_ptr<const K> keys_end(keys_portal.GetArray() + numberOfKeys);
978  thrust::constant_iterator<const V> values_begin(value);
979  thrust::device_ptr<K> keys_output_begin(keys_output_portal.GetArray());
980  thrust::device_ptr<V> values_output_begin(values_output_portal.GetArray());
981 
982  auto ends = thrust::reduce_by_key(keys_begin,
983  keys_end,
984  values_begin,
985  keys_output_begin,
986  values_output_begin,
987  thrust::equal_to<K>(),
988  binary_functor);
989 
990  num_unique_keys = ends.first - keys_output_begin;
991  }
992 
993  // Resize output (reduce allocation)
994  keys_output.Allocate(num_unique_keys, CopyFlag::On);
995  values_output.Allocate(num_unique_keys, CopyFlag::On);
996  }
997 
998  template <typename T,
999  typename U,
1000  class KIn,
1001  class VIn,
1002  class KOut,
1003  class VOut,
1004  class BinaryFunctor>
1005  VTKM_CONT static void ReduceByKeyImpl(const vtkm::cont::ArrayHandle<T, KIn>& keys,
1006  const vtkm::cont::ArrayHandle<U, VIn>& values,
1007  vtkm::cont::ArrayHandle<T, KOut>& keys_output,
1008  vtkm::cont::ArrayHandle<U, VOut>& values_output,
1009  BinaryFunctor binary_functor)
1010  {
1012 
1013  Superclass::ReduceByKey(keys, values, keys_output, values_output, binary_functor);
1014  }
1015 
1016 public:
1017  template <typename T,
1018  typename U,
1019  class KIn,
1020  class VIn,
1021  class KOut,
1022  class VOut,
1023  class BinaryFunctor>
1024  VTKM_CONT static void ReduceByKey(const vtkm::cont::ArrayHandle<T, KIn>& keys,
1025  const vtkm::cont::ArrayHandle<U, VIn>& values,
1026  vtkm::cont::ArrayHandle<T, KOut>& keys_output,
1027  vtkm::cont::ArrayHandle<U, VOut>& values_output,
1028  BinaryFunctor binary_functor)
1029  {
1031 
1032  ReduceByKeyImpl(keys, values, keys_output, values_output, binary_functor);
1033  }
1034 
1035 #endif
1036 
1037  //--------------------------------------------------------------------------
1038 
1039  VTKM_CONT static void Synchronize()
1040  {
1041  vtkm::cont::kokkos::internal::GetExecutionSpaceInstance().fence();
1042  }
1043 };
1044 
1045 //=============================================================================
1046 template <>
1048 {
1049 public:
1050  template <typename Hints, typename WorkletType, typename InvocationType>
1051  VTKM_CONT static vtkm::exec::kokkos::internal::TaskBasic1D<WorkletType, InvocationType, Hints>
1052  MakeTask(WorkletType& worklet, InvocationType& invocation, vtkm::Id, Hints = Hints{})
1053  {
1054  return vtkm::exec::kokkos::internal::TaskBasic1D<WorkletType, InvocationType, Hints>(
1055  worklet, invocation);
1056  }
1057 
1058  template <typename Hints, typename WorkletType, typename InvocationType>
1059  VTKM_CONT static vtkm::exec::kokkos::internal::TaskBasic3D<WorkletType, InvocationType, Hints>
1060  MakeTask(WorkletType& worklet, InvocationType& invocation, vtkm::Id3, Hints = {})
1061  {
1062  return vtkm::exec::kokkos::internal::TaskBasic3D<WorkletType, InvocationType, Hints>(
1063  worklet, invocation);
1064  }
1065 
1066  template <typename WorkletType, typename InvocationType, typename RangeType>
1067  VTKM_CONT static auto MakeTask(WorkletType& worklet,
1068  InvocationType& invocation,
1069  const RangeType& range)
1070  {
1071  return MakeTask<vtkm::cont::internal::HintList<>>(worklet, invocation, range);
1072  }
1073 };
1074 }
1075 } // namespace vtkm::cont
1076 
1077 #undef VTKM_VOLATILE
1078 
1079 #endif //vtk_m_cont_kokkos_internal_DeviceAdapterAlgorithmKokkos_h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveImpl
static T ScanInclusiveImpl(const vtkm::cont::ArrayHandle< T, StorageIn > &input, vtkm::cont::ArrayHandle< T, StorageOut > &output, BinaryOperator binaryOperator, std::true_type)
Definition: DeviceAdapterAlgorithmKokkos.h:608
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::ArrayPortalOut
typename ArrayHandle< T, StorageOut >::WritePortalType ArrayPortalOut
Definition: DeviceAdapterAlgorithmKokkos.h:573
vtkm::cont::DeviceAdapterAlgorithm::ScanExclusive
static T ScanExclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Compute an exclusive prefix sum operation on the input ArrayHandle.
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::operator()
KOKKOS_INLINE_FUNCTION void operator()(vtkm::Id i, ResultType &update) const
Definition: DeviceAdapterAlgorithmKokkos.h:292
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveImpl
static T ScanInclusiveImpl(const vtkm::cont::ArrayHandle< T, StorageIn > &input, vtkm::cont::ArrayHandle< T, StorageOut > &output, BinaryOperator binaryOperator, std::false_type)
Definition: DeviceAdapterAlgorithmKokkos.h:560
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceOperator::ReduceOperator
KOKKOS_INLINE_FUNCTION ReduceOperator(const ArrayPortal &portal)
Definition: DeviceAdapterAlgorithmKokkos.h:317
vtkm::cont::DeviceAdapterAlgorithm::Fill
static void Fill(vtkm::cont::BitField &bits, bool value, vtkm::Id numBits)
Fill the BitField with a specific pattern of bits.
VTKM_THIRDPARTY_POST_INCLUDE
#define VTKM_THIRDPARTY_POST_INCLUDE
Definition: Configure.h:192
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Reduce
static U Reduce(const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Definition: DeviceAdapterAlgorithmKokkos.h:412
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::ScanExclusiveOperator
KOKKOS_INLINE_FUNCTION ScanExclusiveOperator()
Definition: DeviceAdapterAlgorithmKokkos.h:447
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::operator()
KOKKOS_INLINE_FUNCTION void operator()(const BinaryOperator &op, const vtkm::Id i, T &update, const bool final) const
Definition: DeviceAdapterAlgorithmKokkos.h:460
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::operator()
KOKKOS_INLINE_FUNCTION void operator()(vtkm::Id i, ResultType &update, const bool final) const
Definition: DeviceAdapterAlgorithmKokkos.h:299
vtkm::cont::DeviceTaskTypes< vtkm::cont::DeviceAdapterTagKokkos >::MakeTask
static vtkm::exec::kokkos::internal::TaskBasic1D< WorkletType, InvocationType, Hints > MakeTask(WorkletType &worklet, InvocationType &invocation, vtkm::Id, Hints=Hints{})
Definition: DeviceAdapterAlgorithmKokkos.h:1052
vtkm::Product
Binary Predicate that takes two arguments argument x, and y and returns product (multiplication) of t...
Definition: BinaryOperators.h:56
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::UseKokkosScan
UseKokkosReduce< BinaryOperator, ResultType > UseKokkosScan
Definition: DeviceAdapterAlgorithmKokkos.h:426
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::operator()
KOKKOS_INLINE_FUNCTION void operator()(const BinaryOperator &op, const vtkm::Id i, T &update, const bool final) const
Definition: DeviceAdapterAlgorithmKokkos.h:587
vtkm::BitwiseOr
Binary Predicate that takes two arguments argument x, and y and returns the bitwise operation x|y
Definition: BinaryOperators.h:168
vtkm::cont::DeviceTaskTypes< vtkm::cont::DeviceAdapterTagKokkos >::MakeTask
static vtkm::exec::kokkos::internal::TaskBasic3D< WorkletType, InvocationType, Hints > MakeTask(WorkletType &worklet, InvocationType &invocation, vtkm::Id3, Hints={})
Definition: DeviceAdapterAlgorithmKokkos.h:1060
vtkm::cont::make_ArrayHandleImplicit
vtkm::cont::ArrayHandleImplicit< FunctorType > make_ArrayHandleImplicit(FunctorType functor, vtkm::Id length)
make_ArrayHandleImplicit is convenience function to generate an ArrayHandleImplicit.
Definition: ArrayHandleImplicit.h:203
vtkm::MinAndMax
Binary Predicate that takes two arguments argument x, and y and returns a vtkm::Vec<T,...
Definition: BinaryOperators.h:112
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Sort
static void Sort(vtkm::cont::ArrayHandle< T > &values, vtkm::SortLess comp)
Definition: DeviceAdapterAlgorithmKokkos.h:815
vtkm::cont::DeviceAdapterAlgorithm::Schedule
static void Schedule(Functor functor, vtkm::Id numInstances)
Schedule many instances of a function to run on concurrent threads.
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::init
KOKKOS_INLINE_FUNCTION void init(value_type &dst) const
Definition: DeviceAdapterAlgorithmKokkos.h:285
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Schedule
static void Schedule(Hints, Functor functor, const vtkm::Id3 &rangeMax)
Definition: DeviceAdapterAlgorithmKokkos.h:762
DeviceAdapterAlgorithmGeneral.h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::size_type
vtkm::Id size_type
Definition: DeviceAdapterAlgorithmKokkos.h:265
vtkm::cont::DeviceTaskTypes< vtkm::cont::DeviceAdapterTagKokkos >::MakeTask
static auto MakeTask(WorkletType &worklet, InvocationType &invocation, const RangeType &range)
Definition: DeviceAdapterAlgorithmKokkos.h:1067
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveImpl
static T ScanExclusiveImpl(const vtkm::cont::ArrayHandle< T, StorageIn > &input, vtkm::cont::ArrayHandle< T, StorageOut > &output, BinaryOperator binaryOperator, const T &initialValue, std::true_type)
Definition: DeviceAdapterAlgorithmKokkos.h:487
VTKM_VOLATILE
#define VTKM_VOLATILE
Definition: DeviceAdapterAlgorithmKokkos.h:39
vtkm::cont::ArrayHandle::GetNumberOfValues
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:468
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceImpl
static ResultType ReduceImpl(const ArrayHandle &input, BinaryOperator binaryOperator, ResultType initialValue, std::false_type)
Definition: DeviceAdapterAlgorithmKokkos.h:253
ArrayHandleConstant.h
vtkm::Maximum
Binary Predicate that takes two arguments argument x, and y and returns the x if x > y otherwise retu...
Definition: BinaryOperators.h:85
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::CountSetBits
static vtkm::Id CountSetBits(const vtkm::cont::BitField &bits)
Definition: DeviceAdapterAlgorithmKokkos.h:215
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::SortImpl
static void SortImpl(vtkm::cont::ArrayHandle< T > &values, vtkm::SortLess comp, std::false_type)
Definition: DeviceAdapterAlgorithmKokkos.h:804
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::PortalOut
ArrayPortalOut PortalOut
Definition: DeviceAdapterAlgorithmKokkos.h:476
vtkm::cont::BitField::GetNumberOfBits
vtkm::Id GetNumberOfBits() const
Return the number of bits stored by this BitField.
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Copy
static void Copy(const vtkm::cont::ArrayHandle< T > &input, vtkm::cont::ArrayHandle< T > &output)
Definition: DeviceAdapterAlgorithmKokkos.h:231
DeviceAdapterTagKokkos.h
DeviceAdapterAlgorithm.h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveFunctor
KokkosReduceFunctor< BinaryOperator, ScanInclusiveOperator< T, StorageIn, StorageOut, BinaryOperator >, T > ScanInclusiveFunctor
Definition: DeviceAdapterAlgorithmKokkos.h:605
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::KokkosReduceFunctor
KOKKOS_INLINE_FUNCTION KokkosReduceFunctor(const BinaryOperator &op, Args... args)
Definition: DeviceAdapterAlgorithmKokkos.h:272
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::ScanExclusiveOperator
KOKKOS_INLINE_FUNCTION ScanExclusiveOperator(const ArrayPortalIn &portalIn, const ArrayPortalOut &portalOut, const T &initialValue)
Definition: DeviceAdapterAlgorithmKokkos.h:450
vtkm::cont::DeviceAdapterAlgorithm::VIn
static T VIn
Definition: DeviceAdapterAlgorithm.h:349
vtkm::Add
Definition: Types.h:260
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::Sum
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceOperator::operator()
KOKKOS_INLINE_FUNCTION void operator()(const BinaryOperator &op, vtkm::Id i, ResultType &update) const
Definition: DeviceAdapterAlgorithmKokkos.h:323
vtkm::SortLess
Binary Predicate that takes two arguments argument x, and y and returns True if and only if x is less...
Definition: BinaryPredicates.h:45
vtkm::cont::ArrayHandle::PrepareForInPlace
WritePortalType PrepareForInPlace(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used in an in-place operation (both as input and output) in the execution e...
Definition: ArrayHandle.h:618
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceImpl
static ResultType ReduceImpl(const ArrayHandle &input, BinaryOperator binaryOperator, ResultType initialValue, std::true_type)
Definition: DeviceAdapterAlgorithmKokkos.h:338
vtkm::cont::DeviceAdapterAlgorithm::KIn
static T KIn
Definition: DeviceAdapterAlgorithm.h:348
vtkm::cont::DeviceAdapterAlgorithm::ScanInclusive
static T ScanInclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Compute an inclusive prefix sum operation on the input ArrayHandle.
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Schedule
static void Schedule(FunctorType &&functor, vtkm::Id numInstances)
Definition: DeviceAdapterAlgorithmKokkos.h:756
ArrayHandleIndex.h
vtkm::Multiply
Definition: Types.h:300
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::InitialValue
T InitialValue
Definition: DeviceAdapterAlgorithmKokkos.h:477
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceOperator::ReduceOperator
KOKKOS_INLINE_FUNCTION ReduceOperator()
Definition: DeviceAdapterAlgorithmKokkos.h:314
vtkm::cont::DeviceAdapterAlgorithm::U
static T U
Definition: DeviceAdapterAlgorithm.h:347
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::Operator
BinaryOperator Operator
Definition: DeviceAdapterAlgorithmKokkos.h:305
vtkm::cont::ArrayHandle::PrepareForOutput
WritePortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares (allocates) this array to be used as an output from an operation in the execution environmen...
Definition: ArrayHandle.h:638
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::ArrayPortalOut
typename ArrayHandle< T, StorageOut >::WritePortalType ArrayPortalOut
Definition: DeviceAdapterAlgorithmKokkos.h:443
vtkm::cont::DeviceTaskTypes
Class providing a device-specific support for selecting the optimal Task type for a given worklet.
Definition: DeviceAdapterAlgorithm.h:744
vtkm_cont_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandle::ReleaseResources
void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:584
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
VTKM_LOG_SCOPE_FUNCTION
#define VTKM_LOG_SCOPE_FUNCTION(level)
Definition: Logging.h:214
vtkm::cont::DeviceAdapterAlgorithm
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:41
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusive
static T ScanInclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output, BinaryOperator binaryOperator)
Definition: DeviceAdapterAlgorithmKokkos.h:633
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::PortalIn
ArrayPortalIn PortalIn
Definition: DeviceAdapterAlgorithmKokkos.h:475
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScheduleTask
static void ScheduleTask(vtkm::exec::kokkos::internal::TaskBasic3D< WType, IType, Hints > &functor, vtkm::Id3 rangeMax)
Definition: DeviceAdapterAlgorithmKokkos.h:702
vtkm::CopyFlag::On
@ On
vtkm::cont::DeviceAdapterAlgorithm::SortByKey
static void SortByKey(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values)
Unstable ascending sort of keys and values.
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::SortByKey
static void SortByKey(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values, BinaryCompare binary_compare)
Definition: DeviceAdapterAlgorithmKokkos.h:887
vtkm::cont::DeviceAdapterAlgorithm::ReduceByKey
static void ReduceByKey(const vtkm::cont::ArrayHandle< T, CKeyIn > &keys, const vtkm::cont::ArrayHandle< U, CValIn > &values, vtkm::cont::ArrayHandle< T, CKeyOut > &keys_output, vtkm::cont::ArrayHandle< U, CValOut > &values_output, BinaryFunctor binary_functor)
Compute a accumulated sum operation on the input key value pairs.
ErrorExecution.h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::Functor
FunctorOperator Functor
Definition: DeviceAdapterAlgorithmKokkos.h:306
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::ScanInclusiveOperator
KOKKOS_INLINE_FUNCTION ScanInclusiveOperator(const ArrayPortalIn &portalIn, const ArrayPortalOut &portalOut)
Definition: DeviceAdapterAlgorithmKokkos.h:580
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::PortalIn
ArrayPortalIn PortalIn
Definition: DeviceAdapterAlgorithmKokkos.h:597
KokkosTypes.h
vtkm::cont::ArrayHandle::ReadPortal
ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:433
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::value_type
ResultType value_type
Definition: DeviceAdapterAlgorithmKokkos.h:266
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Synchronize
static void Synchronize()
Definition: DeviceAdapterAlgorithmKokkos.h:1039
vtkm::exec::FunctorBase
Base class for all user worklets invoked in the execution environment from a call to vtkm::cont::Devi...
Definition: FunctorBase.h:30
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusive
static T ScanInclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: DeviceAdapterAlgorithmKokkos.h:664
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceFunctor
KokkosReduceFunctor< BinaryOperator, ReduceOperator< ArrayPortal, BinaryOperator, ResultType >, ResultType > ReduceFunctor
Definition: DeviceAdapterAlgorithmKokkos.h:335
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveImpl
static T ScanExclusiveImpl(const vtkm::cont::ArrayHandle< T, StorageIn > &input, vtkm::cont::ArrayHandle< T, StorageOut > &output, BinaryOperator binaryOperator, const T &initialValue, std::false_type)
Definition: DeviceAdapterAlgorithmKokkos.h:429
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusive
static T ScanExclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: DeviceAdapterAlgorithmKokkos.h:546
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusive
static T ScanExclusive(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output, BinaryOperator binaryOperator, const T &initialValue)
Definition: DeviceAdapterAlgorithmKokkos.h:513
VTKM_THIRDPARTY_PRE_INCLUDE
#define VTKM_THIRDPARTY_PRE_INCLUDE
Definition: Configure.h:191
vtkm::BitwiseAnd
Binary Predicate that takes two arguments argument x, and y and returns the bitwise operation x&y
Definition: BinaryOperators.h:145
vtkm::cont::BitField
Definition: BitField.h:497
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Schedule
static void Schedule(FunctorType &&functor, vtkm::Id3 rangeMax)
Definition: DeviceAdapterAlgorithmKokkos.h:772
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::SortImpl
static void SortImpl(vtkm::cont::ArrayHandle< T > &values, vtkm::SortLess, std::true_type)
Definition: DeviceAdapterAlgorithmKokkos.h:780
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::join
KOKKOS_INLINE_FUNCTION void join(volatile value_type &dst, const volatile value_type &src) const
Definition: DeviceAdapterAlgorithmKokkos.h:279
vtkm::cont::DeviceAdapterAlgorithm::CopyIf
static void CopyIf(const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Conditionally copy elements in the input array to the output array.
vtkm::cont::BitField::PrepareForInput
ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this BitField to be used as an input to an operation in the execution environment.
vtkm::cont::ArrayHandle::PrepareForInput
ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:599
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::BitFieldToUnorderedSet
static vtkm::Id BitFieldToUnorderedSet(const vtkm::cont::BitField &bits, vtkm::cont::ArrayHandle< Id, IndicesStorage > &indices)
Definition: DeviceAdapterAlgorithmKokkos.h:199
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScheduleTask
static void ScheduleTask(vtkm::exec::kokkos::internal::TaskBasic1D< WType, IType, Hints > &functor, vtkm::Id numInstances)
Definition: DeviceAdapterAlgorithmKokkos.h:674
vtkm::TypeTraits::ZeroInitialization
static T ZeroInitialization()
A static function that returns 0 (or the closest equivalent to it) for the given type.
Definition: TypeTraits.h:77
vtkm::cont::DeviceAdapterAlgorithm::Reduce
static U Reduce(const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Compute a accumulated sum operation on the input ArrayHandle.
vtkm::cont::ArrayHandle::Allocate
void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:490
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::KokkosReduceFunctor::KokkosReduceFunctor
KOKKOS_INLINE_FUNCTION KokkosReduceFunctor()
Definition: DeviceAdapterAlgorithmKokkos.h:269
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::PortalOut
ArrayPortalOut PortalOut
Definition: DeviceAdapterAlgorithmKokkos.h:598
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >
Definition: DeviceAdapterAlgorithmKokkos.h:184
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Reduce
static U Reduce(const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue, BinaryOperator binaryOperator)
Definition: DeviceAdapterAlgorithmKokkos.h:381
ArrayHandleImplicit.h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveFunctor
KokkosReduceFunctor< BinaryOperator, ScanExclusiveOperator< T, StorageIn, StorageOut, BinaryOperator >, T > ScanExclusiveFunctor
Definition: DeviceAdapterAlgorithmKokkos.h:484
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::SortByKeyImpl
static void SortByKeyImpl(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values, BinaryCompare binary_compare, ValidKeys, ValidValues)
Definition: DeviceAdapterAlgorithmKokkos.h:866
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::SortByKey
static void SortByKey(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values)
Definition: DeviceAdapterAlgorithmKokkos.h:878
vtkm::cont::DeviceAdapterAlgorithm::VOut
static T VOut
Definition: DeviceAdapterAlgorithm.h:350
vtkm::cont::ArrayPortal
A class that points to and access and array of data.
Definition: ArrayPortal.h:62
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanExclusiveOperator::ArrayPortalIn
typename ArrayHandle< T, StorageIn >::ReadPortalType ArrayPortalIn
Definition: DeviceAdapterAlgorithmKokkos.h:442
vtkm::cont::LogLevel::Perf
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
vtkm::cont::DeviceAdapterTagKokkos
Tag for a device adapter that uses the Kokkos library to run algorithms in parallel.
Definition: DeviceAdapterTagKokkos.h:31
TaskBasic.h
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Superclass
vtkm::cont::internal::DeviceAdapterAlgorithmGeneral< DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >, vtkm::cont::DeviceAdapterTagKokkos > Superclass
Definition: DeviceAdapterAlgorithmKokkos.h:192
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:55
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::ArrayPortalIn
typename ArrayHandle< T, StorageIn >::ReadPortalType ArrayPortalIn
Definition: DeviceAdapterAlgorithmKokkos.h:572
vtkm::CountSetBits
vtkm::Int32 CountSetBits(vtkm::UInt32 word)
Count the total number of bits set in word.
Definition: Math.h:2940
vtkm::Minimum
Binary Predicate that takes two arguments argument x, and y and returns the x if x < y otherwise retu...
Definition: BinaryOperators.h:99
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ReduceOperator::Portal
ArrayPortal Portal
Definition: DeviceAdapterAlgorithmKokkos.h:329
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::ScanInclusiveOperator::ScanInclusiveOperator
KOKKOS_INLINE_FUNCTION ScanInclusiveOperator()
Definition: DeviceAdapterAlgorithmKokkos.h:577
vtkm::cont::DeviceAdapterAlgorithm< vtkm::cont::DeviceAdapterTagKokkos >::Schedule
static void Schedule(Hints, Functor functor, vtkm::Id numInstances)
Definition: DeviceAdapterAlgorithmKokkos.h:746