diff --git a/vtkm/cont/ArrayHandleGroupVecVariable.h b/vtkm/cont/ArrayHandleGroupVecVariable.h index 1155d6ae4..39d829729 100644 --- a/vtkm/cont/ArrayHandleGroupVecVariable.h +++ b/vtkm/cont/ArrayHandleGroupVecVariable.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -438,6 +439,76 @@ make_ArrayHandleGroupVecVariable(const SourceArrayHandleType& sourceArray, sourceArray, offsetsArray); } +/// \c ConvertNumComponentsToOffsets takes an array of Vec sizes (i.e. the number of components in +/// each Vec) and returns an array of offsets to a packed array of such Vecs. The resulting array +/// can be used with \c ArrayHandleGroupVecVariable. +/// +/// The first parameter is always the input array that specifies the number of components in each +/// group Vec. +/// +/// The next parameter is the output \c ArrayHandle, which must have a value type of \c vtkm::Id. +/// If the output \c ArrayHandle is not given, it is returned. +/// +/// The next optional parameter is a reference to a \c vtkm::Id and is filled with the expected +/// size of the source values array. +/// +/// The final optional parameter is either a device adapter tag or a \c RuntimeDeviceTracker. If a +/// device is not specified, then devices specified by the global \c RuntimeDeviceTracker are used. +/// +template +VTKM_CONT void ConvertNumComponentsToOffsets( + const NumComponentsArrayType& numComponentsArray, + vtkm::cont::ArrayHandle& offsetsArray, + vtkm::Id& sourceArraySize, + Device) +{ + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + VTKM_IS_DEVICE_ADAPTER_TAG(Device); + + sourceArraySize = vtkm::cont::DeviceAdapterAlgorithm::ScanExclusive( + vtkm::cont::make_ArrayHandleCast(numComponentsArray), offsetsArray); +} + +template +VTKM_CONT void ConvertNumComponentsToOffsets( + const NumComponentsArrayType& numComponentsArray, + vtkm::cont::ArrayHandle& offsetsArray, + Device) +{ + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + VTKM_IS_DEVICE_ADAPTER_TAG(Device); + + vtkm::Id dummy; + vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy, Device()); +} + +template +VTKM_CONT vtkm::cont::ArrayHandle ConvertNumComponentsToOffsets( + const NumComponentsArrayType& numComponentsArray, + vtkm::Id& sourceArraySize, + Device) +{ + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + VTKM_IS_DEVICE_ADAPTER_TAG(Device); + + vtkm::cont::ArrayHandle offsetsArray; + vtkm::cont::ConvertNumComponentsToOffsets( + numComponentsArray, offsetsArray, sourceArraySize, Device()); + return offsetsArray; +} + +template +VTKM_CONT vtkm::cont::ArrayHandle ConvertNumComponentsToOffsets( + const NumComponentsArrayType& numComponentsArray, + Device) +{ + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + VTKM_IS_DEVICE_ADAPTER_TAG(Device); + + vtkm::Id dummy; + return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy, Device()); +} + namespace detail { @@ -458,8 +529,8 @@ struct ConvertNumComponentsToOffsetsFunctor template VTKM_CONT bool operator()(Device) { - this->SourceArraySize = vtkm::cont::DeviceAdapterAlgorithm::ScanExclusive( - this->NumComponentsArray, this->OffsetsArray); + vtkm::cont::ConvertNumComponentsToOffsets( + this->NumComponentsArray, this->OffsetsArray, this->SourceArraySize, Device()); return true; } @@ -468,14 +539,15 @@ struct ConvertNumComponentsToOffsetsFunctor template VTKM_CONT void DoConvertNumComponentsToOffsets(const NumComponentsArrayType& numComponentsArray, OffsetsArrayType& offsetsArray, - vtkm::Id& sourceArraySize) + vtkm::Id& sourceArraySize, + vtkm::cont::RuntimeDeviceTracker tracker) { VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); VTKM_IS_ARRAY_HANDLE(OffsetsArrayType); detail::ConvertNumComponentsToOffsetsFunctor functor( numComponentsArray); - bool success = vtkm::cont::TryExecute(functor); + bool success = vtkm::cont::TryExecute(functor, tracker); if (!success) { @@ -489,50 +561,54 @@ VTKM_CONT void DoConvertNumComponentsToOffsets(const NumComponentsArrayType& num } // namespace detail -/// \c ConvertNumComponentsToOffsets takes an array of Vec sizes (i.e. the -/// number of components in each Vec) and returns an array of offsets to a -/// packed array of such Vecs. The resulting array can be used with -/// \c ArrayHandleGroupVecVariable. -/// -/// If an optional second parameter is given, the expected size of the source -/// values array is returned in it. -/// template VTKM_CONT void ConvertNumComponentsToOffsets( const NumComponentsArrayType& numComponentsArray, vtkm::cont::ArrayHandle& offsetsArray, - vtkm::Id& sourceArraySize) + vtkm::Id& sourceArraySize, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()) { VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); detail::DoConvertNumComponentsToOffsets( - vtkm::cont::make_ArrayHandleCast(numComponentsArray), offsetsArray, sourceArraySize); + numComponentsArray, offsetsArray, sourceArraySize, tracker); } + template VTKM_CONT void ConvertNumComponentsToOffsets( const NumComponentsArrayType& numComponentsArray, - vtkm::cont::ArrayHandle& offsetsArray) + vtkm::cont::ArrayHandle& offsetsArray, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()) { + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + vtkm::Id dummy; - vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy); + vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy, tracker); } + template VTKM_CONT vtkm::cont::ArrayHandle ConvertNumComponentsToOffsets( const NumComponentsArrayType& numComponentsArray, - vtkm::Id& sourceArraySize) + vtkm::Id& sourceArraySize, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()) { VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); vtkm::cont::ArrayHandle offsetsArray; - vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, sourceArraySize); + vtkm::cont::ConvertNumComponentsToOffsets( + numComponentsArray, offsetsArray, sourceArraySize, tracker); return offsetsArray; } + template VTKM_CONT vtkm::cont::ArrayHandle ConvertNumComponentsToOffsets( - const NumComponentsArrayType& numComponentsArray) + const NumComponentsArrayType& numComponentsArray, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()) { + VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType); + vtkm::Id dummy; - return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy); + return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy, tracker); } } } // namespace vtkm::cont diff --git a/vtkm/cont/testing/TestingFancyArrayHandles.h b/vtkm/cont/testing/TestingFancyArrayHandles.h index dafde723b..25fe30019 100644 --- a/vtkm/cont/testing/TestingFancyArrayHandles.h +++ b/vtkm/cont/testing/TestingFancyArrayHandles.h @@ -696,8 +696,8 @@ private: vtkm::Id sourceArraySize; vtkm::cont::ArrayHandleCounting numComponentsArray(1, 1, ARRAY_SIZE); - vtkm::cont::ArrayHandle offsetsArray = - vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, sourceArraySize); + vtkm::cont::ArrayHandle offsetsArray = vtkm::cont::ConvertNumComponentsToOffsets( + numComponentsArray, sourceArraySize, DeviceAdapterTag()); vtkm::cont::ArrayHandle sourceArray; sourceArray.Allocate(sourceArraySize);