Go to the documentation of this file.
10 #ifndef vtk_m_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
11 #define vtk_m_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
28 #include <type_traits>
37 : vtkm::cont::internal::DeviceAdapterAlgorithmGeneral<
38 DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>,
39 vtkm::cont::DeviceAdapterTagSerial>
49 template <
typename InPortal,
typename OutPortal>
57 using OutputType =
typename OutPortal::ValueType;
58 for (
vtkm::Id index = 0; index < numToCopy; ++index)
60 dst.Set(index + startIndex,
static_cast<OutputType
>(src.Get(index + outIndex)));
64 template <
typename InPortal,
typename OutPortal>
78 template <
typename T,
typename U,
class CIn,
class COut>
95 using InputType = decltype(inputPortal.Get(0));
96 using OutputType = decltype(outputPortal.Get(0));
98 DoCopy(inputPortal, outputPortal, std::is_same<InputType, OutputType>{}, 0, inSize, 0);
101 template <
typename T,
typename U,
class CIn,
class CStencil,
class COut>
109 CopyIf(input, stencil, output, unary_predicate);
112 template <
typename T,
typename U,
class CIn,
class CStencil,
class COut,
class UnaryPredicate>
116 UnaryPredicate predicate)
132 for (
vtkm::Id readPos = 0; readPos < inputSize; ++readPos)
134 if (predicate(stencilPortal.Get(readPos)))
136 outputPortal.Set(writePos, inputPortal.Get(readPos));
145 template <
typename T,
typename U,
class CIn,
class COut>
157 if (input == output &&
158 ((outputIndex >= inputStartIndex &&
159 outputIndex < inputStartIndex + numberOfElementsToCopy) ||
160 (inputStartIndex >= outputIndex &&
161 inputStartIndex < outputIndex + numberOfElementsToCopy)))
166 if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
167 inputStartIndex >= inSize)
173 if (inSize < (inputStartIndex + numberOfElementsToCopy))
175 numberOfElementsToCopy = (inSize - inputStartIndex);
179 const vtkm::Id copyOutEnd = outputIndex + numberOfElementsToCopy;
180 if (outSize < copyOutEnd)
200 using InputType = decltype(inputPortal.Get(0));
201 using OutputType = decltype(outputPortal.Get(0));
205 std::is_same<InputType, OutputType>(),
207 numberOfElementsToCopy,
213 template <
typename T,
typename U,
class CIn>
221 template <
typename T,
typename U,
class CIn,
class BinaryFunctor>
224 BinaryFunctor binary_functor)
230 internal::WrappedBinaryOperator<U, BinaryFunctor> wrappedOp(binary_functor);
238 template <
typename T,
249 BinaryFunctor binary_functor)
264 if (numberOfKeys == 0)
274 T currentKey = keysPortalIn.Get(readPos);
275 U currentValue = valuesPortalIn.Get(readPos);
277 for (++readPos; readPos < numberOfKeys; ++readPos)
279 while (readPos < numberOfKeys && currentKey == keysPortalIn.Get(readPos))
281 currentValue = binary_functor(currentValue, valuesPortalIn.Get(readPos));
285 if (readPos < numberOfKeys)
287 keysPortalOut.Set(writePos, currentKey);
288 valuesPortalOut.Set(writePos, currentValue);
291 currentKey = keysPortalIn.Get(readPos);
292 currentValue = valuesPortalIn.Get(readPos);
297 keysPortalOut.Set(writePos, currentKey);
298 valuesPortalOut.Set(writePos, currentValue);
307 template <
typename T,
class CIn,
class COut,
class BinaryFunctor>
310 BinaryFunctor binary_functor)
314 internal::WrappedBinaryOperator<T, BinaryFunctor> wrappedBinaryOp(binary_functor);
323 if (numberOfValues <= 0)
334 return outputPortal.Get(numberOfValues - 1);
337 template <
typename T,
class CIn,
class COut>
346 template <
typename T,
class CIn,
class COut,
class BinaryFunctor>
349 BinaryFunctor binaryFunctor,
350 const T& initialValue)
354 internal::WrappedBinaryOperator<T, BinaryFunctor> wrappedBinaryOp(binaryFunctor);
362 if (numberOfValues <= 0)
374 T lastValue = inputPortal.Get(numberOfValues - 1);
375 for (
vtkm::Id i = (numberOfValues - 1); i >= 1; --i)
377 outputPortal.Set(i, inputPortal.Get(i - 1));
379 outputPortal.Set(0, initialValue);
386 return wrappedBinaryOp(outputPortal.Get(numberOfValues - 1), lastValue);
389 template <
typename T,
class CIn,
class COut>
398 VTKM_CONT_EXPORT static void ScheduleTask(vtkm::exec::serial::internal::TaskTiling1D& functor,
400 VTKM_CONT_EXPORT static void ScheduleTask(vtkm::exec::serial::internal::TaskTiling3D& functor,
403 template <
typename H
ints,
typename FunctorType>
408 vtkm::exec::serial::internal::TaskTiling1D kernel(functor);
409 ScheduleTask(kernel, size);
412 template <
typename FunctorType>
415 Schedule(vtkm::cont::internal::HintList<>{}, functor, size);
418 template <
typename H
ints,
typename FunctorType>
423 vtkm::exec::serial::internal::TaskTiling3D kernel(functor);
424 ScheduleTask(kernel, size);
427 template <
typename FunctorType>
430 Schedule(vtkm::cont::internal::HintList<>{}, functor, size);
434 template <
typename Vin,
457 valuesOutPortal.Set(i, valuesPortal.Get(indexPortal.Get(i)));
462 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
465 BinaryCompare binary_compare)
474 Sort(zipHandle, internal::KeyCompare<T, U, BinaryCompare>(binary_compare));
478 template <
typename T,
typename U,
class StorageT,
class StorageU>
487 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
490 const BinaryCompare& binary_compare)
494 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
495 constexpr
bool larger_than_64bits =
sizeof(
U) >
sizeof(
vtkm::Int64);
496 if (larger_than_64bits)
504 SortByKeyDirect(keys, indexArray, wrappedCompare);
505 Scatter(values, indexArray, valuesScattered);
506 Copy(valuesScattered, values);
510 SortByKeyDirect(keys, values, wrappedCompare);
514 template <
typename T,
class Storage>
519 Sort(values, std::less<T>());
522 template <
typename T,
class Storage,
class BinaryCompare>
524 BinaryCompare binary_compare)
533 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
534 std::sort(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
537 template <
typename T,
class Storage>
542 Unique(values, std::equal_to<T>());
545 template <
typename T,
class Storage,
class BinaryCompare>
547 BinaryCompare binary_compare)
554 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
556 auto end = std::unique(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
572 template <
typename H
ints,
typename WorkletType,
typename InvocationType>
573 static vtkm::exec::serial::internal::TaskTiling1D
MakeTask(WorkletType& worklet,
574 InvocationType& invocation,
579 return vtkm::exec::serial::internal::TaskTiling1D(worklet, invocation);
582 template <
typename H
ints,
typename WorkletType,
typename InvocationType>
583 static vtkm::exec::serial::internal::TaskTiling3D
MakeTask(WorkletType& worklet,
584 InvocationType& invocation,
589 return vtkm::exec::serial::internal::TaskTiling3D(worklet, invocation);
592 template <
typename WorkletType,
typename InvocationType,
typename RangeType>
594 InvocationType& invocation,
595 const RangeType& range)
597 return MakeTask<vtkm::cont::internal::HintList<>>(worklet, invocation, range);
603 #endif //vtk_m_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
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.
Manages an array-worth of data.
Definition: ArrayHandle.h:300
Groups connected points that have the same field value.
Definition: Atomic.h:19
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
static void Schedule(Functor functor, vtkm::Id numInstances)
Schedule many instances of a function to run on concurrent threads.
static void Copy(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Copy the contents of one ArrayHandle to another.
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:468
vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorEnd(const PortalType &portal)
Convenience function for converting an ArrayPortal to an end iterator.
Definition: ArrayPortalToIterators.h:189
static void Unique(vtkm::cont::ArrayHandle< T, Storage > &values)
Reduce an array to only the unique values it contains.
static T VIn
Definition: DeviceAdapterAlgorithm.h:349
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:290
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
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
Definition: ArrayPortalToIterators.h:27
static T KIn
Definition: DeviceAdapterAlgorithm.h:348
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.
static void Sort(vtkm::cont::ArrayHandle< T, Storage > &values)
Unstable ascending sort of input array.
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
static T U
Definition: DeviceAdapterAlgorithm.h:347
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
Class providing a device-specific support for selecting the optimal Task type for a given worklet.
Definition: DeviceAdapterAlgorithm.h:744
#define VTKM_CONT
Definition: ExportMacros.h:57
void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:584
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
#define VTKM_LOG_SCOPE_FUNCTION(level)
Definition: Logging.h:214
signed long long Int64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:204
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:41
static void SortByKey(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values)
Unstable ascending sort of keys and values.
void DetachFromAll()
Detaches this Token from all resources to allow them to be used elsewhere or deleted.
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.
Predicate that takes a single argument x, and returns True if it isn't the identity of the Type T.
Definition: UnaryPredicates.h:32
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::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:178
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
static T ZeroInitialization()
A static function that returns 0 (or the closest equivalent to it) for the given type.
Definition: TypeTraits.h:77
static U Reduce(const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Compute a accumulated sum operation on the input ArrayHandle.
static vtkm::exec::internal::TaskSingular< WorkletType, InvocationType > MakeTask(WorkletType &worklet, InvocationType &invocation, vtkm::Id, vtkm::Id globalIndexOffset=0)
Definition: DeviceAdapterAlgorithmGeneral.h:1208
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
static T VOut
Definition: DeviceAdapterAlgorithm.h:350
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:55