Viskores  1.0
DeviceAdapterAlgorithm.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_DeviceAdapterAlgorithm_h
19 #define viskores_cont_DeviceAdapterAlgorithm_h
20 
21 #include <viskores/Types.h>
22 
24 #include <viskores/cont/Logging.h>
25 
26 
27 #ifdef _WIN32
28 #include <sys/timeb.h>
29 #include <sys/types.h>
30 #else // _WIN32
31 #include <limits.h>
32 #include <sys/time.h>
33 #include <unistd.h>
34 #endif
35 
36 namespace viskores
37 {
38 namespace cont
39 {
40 
48 template <class DeviceAdapterTag>
50 #ifdef VISKORES_DOXYGEN_ONLY
51 {
56  template <typename IndicesStorage>
58  const viskores::cont::BitField& bits,
60 
67  template <typename T, typename U, class CIn, class COut>
70 
82  template <typename T, typename U, class CIn, class CStencil, class COut>
86 
98  template <typename T, typename U, class CIn, class CStencil, class COut, class UnaryPredicate>
102  UnaryPredicate unary_predicate);
103 
122  template <typename T, typename U, class CIn, class COut>
124  viskores::Id inputStartIndex,
125  viskores::Id numberOfElementsToCopy,
127  viskores::Id outputIndex = 0);
128 
131 
139  VISKORES_CONT static void Fill(viskores::cont::BitField& bits, bool value, viskores::Id numBits);
140  VISKORES_CONT static void Fill(viskores::cont::BitField& bits, bool value);
141  template <typename WordType>
142  VISKORES_CONT static void Fill(viskores::cont::BitField& bits,
143  WordType word,
144  viskores::Id numBits);
145  template <typename WordType>
146  VISKORES_CONT static void Fill(viskores::cont::BitField& bits, WordType word);
148 
152  template <typename T, typename S>
153  VISKORES_CONT static void Fill(viskores::cont::ArrayHandle<T, S>& array, const T& value);
154  template <typename T, typename S>
156  const T& value,
157  const viskores::Id numValues);
159 
169  template <typename T, class CIn, class CVal, class COut>
173 
184  template <typename T, class CIn, class CVal, class COut, class BinaryCompare>
188  BinaryCompare binary_compare);
189 
197  template <class CIn, class COut>
198  VISKORES_CONT static void LowerBounds(
201 
211  template <typename T, typename U, class CIn>
212  VISKORES_CONT static U Reduce(const viskores::cont::ArrayHandle<T, CIn>& input, U initialValue);
213 
224  template <typename T, typename U, class CIn, class BinaryFunctor>
226  U initialValue,
227  BinaryFunctor binary_functor);
228 
237  template <typename T,
238  typename U,
239  class CKeyIn,
240  class CValIn,
241  class CKeyOut,
242  class CValOut,
243  class BinaryFunctor>
248  BinaryFunctor binary_functor);
249 
262  template <typename T, class CIn, class COut>
265 
266 
279  template <typename T, class CIn, class COut, class BinaryFunctor>
282  BinaryFunctor binary_functor);
283 
292  template <typename T,
293  typename U,
294  typename KIn,
295  typename VIn,
296  typename VOut,
297  typename BinaryFunctor>
301  BinaryFunctor binary_functor);
302 
310  template <typename T, typename U, typename KIn, typename VIn, typename VOut>
313  viskores::cont::ArrayHandle<U, VOut>& values_output);
314 
327  template <typename T, class CIn, class COut>
330 
343  template <typename T, class CIn, class COut, class BinaryFunctor>
346  BinaryFunctor binaryFunctor,
347  const T& initialValue)
348 
349 
350  template <typename T,
358  typename U,
359  typename KIn,
360  typename VIn,
361  typename VOut,
362  class BinaryFunctor>
366  const U& initialValue,
367  BinaryFunctor binaryFunctor);
368 
376  template <typename T, typename U, class KIn, typename VIn, typename VOut>
380 
405  template <typename T, class CIn, class COut>
408 
430  template <typename T, class CIn, class COut, class BinaryFunctor>
433  BinaryFunctor binaryFunctor,
434  const T& initialValue);
435 
453  template <class Functor>
454  VISKORES_CONT static void Schedule(Functor functor, viskores::Id numInstances);
455 
478  template <class Functor, class IndiceType>
479  VISKORES_CONT static void Schedule(Functor functor, viskores::Id3 rangeMax);
480 
486  template <typename T, class Storage>
488 
496  template <typename T, class Storage, class BinaryCompare>
498  BinaryCompare binary_compare);
499 
505  template <typename T, typename U, class StorageT, class StorageU>
508 
516  template <typename T, typename U, class StorageT, class StorageU, class BinaryCompare>
519  BinaryCompare binary_compare)
520 
521 
522  VISKORES_CONT static void Synchronize();
526 
535  template <typename T,
536  typename U,
537  typename V,
538  typename StorageT,
539  typename StorageU,
540  typename StorageV,
541  typename BinaryFunctor>
545  BinaryFunctor binaryFunctor);
546 
554  template <typename T, class Storage>
556 
567  template <typename T, class Storage, class BinaryCompare>
569  BinaryCompare binary_compare);
570 
580  template <typename T, class CIn, class CVal, class COut>
584 
595  template <typename T, class CIn, class CVal, class COut, class BinaryCompare>
599  BinaryCompare binary_compare);
600 
608  template <class CIn, class COut>
609  VISKORES_CONT static void UpperBounds(
612 };
613 #else // VISKORES_DOXYGEN_ONLY
614  ;
615 #endif //VISKORES_DOXYGEN_ONLY
616 
624 template <class DeviceAdapterTag>
626 {
627 public:
628  struct TimeStamp
629  {
632  };
637 
643  {
644  this->StartReady = false;
645  this->StopReady = false;
646  }
647 
649  {
650  this->Reset();
651  this->StartTime = this->GetCurrentTime();
652  this->StartReady = true;
653  }
654 
656  {
657  this->StopTime = this->GetCurrentTime();
658  this->StopReady = true;
659  }
660 
661  VISKORES_CONT bool Started() const { return this->StartReady; }
662 
663  VISKORES_CONT bool Stopped() const { return this->StopReady; }
664 
665  VISKORES_CONT bool Ready() const { return true; }
666 
674  {
675  assert(this->StartReady);
676  if (!this->StartReady)
677  {
680  "Start() function should be called first then trying to call GetElapsedTime().");
681  return 0;
682  }
683 
684  TimeStamp startTime = this->StartTime;
685  TimeStamp stopTime = this->StopReady ? this->StopTime : this->GetCurrentTime();
686 
687  viskores::Float64 elapsedTime;
688  elapsedTime = viskores::Float64(stopTime.Seconds - startTime.Seconds);
689  elapsedTime += (viskores::Float64(stopTime.Microseconds - startTime.Microseconds) /
690  viskores::Float64(1000000));
691 
692  return elapsedTime;
693  }
694 
696  {
698 
699  TimeStamp retval;
700 #ifdef _WIN32
701  timeb currentTime;
702  ::ftime(&currentTime);
703  retval.Seconds = currentTime.time;
704  retval.Microseconds = 1000 * currentTime.millitm;
705 #else
706  timeval currentTime;
707  gettimeofday(&currentTime, nullptr);
708  retval.Seconds = currentTime.tv_sec;
709  retval.Microseconds = currentTime.tv_usec;
710 #endif
711  return retval;
712  }
713 
715  bool StopReady;
718 };
719 
729 template <class DeviceAdapterTag>
731 {
732 public:
738 #ifdef VISKORES_DOXYGEN_ONLY
739  VISKORES_CONT bool Exists() const;
740 #endif
741 };
742 
756 template <typename DeviceTag>
758 }
759 } // namespace viskores::cont
760 
761 #endif //viskores_cont_DeviceAdapterAlgorithm_h
viskores::cont::DeviceAdapterTimerImplementation::TimeStamp::Seconds
viskores::Int64 Seconds
Definition: DeviceAdapterAlgorithm.h:630
viskores::cont::DeviceAdapterAlgorithm::CopyIf
static void CopyIf(const viskores::cont::ArrayHandle< T, CIn > &input, const viskores::cont::ArrayHandle< U, CStencil > &stencil, viskores::cont::ArrayHandle< T, COut > &output)
Conditionally copy elements in the input array to the output array.
viskores::cont::DeviceAdapterAlgorithm
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:49
viskores::cont::LogLevel::Error
@ Error
Important but non-fatal errors, such as device fail-over.
viskores::cont::DeviceAdapterAlgorithm::UpperBounds
static void UpperBounds(const viskores::cont::ArrayHandle< T, CIn > &input, const viskores::cont::ArrayHandle< T, CVal > &values, viskores::cont::ArrayHandle< viskores::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
viskores::cont::DeviceAdapterTimerImplementation::GetCurrentTime
TimeStamp GetCurrentTime() const
Definition: DeviceAdapterAlgorithm.h:695
viskores::cont::DeviceAdapterTimerImplementation::Start
void Start()
Definition: DeviceAdapterAlgorithm.h:648
viskores::cont::DeviceAdapterTimerImplementation::StartReady
bool StartReady
Definition: DeviceAdapterAlgorithm.h:714
DeviceAdapterTag.h
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::DeviceAdapterTimerImplementation::Started
bool Started() const
Definition: DeviceAdapterAlgorithm.h:661
viskores::cont::DeviceAdapterRuntimeDetector
Class providing a device-specific runtime support detector.
Definition: DeviceAdapterRuntimeDetectorCuda.h:33
viskores::cont::DeviceAdapterTimerImplementation::Ready
bool Ready() const
Definition: DeviceAdapterAlgorithm.h:665
viskores::cont::DeviceAdapterAlgorithm::VIn
static T VIn
Definition: DeviceAdapterAlgorithm.h:360
viskores::cont::DeviceAdapterRuntimeDetector::Exists
bool Exists() const
Returns true if the given device adapter is supported on the current machine.
viskores::cont::DeviceAdapterAlgorithm::U
static T U
Definition: DeviceAdapterAlgorithm.h:358
viskores::cont::DeviceAdapterTimerImplementation::Reset
void Reset()
Resets the timer.
Definition: DeviceAdapterAlgorithm.h:642
viskores::cont::DeviceAdapterAlgorithm::VOut
static T VOut
Definition: DeviceAdapterAlgorithm.h:361
viskores::cont::DeviceAdapterAlgorithm::ScanExclusive
static T ScanExclusive(const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< T, COut > &output)
Compute an exclusive prefix sum operation on the input ArrayHandle.
viskores::cont::DeviceAdapterAlgorithm::Reduce
static U Reduce(const viskores::cont::ArrayHandle< T, CIn > &input, U initialValue)
Compute a accumulated sum operation on the input ArrayHandle.
viskores::cont::DeviceAdapterAlgorithm::Sort
static void Sort(viskores::cont::ArrayHandle< T, Storage > &values)
Unstable ascending sort of input array.
viskores::cont::DeviceAdapterTimerImplementation::TimeStamp::Microseconds
viskores::Int64 Microseconds
Definition: DeviceAdapterAlgorithm.h:631
viskores::Int64
signed long long Int64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:212
viskores::cont::DeviceAdapterAlgorithm::ScanInclusiveByKey
static void ScanInclusiveByKey(const viskores::cont::ArrayHandle< T, KIn > &keys, const viskores::cont::ArrayHandle< U, VIn > &values, viskores::cont::ArrayHandle< U, VOut > &values_output, BinaryFunctor binary_functor)
Compute a segmented inclusive prefix sum operation on the input key value pairs.
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores::cont::DeviceAdapterAlgorithm::CopySubRange
static bool CopySubRange(const viskores::cont::ArrayHandle< T, CIn > &input, viskores::Id inputStartIndex, viskores::Id numberOfElementsToCopy, viskores::cont::ArrayHandle< U, COut > &output, viskores::Id outputIndex=0)
Copy the contents of a section of one ArrayHandle to another.
viskores::cont::DeviceAdapterAlgorithm::SortByKey
static void SortByKey(viskores::cont::ArrayHandle< T, StorageT > &keys, viskores::cont::ArrayHandle< U, StorageU > &values)
Unstable ascending sort of keys and values.
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::cont::BitField
Definition: BitField.h:507
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::DeviceAdapterAlgorithm::ScanExtended
static void ScanExtended(const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< T, COut > &output)
Compute an extended prefix sum operation on the input ArrayHandle.
viskores::cont::DeviceAdapterAlgorithm::Copy
static void Copy(const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< U, COut > &output)
Copy the contents of one ArrayHandle to another.
viskores::cont::DeviceAdapterTimerImplementation::StopTime
TimeStamp StopTime
Definition: DeviceAdapterAlgorithm.h:717
viskores::cont::DeviceAdapterAlgorithm::Unique
static void Unique(viskores::cont::ArrayHandle< T, Storage > &values)
Reduce an array to only the unique values it contains.
viskores::cont::DeviceAdapterTimerImplementation::TimeStamp
Definition: DeviceAdapterAlgorithm.h:628
viskores::cont::DeviceAdapterAlgorithm::ScanInclusive
static T ScanInclusive(const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< T, COut > &output)
Compute an inclusive prefix sum operation on the input ArrayHandle.
viskores::cont::DeviceAdapterAlgorithm::Transform
static void Transform(const viskores::cont::ArrayHandle< T, StorageT > &input1, const viskores::cont::ArrayHandle< U, StorageU > &input2, viskores::cont::ArrayHandle< V, StorageV > &output, BinaryFunctor binaryFunctor)
Apply a given binary operation function element-wise to input arrays.
viskores::cont::DeviceAdapterTimerImplementation
Class providing a device-specific timer.
Definition: DeviceAdapterAlgorithm.h:625
viskores::cont::DeviceAdapterAlgorithm::KIn
static T KIn
Definition: DeviceAdapterAlgorithm.h:359
viskores::cont::DeviceAdapterTimerImplementation::Stop
void Stop()
Definition: DeviceAdapterAlgorithm.h:655
viskores::cont::DeviceAdapterTimerImplementation::GetElapsedTime
viskores::Float64 GetElapsedTime() const
Returns the elapsed time in seconds between the construction of this class or the last call to Reset ...
Definition: DeviceAdapterAlgorithm.h:673
viskores::cont::DeviceAdapterAlgorithm::ReduceByKey
static void ReduceByKey(const viskores::cont::ArrayHandle< T, CKeyIn > &keys, const viskores::cont::ArrayHandle< U, CValIn > &values, viskores::cont::ArrayHandle< T, CKeyOut > &keys_output, viskores::cont::ArrayHandle< U, CValOut > &values_output, BinaryFunctor binary_functor)
Compute a accumulated sum operation on the input key value pairs.
VISKORES_LOG_S
#define VISKORES_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:216
viskores::cont::DeviceAdapterAlgorithm::BitFieldToUnorderedSet
static viskores::Id BitFieldToUnorderedSet(const viskores::cont::BitField &bits, viskores::cont::ArrayHandle< Id, IndicesStorage > &indices)
Create a unique, unsorted list of indices denoting which bits are set in a bitfield.
viskores::cont::DeviceAdapterAlgorithm::ScanExclusiveByKey
static T class BinaryFunctor static void ScanExclusiveByKey(const viskores::cont::ArrayHandle< T, KIn > &keys, const viskores::cont::ArrayHandle< U, VIn > &values, viskores::cont::ArrayHandle< U, VOut > &output, const U &initialValue, BinaryFunctor binaryFunctor)
viskores::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:636
viskores::cont::DeviceAdapterTimerImplementation::StartTime
TimeStamp StartTime
Definition: DeviceAdapterAlgorithm.h:716
viskores::cont::DeviceAdapterTimerImplementation::Stopped
bool Stopped() const
Definition: DeviceAdapterAlgorithm.h:663
viskores::cont::DeviceTaskTypes
Class providing a device-specific support for selecting the optimal Task type for a given worklet.
Definition: DeviceAdapterAlgorithm.h:757
Logging.h
Logging utilities.
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
viskores::cont::DeviceAdapterAlgorithm::Fill
static void Fill(viskores::cont::BitField &bits, bool value, viskores::Id numBits)
Fill the BitField with a specific pattern of bits.
viskores::cont::DeviceAdapterAlgorithm::CountSetBits
static viskores::Id CountSetBits(const viskores::cont::BitField &bits)
Returns the total number of "1" bits in BitField.
viskores::Vec< viskores::Id, 3 >
viskores::cont::DeviceAdapterAlgorithm::LowerBounds
static void LowerBounds(const viskores::cont::ArrayHandle< T, CIn > &input, const viskores::cont::ArrayHandle< T, CVal > &values, viskores::cont::ArrayHandle< viskores::Id, COut > &output)
Output is the first index in input for each item in values that wouldn't alter the ordering of input.
viskores::cont::DeviceAdapterAlgorithm::Schedule
static void Schedule(Functor functor, viskores::Id numInstances)
Schedule many instances of a function to run on concurrent threads.
viskores::cont::DeviceAdapterTimerImplementation::StopReady
bool StopReady
Definition: DeviceAdapterAlgorithm.h:715