Go to the documentation of this file.
18 #ifndef viskores_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
19 #define viskores_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
36 #include <type_traits>
45 : viskores::cont::internal::DeviceAdapterAlgorithmGeneral<
46 DeviceAdapterAlgorithm<viskores::cont::DeviceAdapterTagSerial>,
47 viskores::cont::DeviceAdapterTagSerial>
57 template <
typename InPortal,
typename OutPortal>
65 using OutputType =
typename OutPortal::ValueType;
68 dst.Set(index + startIndex,
static_cast<OutputType
>(src.Get(index + outIndex)));
72 template <
typename InPortal,
typename OutPortal>
86 template <
typename T,
typename U,
class CIn,
class COut>
103 using InputType = decltype(inputPortal.Get(0));
104 using OutputType = decltype(outputPortal.Get(0));
106 DoCopy(inputPortal, outputPortal, std::is_same<InputType, OutputType>{}, 0, inSize, 0);
109 template <
typename T,
typename U,
class CIn,
class CStencil,
class COut>
117 CopyIf(input, stencil, output, unary_predicate);
120 template <
typename T,
typename U,
class CIn,
class CStencil,
class COut,
class UnaryPredicate>
124 UnaryPredicate predicate)
140 for (
viskores::Id readPos = 0; readPos < inputSize; ++readPos)
142 if (predicate(stencilPortal.Get(readPos)))
144 outputPortal.Set(writePos, inputPortal.Get(readPos));
153 template <
typename T,
typename U,
class CIn,
class COut>
165 if (input == output &&
166 ((outputIndex >= inputStartIndex &&
167 outputIndex < inputStartIndex + numberOfElementsToCopy) ||
168 (inputStartIndex >= outputIndex &&
169 inputStartIndex < outputIndex + numberOfElementsToCopy)))
174 if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
175 inputStartIndex >= inSize)
181 if (inSize < (inputStartIndex + numberOfElementsToCopy))
183 numberOfElementsToCopy = (inSize - inputStartIndex);
187 const viskores::Id copyOutEnd = outputIndex + numberOfElementsToCopy;
188 if (outSize < copyOutEnd)
208 using InputType = decltype(inputPortal.Get(0));
209 using OutputType = decltype(outputPortal.Get(0));
213 std::is_same<InputType, OutputType>(),
215 numberOfElementsToCopy,
221 template <
typename T,
typename U,
class CIn>
229 template <
typename T,
typename U,
class CIn,
class BinaryFunctor>
232 BinaryFunctor binary_functor)
238 internal::WrappedBinaryOperator<U, BinaryFunctor> wrappedOp(binary_functor);
246 template <
typename T,
257 BinaryFunctor binary_functor)
272 if (numberOfKeys == 0)
282 T currentKey = keysPortalIn.Get(readPos);
283 U currentValue = valuesPortalIn.Get(readPos);
285 for (++readPos; readPos < numberOfKeys; ++readPos)
287 while (readPos < numberOfKeys && currentKey == keysPortalIn.Get(readPos))
289 currentValue = binary_functor(currentValue, valuesPortalIn.Get(readPos));
293 if (readPos < numberOfKeys)
295 keysPortalOut.Set(writePos, currentKey);
296 valuesPortalOut.Set(writePos, currentValue);
299 currentKey = keysPortalIn.Get(readPos);
300 currentValue = valuesPortalIn.Get(readPos);
305 keysPortalOut.Set(writePos, currentKey);
306 valuesPortalOut.Set(writePos, currentValue);
315 template <
typename T,
class CIn,
class COut,
class BinaryFunctor>
318 BinaryFunctor binary_functor)
322 internal::WrappedBinaryOperator<T, BinaryFunctor> wrappedBinaryOp(binary_functor);
331 if (numberOfValues <= 0)
342 return outputPortal.Get(numberOfValues - 1);
345 template <
typename T,
class CIn,
class COut>
354 template <
typename T,
class CIn,
class COut,
class BinaryFunctor>
357 BinaryFunctor binaryFunctor,
358 const T& initialValue)
362 internal::WrappedBinaryOperator<T, BinaryFunctor> wrappedBinaryOp(binaryFunctor);
370 if (numberOfValues <= 0)
382 T lastValue = inputPortal.Get(numberOfValues - 1);
383 for (
viskores::Id i = (numberOfValues - 1); i >= 1; --i)
385 outputPortal.Set(i, inputPortal.Get(i - 1));
387 outputPortal.Set(0, initialValue);
394 return wrappedBinaryOp(outputPortal.Get(numberOfValues - 1), lastValue);
397 template <
typename T,
class CIn,
class COut>
407 VISKORES_CONT_EXPORT
static void ScheduleTask(
408 viskores::exec::serial::internal::TaskTiling1D& functor,
410 VISKORES_CONT_EXPORT
static void ScheduleTask(
411 viskores::exec::serial::internal::TaskTiling3D& functor,
414 template <
typename H
ints,
typename FunctorType>
419 viskores::exec::serial::internal::TaskTiling1D kernel(functor);
420 ScheduleTask(kernel, size);
423 template <
typename FunctorType>
426 Schedule(viskores::cont::internal::HintList<>{}, functor, size);
429 template <
typename H
ints,
typename FunctorType>
434 viskores::exec::serial::internal::TaskTiling3D kernel(functor);
435 ScheduleTask(kernel, size);
438 template <
typename FunctorType>
441 Schedule(viskores::cont::internal::HintList<>{}, functor, size);
445 template <
typename Vin,
468 valuesOutPortal.Set(i, valuesPortal.Get(indexPortal.Get(i)));
473 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
476 BinaryCompare binary_compare)
485 Sort(zipHandle, internal::KeyCompare<T, U, BinaryCompare>(binary_compare));
489 template <
typename T,
typename U,
class StorageT,
class StorageU>
498 template <
typename T,
typename U,
class StorageT,
class StorageU,
class BinaryCompare>
501 const BinaryCompare& binary_compare)
505 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
507 if (larger_than_64bits)
515 SortByKeyDirect(keys, indexArray, wrappedCompare);
516 Scatter(values, indexArray, valuesScattered);
517 Copy(valuesScattered, values);
521 SortByKeyDirect(keys, values, wrappedCompare);
525 template <
typename T,
class Storage>
530 Sort(values, std::less<T>());
533 template <
typename T,
class Storage,
class BinaryCompare>
535 BinaryCompare binary_compare)
544 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
545 std::sort(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
548 template <
typename T,
class Storage>
553 Unique(values, std::equal_to<T>());
556 template <
typename T,
class Storage,
class BinaryCompare>
558 BinaryCompare binary_compare)
565 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
567 auto end = std::unique(iterators.GetBegin(), iterators.GetEnd(), wrappedCompare);
583 template <
typename H
ints,
typename WorkletType,
typename InvocationType>
584 static viskores::exec::serial::internal::TaskTiling1D
MakeTask(WorkletType& worklet,
585 InvocationType& invocation,
590 return viskores::exec::serial::internal::TaskTiling1D(worklet, invocation);
593 template <
typename H
ints,
typename WorkletType,
typename InvocationType>
594 static viskores::exec::serial::internal::TaskTiling3D
MakeTask(WorkletType& worklet,
595 InvocationType& invocation,
600 return viskores::exec::serial::internal::TaskTiling3D(worklet, invocation);
603 template <
typename WorkletType,
typename InvocationType,
typename RangeType>
605 InvocationType& invocation,
606 const RangeType& range)
608 return MakeTask<viskores::cont::internal::HintList<>>(worklet, invocation, range);
614 #endif //viskores_cont_serial_internal_DeviceAdapterAlgorithmSerial_h
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.
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:49
ReadPortalType PrepareForInput(viskores::cont::DeviceAdapterId device, viskores::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:615
viskores::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:300
static T ZeroInitialization()
A static function that returns 0 (or the closest equivalent to it) for the given type.
Definition: TypeTraits.h:85
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorEnd(const PortalType &portal)
Convenience function for converting an ArrayPortal to an end iterator.
Definition: ArrayPortalToIterators.h:200
static T VIn
Definition: DeviceAdapterAlgorithm.h:360
static T U
Definition: DeviceAdapterAlgorithm.h:358
static T VOut
Definition: DeviceAdapterAlgorithm.h:361
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.
static U Reduce(const viskores::cont::ArrayHandle< T, CIn > &input, U initialValue)
Compute a accumulated sum operation on the input ArrayHandle.
static void Sort(viskores::cont::ArrayHandle< T, Storage > &values)
Unstable ascending sort of input array.
signed long long Int64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:212
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:600
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.
static void SortByKey(viskores::cont::ArrayHandle< T, StorageT > &keys, viskores::cont::ArrayHandle< U, StorageU > &values)
Unstable ascending sort of keys and values.
#define VISKORES_CONT
Definition: ExportMacros.h:65
Groups connected points that have the same field value.
Definition: Atomic.h:27
Predicate that takes a single argument x, and returns True if it isn't the identity of the Type T.
Definition: UnaryPredicates.h:40
void DetachFromAll()
Detaches this Token from all resources to allow them to be used elsewhere or deleted.
WritePortalType PrepareForInPlace(viskores::cont::DeviceAdapterId device, viskores::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:634
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::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:189
static void Unique(viskores::cont::ArrayHandle< T, Storage > &values)
Reduce an array to only the unique values it contains.
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.
void Allocate(viskores::Id numberOfValues, viskores::CopyFlag preserve, viskores::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:504
viskores::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:482
WritePortalType PrepareForOutput(viskores::Id numberOfValues, viskores::cont::DeviceAdapterId device, viskores::cont::Token &token) const
Prepares (allocates) this array to be used as an output from an operation in the execution environmen...
Definition: ArrayHandle.h:654
static viskores::exec::internal::TaskSingular< WorkletType, InvocationType > MakeTask(WorkletType &worklet, InvocationType &invocation, viskores::Id, viskores::Id globalIndexOffset=0)
Definition: DeviceAdapterAlgorithmGeneral.h:1228
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
Definition: ArrayPortalToIterators.h:35
static T KIn
Definition: DeviceAdapterAlgorithm.h:359
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:41
#define VISKORES_LOG_SCOPE_FUNCTION(level)
Definition: Logging.h:225
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
Class providing a device-specific support for selecting the optimal Task type for a given worklet.
Definition: DeviceAdapterAlgorithm.h:757
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:64
static void Schedule(Functor functor, viskores::Id numInstances)
Schedule many instances of a function to run on concurrent threads.