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>
42 using Device = 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>
87 auto inputPortal = input.
PrepareForInput(DeviceAdapterTagSerial(), token);
88 auto outputPortal = output.
PrepareForOutput(inSize, DeviceAdapterTagSerial(), token);
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)
128 auto inputPortal = input.
PrepareForInput(DeviceAdapterTagSerial(), token);
129 auto stencilPortal = stencil.
PrepareForInput(DeviceAdapterTagSerial(), token);
130 auto outputPortal = output.
PrepareForOutput(inputSize, DeviceAdapterTagSerial(), token);
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)
197 auto inputPortal = input.
PrepareForInput(DeviceAdapterTagSerial(), token);
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 <
class FunctorType>
408 vtkm::exec::serial::internal::TaskTiling1D kernel(functor);
409 ScheduleTask(kernel, size);
412 template <
class FunctorType>
417 vtkm::exec::serial::internal::TaskTiling3D kernel(functor);
418 ScheduleTask(kernel, size);
422 template <
typename Vin,
445 valuesOutPortal.Set(i, valuesPortal.Get(indexPortal.Get(i)));
451 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
454 BinaryCompare binary_compare)
463 Sort(zipHandle, internal::KeyCompare<T, U, BinaryCompare>(binary_compare));
467 template <
typename T,
typename U,
class StorageT,
class StorageU>
476 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
479 const BinaryCompare& binary_compare)
483 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
484 constexpr
bool larger_than_64bits =
sizeof(
U) >
sizeof(vtkm::Int64);
485 if (larger_than_64bits)
493 SortByKeyDirect(keys, indexArray, wrappedCompare);
494 Scatter(values, indexArray, valuesScattered);
495 Copy(valuesScattered, values);
499 SortByKeyDirect(keys, values, wrappedCompare);
503 template <
typename T,
class Storage>
508 Sort(values, std::less<T>());
511 template <
typename T,
class Storage,
class BinaryCompare>
513 BinaryCompare binary_compare)
522 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
523 std::sort(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
526 template <
typename T,
class Storage>
531 Unique(values, std::equal_to<T>());
534 template <
typename T,
class Storage,
class BinaryCompare>
536 BinaryCompare binary_compare)
543 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
545 auto end = std::unique(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
561 template <
typename WorkletType,
typename InvocationType>
562 static vtkm::exec::serial::internal::TaskTiling1D
MakeTask(WorkletType& worklet,
563 InvocationType& invocation,
566 return vtkm::exec::serial::internal::TaskTiling1D(worklet, invocation);
569 template <
typename WorkletType,
typename InvocationType>
570 static vtkm::exec::serial::internal::TaskTiling3D
MakeTask(WorkletType& worklet,
571 InvocationType& invocation,
574 return vtkm::exec::serial::internal::TaskTiling3D(worklet, invocation);
580 #endif //vtk_m_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:178
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
Manages an array-worth of data.
Definition: ArrayHandle.h:283
static VTKM_CONT void Copy(const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Copy the contents of one ArrayHandle to another.
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
static VTKM_CONT T VIn
Definition: DeviceAdapterAlgorithm.h:349
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_CONT 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:465
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorEnd(const PortalType &portal)
Convenience function for converting an ArrayPortal to an end iterator.
Definition: ArrayPortalToIterators.h:189
VTKM_CONT 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:574
VTKM_CONT void DetachFromAll()
Detaches this Token from all resources to allow them to be used elsewhere or deleted.
static VTKM_CONT U Reduce(const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Compute a accumulated sum operation on the input ArrayHandle.
VTKM_CONT 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:593
static VTKM_CONT T KIn
Definition: DeviceAdapterAlgorithm.h:348
static VTKM_CONT void Sort(vtkm::cont::ArrayHandle< T, Storage > &values)
Unstable ascending sort of input array.
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
static VTKM_CONT 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.
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
Definition: ArrayPortalToIterators.h:27
VTKM_CONT vtkm::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:288
static VTKM_CONT 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.
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
#define VTKM_LOG_SCOPE_FUNCTION(level)
Definition: Logging.h:266
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:41
static VTKM_CONT T VOut
Definition: DeviceAdapterAlgorithm.h:350
static VTKM_CONT T U
Definition: DeviceAdapterAlgorithm.h:347
static VTKM_CONT void Unique(vtkm::cont::ArrayHandle< T, Storage > &values)
Reduce an array to only the unique values it contains.
static VTKM_CONT 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 VTKM_CONT void SortByKey(vtkm::cont::ArrayHandle< T, StorageT > &keys, vtkm::cont::ArrayHandle< U, StorageU > &values)
Unstable ascending sort of keys and values.
VTKM_CONT 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:613
static VTKM_CONT 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.
static vtkm::exec::internal::TaskSingular< WorkletType, InvocationType > MakeTask(WorkletType &worklet, InvocationType &invocation, vtkm::Id, vtkm::Id globalIndexOffset=0)
Definition: DeviceAdapterAlgorithmGeneral.h:1195
VTKM_CONT void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:559
static VTKM_EXEC_CONT T ZeroInitialization()
Definition: TypeTraits.h:75
@ 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:54