From 76f870150b5c9e6d10ca7f7ac64b90c8d4928703 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 19 Mar 2020 15:02:54 -0600 Subject: [PATCH 1/3] Type check input and output array arguments differently Read-only arrays (usually) do not define Set methods. Thus, using one in an Invoke argument that does output will result in compile errors. To help avoid that, modify the type checks to differentiate input and output arrays. --- vtkm/cont/arg/CMakeLists.txt | 4 +- vtkm/cont/arg/TypeCheckTagArray.h | 42 ------------ vtkm/cont/arg/TypeCheckTagArrayIn.h | 66 ++++++++++++++++++ vtkm/cont/arg/TypeCheckTagArrayInOut.h | 67 +++++++++++++++++++ vtkm/cont/arg/TypeCheckTagArrayOut.h | 67 +++++++++++++++++++ vtkm/cont/arg/TypeCheckTagCellSetStructured.h | 2 +- .../arg/testing/UnitTestTypeCheckArray.cxx | 41 +++++++++--- vtkm/worklet/WorkletMapField.h | 10 +-- vtkm/worklet/WorkletMapTopology.h | 12 ++-- vtkm/worklet/WorkletPointNeighborhood.h | 12 ++-- vtkm/worklet/WorkletReduceByKey.h | 16 +++-- vtkm/worklet/internal/WorkletBase.h | 10 +-- 12 files changed, 272 insertions(+), 77 deletions(-) delete mode 100644 vtkm/cont/arg/TypeCheckTagArray.h create mode 100644 vtkm/cont/arg/TypeCheckTagArrayIn.h create mode 100644 vtkm/cont/arg/TypeCheckTagArrayInOut.h create mode 100644 vtkm/cont/arg/TypeCheckTagArrayOut.h diff --git a/vtkm/cont/arg/CMakeLists.txt b/vtkm/cont/arg/CMakeLists.txt index 890bd9a85..1e879a951 100644 --- a/vtkm/cont/arg/CMakeLists.txt +++ b/vtkm/cont/arg/CMakeLists.txt @@ -27,7 +27,9 @@ set(headers TransportTagWholeArrayInOut.h TransportTagWholeArrayOut.h TypeCheck.h - TypeCheckTagArray.h + TypeCheckTagArrayIn.h + TypeCheckTagArrayInOut.h + TypeCheckTagArrayOut.h TypeCheckTagAtomicArray.h TypeCheckTagBitField.h TypeCheckTagCellSet.h diff --git a/vtkm/cont/arg/TypeCheckTagArray.h b/vtkm/cont/arg/TypeCheckTagArray.h deleted file mode 100644 index 29705bab3..000000000 --- a/vtkm/cont/arg/TypeCheckTagArray.h +++ /dev/null @@ -1,42 +0,0 @@ -//============================================================================ -// 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_arg_TypeCheckTagArray_h -#define vtk_m_cont_arg_TypeCheckTagArray_h - -#include - -#include - -#include - -namespace vtkm -{ -namespace cont -{ -namespace arg -{ - -/// The Array type check passes for any object that behaves like an \c -/// ArrayHandle class and can be passed to the ArrayIn and ArrayOut transports. -/// -struct TypeCheckTagArray -{ -}; - -template -struct TypeCheck -{ - static constexpr bool value = vtkm::cont::internal::ArrayHandleCheck::type::value; -}; -} -} -} // namespace vtkm::cont::arg - -#endif //vtk_m_cont_arg_TypeCheckTagArray_h diff --git a/vtkm/cont/arg/TypeCheckTagArrayIn.h b/vtkm/cont/arg/TypeCheckTagArrayIn.h new file mode 100644 index 000000000..0a258c40f --- /dev/null +++ b/vtkm/cont/arg/TypeCheckTagArrayIn.h @@ -0,0 +1,66 @@ +//============================================================================ +// 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_arg_TypeCheckTagArrayIn_h +#define vtk_m_cont_arg_TypeCheckTagArrayIn_h + +#include + +#include + +#include + +#include + +namespace vtkm +{ +namespace cont +{ +namespace arg +{ + +/// The Array type check passes for any object that behaves like an \c +/// ArrayHandle class and can be passed to the ArrayIn transport. +/// +struct TypeCheckTagArrayIn +{ +}; + +namespace detail +{ + +template ::type::value> +struct IsArrayHandleIn; + +template +struct IsArrayHandleIn +{ + static constexpr bool value = + vtkm::internal::PortalSupportsGets::value; +}; + +template +struct IsArrayHandleIn +{ + static constexpr bool value = false; +}; + +} // namespace detail + +template +struct TypeCheck +{ + static constexpr bool value = detail::IsArrayHandleIn::value; +}; +} +} +} // namespace vtkm::cont::arg + +#endif //vtk_m_cont_arg_TypeCheckTagArray_h diff --git a/vtkm/cont/arg/TypeCheckTagArrayInOut.h b/vtkm/cont/arg/TypeCheckTagArrayInOut.h new file mode 100644 index 000000000..823f8bae9 --- /dev/null +++ b/vtkm/cont/arg/TypeCheckTagArrayInOut.h @@ -0,0 +1,67 @@ +//============================================================================ +// 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_arg_TypeCheckTagArrayInOut_h +#define vtk_m_cont_arg_TypeCheckTagArrayInOut_h + +#include + +#include + +#include + +#include + +namespace vtkm +{ +namespace cont +{ +namespace arg +{ + +/// The Array type check passes for any object that behaves like an +/// `ArrayHandle` class and can be passed to the ArrayInOut transport. +/// +struct TypeCheckTagArrayInOut +{ +}; + +namespace detail +{ + +template ::type::value> +struct IsArrayHandleInOut; + +template +struct IsArrayHandleInOut +{ + static constexpr bool value = + (vtkm::internal::PortalSupportsGets::value && + vtkm::internal::PortalSupportsSets::value); +}; + +template +struct IsArrayHandleInOut +{ + static constexpr bool value = false; +}; + +} // namespace detail + +template +struct TypeCheck +{ + static constexpr bool value = detail::IsArrayHandleInOut::value; +}; +} +} +} // namespace vtkm::cont::arg + +#endif //vtk_m_cont_arg_TypeCheckTagArray_h diff --git a/vtkm/cont/arg/TypeCheckTagArrayOut.h b/vtkm/cont/arg/TypeCheckTagArrayOut.h new file mode 100644 index 000000000..f694b4c11 --- /dev/null +++ b/vtkm/cont/arg/TypeCheckTagArrayOut.h @@ -0,0 +1,67 @@ +//============================================================================ +// 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_arg_TypeCheckTagArrayOut_h +#define vtk_m_cont_arg_TypeCheckTagArrayOut_h + +#include + +#include + +#include + +#include + +namespace vtkm +{ +namespace cont +{ +namespace arg +{ + +/// The Array type check passes for any object that behaves like an +/// `ArrayHandle` class and can be passed to the ArrayOut transport. +/// +struct TypeCheckTagArrayOut +{ +}; + +namespace detail +{ + +template ::type::value> +struct IsArrayHandleOut; + +template +struct IsArrayHandleOut +{ + static constexpr bool value = + (vtkm::internal::PortalSupportsGets::value && + vtkm::internal::PortalSupportsSets::value); +}; + +template +struct IsArrayHandleOut +{ + static constexpr bool value = false; +}; + +} // namespace detail + +template +struct TypeCheck +{ + static constexpr bool value = detail::IsArrayHandleOut::value; +}; +} +} +} // namespace vtkm::cont::arg + +#endif //vtk_m_cont_arg_TypeCheckTagArray_h diff --git a/vtkm/cont/arg/TypeCheckTagCellSetStructured.h b/vtkm/cont/arg/TypeCheckTagCellSetStructured.h index 45d9431ba..0d9bdb393 100644 --- a/vtkm/cont/arg/TypeCheckTagCellSetStructured.h +++ b/vtkm/cont/arg/TypeCheckTagCellSetStructured.h @@ -12,7 +12,7 @@ #include -#include +#include namespace vtkm { diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx index cb3200b64..1fcedcf44 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx @@ -8,7 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include +#include +#include #include #include @@ -26,27 +28,50 @@ struct TryArraysOfType void operator()(T) const { using vtkm::cont::arg::TypeCheck; - using vtkm::cont::arg::TypeCheckTagArray; + using vtkm::cont::arg::TypeCheckTagArrayIn; + using vtkm::cont::arg::TypeCheckTagArrayInOut; + using vtkm::cont::arg::TypeCheckTagArrayOut; using StandardArray = vtkm::cont::ArrayHandle; - VTKM_TEST_ASSERT((TypeCheck::value), + VTKM_TEST_ASSERT((TypeCheck::value), + "Standard array type check failed."); + VTKM_TEST_ASSERT((TypeCheck::value), + "Standard array type check failed."); + VTKM_TEST_ASSERT((TypeCheck::value), "Standard array type check failed."); using CountingArray = vtkm::cont::ArrayHandleCounting; - VTKM_TEST_ASSERT((TypeCheck::value), + VTKM_TEST_ASSERT((TypeCheck::value), + "Counting array type check failed."); + VTKM_TEST_ASSERT((!TypeCheck::value), + "Counting array type check failed."); + VTKM_TEST_ASSERT((!TypeCheck::value), "Counting array type check failed."); - using CompositeArray = vtkm::cont::ArrayHandleCompositeVector; - VTKM_TEST_ASSERT((TypeCheck::value), + using CompositeArray = vtkm::cont::ArrayHandleCompositeVector; + VTKM_TEST_ASSERT((TypeCheck::value), "Composite array type check failed."); + VTKM_TEST_ASSERT((TypeCheck::value), + "Counting array type check failed."); + VTKM_TEST_ASSERT((TypeCheck::value), + "Counting array type check failed."); // Just some type that is not a valid array. using NotAnArray = typename StandardArray::WritePortalType; - VTKM_TEST_ASSERT(!(TypeCheck::value), + VTKM_TEST_ASSERT(!(TypeCheck::value), + "Not an array type check failed."); + VTKM_TEST_ASSERT(!(TypeCheck::value), + "Not an array type check failed."); + VTKM_TEST_ASSERT(!(TypeCheck::value), "Not an array type check failed."); // Another type that is not a valid array. - VTKM_TEST_ASSERT(!(TypeCheck::value), "Not an array type check failed."); + VTKM_TEST_ASSERT(!(TypeCheck::value), + "Not an array type check failed."); + VTKM_TEST_ASSERT(!(TypeCheck::value), + "Not an array type check failed."); + VTKM_TEST_ASSERT(!(TypeCheck::value), + "Not an array type check failed."); } }; diff --git a/vtkm/worklet/WorkletMapField.h b/vtkm/worklet/WorkletMapField.h index 4ce40558d..7af385610 100644 --- a/vtkm/worklet/WorkletMapField.h +++ b/vtkm/worklet/WorkletMapField.h @@ -16,7 +16,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -47,7 +49,7 @@ public: /// struct FieldIn : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagArrayIn; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -58,7 +60,7 @@ public: /// struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagArrayOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut; }; @@ -69,7 +71,7 @@ public: /// struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagArrayInOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut; }; diff --git a/vtkm/worklet/WorkletMapTopology.h b/vtkm/worklet/WorkletMapTopology.h index d989160f9..6d3009f07 100644 --- a/vtkm/worklet/WorkletMapTopology.h +++ b/vtkm/worklet/WorkletMapTopology.h @@ -19,7 +19,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -75,7 +77,7 @@ public: /// struct FieldInVisit : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagTopologyFieldIn; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -85,7 +87,7 @@ public: /// struct FieldInIncident : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagTopologyFieldIn; using FetchTag = vtkm::exec::arg::FetchTagArrayTopologyMapIn; }; @@ -97,7 +99,7 @@ public: /// struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagArrayOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut; }; @@ -107,7 +109,7 @@ public: /// struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagArrayInOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut; }; diff --git a/vtkm/worklet/WorkletPointNeighborhood.h b/vtkm/worklet/WorkletPointNeighborhood.h index 0b4b274e4..f57431597 100644 --- a/vtkm/worklet/WorkletPointNeighborhood.h +++ b/vtkm/worklet/WorkletPointNeighborhood.h @@ -25,7 +25,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -110,7 +112,7 @@ public: /// struct FieldIn : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagArrayIn; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -122,7 +124,7 @@ public: /// struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagArrayOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut; }; @@ -134,7 +136,7 @@ public: /// struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagArrayInOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut; }; @@ -166,7 +168,7 @@ public: /// struct FieldInNeighborhood : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagArrayIn; using FetchTag = vtkm::exec::arg::FetchTagArrayNeighborhoodIn; }; diff --git a/vtkm/worklet/WorkletReduceByKey.h b/vtkm/worklet/WorkletReduceByKey.h index 6f2ff2ea1..4f0156a34 100644 --- a/vtkm/worklet/WorkletReduceByKey.h +++ b/vtkm/worklet/WorkletReduceByKey.h @@ -19,7 +19,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -69,7 +71,7 @@ public: /// struct ValuesIn : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesIn; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -85,7 +87,7 @@ public: /// struct ValuesInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesInOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -101,7 +103,7 @@ public: /// struct ValuesOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -118,7 +120,7 @@ public: /// struct ReducedValuesIn : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagArrayIn; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn; }; @@ -135,7 +137,7 @@ public: /// struct ReducedValuesInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagArrayInOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut; }; @@ -149,7 +151,7 @@ public: /// struct ReducedValuesOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagArrayOut; using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut; }; diff --git a/vtkm/worklet/internal/WorkletBase.h b/vtkm/worklet/internal/WorkletBase.h index 943f4bd6b..77f0fbd7c 100644 --- a/vtkm/worklet/internal/WorkletBase.h +++ b/vtkm/worklet/internal/WorkletBase.h @@ -32,7 +32,9 @@ #include #include #include -#include +#include +#include +#include #include #include #include @@ -140,7 +142,7 @@ public: /// struct WholeArrayIn : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn; using TransportTag = vtkm::cont::arg::TransportTagWholeArrayIn; using FetchTag = vtkm::exec::arg::FetchTagExecObject; }; @@ -158,7 +160,7 @@ public: /// struct WholeArrayOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut; using TransportTag = vtkm::cont::arg::TransportTagWholeArrayOut; using FetchTag = vtkm::exec::arg::FetchTagExecObject; }; @@ -177,7 +179,7 @@ public: /// struct WholeArrayInOut : vtkm::cont::arg::ControlSignatureTagBase { - using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray; + using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut; using TransportTag = vtkm::cont::arg::TransportTagWholeArrayInOut; using FetchTag = vtkm::exec::arg::FetchTagExecObject; }; From dc112b5169e6d0a07c78dc4f3de2dc9a6a9e77a9 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 17 Mar 2020 17:22:35 -0600 Subject: [PATCH 2/3] Enable changing policy used for library compiles Previously, the PolicyDefault used to compile all the filters was hard- coded. The problem was that if any external project that depends on VTK- m needs a different policy, it had to recompile everything in its own translation units with a custom policy. This change allows an external project provide a simple header file that changes the type lists used in the default policy. That allows VTK-m to compile the filters exactly as specified by the external project. --- docs/changelog/configurable-default-types.md | 53 +++++++++ vtkm/TypeList.h | 4 - vtkm/TypeListTag.h | 2 +- vtkm/cont/ArrayHandleExtrudeCoords.h | 2 - vtkm/cont/CMakeLists.txt | 33 ++++++ vtkm/cont/CellSet.h | 3 - vtkm/cont/CellSetList.h | 4 - vtkm/cont/CellSetStructured.h | 1 + vtkm/cont/CoordinateSystem.h | 5 +- vtkm/cont/CoordinateSystem.hxx | 7 -- vtkm/cont/DefaultTypes.h.in | 104 +++++++++++++++++ vtkm/cont/DynamicCellSet.h | 1 + vtkm/cont/StorageList.h | 8 -- vtkm/cont/StorageListTag.h | 6 +- vtkm/cont/VariantArrayHandle.h | 1 + vtkm/cont/internal/DefaultTypesVTK.h.in | 107 ++++++++++++++++++ .../testing/UnitTestVariantArrayHandle.cxx | 8 +- vtkm/filter/PolicyBase.h | 16 +-- vtkm/rendering/raytracing/ChannelBuffer.cxx | 1 + 19 files changed, 320 insertions(+), 46 deletions(-) create mode 100644 docs/changelog/configurable-default-types.md create mode 100644 vtkm/cont/DefaultTypes.h.in create mode 100644 vtkm/cont/internal/DefaultTypesVTK.h.in diff --git a/docs/changelog/configurable-default-types.md b/docs/changelog/configurable-default-types.md new file mode 100644 index 000000000..01da1600e --- /dev/null +++ b/docs/changelog/configurable-default-types.md @@ -0,0 +1,53 @@ +# Configurable default types + +Because VTK-m compiles efficient code for accelerator architectures, it +often has to compile for static types. This means that dynamic types often +have to be determined at runtime and converted to static types. This is the +reason for the `CastAndCall` architecture in VTK-m. + +For this `CastAndCall` to work, there has to be a finite set of static +types to try at runtime. If you don't compile in the types you need, you +will get runtime errors. However, the more types you compile in, the longer +the compile time and executable size. Thus, getting the types right is +important. + +The "right" types to use can change depending on the application using +VTK-m. For example, when VTK links in VTK-m, it needs to support lots of +types and can sacrifice the compile times to do so. However, if using VTK-m +in situ with a fortran simulation, space and time are critical and you +might only need to worry about double SoA arrays. + +Thus, it is important to customize what types VTK-m uses based on the +application. This leads to the oxymoronic phrase of configuring the default +types used by VTK-m. + +This is being implemented by providing VTK-m with a header file that +defines the default types. The header file provided to VTK-m should define +one or more of the following preprocessor macros: + + * `VTKM_DEFAULT_TYPE_LIST` - a `vtkm::List` of value types for fields that + filters should directly operate on (where applicable). + * `VTKM_DEFAULT_STORAGE_LIST` - a `vtkm::List` of storage tags for fields + that filters should directly operate on. + * `VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED` - a `vtkm::List` of + `vtkm::cont::CellSet` types that filters should operate on as a + strutured cell set. + * `VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED` - a `vtkm::List` of + `vtkm::cont::CellSet` types that filters should operate on as an + unstrutured cell set. + * `VTKM_DEFAULT_CELL_SET_LIST` - a `vtkm::List` of `vtkm::cont::CellSet` + types that filters should operate on (where applicable). The default of + `vtkm::ListAppend` + is usually correct. + +If any of these macros are not defined, a default version will be defined. +(This is the same default used if no header file is provided.) + +This header file is provided to the build by setting the +`VTKm_DEFAULT_TYPES_HEADER` CMake variable. `VTKm_DEFAULT_TYPES_HEADER` +points to the file, which will be configured and copied to VTK-m's build +directory. + +For convenience, header files can be added to the VTK_m source directory +(conventionally under vtkm/cont/internal). If this is the case, an advanced +CMake option should be added to select the provided header file. diff --git a/vtkm/TypeList.h b/vtkm/TypeList.h index 248602441..fab650f15 100644 --- a/vtkm/TypeList.h +++ b/vtkm/TypeList.h @@ -10,10 +10,6 @@ #ifndef vtk_m_TypeList_h #define vtk_m_TypeList_h -#ifndef VTKM_DEFAULT_TYPE_LIST -#define VTKM_DEFAULT_TYPE_LIST ::vtkm::TypeListCommon -#endif - #include #include diff --git a/vtkm/TypeListTag.h b/vtkm/TypeListTag.h index a9984dcf6..d32041b8f 100644 --- a/vtkm/TypeListTag.h +++ b/vtkm/TypeListTag.h @@ -63,7 +63,7 @@ VTKM_DEPRECATED( 1.6, "VTKM_DEFAULT_TYPE_LIST_TAG replaced by VTKM_DEFAULT_TYPE_LIST. " "Note that the new VTKM_DEFAULT_TYPE_LIST cannot be subclassed.") -TypeListTagDefault : vtkm::internal::ListAsListTag +TypeListTagDefault : vtkm::internal::ListAsListTag { }; diff --git a/vtkm/cont/ArrayHandleExtrudeCoords.h b/vtkm/cont/ArrayHandleExtrudeCoords.h index 0dc3c409f..acddbaee0 100644 --- a/vtkm/cont/ArrayHandleExtrudeCoords.h +++ b/vtkm/cont/ArrayHandleExtrudeCoords.h @@ -13,8 +13,6 @@ #include #include -#include -#include namespace vtkm { diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 7f1967382..088dad24c 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -189,6 +189,39 @@ set(sources Timer.cxx ) +#----------------------------------------------------------------------------- +# Set up default types, which can be custom configured by other build systems. +vtkm_get_kit_name(kit_name kit_dir) + +# Some custom types included with VTK-m +option(VTKm_USE_DEFAULT_TYPES_FOR_VTK "Compile VTK-m algorithms for use with types from VTK." OFF) +if (VTKm_USE_DEFAULT_TYPES_FOR_VTK) + set(VTKm_DEFAULT_TYPES_HEADER "internal/DefaultTypesVTK.h.in") +endif() + +mark_as_advanced(VTKm_USE_DEFAULT_TYPES_FOR_VTK) + +if (VTKm_DEFAULT_TYPES_HEADER) + set(VTK_M_HAS_DEFAULT_TYPES_HEADER TRUE) + get_filename_component(VTKm_DEFAULT_TYPES_HEADER_FILENAME ${VTKm_DEFAULT_TYPES_HEADER} NAME_WE) + set(VTKm_DEFAULT_TYPES_HEADER_FILENAME "${VTKm_DEFAULT_TYPES_HEADER_FILENAME}.h") + configure_file(${VTKm_DEFAULT_TYPES_HEADER} + ${VTKm_BINARY_INCLUDE_DIR}/${kit_dir}/internal/${VTKm_DEFAULT_TYPES_HEADER_FILENAME} + @ONLY + ) + vtkm_install_headers(vtkm/cont/internal + ${VTKm_BINARY_INCLUDE_DIR}/${kit_dir}/internal/${VTKm_DEFAULT_TYPES_HEADER_FILENAME} + ) +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DefaultTypes.h.in + ${VTKm_BINARY_INCLUDE_DIR}/${kit_dir}/DefaultTypes.h + @ONLY + ) +vtkm_install_headers(vtkm/cont + ${VTKm_BINARY_INCLUDE_DIR}/${kit_dir}/DefaultTypes.h + ) + #----------------------------------------------------------------------------- vtkm_library( NAME vtkm_cont SOURCES ${sources} diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index f4953de04..c63e201cc 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -15,9 +15,6 @@ #include #include -#include -#include -#include namespace vtkm { diff --git a/vtkm/cont/CellSetList.h b/vtkm/cont/CellSetList.h index 61dcca1f7..4ca83b51a 100644 --- a/vtkm/cont/CellSetList.h +++ b/vtkm/cont/CellSetList.h @@ -10,10 +10,6 @@ #ifndef vtk_m_cont_CellSetList_h #define vtk_m_cont_CellSetList_h -#ifndef VTKM_DEFAULT_CELL_SET_LIST -#define VTKM_DEFAULT_CELL_SET_LIST ::vtkm::cont::CellSetListCommon -#endif - #include #include diff --git a/vtkm/cont/CellSetStructured.h b/vtkm/cont/CellSetStructured.h index 7e03743f7..d6e31e3ff 100644 --- a/vtkm/cont/CellSetStructured.h +++ b/vtkm/cont/CellSetStructured.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index 9691b7bd1..6e532c69d 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -38,7 +38,10 @@ public: const vtkm::cont::VariantArrayHandleBase& data); template - VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle& data); + VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle& data) + : Superclass(name, Association::POINTS, vtkm::cont::ArrayHandleVirtualCoordinates(data)) + { + } /// This constructor of coordinate system sets up a regular grid of points. /// diff --git a/vtkm/cont/CoordinateSystem.hxx b/vtkm/cont/CoordinateSystem.hxx index 9192bcf60..f846729fc 100644 --- a/vtkm/cont/CoordinateSystem.hxx +++ b/vtkm/cont/CoordinateSystem.hxx @@ -56,13 +56,6 @@ VTKM_CONT CoordinateSystem::CoordinateSystem( { } -template -VTKM_CONT CoordinateSystem::CoordinateSystem(std::string name, - const vtkm::cont::ArrayHandle& data) - : Superclass(name, Association::POINTS, vtkm::cont::ArrayHandleVirtualCoordinates(data)) -{ -} - template VTKM_CONT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandle& newdata) { diff --git a/vtkm/cont/DefaultTypes.h.in b/vtkm/cont/DefaultTypes.h.in new file mode 100644 index 000000000..538b1594e --- /dev/null +++ b/vtkm/cont/DefaultTypes.h.in @@ -0,0 +1,104 @@ +//============================================================================ +// 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. +//============================================================================ + +// The intention of the header file is to configure VTK-m to compile its algorithms +// and filters for some set of types and data storage. You can customize the types +// for which VTK-m is compiled for by setting the VTKm_DEFAULT_TYPES_HEADER CMake +// variable. This CMake variable can be set to a header file that defines one or +// more of the following macros: +// +// VTKM_FIELD_TYPE_LIST - a vtkm::List of value types for fields that filters +// should directly operate on (where applicable). +// VTKM_FIELD_STORAGE_LIST - a vtkm::List of storage tags for fields that +// filters should directly operate on. +// VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED - a vtkm::List of vtkm::cont::CellSet types +// that filters should operate on as a strutured cell set. +// VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED - a vtkm::List of vtkm::cont::CellSet types +// that filters should operate on as an unstrutured cell set. +// VTKM_DEFAULT_CELL_SET_LIST - a vtkm::List of vtkm::cont::CellSet types that filters +// should operate on (where applicable). The default of +// vtkm::ListAppend +// is usually correct. +// +// Note that if you specify VTKm_DEFAULT_TYPES_HEADER, that file will be copied +// to the VTK-m build directory. Thus, be careful about editing the file included +// by this one (if it exists). + +#ifndef vtk_m_cont_DefaultTypes_h +#define vtk_m_cont_DefaultTypes_h + +#cmakedefine VTK_M_HAS_DEFAULT_TYPES_HEADER + +#ifdef VTK_M_HAS_DEFAULT_TYPES_HEADER +#include "internal/@VTKm_DEFAULT_TYPES_HEADER_FILENAME@" +#endif + +#ifndef VTKM_DEFAULT_TYPE_LIST +#include +#define VTKM_DEFAULT_TYPE_LIST ::vtkm::TypeListCommon +#endif //VTKM_DEFAULT_TYPE_LIST + +#ifndef VTKM_DEFAULT_STORAGE_LIST +#include +#include +#include +namespace vtkm +{ +namespace cont +{ +namespace internal +{ + +using StorageListField = vtkm::ListAppend< + vtkm::cont::StorageListBasic, + vtkm::List< + vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag, + vtkm::cont::ArrayHandleCartesianProduct, + vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandle>::StorageTag, + vtkm::cont::ArrayHandleCartesianProduct, + vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandle>::StorageTag>>; + +} +} +} // namespace vtkm::cont + +#define VTKM_DEFAULT_STORAGE_LIST ::vtkm::cont::internal::StorageListField +#endif // VTKM_FIELD_STORAGE_LIST + +#ifndef VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED +#include +#define VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED ::vtkm::cont::CellSetListStructured +#endif // VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED + +#ifndef VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED +#include +#define VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED ::vtkm::cont::CellSetListUnstructured +#endif // VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED + +#ifndef VTKM_DEFAULT_CELL_SET_LIST +namespace vtkm +{ +namespace cont +{ +namespace internal +{ + +using CellSetList = vtkm::ListAppend; + +} +} +} // namespace vtkm::cont::internal + +#define VTKM_DEFAULT_CELL_SET_LIST ::vtkm::cont::internal::CellSetList +#endif // VTKM_CELL_SET_LIST + +#endif //vtk_m_cont_DefaultTypes_h diff --git a/vtkm/cont/DynamicCellSet.h b/vtkm/cont/DynamicCellSet.h index 4275dcc55..18225f01f 100644 --- a/vtkm/cont/DynamicCellSet.h +++ b/vtkm/cont/DynamicCellSet.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/vtkm/cont/StorageList.h b/vtkm/cont/StorageList.h index 833540768..983ed38a3 100644 --- a/vtkm/cont/StorageList.h +++ b/vtkm/cont/StorageList.h @@ -10,10 +10,6 @@ #ifndef vtk_m_cont_StorageList_h #define vtk_m_cont_StorageList_h -#ifndef VTKM_DEFAULT_STORAGE_LIST -#define VTKM_DEFAULT_STORAGE_LIST ::vtkm::cont::StorageListBasic -#endif - #include #include @@ -25,10 +21,6 @@ namespace cont { using StorageListBasic = vtkm::List; - -// If we want to compile VTK-m with support of memory layouts other than the basic layout, then -// add the appropriate storage tags here. -using StorageListSupported = vtkm::List; } } // namespace vtkm::cont diff --git a/vtkm/cont/StorageListTag.h b/vtkm/cont/StorageListTag.h index 6ec71b069..74a88d951 100644 --- a/vtkm/cont/StorageListTag.h +++ b/vtkm/cont/StorageListTag.h @@ -35,9 +35,9 @@ struct VTKM_ALWAYS_EXPORT VTKM_DEPRECATED( struct VTKM_ALWAYS_EXPORT VTKM_DEPRECATED( 1.6, - "StorageListTagSupported replaced by StorageListSupported. " + "StorageListTagSupported replaced by StorageListBasic. " "Note that the new StorageListSupported cannot be subclassed.") StorageListTagSupported - : vtkm::internal::ListAsListTag + : vtkm::internal::ListAsListTag { }; @@ -48,7 +48,7 @@ struct VTKM_ALWAYS_EXPORT VTKM_DEPRECATED( 1.6, "VTKM_DEFAULT_STORAGE_LIST_TAG replaced by VTKM_DEFAULT_STORAGE_LIST. " "Note that the new VTKM_DEFAULT_STORAGE_LIST cannot be subclassed.") StorageListTagDefault - : vtkm::internal::ListAsListTag + : vtkm::internal::ListAsListTag { }; diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index 875eae251..837f6e8d0 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/vtkm/cont/internal/DefaultTypesVTK.h.in b/vtkm/cont/internal/DefaultTypesVTK.h.in new file mode 100644 index 000000000..3d00ec403 --- /dev/null +++ b/vtkm/cont/internal/DefaultTypesVTK.h.in @@ -0,0 +1,107 @@ +//============================================================================ +// 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 vtkmDefaultTypes_h +#define vtkmDefaultTypes_h + +// This configures the default types to use when compiling VTK-m for use as an +// accelerator in VTK. + +#include + +#include + +namespace tovtkm +{ + +//------------------------------------------------------------------------------ +// All scalar types in vtkType.h +using VTKScalarTypes = vtkm::List< // + char, // + signed char, // + unsigned char, // + short, // + unsigned short, // + int, // + unsigned int, // + long, // + unsigned long, // + long long, // + unsigned long long, // + float, // + double // + >; + +using SpecialGradientOutTypes = + vtkm::List, 3>, vtkm::Vec, 3> >; + +using FieldTypeInVTK = vtkm::ListAppend; + +using FieldTypeOutVTK = + vtkm::ListAppend; + +//------------------------------------------------------------------------------ +using CellListStructuredInVTK = + vtkm::List, vtkm::cont::CellSetStructured<2>, vtkm::cont::CellSetStructured<1> >; +using CellListStructuredOutVTK = CellListStructuredInVTK; + +// vtkCellArray may use either 32 or 64 bit arrays to hold connectivity/offset +// data, so we may be using ArrayHandleCast to convert to vtkm::Ids. +#ifdef VTKM_USE_64BIT_IDS +using Int32AOSHandle = vtkm::cont::ArrayHandle; +using Int32AsIdAOSHandle = vtkm::cont::ArrayHandleCast; +using Int32AsIdAOSStorage = typename Int32AsIdAOSHandle::StorageTag; + +using CellSetExplicit32Bit = vtkm::cont::CellSetExplicit; +using CellSetExplicit64Bit = vtkm::cont::CellSetExplicit; +using CellSetSingleType32Bit = vtkm::cont::CellSetSingleType; +using CellSetSingleType64Bit = vtkm::cont::CellSetSingleType; +#else // VTKM_USE_64BIT_IDS +using Int64AOSHandle = vtkm::cont::ArrayHandle; +using Int64AsIdAOSHandle = vtkm::cont::ArrayHandleCast; +using Int64AsIdAOSStorage = typename Int64AsIdAOSHandle::StorageTag; + +using CellSetExplicit32Bit = vtkm::cont::CellSetExplicit; +using CellSetExplicit64Bit = vtkm::cont::CellSetExplicit; +using CellSetSingleType32Bit = vtkm::cont::CellSetSingleType; +using CellSetSingleType64Bit = vtkm::cont::CellSetSingleType; +#endif // VTKM_USE_64BIT_IDS + +//------------------------------------------------------------------------------ +using CellListUnstructuredInVTK = vtkm::List< // + CellSetExplicit32Bit, // + CellSetExplicit64Bit, // + CellSetSingleType32Bit, // + CellSetSingleType64Bit // + >; + +using CellListUnstructuredOutVTK = vtkm::List< // + vtkm::cont::CellSetExplicit<>, // + vtkm::cont::CellSetSingleType<>, // + CellSetExplicit32Bit, // + CellSetExplicit64Bit, // + CellSetSingleType32Bit, // + CellSetSingleType64Bit // + >; + +//------------------------------------------------------------------------------ +using CellListAllInVTK = vtkm::ListAppend; +using CellListAllOutVTK = vtkm::ListAppend; + +} // end namespace tovtkm + +#define VTKM_DEFAULT_TYPE_LIST ::tovtkm::FieldTypeInVTK +#define VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED ::tovtkm::CellListStructuredInVTK +#define VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED ::tovtkm::CellListUnstructuredInVTK + +#endif //vtkmDefaultTypes_h diff --git a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx index e8c3c3bf8..37831dad4 100644 --- a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx @@ -110,7 +110,7 @@ struct CheckFunctor template void operator()( - const vtkm::cont::ArrayHandle::StorageTag>& array, + const vtkm::cont::ArrayHandle>>& array, bool& vtkmNotUsed(calledBasic), bool& calledUnusual, bool& vtkmNotUsed(calledVirtual)) const @@ -138,6 +138,12 @@ struct CheckFunctor auto portal = array.ReadPortal(); CheckPortal(portal); } + + template + void operator()(const vtkm::cont::ArrayHandle&, bool&, bool&, bool&) const + { + VTKM_TEST_FAIL("Array resolved to unexpected type."); + } }; template diff --git a/vtkm/filter/PolicyBase.h b/vtkm/filter/PolicyBase.h index 0da1fd17b..f4cbbc551 100644 --- a/vtkm/filter/PolicyBase.h +++ b/vtkm/filter/PolicyBase.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -32,19 +33,10 @@ template struct PolicyBase { using FieldTypeList = VTKM_DEFAULT_TYPE_LIST; - using StorageList = vtkm::ListAppend< - VTKM_DEFAULT_STORAGE_LIST, - vtkm::List< - vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag, - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>::StorageTag, - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>::StorageTag>>; + using StorageList = VTKM_DEFAULT_STORAGE_LIST; - using StructuredCellSetList = vtkm::cont::CellSetListStructured; - using UnstructuredCellSetList = vtkm::cont::CellSetListUnstructured; + using StructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED; + using UnstructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED; using AllCellSetList = VTKM_DEFAULT_CELL_SET_LIST; }; diff --git a/vtkm/rendering/raytracing/ChannelBuffer.cxx b/vtkm/rendering/raytracing/ChannelBuffer.cxx index f21263e04..40365fd6e 100644 --- a/vtkm/rendering/raytracing/ChannelBuffer.cxx +++ b/vtkm/rendering/raytracing/ChannelBuffer.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include #include From 42bc9a393c0a2e2bec2b3de2e472eadacc5dab26 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 19 Mar 2020 16:51:43 -0600 Subject: [PATCH 3/3] Fix gaps in type support With recent changes to allow a configuration to change the default types, storage, and cell sets, it is possible to feed filters and other components types they were not previously expecting. Fix feature gaps where these components were not accepting the types they should. --- .../arg/testing/UnitTestTypeCheckArray.cxx | 4 +-- .../exec/arg/ThreadIndicesPointNeighborhood.h | 7 ++++ vtkm/filter/CrossProduct.h | 4 +-- vtkm/filter/DotProduct.h | 12 +++---- vtkm/filter/DotProduct.hxx | 7 ++-- vtkm/rendering/Cylinderizer.h | 7 ++-- vtkm/rendering/Quadralizer.h | 33 ++++++++++++++----- vtkm/rendering/Triangulator.h | 6 ++-- .../raytracing/CylinderExtractor.cxx | 6 ++-- vtkm/rendering/raytracing/QuadExtractor.cxx | 6 ++-- vtkm/rendering/raytracing/SphereExtractor.cxx | 6 ++-- vtkm/worklet/DotProduct.h | 9 ++++- 12 files changed, 71 insertions(+), 36 deletions(-) diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx index 1fcedcf44..cca2bbf7a 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx @@ -51,9 +51,9 @@ struct TryArraysOfType using CompositeArray = vtkm::cont::ArrayHandleCompositeVector; VTKM_TEST_ASSERT((TypeCheck::value), "Composite array type check failed."); - VTKM_TEST_ASSERT((TypeCheck::value), + VTKM_TEST_ASSERT((TypeCheck::value), "Counting array type check failed."); - VTKM_TEST_ASSERT((TypeCheck::value), + VTKM_TEST_ASSERT((TypeCheck::value), "Counting array type check failed."); // Just some type that is not a valid array. diff --git a/vtkm/exec/arg/ThreadIndicesPointNeighborhood.h b/vtkm/exec/arg/ThreadIndicesPointNeighborhood.h index fec183e2b..a957afe72 100644 --- a/vtkm/exec/arg/ThreadIndicesPointNeighborhood.h +++ b/vtkm/exec/arg/ThreadIndicesPointNeighborhood.h @@ -46,6 +46,13 @@ inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Vec index) { return vtkm::Id3(index[0], 1, 1); } + +/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros. +/// \overload +inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id index) +{ + return vtkm::Id3(index, 1, 1); +} } /// \brief Container for thread information in a WorkletPointNeighborhood. diff --git a/vtkm/filter/CrossProduct.h b/vtkm/filter/CrossProduct.h index 76967bbc0..879344550 100644 --- a/vtkm/filter/CrossProduct.h +++ b/vtkm/filter/CrossProduct.h @@ -22,8 +22,8 @@ namespace filter class CrossProduct : public vtkm::filter::FilterField { public: - //currently the DotProduct filter only works on vector data. - using SupportedTypes = TypeListVecCommon; + //CrossProduct filter only works on vec3 data. + using SupportedTypes = vtkm::TypeListFieldVec3; VTKM_CONT CrossProduct(); diff --git a/vtkm/filter/DotProduct.h b/vtkm/filter/DotProduct.h index d59587e61..01e705180 100644 --- a/vtkm/filter/DotProduct.h +++ b/vtkm/filter/DotProduct.h @@ -22,9 +22,6 @@ namespace filter class DotProduct : public vtkm::filter::FilterField { public: - //currently the DotProduct filter only works on vector data. - using SupportedTypes = TypeListVecCommon; - VTKM_CONT DotProduct(); @@ -123,11 +120,10 @@ public: //@} template - VTKM_CONT vtkm::cont::DataSet DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, + const vtkm::cont::ArrayHandle& field, + const vtkm::filter::FieldMetadata& fieldMeta, + vtkm::filter::PolicyBase policy); private: std::string SecondaryFieldName; diff --git a/vtkm/filter/DotProduct.hxx b/vtkm/filter/DotProduct.hxx index be1097b86..0b68fa011 100644 --- a/vtkm/filter/DotProduct.hxx +++ b/vtkm/filter/DotProduct.hxx @@ -33,7 +33,7 @@ inline VTKM_CONT DotProduct::DotProduct() template inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle, StorageType>& primary, + const vtkm::cont::ArrayHandle& primary, const vtkm::filter::FieldMetadata& fieldMetadata, vtkm::filter::PolicyBase policy) { @@ -46,10 +46,9 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( { secondaryField = inDataSet.GetField(this->SecondaryFieldName, this->SecondaryFieldAssociation); } - auto secondary = - vtkm::filter::ApplyPolicyFieldOfType>(secondaryField, policy, *this); + auto secondary = vtkm::filter::ApplyPolicyFieldOfType(secondaryField, policy, *this); - vtkm::cont::ArrayHandle output; + vtkm::cont::ArrayHandle::ComponentType> output; this->Invoke(vtkm::worklet::DotProduct{}, primary, secondary, output); return CreateResult(inDataSet, output, this->GetOutputFieldName(), fieldMetadata); diff --git a/vtkm/rendering/Cylinderizer.h b/vtkm/rendering/Cylinderizer.h index ead7a1624..461b9620e 100644 --- a/vtkm/rendering/Cylinderizer.h +++ b/vtkm/rendering/Cylinderizer.h @@ -428,9 +428,12 @@ public: } else { + auto cellSetUnstructured = + cellset.ResetCellSetList(VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED{}); + vtkm::cont::ArrayHandle segmentsPerCell; vtkm::worklet::DispatcherMapTopology countInvoker; - countInvoker.Invoke(cellset, segmentsPerCell); + countInvoker.Invoke(cellSetUnstructured, segmentsPerCell); vtkm::Id total = 0; total = vtkm::cont::Algorithm::Reduce(segmentsPerCell, vtkm::Id(0)); @@ -440,7 +443,7 @@ public: outputIndices.Allocate(total); vtkm::worklet::DispatcherMapTopology cylInvoker; - cylInvoker.Invoke(cellset, cellOffsets, outputIndices); + cylInvoker.Invoke(cellSetUnstructured, cellOffsets, outputIndices); output = total; } diff --git a/vtkm/rendering/Quadralizer.h b/vtkm/rendering/Quadralizer.h index b4f12655d..14512ab39 100644 --- a/vtkm/rendering/Quadralizer.h +++ b/vtkm/rendering/Quadralizer.h @@ -113,7 +113,8 @@ public: { if (DIM == 2) { - // Do nothing mark says + outputIndices.Set( + cellIndex, { cellIndex, cellIndices[0], cellIndices[1], cellIndices[2], cellIndices[3] }); } else if (DIM == 3) { @@ -123,7 +124,8 @@ public: vtkm::Id4 idx; idx[0] = 0; idx[1] = 1; - idx[2] = 5, idx[3] = 4; + idx[2] = 5; + idx[3] = 4; cell2quad(idx, quad, offset, cellIndices, outputIndices); idx[0] = 1; @@ -300,24 +302,38 @@ public: vtkm::cont::ArrayHandle>& outputIndices, vtkm::Id& output) { + vtkm::cont::Invoker invoke; + if (cellset.IsSameType(vtkm::cont::CellSetStructured<3>())) { vtkm::cont::CellSetStructured<3> cellSetStructured3D = cellset.Cast>(); const vtkm::Id numCells = cellSetStructured3D.GetNumberOfCells(); - vtkm::cont::ArrayHandleCounting cellIdxs(0, 1, numCells); + vtkm::cont::ArrayHandleIndex cellIdxs(numCells); outputIndices.Allocate(numCells * QUAD_PER_CSS); - vtkm::worklet::DispatcherMapTopology> segInvoker; - segInvoker.Invoke(cellSetStructured3D, cellIdxs, outputIndices); + invoke(SegmentedStructured<3>{}, cellSetStructured3D, cellIdxs, outputIndices); output = numCells * QUAD_PER_CSS; } + else if (cellset.IsSameType(vtkm::cont::CellSetStructured<2>())) + { + vtkm::cont::CellSetStructured<2> cellSetStructured2D = + cellset.Cast>(); + const vtkm::Id numCells = cellSetStructured2D.GetNumberOfCells(); + + vtkm::cont::ArrayHandleIndex cellIdxs(numCells); + outputIndices.Allocate(numCells); + invoke(SegmentedStructured<2>{}, cellSetStructured2D, cellIdxs, outputIndices); + + output = numCells; + } else { + auto cellSetUnstructured = + cellset.ResetCellSetList(VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED{}); vtkm::cont::ArrayHandle quadsPerCell; - vtkm::worklet::DispatcherMapTopology countInvoker; - countInvoker.Invoke(cellset, quadsPerCell); + invoke(CountQuads{}, cellSetUnstructured, quadsPerCell); vtkm::Id total = 0; total = vtkm::cont::Algorithm::Reduce(quadsPerCell, vtkm::Id(0)); @@ -326,8 +342,7 @@ public: vtkm::cont::Algorithm::ScanExclusive(quadsPerCell, cellOffsets); outputIndices.Allocate(total); - vtkm::worklet::DispatcherMapTopology quadInvoker; - quadInvoker.Invoke(cellset, cellOffsets, outputIndices); + invoke(Quadralize{}, cellSetUnstructured, cellOffsets, outputIndices); output = total; } diff --git a/vtkm/rendering/Triangulator.h b/vtkm/rendering/Triangulator.h index 96c19fe8d..9ca5b3712 100644 --- a/vtkm/rendering/Triangulator.h +++ b/vtkm/rendering/Triangulator.h @@ -682,9 +682,11 @@ public: } else { + auto cellSetUnstructured = + cellset.ResetCellSetList(VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED{}); vtkm::cont::ArrayHandle trianglesPerCell; vtkm::worklet::DispatcherMapTopology(CountTriangles()) - .Invoke(cellset, trianglesPerCell); + .Invoke(cellSetUnstructured, trianglesPerCell); vtkm::Id totalTriangles = 0; totalTriangles = vtkm::cont::Algorithm::Reduce(trianglesPerCell, vtkm::Id(0)); @@ -694,7 +696,7 @@ public: outputIndices.Allocate(totalTriangles); vtkm::worklet::DispatcherMapTopology(Trianglulate()) - .Invoke(cellset, cellOffsets, outputIndices); + .Invoke(cellSetUnstructured, cellOffsets, outputIndices); outputTriangles = totalTriangles; } diff --git a/vtkm/rendering/raytracing/CylinderExtractor.cxx b/vtkm/rendering/raytracing/CylinderExtractor.cxx index fbb2f6880..50243b21b 100644 --- a/vtkm/rendering/raytracing/CylinderExtractor.cxx +++ b/vtkm/rendering/raytracing/CylinderExtractor.cxx @@ -255,9 +255,11 @@ void CylinderExtractor::SetCylinderIdsFromCells(const vtkm::cont::DynamicCellSet // if (cells.IsSameType(vtkm::cont::CellSetExplicit<>())) { + auto cellsExplicit = cells.Cast>(); + vtkm::cont::ArrayHandle points; vtkm::worklet::DispatcherMapTopology(detail::CountSegments()) - .Invoke(cells, points); + .Invoke(cellsExplicit, points); vtkm::Id totalPoints = 0; totalPoints = vtkm::cont::Algorithm::Reduce(points, vtkm::Id(0)); @@ -267,7 +269,7 @@ void CylinderExtractor::SetCylinderIdsFromCells(const vtkm::cont::DynamicCellSet CylIds.Allocate(totalPoints); vtkm::worklet::DispatcherMapTopology(detail::Pointify()) - .Invoke(cells, cellOffsets, this->CylIds); + .Invoke(cellsExplicit, cellOffsets, this->CylIds); } } diff --git a/vtkm/rendering/raytracing/QuadExtractor.cxx b/vtkm/rendering/raytracing/QuadExtractor.cxx index 2d21b6aa2..5495d5a56 100644 --- a/vtkm/rendering/raytracing/QuadExtractor.cxx +++ b/vtkm/rendering/raytracing/QuadExtractor.cxx @@ -221,9 +221,11 @@ void QuadExtractor::SetQuadIdsFromCells(const vtkm::cont::DynamicCellSet& cells) // if (cells.IsSameType(vtkm::cont::CellSetExplicit<>())) { + auto cellsExplicit = cells.Cast>(); + vtkm::cont::ArrayHandle points; vtkm::worklet::DispatcherMapTopology(detail::CountQuads()) - .Invoke(cells, points); + .Invoke(cellsExplicit, points); vtkm::Id total = 0; total = vtkm::cont::Algorithm::Reduce(points, vtkm::Id(0)); @@ -233,7 +235,7 @@ void QuadExtractor::SetQuadIdsFromCells(const vtkm::cont::DynamicCellSet& cells) QuadIds.Allocate(total); vtkm::worklet::DispatcherMapTopology(detail::Pointify()) - .Invoke(cells, cellOffsets, this->QuadIds); + .Invoke(cellsExplicit, cellOffsets, this->QuadIds); } } diff --git a/vtkm/rendering/raytracing/SphereExtractor.cxx b/vtkm/rendering/raytracing/SphereExtractor.cxx index a429ed5c9..c404aa8e8 100644 --- a/vtkm/rendering/raytracing/SphereExtractor.cxx +++ b/vtkm/rendering/raytracing/SphereExtractor.cxx @@ -224,9 +224,11 @@ void SphereExtractor::SetPointIdsFromCells(const vtkm::cont::DynamicCellSet& cel // if (cells.IsSameType(vtkm::cont::CellSetExplicit<>())) { + auto cellsExplicit = cells.Cast>(); + vtkm::cont::ArrayHandle points; vtkm::worklet::DispatcherMapTopology(detail::CountPoints()) - .Invoke(cells, points); + .Invoke(cellsExplicit, points); vtkm::Id totalPoints = 0; totalPoints = vtkm::cont::Algorithm::Reduce(points, vtkm::Id(0)); @@ -236,7 +238,7 @@ void SphereExtractor::SetPointIdsFromCells(const vtkm::cont::DynamicCellSet& cel PointIds.Allocate(totalPoints); vtkm::worklet::DispatcherMapTopology(detail::Pointify()) - .Invoke(cells, cellOffsets, this->PointIds); + .Invoke(cellsExplicit, cellOffsets, this->PointIds); } else if (cells.IsSameType(SingleType())) { diff --git a/vtkm/worklet/DotProduct.h b/vtkm/worklet/DotProduct.h index f17064e58..9c65bbce8 100644 --- a/vtkm/worklet/DotProduct.h +++ b/vtkm/worklet/DotProduct.h @@ -12,6 +12,7 @@ #include +#include #include namespace vtkm @@ -29,7 +30,13 @@ public: const vtkm::Vec& v2, T& outValue) const { - outValue = vtkm::Dot(v1, v2); + outValue = static_cast(vtkm::Dot(v1, v2)); + } + + template + VTKM_EXEC void operator()(T s1, T s2, T& outValue) const + { + outValue = static_cast(s1 * s2); } }; }