VTK-m  2.2
DeviceAdapterAlgorithm.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_DeviceAdapterAlgorithm_h
11 #define vtk_m_cont_DeviceAdapterAlgorithm_h
12 
13 #include <vtkm/Types.h>
14 
16 #include <vtkm/cont/Logging.h>
17 
18 
19 #ifdef _WIN32
20 #include <sys/timeb.h>
21 #include <sys/types.h>
22 #else // _WIN32
23 #include <limits.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #endif
27 
28 namespace vtkm
29 {
30 namespace cont
31 {
32 
40 template <class DeviceAdapterTag>
42 #ifdef VTKM_DOXYGEN_ONLY
43 {
48  template <typename IndicesStorage>
50  const vtkm::cont::BitField& bits,
52 
59  template <typename T, typename U, class CIn, class COut>
60  VTKM_CONT static void Copy(const vtkm::cont::ArrayHandle<T, CIn>& input,
62 
74  template <typename T, typename U, class CIn, class CStencil, class COut>
75  VTKM_CONT static void CopyIf(const vtkm::cont::ArrayHandle<T, CIn>& input,
78 
90  template <typename T, typename U, class CIn, class CStencil, class COut, class UnaryPredicate>
91  VTKM_CONT static void CopyIf(const vtkm::cont::ArrayHandle<T, CIn>& input,
94  UnaryPredicate unary_predicate);
95 
114  template <typename T, typename U, class CIn, class COut>
115  VTKM_CONT static bool CopySubRange(const vtkm::cont::ArrayHandle<T, CIn>& input,
116  vtkm::Id inputStartIndex,
117  vtkm::Id numberOfElementsToCopy,
119  vtkm::Id outputIndex = 0);
120 
123 
131  VTKM_CONT static void Fill(vtkm::cont::BitField& bits, bool value, vtkm::Id numBits);
132  VTKM_CONT static void Fill(vtkm::cont::BitField& bits, bool value);
133  template <typename WordType>
134  VTKM_CONT static void Fill(vtkm::cont::BitField& bits, WordType word, vtkm::Id numBits);
135  template <typename WordType>
136  VTKM_CONT static void Fill(vtkm::cont::BitField& bits, WordType word);
138 
142  template <typename T, typename S>
143  VTKM_CONT static void Fill(vtkm::cont::ArrayHandle<T, S>& array, const T& value);
144  template <typename T, typename S>
145  VTKM_CONT static void Fill(vtkm::cont::ArrayHandle<T, S>& array,
146  const T& value,
147  const vtkm::Id numValues);
149 
159  template <typename T, class CIn, class CVal, class COut>
160  VTKM_CONT static void LowerBounds(const vtkm::cont::ArrayHandle<T, CIn>& input,
161  const vtkm::cont::ArrayHandle<T, CVal>& values,
163 
174  template <typename T, class CIn, class CVal, class COut, class BinaryCompare>
175  VTKM_CONT static void LowerBounds(const vtkm::cont::ArrayHandle<T, CIn>& input,
176  const vtkm::cont::ArrayHandle<T, CVal>& values,
178  BinaryCompare binary_compare);
179 
187  template <class CIn, class COut>
190 
200  template <typename T, typename U, class CIn>
201  VTKM_CONT static U Reduce(const vtkm::cont::ArrayHandle<T, CIn>& input, U initialValue);
202 
213  template <typename T, typename U, class CIn, class BinaryFunctor>
215  U initialValue,
216  BinaryFunctor binary_functor);
217 
226  template <typename T,
227  typename U,
228  class CKeyIn,
229  class CValIn,
230  class CKeyOut,
231  class CValOut,
232  class BinaryFunctor>
237  BinaryFunctor binary_functor);
238 
251  template <typename T, class CIn, class COut>
254 
255 
268  template <typename T, class CIn, class COut, class BinaryFunctor>
271  BinaryFunctor binary_functor);
272 
281  template <typename T,
282  typename U,
283  typename KIn,
284  typename VIn,
285  typename VOut,
286  typename BinaryFunctor>
288  const vtkm::cont::ArrayHandle<U, VIn>& values,
289  vtkm::cont::ArrayHandle<U, VOut>& values_output,
290  BinaryFunctor binary_functor);
291 
299  template <typename T, typename U, typename KIn, typename VIn, typename VOut>
301  const vtkm::cont::ArrayHandle<U, VIn>& values,
302  vtkm::cont::ArrayHandle<U, VOut>& values_output);
303 
316  template <typename T, class CIn, class COut>
319 
332  template <typename T, class CIn, class COut, class BinaryFunctor>
335  BinaryFunctor binaryFunctor,
336  const T& initialValue)
337 
338 
339  template <typename T,
347  typename U,
348  typename KIn,
349  typename VIn,
350  typename VOut,
351  class BinaryFunctor>
353  const vtkm::cont::ArrayHandle<U, VIn>& values,
355  const U& initialValue,
356  BinaryFunctor binaryFunctor);
357 
365  template <typename T, typename U, class KIn, typename VIn, typename VOut>
367  const vtkm::cont::ArrayHandle<U, VIn>& values,
369 
394  template <typename T, class CIn, class COut>
395  VTKM_CONT static void ScanExtended(const vtkm::cont::ArrayHandle<T, CIn>& input,
397 
419  template <typename T, class CIn, class COut, class BinaryFunctor>
420  VTKM_CONT static void ScanExtended(const vtkm::cont::ArrayHandle<T, CIn>& input,
422  BinaryFunctor binaryFunctor,
423  const T& initialValue);
424 
442  template <class Functor>
443  VTKM_CONT static void Schedule(Functor functor, vtkm::Id numInstances);
444 
467  template <class Functor, class IndiceType>
468  VTKM_CONT static void Schedule(Functor functor, vtkm::Id3 rangeMax);
469 
475  template <typename T, class Storage>
477 
485  template <typename T, class Storage, class BinaryCompare>
487  BinaryCompare binary_compare);
488 
494  template <typename T, typename U, class StorageT, class StorageU>
497 
505  template <typename T, typename U, class StorageT, class StorageU, class BinaryCompare>
508  BinaryCompare binary_compare)
509 
510 
511  VTKM_CONT static void Synchronize();
515 
524  template <typename T,
525  typename U,
526  typename V,
527  typename StorageT,
528  typename StorageU,
529  typename StorageV,
530  typename BinaryFunctor>
531  VTKM_CONT static void Transform(const vtkm::cont::ArrayHandle<T, StorageT>& input1,
534  BinaryFunctor binaryFunctor);
535 
543  template <typename T, class Storage>
545 
556  template <typename T, class Storage, class BinaryCompare>
558  BinaryCompare binary_compare);
559 
569  template <typename T, class CIn, class CVal, class COut>
570  VTKM_CONT static void UpperBounds(const vtkm::cont::ArrayHandle<T, CIn>& input,
571  const vtkm::cont::ArrayHandle<T, CVal>& values,
573 
584  template <typename T, class CIn, class CVal, class COut, class BinaryCompare>
585  VTKM_CONT static void UpperBounds(const vtkm::cont::ArrayHandle<T, CIn>& input,
586  const vtkm::cont::ArrayHandle<T, CVal>& values,
588  BinaryCompare binary_compare);
589 
597  template <class CIn, class COut>
600 };
601 #else // VTKM_DOXYGEN_ONLY
602  ;
603 #endif //VTKM_DOXYGEN_ONLY
604 
612 template <class DeviceAdapterTag>
614 {
615 public:
616  struct TimeStamp
617  {
620  };
625 
631  {
632  this->StartReady = false;
633  this->StopReady = false;
634  }
635 
637  {
638  this->Reset();
639  this->StartTime = this->GetCurrentTime();
640  this->StartReady = true;
641  }
642 
644  {
645  this->StopTime = this->GetCurrentTime();
646  this->StopReady = true;
647  }
648 
649  VTKM_CONT bool Started() const { return this->StartReady; }
650 
651  VTKM_CONT bool Stopped() const { return this->StopReady; }
652 
653  VTKM_CONT bool Ready() const { return true; }
654 
662  {
663  assert(this->StartReady);
664  if (!this->StartReady)
665  {
667  "Start() function should be called first then trying to call GetElapsedTime().");
668  return 0;
669  }
670 
671  TimeStamp startTime = this->StartTime;
672  TimeStamp stopTime = this->StopReady ? this->StopTime : this->GetCurrentTime();
673 
674  vtkm::Float64 elapsedTime;
675  elapsedTime = vtkm::Float64(stopTime.Seconds - startTime.Seconds);
676  elapsedTime +=
677  (vtkm::Float64(stopTime.Microseconds - startTime.Microseconds) / vtkm::Float64(1000000));
678 
679  return elapsedTime;
680  }
681 
683  {
685 
686  TimeStamp retval;
687 #ifdef _WIN32
688  timeb currentTime;
689  ::ftime(&currentTime);
690  retval.Seconds = currentTime.time;
691  retval.Microseconds = 1000 * currentTime.millitm;
692 #else
693  timeval currentTime;
694  gettimeofday(&currentTime, nullptr);
695  retval.Seconds = currentTime.tv_sec;
696  retval.Microseconds = currentTime.tv_usec;
697 #endif
698  return retval;
699  }
700 
702  bool StopReady;
705 };
706 
716 template <class DeviceAdapterTag>
718 {
719 public:
725 #ifdef VTKM_DOXYGEN_ONLY
726  VTKM_CONT bool Exists() const;
727 #endif
728 };
729 
743 template <typename DeviceTag>
745 }
746 } // namespace vtkm::cont
747 
748 #endif //vtk_m_cont_DeviceAdapterAlgorithm_h
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::DeviceAdapterTimerImplementation::StopTime
TimeStamp StopTime
Definition: DeviceAdapterAlgorithm.h:704
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
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::cont::DeviceAdapterTimerImplementation::Ready
bool Ready() const
Definition: DeviceAdapterAlgorithm.h:653
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::DeviceAdapterAlgorithm::UpperBounds
static void UpperBounds(const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< T, CVal > &values, vtkm::cont::ArrayHandle< vtkm::Id, COut > &output)
Output is the last index in input for each item in values that wouldn't alter the ordering of input.
Types.h
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::ScanExtended
static void ScanExtended(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Compute an extended prefix sum operation on the input ArrayHandle.
vtkm::cont::DeviceAdapterTimerImplementation::Started
bool Started() const
Definition: DeviceAdapterAlgorithm.h:649
vtkm::cont::DeviceAdapterTimerImplementation::TimeStamp::Seconds
vtkm::Int64 Seconds
Definition: DeviceAdapterAlgorithm.h:618
vtkm::cont::DeviceAdapterAlgorithm::Copy
static void Copy(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Copy the contents of one ArrayHandle to another.
DeviceAdapterTag.h
vtkm::cont::DeviceAdapterAlgorithm::Transform
static void Transform(const vtkm::cont::ArrayHandle< T, StorageT > &input1, const vtkm::cont::ArrayHandle< U, StorageU > &input2, vtkm::cont::ArrayHandle< V, StorageV > &output, BinaryFunctor binaryFunctor)
Apply a given binary operation function element-wise to input arrays.
vtkm::cont::DeviceAdapterAlgorithm::ScanInclusiveByKey
static void ScanInclusiveByKey(const vtkm::cont::ArrayHandle< T, KIn > &keys, const vtkm::cont::ArrayHandle< U, VIn > &values, vtkm::cont::ArrayHandle< U, VOut > &values_output, BinaryFunctor binary_functor)
Compute a segmented inclusive prefix sum operation on the input key value pairs.
vtkm::cont::DeviceAdapterAlgorithm::CountSetBits
static vtkm::Id CountSetBits(const vtkm::cont::BitField &bits)
Returns the total number of "1" bits in BitField.
vtkm::cont::DeviceAdapterAlgorithm::Unique
static void Unique(vtkm::cont::ArrayHandle< T, Storage > &values)
Reduce an array to only the unique values it contains.
vtkm::cont::DeviceAdapterAlgorithm::VIn
static T VIn
Definition: DeviceAdapterAlgorithm.h:349
vtkm::cont::DeviceAdapterAlgorithm::ScanExclusiveByKey
static T class BinaryFunctor static void ScanExclusiveByKey(const vtkm::cont::ArrayHandle< T, KIn > &keys, const vtkm::cont::ArrayHandle< U, VIn > &values, vtkm::cont::ArrayHandle< U, VOut > &output, const U &initialValue, BinaryFunctor binaryFunctor)
vtkm::cont::DeviceAdapterRuntimeDetector
Class providing a device-specific runtime support detector.
Definition: DeviceAdapterRuntimeDetectorCuda.h:25
vtkm::cont::DeviceAdapterTimerImplementation::Stop
void Stop()
Definition: DeviceAdapterAlgorithm.h:643
vtkm::cont::DeviceAdapterAlgorithm::KIn
static T KIn
Definition: DeviceAdapterAlgorithm.h:348
vtkm::cont::DeviceAdapterTimerImplementation::TimeStamp::Microseconds
vtkm::Int64 Microseconds
Definition: DeviceAdapterAlgorithm.h:619
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::Sort
static void Sort(vtkm::cont::ArrayHandle< T, Storage > &values)
Unstable ascending sort of input array.
vtkm::cont::DeviceAdapterTimerImplementation::Stopped
bool Stopped() const
Definition: DeviceAdapterAlgorithm.h:651
vtkm::cont::DeviceAdapterAlgorithm::U
static T U
Definition: DeviceAdapterAlgorithm.h:347
vtkm::cont::DeviceAdapterTimerImplementation::StartReady
bool StartReady
Definition: DeviceAdapterAlgorithm.h:701
vtkm::cont::DeviceAdapterTimerImplementation::StopReady
bool StopReady
Definition: DeviceAdapterAlgorithm.h:702
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
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::Int64
signed long long Int64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:204
vtkm::cont::DeviceAdapterAlgorithm
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:41
vtkm::cont::DeviceAdapterRuntimeDetector::Exists
bool Exists() const
Returns true if the given device adapter is supported on the current machine.
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::DeviceAdapterTimerImplementation::DeviceAdapterTimerImplementation
DeviceAdapterTimerImplementation()
When a timer is constructed, all threads are synchronized and the current time is marked so that GetE...
Definition: DeviceAdapterAlgorithm.h:624
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.
vtkm::cont::LogLevel::Error
@ Error
Important but non-fatal errors, such as device fail-over.
vtkm::cont::DeviceAdapterAlgorithm::CopySubRange
static bool CopySubRange(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::Id inputStartIndex, vtkm::Id numberOfElementsToCopy, vtkm::cont::ArrayHandle< U, COut > &output, vtkm::Id outputIndex=0)
Copy the contents of a section of one ArrayHandle to another.
VTKM_LOG_S
#define VTKM_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:208
vtkm::cont::DeviceAdapterTimerImplementation
Class providing a device-specific timer.
Definition: DeviceAdapterAlgorithm.h:613
vtkm::Vec< vtkm::Id, 3 >
vtkm::cont::DeviceAdapterTimerImplementation::GetElapsedTime
vtkm::Float64 GetElapsedTime() const
Returns the elapsed time in seconds between the construction of this class or the last call to Reset ...
Definition: DeviceAdapterAlgorithm.h:661
vtkm::cont::DeviceAdapterAlgorithm::LowerBounds
static void LowerBounds(const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< T, CVal > &values, vtkm::cont::ArrayHandle< vtkm::Id, COut > &output)
Output is the first index in input for each item in values that wouldn't alter the ordering of input.
vtkm::cont::BitField
Definition: BitField.h:497
vtkm::cont::DeviceAdapterTimerImplementation::TimeStamp
Definition: DeviceAdapterAlgorithm.h:616
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::DeviceAdapterTimerImplementation::Reset
void Reset()
Resets the timer.
Definition: DeviceAdapterAlgorithm.h:630
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
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.
Logging.h
Logging utilities.
vtkm::cont::DeviceAdapterTimerImplementation::Start
void Start()
Definition: DeviceAdapterAlgorithm.h:636
vtkm::cont::DeviceAdapterTimerImplementation::GetCurrentTime
TimeStamp GetCurrentTime() const
Definition: DeviceAdapterAlgorithm.h:682
vtkm::cont::DeviceAdapterAlgorithm::BitFieldToUnorderedSet
static vtkm::Id BitFieldToUnorderedSet(const vtkm::cont::BitField &bits, vtkm::cont::ArrayHandle< Id, IndicesStorage > &indices)
Create a unique, unsorted list of indices denoting which bits are set in a bitfield.
vtkm::cont::DeviceAdapterTimerImplementation::StartTime
TimeStamp StartTime
Definition: DeviceAdapterAlgorithm.h:703
vtkm::cont::DeviceAdapterAlgorithm::VOut
static T VOut
Definition: DeviceAdapterAlgorithm.h:350