From 2caad9c4af85dd610b9dce25f9bdd9cec9649b03 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 17 Nov 2020 12:44:48 -0500 Subject: [PATCH 1/4] Mark VTKm_NO_ASSERT_HIP as an advanced CMake flag --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bab37198f..d51329d4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,6 +149,7 @@ mark_as_advanced( VTKm_ENABLE_LOGGING VTKm_NO_ASSERT VTKm_NO_ASSERT_CUDA + VTKm_NO_ASSERT_HIP VTKm_INSTALL_ONLY_LIBRARIES VTKm_HIDE_PRIVATE_SYMBOLS VTKm_ENABLE_DEVELOPER_FLAGS From f8007189471599969d664eaaeb81f8700e7cf65c Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 19 Nov 2020 12:16:36 -0700 Subject: [PATCH 2/4] Convert ArrayHandleDecorator to new buffer-style arrays It should be noted that a break in backward compatibility is introduced. The implementation class passed to `ArrayHandleDecorator` changed the specification of `AllocateSourceArrays`. Thus, decorators that were previously allocatable now no longer will be until that method is updated to the new form. --- vtkm/cont/ArrayHandle.h | 2 +- vtkm/cont/ArrayHandleDecorator.h | 609 ++++++------------ .../testing/UnitTestArrayHandleDecorator.cxx | 56 +- 3 files changed, 221 insertions(+), 446 deletions(-) diff --git a/vtkm/cont/ArrayHandle.h b/vtkm/cont/ArrayHandle.h index 2ed4cacf0..73dcfec26 100644 --- a/vtkm/cont/ArrayHandle.h +++ b/vtkm/cont/ArrayHandle.h @@ -1109,7 +1109,7 @@ public: return true; // different valuetype and/or storage } - VTKM_CONT constexpr vtkm::IdComponent GetNumberOfBuffers() const + VTKM_CONT static constexpr vtkm::IdComponent GetNumberOfBuffers() { return StorageType::GetNumberOfBuffers(); } diff --git a/vtkm/cont/ArrayHandleDecorator.h b/vtkm/cont/ArrayHandleDecorator.h index 9d12b33fa..1cfd1822d 100644 --- a/vtkm/cont/ArrayHandleDecorator.h +++ b/vtkm/cont/ArrayHandleDecorator.h @@ -29,8 +29,6 @@ namespace vtkm { -namespace cont -{ namespace internal { @@ -94,6 +92,16 @@ private: InverseFunctorType InverseFunctor; vtkm::Id NumberOfValues; }; +} +} // namespace vtkm::internal + +namespace vtkm +{ +namespace cont +{ + +namespace internal +{ namespace decor { @@ -137,26 +145,10 @@ struct IsDecoratorAllocatableImpl> private: template < typename T, - typename U = decltype(std::declval().AllocateSourceArrays(0, std::declval()...))> - static std::true_type Exists(int); - template - static std::false_type Exists(...); - -public: - using type = decltype(Exists(0)); -}; - -// Tests whether DecoratorImplT has a ShrinkSourceArrays(size, Arrays...) method. -template -struct IsDecoratorShrinkableImpl; - -template class List, typename... ArrayTs> -struct IsDecoratorShrinkableImpl> -{ -private: - template < - typename T, - typename U = decltype(std::declval().ShrinkSourceArrays(0, std::declval()...))> + typename U = decltype(std::declval().AllocateSourceArrays(0, + vtkm::CopyFlag::Off, + std::declval(), + std::declval()...))> static std::true_type Exists(int); template static std::false_type Exists(...); @@ -193,56 +185,30 @@ struct GetInverseFunctorTypeImpl struct GetInverseFunctorTypeImpl { - using type = NoOpInverseFunctor; + using type = vtkm::internal::decor::NoOpInverseFunctor; }; // Get appropriate portals from a source array. // See note below about using non-writable portals in invertible functors. // We need to sub in const portals when writable ones don't exist. template -typename std::decay::type::WritePortalType GetPortalControlImpl(std::true_type, - ArrayT&& array) +typename std::decay::type::WritePortalType GetWritePortalImpl( + std::true_type, + ArrayT&& array, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - return array.WritePortal(); + return ArrayT::StorageType::CreateWritePortal(array.GetBuffers(), device, token); } template -typename std::decay::type::ReadPortalType GetPortalControlImpl(std::false_type, - ArrayT&& array) +typename std::decay::type::ReadPortalType GetWritePortalImpl( + std::false_type, + ArrayT&& array, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - return array.ReadPortal(); -} - -template -typename std::decay::type::template ExecutionTypes::Portal -GetPortalInPlaceImpl(std::true_type, ArrayT&& array, Device, vtkm::cont::Token& token) -{ - return array.PrepareForInPlace(Device{}, token); -} - -template -typename std::decay::type::template ExecutionTypes::PortalConst -GetPortalInPlaceImpl(std::false_type, ArrayT&& array, Device, vtkm::cont::Token& token) -{ - // ArrayT is read-only -- prepare for input instead. - return array.PrepareForInput(Device{}, token); -} - -template -typename std::decay::type::template ExecutionTypes::Portal -GetPortalOutputImpl(std::true_type, ArrayT&& array, Device, vtkm::cont::Token& token) -{ - // Prepare these for inplace usage instead -- we'll likely need to read - // from these in addition to writing. - return array.PrepareForInPlace(Device{}, token); -} - -template -typename std::decay::type::template ExecutionTypes::PortalConst -GetPortalOutputImpl(std::false_type, ArrayT&& array, Device, vtkm::cont::Token& token) -{ - // ArrayT is read-only -- prepare for input instead. - return array.PrepareForInput(Device{}, token); + return ArrayT::StorageType::CreateReadPortal(array.GetBuffers(), device, token); } } // namespace detail @@ -256,11 +222,11 @@ GetPortalOutputImpl(std::false_type, ArrayT&& array, Device, vtkm::cont::Token& template ::type::WritePortalType, typename PortalConst = typename std::decay::type::ReadPortalType> -using GetPortalControlType = +using GetWritePortalType = typename brigand::if_, Portal, PortalConst>::type; template -using GetPortalConstControlType = typename std::decay::type::ReadPortalType; +using GetReadPortalType = typename std::decay::type::ReadPortalType; template -GetPortalControlType::type> WritePortal(ArrayT&& array) +GetWritePortalType::type> +WritePortal(ArrayT&& array, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) { - return detail::GetPortalControlImpl(IsWritableArrayHandle{}, std::forward(array)); + return detail::GetWritePortalImpl( + IsWritableArrayHandle{}, std::forward(array), device, token); } template -GetPortalConstControlType::type> ReadPortal(const ArrayT& array) +GetReadPortalType::type> ReadPortal(const ArrayT& array, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - return array.ReadPortal(); -} - -template -GetPortalConstExecutionType::type, Device> -GetPortalInput(const ArrayT& array, Device, vtkm::cont::Token& token) -{ - return array.PrepareForInput(Device{}, token); -} - -template -GetPortalExecutionType::type, Device> -GetPortalInPlace(ArrayT&& array, Device, vtkm::cont::Token& token) -{ - return detail::GetPortalInPlaceImpl( - IsWritableArrayHandle{}, std::forward(array), Device{}, token); -} - -template -GetPortalExecutionType::type, Device> -GetPortalOutput(ArrayT&& array, Device, vtkm::cont::Token& token) -{ - return detail::GetPortalOutputImpl( - IsWritableArrayHandle{}, std::forward(array), Device{}, token); + return ArrayT::StorageType::CreateReadPortal(array.GetBuffers(), device, token); } // Equivalent to std::true_type if *any* portal in PortalList can be written to. @@ -331,12 +278,6 @@ template using IsDecoratorAllocatable = typename detail::IsDecoratorAllocatableImpl::type; -// Set to std::true_type if DecoratorImplT::ShrinkSourceArrays can be called -// with the supplied arrays, or std::false_type otherwise. -template -using IsDecoratorShrinkable = - typename detail::IsDecoratorShrinkableImpl::type; - // std::true_type/std::false_type depending on whether the decorator impl has a // CreateInversePortal method AND any of the arrays are writable. template @@ -360,23 +301,54 @@ using GetInverseFunctorType = // Some notes on this implementation: // - MSVC 2015 ICEs when using brigand::transform to convert a brigand::list // of arrayhandles to portals. So instead we pass the ArrayTs. -// - Just using brigand::list...> fails, as +// - Just using brigand::list...> fails, as // apparently that is an improper parameter pack expansion // - So we jump through some decltype/declval hoops here to get this to work: template -using GetPortalConstControlList = - brigand::list())))...>; - -template -using GetPortalConstExecutionList = brigand::list(), Device{}, std::declval())))...>; +using GetReadPortalList = + brigand::list(), + std::declval(), + std::declval())))...>; template -using GetPortalControlList = brigand::list())))...>; +using GetWritePortalList = + brigand::list(), + std::declval(), + std::declval())))...>; -template -using GetPortalExecutionList = brigand::list(), Device{}, std::declval())))...>; +template +struct BufferIndexImpl +{ + static constexpr vtkm::IdComponent Value() + { + return BufferIndexImpl::Value() + + vtkm::TupleElement::GetNumberOfBuffers(); + } +}; +template +struct BufferIndexImpl<0, ArrayTupleType> +{ + static constexpr vtkm::IdComponent Value() + { + // One buffer reserved for metadata. + return 1; + } +}; + +template +struct DecoratorMetaData +{ + DecoratorImplT Implementation; + vtkm::Id NumberOfValues = 0; + + DecoratorMetaData(const DecoratorImplT& implementation, vtkm::Id numValues) + : Implementation(implementation) + , NumberOfValues(numValues) + { + } + + DecoratorMetaData() = default; +}; template struct DecoratorStorageTraits @@ -401,63 +373,56 @@ struct DecoratorStorageTraits // size_t integral constants that index ArrayTs: using IndexList = vtkmstd::make_index_sequence; - // true_type/false_type depending on whether the decorator supports Allocate/Shrink: + // Returns the index into the buffers array for the array at the given index. + template + static constexpr vtkm::IdComponent BufferIndex() + { + return BufferIndexImpl::Value(); + } + + // Converts a buffers array to the ArrayHandle at the given index. + template + static vtkm::TupleElement BuffersToArray( + const vtkm::cont::internal::Buffer* buffers) + { + return vtkm::TupleElement(buffers + BufferIndex()); + } + + using MetaData = DecoratorMetaData; + + static MetaData& GetMetaData(const vtkm::cont::internal::Buffer* buffers) + { + return buffers[0].GetMetaData(); + } + + // true_type/false_type depending on whether the decorator supports Allocate: using IsAllocatable = IsDecoratorAllocatable; - using IsShrinkable = IsDecoratorShrinkable; // Portal lists: // NOTE we have to pass the parameter pack here instead of using ArrayList // with brigand::transform, since that's causing MSVC 2015 to ice: - using PortalControlList = GetPortalControlList; - using PortalConstControlList = GetPortalConstControlList; - template - using PortalExecutionList = GetPortalExecutionList; - template - using PortalConstExecutionList = GetPortalConstExecutionList; + using WritePortalList = GetWritePortalList; + using ReadPortalList = GetReadPortalList; // Functors: - using FunctorControlType = GetFunctorType; - using FunctorConstControlType = GetFunctorType; - - template - using FunctorExecutionType = GetFunctorType>; - - template - using FunctorConstExecutionType = - GetFunctorType>; + using WriteFunctorType = GetFunctorType; + using ReadFunctorType = GetFunctorType; // Inverse functors: - using InverseFunctorControlType = GetInverseFunctorType; + using InverseWriteFunctorType = GetInverseFunctorType; - using InverseFunctorConstControlType = NoOpInverseFunctor; - - template - using InverseFunctorExecutionType = - GetInverseFunctorType>; - - template - using InverseFunctorConstExecutionType = NoOpInverseFunctor; + using InverseReadFunctorType = vtkm::internal::decor::NoOpInverseFunctor; // Misc: // ValueType is derived from DecoratorImplT::CreateFunctor(...)'s operator(). - using ValueType = decltype(std::declval()(0)); + using ValueType = decltype(std::declval()(0)); // Decorator portals: - using PortalControlType = - ArrayPortalDecorator; + using WritePortalType = + vtkm::internal::ArrayPortalDecorator; - using PortalConstControlType = - ArrayPortalDecorator; - - template - using PortalExecutionType = ArrayPortalDecorator, - InverseFunctorExecutionType>; - - template - using PortalConstExecutionType = ArrayPortalDecorator, - InverseFunctorConstExecutionType>; + using ReadPortalType = + vtkm::internal::ArrayPortalDecorator; // helper for constructing portals with the appropriate functors. This is // where we decide whether or not to call `CreateInverseFunctor` on the @@ -484,115 +449,64 @@ struct DecoratorStorageTraits // Static dispatch for calling AllocateSourceArrays on supported implementations: VTKM_CONT [[noreturn]] static void CallAllocate(std::false_type, - const DecoratorImplT&, vtkm::Id, - ArrayTs&...) + vtkm::cont::internal::Buffer*, + vtkm::CopyFlag, + vtkm::cont::Token&, + ArrayTs...) { throw vtkm::cont::ErrorBadType("Allocate not supported by this ArrayHandleDecorator."); } VTKM_CONT static void CallAllocate(std::true_type, - const DecoratorImplT& impl, vtkm::Id newSize, - ArrayTs&... arrays) + vtkm::cont::internal::Buffer* buffers, + vtkm::CopyFlag preserve, + vtkm::cont::Token& token, + ArrayTs... arrays) { - impl.AllocateSourceArrays(newSize, arrays...); - } - - // Static dispatch for calling ShrinkSourceArrays on supported implementations. - VTKM_CONT [[noreturn]] static void CallShrink(std::false_type, - const DecoratorImplT&, - vtkm::Id, - ArrayTs&...) - { - throw vtkm::cont::ErrorBadType("Shrink not supported by this ArrayHandleDecorator."); - } - - VTKM_CONT static void CallShrink(std::true_type, - const DecoratorImplT& impl, - vtkm::Id newSize, - ArrayTs&... arrays) - { - impl.ShrinkSourceArrays(newSize, arrays...); + MetaData& metadata = GetMetaData(buffers); + metadata.Implementation.AllocateSourceArrays(newSize, preserve, token, arrays...); + metadata.NumberOfValues = newSize; } // Portal construction methods. These actually create portals. template - VTKM_CONT static PortalControlType MakePortalControl(const DecoratorImplT& impl, - ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence) + VTKM_CONT static WritePortalType CreateWritePortal(const vtkm::cont::internal::Buffer* buffers, + vtkm::Id numValues, + vtkmstd::index_sequence, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - return CreatePortalDecorator( - numValues, impl, WritePortal(vtkm::Get(arrays))...); + return CreatePortalDecorator( + numValues, + GetMetaData(buffers).Implementation, + WritePortal(BuffersToArray(buffers), device, token)...); } template - VTKM_CONT static PortalConstControlType MakePortalConstControl( - const DecoratorImplT& impl, - const ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence) + VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, + vtkm::Id numValues, + vtkmstd::index_sequence, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - return CreatePortalDecorator( - numValues, impl, ReadPortal(vtkm::Get(arrays))...); - } - - template - VTKM_CONT static PortalConstExecutionType MakePortalInput( - const DecoratorImplT& impl, - const ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence, - Device dev, - vtkm::cont::Token& token) - { - return CreatePortalDecorator>( - numValues, impl, GetPortalInput(vtkm::Get(arrays), dev, token)...); - } - - template - VTKM_CONT static PortalExecutionType MakePortalInPlace( - const DecoratorImplT& impl, - ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence, - Device dev, - vtkm::cont::Token& token) - { - return CreatePortalDecorator>( - numValues, impl, GetPortalInPlace(vtkm::Get(arrays), dev, token)...); - } - - template - VTKM_CONT static PortalExecutionType MakePortalOutput(const DecoratorImplT& impl, - ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence, - Device dev, - vtkm::cont::Token& token) - { - return CreatePortalDecorator>( - numValues, impl, GetPortalOutput(vtkm::Get(arrays), dev, token)...); + return CreatePortalDecorator( + numValues, + GetMetaData(buffers).Implementation, + ReadPortal(BuffersToArray(buffers), device, token)...); } template - VTKM_CONT static void AllocateSourceArrays(const DecoratorImplT& impl, - ArrayTupleType& arrays, - vtkm::Id numValues, + VTKM_CONT static void AllocateSourceArrays(vtkm::Id numValues, + vtkm::cont::internal::Buffer* buffers, + vtkm::CopyFlag preserve, + vtkm::cont::Token& token, vtkmstd::index_sequence) { - CallAllocate(IsAllocatable{}, impl, numValues, vtkm::Get(arrays)...); - } - - template - VTKM_CONT static void ShrinkSourceArrays(const DecoratorImplT& impl, - ArrayTupleType& arrays, - vtkm::Id numValues, - vtkmstd::index_sequence) - { - CallShrink(IsShrinkable{}, impl, numValues, vtkm::Get(arrays)...); + CallAllocate( + IsAllocatable{}, numValues, buffers, preserve, token, BuffersToArray(buffers)...); } }; @@ -609,110 +523,59 @@ class Storage { using Traits = decor::DecoratorStorageTraits; using IndexList = typename Traits::IndexList; + using MetaData = typename Traits::MetaData; public: - using ArrayTupleType = typename Traits::ArrayTupleType; - using ValueType = typename Traits::ValueType; - using PortalType = typename Traits::PortalControlType; - using PortalConstType = typename Traits::PortalConstControlType; + using ReadPortalType = typename Traits::ReadPortalType; + using WritePortalType = typename Traits::WritePortalType; - VTKM_CONT - Storage() - : Valid{ false } + VTKM_CONT constexpr static vtkm::IdComponent GetNumberOfBuffers() { + return Traits::template BufferIndex(sizeof...(ArrayTs))>(); } - VTKM_CONT - Storage(const DecoratorImplT& impl, const ArrayTupleType& arrayTuple, vtkm::Id numValues) - : Implementation(impl) - , ArrayTuple{ arrayTuple } - , NumberOfValues(numValues) - , Valid{ true } + VTKM_CONT static vtkm::Id GetNumberOfValues(const vtkm::cont::internal::Buffer* buffers) { + return Traits::GetMetaData(buffers).NumberOfValues; } - VTKM_CONT - PortalType GetPortal() + VTKM_CONT static void ResizeBuffers(vtkm::Id numValues, + vtkm::cont::internal::Buffer* buffers, + vtkm::CopyFlag preserve, + vtkm::cont::Token& token) { - VTKM_ASSERT(this->Valid); - return Traits::MakePortalControl( - this->Implementation, this->ArrayTuple, this->NumberOfValues, IndexList{}); + if (numValues != GetNumberOfValues(buffers)) + { + Traits::AllocateSourceArrays(numValues, buffers, preserve, token, IndexList{}); + } + else + { + // Do nothing. We have this condition to allow allocating the same size when the + // array cannot be resized. + } } - VTKM_CONT - PortalConstType GetPortalConst() const + VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - VTKM_ASSERT(this->Valid); - return Traits::MakePortalConstControl( - this->Implementation, this->ArrayTuple, this->NumberOfValues, IndexList{}); + return Traits::CreateReadPortal( + buffers, GetNumberOfValues(buffers), IndexList{}, device, token); } - VTKM_CONT - vtkm::Id GetNumberOfValues() const + VTKM_CONT static WritePortalType CreateWritePortal(vtkm::cont::internal::Buffer* buffers, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) { - VTKM_ASSERT(this->Valid); - return this->NumberOfValues; + return Traits::CreateWritePortal( + buffers, GetNumberOfValues(buffers), IndexList{}, device, token); } - VTKM_CONT - void Allocate(vtkm::Id numValues) + VTKM_CONT static std::vector + CreateBuffers(const DecoratorImplT& implementation, vtkm::Id numValues, const ArrayTs&... arrays) { - VTKM_ASSERT(this->Valid); - Traits::AllocateSourceArrays(this->Implementation, this->ArrayTuple, numValues, IndexList{}); - // If the above call doesn't throw, update our state. - this->NumberOfValues = numValues; + return vtkm::cont::internal::CreateBuffers(MetaData(implementation, numValues), arrays...); } - - VTKM_CONT - void Shrink(vtkm::Id numValues) - { - VTKM_ASSERT(this->Valid); - Traits::ShrinkSourceArrays(this->Implementation, this->ArrayTuple, numValues, IndexList{}); - // If the above call doesn't throw, update our state. - this->NumberOfValues = numValues; - } - - VTKM_CONT - void ReleaseResources() - { - VTKM_ASSERT(this->Valid); - // No-op. Again, could eventually be passed down to the implementation. - } - - VTKM_CONT - const ArrayTupleType& GetArrayTuple() const - { - VTKM_ASSERT(this->Valid); - return this->ArrayTuple; - } - - VTKM_CONT - ArrayTupleType& GetArrayTuple() - { - VTKM_ASSERT(this->Valid); - return this->ArrayTuple; - } - - VTKM_CONT - const DecoratorImplT& GetImplementation() const - { - VTKM_ASSERT(this->Valid); - return this->Implementation; - } - - VTKM_CONT - DecoratorImplT& GetImplementation() - { - VTKM_ASSERT(this->Valid); - return this->Implementation; - } - -private: - DecoratorImplT Implementation; - ArrayTupleType ArrayTuple; - vtkm::Id NumberOfValues; - - bool Valid; }; template @@ -725,93 +588,13 @@ struct DecoratorHandleTraits using Superclass = vtkm::cont::ArrayHandle; }; -template -class ArrayTransfer::ValueType, - StorageTagDecorator, - Device> -{ - VTKM_IS_DEVICE_ADAPTER_TAG(Device); - - using HandleTraits = DecoratorHandleTraits; - using Traits = typename HandleTraits::StorageTraits; - using IndexList = typename Traits::IndexList; - using StorageType = typename HandleTraits::StorageType; - -public: - using ValueType = typename Traits::ValueType; - - using PortalControl = typename Traits::PortalControlType; - using PortalConstControl = typename Traits::PortalConstControlType; - - using PortalExecution = typename Traits::template PortalExecutionType; - using PortalConstExecution = typename Traits::template PortalConstExecutionType; - - VTKM_CONT - ArrayTransfer(StorageType* storage) - : Storage(storage) - { - } - - VTKM_CONT - vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); } - - VTKM_CONT - PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData), vtkm::cont::Token& token) const - { - return Traits::MakePortalInput(this->Storage->GetImplementation(), - this->Storage->GetArrayTuple(), - this->Storage->GetNumberOfValues(), - IndexList{}, - Device{}, - token); - } - - VTKM_CONT - PortalExecution PrepareForInPlace(bool vtkmNotUsed(updateData), vtkm::cont::Token& token) - { - return Traits::MakePortalInPlace(this->Storage->GetImplementation(), - this->Storage->GetArrayTuple(), - this->Storage->GetNumberOfValues(), - IndexList{}, - Device{}, - token); - } - - VTKM_CONT - PortalExecution PrepareForOutput(vtkm::Id, vtkm::cont::Token& token) - { - return Traits::MakePortalOutput(this->Storage->GetImplementation(), - this->Storage->GetArrayTuple(), - this->Storage->GetNumberOfValues(), - IndexList{}, - Device{}, - token); - } - - VTKM_CONT - void RetrieveOutputData(StorageType* vtkmNotUsed(storage)) const - { - // Implementation of this method should be unnecessary. The internal - // array handles should automatically retrieve the output data as - // necessary. - } - - VTKM_CONT - void Shrink(vtkm::Id numValues) { this->Storage->Shrink(numValues); } - - - VTKM_CONT - void ReleaseResources() - { - // no-op - } - -private: - StorageType* Storage; -}; - } // namespace internal +template +VTKM_ARRAY_HANDLE_NEW_STYLE( + T, + VTKM_PASS_COMMAS(internal::StorageTagDecorator)); + /// \brief A fancy ArrayHandle that can be used to modify the results from one /// or more source ArrayHandle. /// @@ -872,19 +655,11 @@ private: /// // number of values. /// template /// VTKM_CONT -/// void AllocateSourceArrays(vtkm::Id size, Array1Type array1, Array2Type array2) const; -/// -/// // Given a set of ArrayHandles and a size, implement what should happen to -/// // the source ArrayHandles when Shrink() is called on the decorator handle. -/// // -/// // ShrinkSourceArrays is optional; if not provided, the -/// // ArrayHandleDecorator will throw if its Shrink method is called. If -/// // an implementation is present and doesn't throw, the -/// // ArrayHandleDecorator's internal state is updated to show `size` as the -/// // number of values. -/// template -/// VTKM_CONT -/// void ShrinkSourceArrays(vtkm::Id size, Array1Type array1, Array2Type array2) const; +/// void AllocateSourceArrays(vtkm::Id size, +/// vtkm::CopyFlag preserve, +/// vtkm::cont::Token& token, +/// Array1Type array1, +/// Array2Type array2) const; /// /// }; /// ``` @@ -912,7 +687,7 @@ public: ArrayHandleDecorator(vtkm::Id numValues, const typename std::decay::type& impl, const typename std::decay::type&... arrays) - : Superclass{ StorageType{ impl, vtkm::MakeTuple(arrays...), numValues } } + : Superclass{ StorageType::CreateBuffers(impl, numValues, arrays...) } { } }; diff --git a/vtkm/cont/testing/UnitTestArrayHandleDecorator.cxx b/vtkm/cont/testing/UnitTestArrayHandleDecorator.cxx index f95469ece..a50d2727d 100644 --- a/vtkm/cont/testing/UnitTestArrayHandleDecorator.cxx +++ b/vtkm/cont/testing/UnitTestArrayHandleDecorator.cxx @@ -261,17 +261,14 @@ struct DecoratorTests // Resize methods: template - VTKM_CONT void AllocateSourceArrays(vtkm::Id numVals, Array1T&& array1, Array2T&& array2) const + VTKM_CONT void AllocateSourceArrays(vtkm::Id numVals, + vtkm::CopyFlag preserve, + vtkm::cont::Token& token, + Array1T&& array1, + Array2T&& array2) const { - array1.Allocate(numVals); - array2.Allocate(numVals); - } - - template - VTKM_CONT void ShrinkSourceArrays(vtkm::Id numVals, Array1T&& array1, Array2T&& array2) const - { - array1.Shrink(numVals); - array2.Shrink(numVals); + array1.Allocate(numVals, preserve, token); + array2.Allocate(numVals, preserve, token); } }; @@ -521,7 +518,7 @@ struct DecoratorTests } }; -// ArrayHandleDecorator that implements AllocateSourceArrays and ShrinkSourceArrays, thus allowing +// ArrayHandleDecorator that implements AllocateSourceArrays, thus allowing // it to be resized. struct ResizableDecorImpl { @@ -538,29 +535,32 @@ struct ResizableDecorImpl } template - void ShrinkSourceArrays(vtkm::Id newSize, Array1T& a1, Array2T& a2) const + void AllocateSourceArrays(vtkm::Id newSize, + vtkm::CopyFlag preserve, + vtkm::cont::Token& token, + Array1T& a1, + Array2T& a2) const { VTKM_IS_ARRAY_HANDLE(Array1T); VTKM_IS_ARRAY_HANDLE(Array2T); - // Resize each to 2*newSize: - a1.Shrink(2 * newSize); - a2.Shrink(2 * newSize); - } - - template - void AllocateSourceArrays(vtkm::Id newSize, Array1T& a1, Array2T& a2) const - { - VTKM_IS_ARRAY_HANDLE(Array1T); - VTKM_IS_ARRAY_HANDLE(Array2T); - - // Resize each to 3*newSize: - a1.Allocate(3 * newSize); - a2.Allocate(3 * newSize); + // Resize differently based on preserve to verify the flag is correct. + if (preserve == vtkm::CopyFlag::Off) + { + // Resize each to 3*newSize: + a1.Allocate(3 * newSize, preserve, token); + a2.Allocate(3 * newSize, preserve, token); + } + else + { + // Resize each to 2*newSize: + a1.Shrink(2 * newSize); + a2.Shrink(2 * newSize); + } } }; -// ArrayHandleDecorator that implements AllocateSourceArrays and ShrinkSourceArrays, thus allowing +// ArrayHandleDecorator that does not implement AllocateSourceArrays, thus not allowing // it to be resized. struct NonResizableDecorImpl { @@ -591,7 +591,7 @@ void ResizeTest() VTKM_TEST_ASSERT(a1.GetNumberOfValues() == 30); VTKM_TEST_ASSERT(a2.GetNumberOfValues() == 30); VTKM_TEST_ASSERT(decor.GetNumberOfValues() == 10); - decor.Shrink(3); // Should resize a1&a2 to have 6 values: + decor.Allocate(3, vtkm::CopyFlag::On); // Should resize a1&a2 to have 6 values: VTKM_TEST_ASSERT(a1.GetNumberOfValues() == 6); VTKM_TEST_ASSERT(a2.GetNumberOfValues() == 6); VTKM_TEST_ASSERT(decor.GetNumberOfValues() == 3); From 5ddfb719a3c9302f3cc90612e0b389d908933727 Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Thu, 19 Nov 2020 19:14:16 -0500 Subject: [PATCH 3/4] ClipWithField: Use primive types in instantiations `vtkm::[U]Int*` types depending of each platform/arch would translate to different integer types. We cannot make a generalization with this. A simple way to handle this is to simply use primitive types, such as char, signed char, long..., instead of vtkm::[U]Int*. This makes sure that every primitive type is actually instantiated. We could potentially use this in other filters instantiation file. This error has been reported in VTK when being build with vtkm. --- vtkm/filter/ClipWithFieldSignedInteger.cxx | 48 +++++++++++++++---- vtkm/filter/ClipWithFieldSignedInteger.cxx.in | 2 +- vtkm/filter/ClipWithFieldUnsignedInteger.cxx | 32 +++++++++---- .../ClipWithFieldUnsignedInteger.cxx.in | 2 +- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/vtkm/filter/ClipWithFieldSignedInteger.cxx b/vtkm/filter/ClipWithFieldSignedInteger.cxx index 41fd085ec..e9a4063ef 100644 --- a/vtkm/filter/ClipWithFieldSignedInteger.cxx +++ b/vtkm/filter/ClipWithFieldSignedInteger.cxx @@ -24,7 +24,7 @@ namespace filter template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -32,7 +32,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -40,7 +40,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -48,7 +48,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -56,7 +56,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -64,7 +64,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -72,7 +72,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -80,7 +80,39 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); +VTKM_DEPRECATED_SUPPRESS_END +#endif + +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); + +#ifndef VTKM_NO_DEPRECATED_VIRTUAL +VTKM_DEPRECATED_SUPPRESS_BEGIN +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); +VTKM_DEPRECATED_SUPPRESS_END +#endif + +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); + +#ifndef VTKM_NO_DEPRECATED_VIRTUAL +VTKM_DEPRECATED_SUPPRESS_BEGIN +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END diff --git a/vtkm/filter/ClipWithFieldSignedInteger.cxx.in b/vtkm/filter/ClipWithFieldSignedInteger.cxx.in index 58f9eb2fc..bffa0b6b3 100644 --- a/vtkm/filter/ClipWithFieldSignedInteger.cxx.in +++ b/vtkm/filter/ClipWithFieldSignedInteger.cxx.in @@ -36,7 +36,7 @@ namespace filter $py( # These values are taken from vtkm/TypeList.h -types = [ "vtkm::Int8", "vtkm::Int16", "vtkm::Int32", "vtkm::Int64"] +types = [ "char", "signed char", "short", "int", "long", "long long" ] )\ \ $for(TYPE in types)\ diff --git a/vtkm/filter/ClipWithFieldUnsignedInteger.cxx b/vtkm/filter/ClipWithFieldUnsignedInteger.cxx index 5bb472856..a67ae2e65 100644 --- a/vtkm/filter/ClipWithFieldUnsignedInteger.cxx +++ b/vtkm/filter/ClipWithFieldUnsignedInteger.cxx @@ -24,7 +24,7 @@ namespace filter template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -32,7 +32,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -40,7 +40,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -48,7 +48,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -56,7 +56,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -64,7 +64,7 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END @@ -72,7 +72,7 @@ VTKM_DEPRECATED_SUPPRESS_END template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); @@ -80,7 +80,23 @@ template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( VTKM_DEPRECATED_SUPPRESS_BEGIN template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); +VTKM_DEPRECATED_SUPPRESS_END +#endif + +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, + const vtkm::filter::FieldMetadata&, + vtkm::filter::PolicyBase); + +#ifndef VTKM_NO_DEPRECATED_VIRTUAL +VTKM_DEPRECATED_SUPPRESS_BEGIN +template VTKM_FILTER_EXTRA_EXPORT vtkm::cont::DataSet ClipWithField::DoExecute( + const vtkm::cont::DataSet&, + const vtkm::cont::ArrayHandle&, const vtkm::filter::FieldMetadata&, vtkm::filter::PolicyBase); VTKM_DEPRECATED_SUPPRESS_END diff --git a/vtkm/filter/ClipWithFieldUnsignedInteger.cxx.in b/vtkm/filter/ClipWithFieldUnsignedInteger.cxx.in index 0519c3ea5..883c2f186 100644 --- a/vtkm/filter/ClipWithFieldUnsignedInteger.cxx.in +++ b/vtkm/filter/ClipWithFieldUnsignedInteger.cxx.in @@ -36,7 +36,7 @@ namespace filter $py( # These values are taken from vtkm/TypeList.h -types = ["vtkm::UInt8", "vtkm::UInt16", "vtkm::UInt32", "vtkm::UInt64"] +types = ["unsigned char", "unsigned short", "unsigned int", "unsigned long", "unsigned long long"] )\ \ $for(TYPE in types)\ From b7a09f5ecb2a73d9bd356068f5a1ffbbd3ec49de Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 19 Nov 2020 17:31:55 -0700 Subject: [PATCH 4/4] Re-introduced deprecated StorageImplicit.h The `StorageImplicit.h` header is no longer used. However, just removing it causes compiles to fail if they include it. To make the transition better, re-add this file, but cause a deprecation warning if it is included. --- vtkm/cont/CMakeLists.txt | 1 + vtkm/cont/StorageImplicit.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 vtkm/cont/StorageImplicit.h diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index a55bc56da..0e7bade2b 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -110,6 +110,7 @@ set(headers Serialization.h Storage.h StorageExtrude.h + StorageImplicit.h # Deprecated, rolled into ArrayHandleImplicit.h StorageList.h StorageListTag.h Timer.h diff --git a/vtkm/cont/StorageImplicit.h b/vtkm/cont/StorageImplicit.h new file mode 100644 index 000000000..cd5f4e5be --- /dev/null +++ b/vtkm/cont/StorageImplicit.h @@ -0,0 +1,29 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//============================================================================ +#ifndef vtk_m_cont_StorageImplicit_h +#define vtk_m_cont_StorageImplicit_h + +#include +#include + +namespace vtkm +{ + +VTKM_DEPRECATED(1.6, "Use ArrayHandleImplicit.h instead of StorageImplicit.h.") +inline void StorageImplicit_h_deprecated() {} + +inline void ActivateStorageImplicit_h_deprecated_warning() +{ + StorageImplicit_h_deprecated(); +} + +} // namespace vtkm + +#endif //vtk_m_cont_StorageImplicit_h