From 7c27bedc08c4691607217f5a04d912bf35ea0795 Mon Sep 17 00:00:00 2001 From: Sujin Philip Date: Thu, 16 Aug 2018 16:34:44 -0400 Subject: [PATCH 01/36] Enable Separable Compilation for CUDA --- CMake/VTKmWrappers.cmake | 15 +++++++++++++++ vtkm/cont/CMakeLists.txt | 1 + 2 files changed, 16 insertions(+) diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index fd9a2c5e3..4af341d9f 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -269,6 +269,7 @@ endfunction(vtkm_declare_headers) # [WRAP_FOR_CUDA ] # ) function(vtkm_library) + set(options STATIC SHARED) set(oneValueArgs NAME) set(multiValueArgs SOURCES HEADERS TEMPLATE_SOURCES WRAP_FOR_CUDA) cmake_parse_arguments(VTKm_LIB @@ -286,14 +287,26 @@ function(vtkm_library) set(VTKm_LIB_WRAP_FOR_CUDA ${cu_srcs}) endif() + if(VTKm_LIB_STATIC) + set(VTKm_LIB_type STATIC) + elseif(VTKm_LIB_SHARED) + set(VTKm_LIB_type SHARED) + endif() add_library(${lib_name} + ${VTKm_LIB_type} ${VTKm_LIB_SOURCES} ${VTKm_LIB_HEADERS} ${VTKm_LIB_TEMPLATE_SOURCES} ${VTKm_LIB_WRAP_FOR_CUDA} ) + #when building either static or shared we want pic code + set_target_properties(${lib_name} PROPERTIES POSITION_INDEPENDENT_CODE ON) + + #specify when building with cuda we want separable compilation + set_property(TARGET ${lib_name} PROPERTY CUDA_SEPARABLE_COMPILATION ON) + #specify where to place the built library set_property(TARGET ${lib_name} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}) set_property(TARGET ${lib_name} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}) @@ -446,6 +459,8 @@ function(vtkm_unit_tests) endif() add_executable(${test_prog} ${test_prog}.cxx ${VTKm_UT_SOURCES}) + set_property(TARGET ${test_prog} PROPERTY CUDA_SEPARABLE_COMPILATION ON) + set_property(TARGET ${test_prog} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}) set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}) set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH}) diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index d62e71708..8b915ccd9 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -169,6 +169,7 @@ vtkm_library( NAME vtkm_cont HEADERS ${headers} WRAP_FOR_CUDA ${device_sources} ) + add_subdirectory(internal) add_subdirectory(arg) add_subdirectory(serial) From 2a8f7ec4c7b98203bfa4ede5e07b60b453582cd8 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 30 Oct 2018 11:02:21 -0400 Subject: [PATCH 02/36] Fix more build system issues with separable compilation --- CMake/VTKmWrappers.cmake | 9 ++++++++- benchmarking/CMakeLists.txt | 18 ++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index 4af341d9f..fedbaec39 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -465,7 +465,14 @@ function(vtkm_unit_tests) set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}) set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH}) - target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES}) + #Starting in CMake 3.13, cmake will properly drop duplicate libraries + #from the link line so this workaround can be dropped + if (CMAKE_VERSION VERSION_LESS 3.13 AND "vtkm_rendering" IN_LIST VTKm_UT_LIBRARIES) + list(REMOVE_ITEM VTKm_UT_LIBRARIES "vtkm_cont") + target_link_libraries(${test_prog} PRIVATE ${VTKm_UT_LIBRARIES}) + else() + target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES}) + endif() foreach(current_backend ${all_backends}) set (device_command_line_argument --device=${current_backend}) diff --git a/benchmarking/CMakeLists.txt b/benchmarking/CMakeLists.txt index 8cce00893..f06fbe3b1 100644 --- a/benchmarking/CMakeLists.txt +++ b/benchmarking/CMakeLists.txt @@ -17,7 +17,7 @@ ## Laboratory (LANL), the U.S. Government retains certain rights in ## this software. ##============================================================================ -function(add_benchmark name files) +function(add_benchmark name files lib) set(benchmarks ) add_executable(${name}_SERIAL ${files}) @@ -49,7 +49,7 @@ function(add_benchmark name files) endif() foreach(benchmark ${benchmarks}) - target_link_libraries(${benchmark} PRIVATE vtkm_cont) + target_link_libraries(${benchmark} PRIVATE ${lib}) set_target_properties(${benchmark} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH} ) @@ -69,19 +69,9 @@ set(benchmarks ) foreach (benchmark ${benchmarks}) - add_benchmark(${benchmark} ${benchmark}.cxx) + add_benchmark(${benchmark} ${benchmark}.cxx vtkm_cont) endforeach () if(TARGET vtkm_rendering) - add_benchmark(BenchmarkRayTracing BenchmarkRayTracing.cxx) - target_link_libraries(BenchmarkRayTracing_SERIAL PRIVATE vtkm_rendering) - if(TARGET BenchmarkRayTracing_TBB) - target_link_libraries(BenchmarkRayTracing_TBB PRIVATE vtkm_rendering) - endif() - if(TARGET BenchmarkRayTracing_OPENMP) - target_link_libraries(BenchmarkRayTracing_OPENMP PRIVATE vtkm_rendering) - endif() - if(TARGET BenchmarkRayTracing_CUDA) - target_link_libraries(BenchmarkRayTracing_CUDA PRIVATE vtkm_rendering) - endif() + add_benchmark(BenchmarkRayTracing BenchmarkRayTracing.cxx vtkm_rendering) endif() From 181d5f9f30e443ecb87e9dafb95a253989b9d58d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 6 Dec 2018 12:57:41 -0500 Subject: [PATCH 03/36] ArrayHandleZip now gracefully handles writes to implicit handles. --- vtkm/cont/ArrayHandleZip.h | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/vtkm/cont/ArrayHandleZip.h b/vtkm/cont/ArrayHandleZip.h index 1b34116e3..e6808b5b7 100644 --- a/vtkm/cont/ArrayHandleZip.h +++ b/vtkm/cont/ArrayHandleZip.h @@ -22,6 +22,7 @@ #include #include +#include namespace vtkm { @@ -37,6 +38,9 @@ class ArrayPortalZip { public: using ValueType = ValueType_; + using T = typename ValueType::FirstType; + using U = typename ValueType::SecondType; + using IteratorType = ValueType_; using PortalTypeFirst = PortalTypeFirst_; using PortalTypeSecond = PortalTypeSecond_; @@ -73,14 +77,20 @@ public: VTKM_EXEC ValueType Get(vtkm::Id index) const { - return vtkm::make_Pair(this->PortalFirst.Get(index), this->PortalSecond.Get(index)); + using call_supported_t1 = typename vtkm::internal::PortalSupportsGets::type; + using call_supported_t2 = typename vtkm::internal::PortalSupportsGets::type; + + return vtkm::make_Pair(this->GetFirst(call_supported_t1(), index), + this->GetSecond(call_supported_t2(), index)); } VTKM_EXEC void Set(vtkm::Id index, const ValueType& value) const { - this->PortalFirst.Set(index, value.first); - this->PortalSecond.Set(index, value.second); + using call_supported_t1 = typename vtkm::internal::PortalSupportsSets::type; + using call_supported_t2 = typename vtkm::internal::PortalSupportsSets::type; + this->SetFirst(call_supported_t1(), index, value.first); + this->SetSecond(call_supported_t2(), index, value.second); } VTKM_EXEC_CONT @@ -90,6 +100,28 @@ public: const PortalTypeSecond& GetSecondPortal() const { return this->PortalSecond; } private: + VTKM_EXEC inline T GetFirst(std::true_type, vtkm::Id index) const noexcept + { + return this->PortalFirst.Get(index); + } + VTKM_EXEC inline T GetFirst(std::false_type, vtkm::Id) const noexcept { return T{}; } + VTKM_EXEC inline U GetSecond(std::true_type, vtkm::Id index) const noexcept + { + return this->PortalSecond.Get(index); + } + VTKM_EXEC inline U GetSecond(std::false_type, vtkm::Id) const noexcept { return U{}; } + + VTKM_EXEC inline void SetFirst(std::true_type, vtkm::Id index, const T& value) const noexcept + { + this->PortalFirst.Set(index, value); + } + VTKM_EXEC inline void SetFirst(std::false_type, vtkm::Id, const T&) const noexcept {} + VTKM_EXEC inline void SetSecond(std::true_type, vtkm::Id index, const U& value) const noexcept + { + this->PortalSecond.Set(index, value); + } + VTKM_EXEC inline void SetSecond(std::false_type, vtkm::Id, const U&) const noexcept {} + PortalTypeFirst PortalFirst; PortalTypeSecond PortalSecond; }; From e31c73ef698884db9f212ad4af974c60e8e83c6e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 7 Nov 2018 17:32:19 -0500 Subject: [PATCH 04/36] vtkm::cont Locators include all headers they need. --- vtkm/cont/BoundingIntervalHierarchy.h | 2 ++ vtkm/cont/CellLocator.h | 1 + vtkm/cont/PointLocator.h | 1 + 3 files changed, 4 insertions(+) diff --git a/vtkm/cont/BoundingIntervalHierarchy.h b/vtkm/cont/BoundingIntervalHierarchy.h index c5b08070b..5da26e348 100644 --- a/vtkm/cont/BoundingIntervalHierarchy.h +++ b/vtkm/cont/BoundingIntervalHierarchy.h @@ -24,8 +24,10 @@ #include #include #include + #include #include + #include namespace vtkm diff --git a/vtkm/cont/CellLocator.h b/vtkm/cont/CellLocator.h index 4a77d18b8..9044ddef7 100644 --- a/vtkm/cont/CellLocator.h +++ b/vtkm/cont/CellLocator.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace vtkm diff --git a/vtkm/cont/PointLocator.h b/vtkm/cont/PointLocator.h index cf5eff06e..e0ac21f68 100644 --- a/vtkm/cont/PointLocator.h +++ b/vtkm/cont/PointLocator.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace vtkm From 36100311d06fe1e508d4470aadc0d73e4973032a Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 21 Nov 2018 09:37:04 -0500 Subject: [PATCH 05/36] BoundingVolumeHierarchy now uses Invoker to simplify worklet dispatching --- .../raytracing/BoundingVolumeHierarchy.cxx | 118 +++++++----------- 1 file changed, 42 insertions(+), 76 deletions(-) diff --git a/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx b/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx index aee8acee8..c67ce81cb 100644 --- a/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx +++ b/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx @@ -38,7 +38,7 @@ #include #include -#include +#include #include #define AABB_EPSILON 0.00001f @@ -555,17 +555,15 @@ public: }; // class TreeBuilder template -VTKM_CONT void LinearBVHBuilder::SortAABBS(BVHData& bvh, - Device vtkmNotUsed(device), - bool singleAABB) +VTKM_CONT void LinearBVHBuilder::SortAABBS(BVHData& bvh, Device device, bool singleAABB) { + vtkm::worklet::Invoker invoke(device); //create array of indexes to be sorted with morton codes vtkm::cont::ArrayHandle iterator; - iterator.PrepareForOutput(bvh.GetNumberOfPrimitives(), Device()); - vtkm::worklet::DispatcherMapField iteratorDispatcher; - iteratorDispatcher.SetDevice(Device()); - iteratorDispatcher.Invoke(iterator); + iterator.PrepareForOutput(bvh.GetNumberOfPrimitives(), device); + invoke(CountingIterator{}, iterator); + //sort the morton codes @@ -578,66 +576,37 @@ VTKM_CONT void LinearBVHBuilder::SortAABBS(BVHData& bvh, //tempStorage = new vtkm::cont::ArrayHandle(); //xmins - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.xmins, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + invoke(GatherFloat32{ bvh.AABB.xmins, temp1, arraySize }, iterator); + temp2 = bvh.AABB.xmins; bvh.AABB.xmins = temp1; temp1 = temp2; - - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.ymins, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + //ymins + invoke(GatherFloat32{ bvh.AABB.ymins, temp1, arraySize }, iterator); temp2 = bvh.AABB.ymins; bvh.AABB.ymins = temp1; temp1 = temp2; //zmins - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.zmins, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + invoke(GatherFloat32{ bvh.AABB.zmins, temp1, arraySize }, iterator); temp2 = bvh.AABB.zmins; bvh.AABB.zmins = temp1; temp1 = temp2; //xmaxs - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.xmaxs, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + invoke(GatherFloat32{ bvh.AABB.xmaxs, temp1, arraySize }, iterator); temp2 = bvh.AABB.xmaxs; bvh.AABB.xmaxs = temp1; temp1 = temp2; //ymaxs - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.ymaxs, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + invoke(GatherFloat32{ bvh.AABB.ymaxs, temp1, arraySize }, iterator); temp2 = bvh.AABB.ymaxs; bvh.AABB.ymaxs = temp1; temp1 = temp2; //zmaxs - { - vtkm::worklet::DispatcherMapField> dispatcher( - GatherFloat32(bvh.AABB.zmaxs, temp1, arraySize)); - dispatcher.SetDevice(Device()); - dispatcher.Invoke(iterator); - } + invoke(GatherFloat32{ bvh.AABB.zmaxs, temp1, arraySize }, iterator); temp2 = bvh.AABB.zmaxs; bvh.AABB.zmaxs = temp1; @@ -656,9 +625,7 @@ VTKM_CONT void LinearBVHBuilder::SortAABBS(BVHData& bvh, iterPortal.Set(i, 0); } } - vtkm::worklet::DispatcherMapField createDis; - createDis.SetDevice(Device()); - createDis.Invoke(iterator, bvh.leafs); + invoke(CreateLeafs{}, iterator, bvh.leafs); } // method SortAABB @@ -669,6 +636,8 @@ VTKM_CONT void LinearBVHBuilder::SortAABBS(BVHData& bvh, template VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device) { + vtkm::worklet::Invoker invoke(device); + Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("bvh_constuct"); @@ -751,33 +720,30 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device } //Generate the morton codes - vtkm::worklet::DispatcherMapField mortonDis( - MortonCodeAABB(inverseExtent, minExtent)); - mortonDis.SetDevice(Device()); - mortonDis.Invoke(bvh.AABB.xmins, - bvh.AABB.ymins, - bvh.AABB.zmins, - bvh.AABB.xmaxs, - bvh.AABB.ymaxs, - bvh.AABB.zmaxs, - bvh.mortonCodes); + invoke(MortonCodeAABB{ inverseExtent, minExtent }, + bvh.AABB.xmins, + bvh.AABB.ymins, + bvh.AABB.zmins, + bvh.AABB.xmaxs, + bvh.AABB.ymaxs, + bvh.AABB.zmaxs, + bvh.mortonCodes); time = timer.GetElapsedTime(); logger->AddLogData("morton_codes", time); timer.Reset(); - linearBVH.Allocate(bvh.GetNumberOfPrimitives(), Device()); + linearBVH.Allocate(bvh.GetNumberOfPrimitives(), device); - SortAABBS(bvh, Device(), singleAABB); + SortAABBS(bvh, device, singleAABB); time = timer.GetElapsedTime(); logger->AddLogData("sort_aabbs", time); timer.Reset(); - vtkm::worklet::DispatcherMapField> treeDis( - TreeBuilder(bvh.mortonCodes, bvh.parent, bvh.GetNumberOfPrimitives())); - treeDis.SetDevice(Device()); - treeDis.Invoke(bvh.leftChild, bvh.rightChild); + invoke(TreeBuilder{ bvh.mortonCodes, bvh.parent, bvh.GetNumberOfPrimitives() }, + bvh.leftChild, + bvh.rightChild); time = timer.GetElapsedTime(); logger->AddLogData("build_tree", time); @@ -786,24 +752,24 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device const vtkm::Int32 primitiveCount = vtkm::Int32(bvh.GetNumberOfPrimitives()); vtkm::cont::ArrayHandle counters; - counters.PrepareForOutput(bvh.GetNumberOfPrimitives() - 1, Device()); + counters.PrepareForOutput(bvh.GetNumberOfPrimitives() - 1, device); vtkm::cont::ArrayHandleConstant zero(0, bvh.GetNumberOfPrimitives() - 1); - vtkm::cont::Algorithm::Copy(Device(), zero, counters); + vtkm::cont::DeviceAdapterAlgorithm::Copy(zero, counters); vtkm::cont::AtomicArray atomicCounters(counters); - vtkm::worklet::DispatcherMapField> propDis(PropagateAABBs( - bvh.parent, bvh.leftChild, bvh.rightChild, primitiveCount, linearBVH.FlatBVH, atomicCounters)); - propDis.SetDevice(Device()); - propDis.Invoke(bvh.AABB.xmins, - bvh.AABB.ymins, - bvh.AABB.zmins, - bvh.AABB.xmaxs, - bvh.AABB.ymaxs, - bvh.AABB.zmaxs, - bvh.leafOffsets); + PropagateAABBs propagateWorklet( + bvh.parent, bvh.leftChild, bvh.rightChild, primitiveCount, linearBVH.FlatBVH, atomicCounters); + invoke(propagateWorklet, + bvh.AABB.xmins, + bvh.AABB.ymins, + bvh.AABB.zmins, + bvh.AABB.xmaxs, + bvh.AABB.ymaxs, + bvh.AABB.zmaxs, + bvh.leafOffsets); linearBVH.Leafs = bvh.leafs; time = timer.GetElapsedTime(); From 7ba3c66727305273e04df8784a8c84f08fbaac9c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 21 Nov 2018 14:57:16 -0500 Subject: [PATCH 06/36] Make sure rendering builds Actor with cuda as it calls worklets --- vtkm/rendering/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtkm/rendering/CMakeLists.txt b/vtkm/rendering/CMakeLists.txt index 03dca45f9..15055c5c1 100644 --- a/vtkm/rendering/CMakeLists.txt +++ b/vtkm/rendering/CMakeLists.txt @@ -87,7 +87,6 @@ set(headers ) set(sources - Actor.cxx AxisAnnotation.cxx AxisAnnotation2D.cxx AxisAnnotation3D.cxx @@ -154,6 +153,7 @@ set(osmesa_sources # This list of sources has code that uses devices and so might need to be # compiled with a device-specific compiler (like CUDA). set(device_sources + Actor.cxx Canvas.cxx CanvasRayTracer.cxx ConnectivityProxy.cxx From 65b019d44314a59d2ec5f96737f97be2971c04d9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 21 Nov 2018 14:57:44 -0500 Subject: [PATCH 07/36] raytracing intersector kernels use FieldOut where appropriate. Previously a couple used FieldInOut when they only needed FieldOut, this can help performance if the input is not already on the device --- vtkm/rendering/raytracing/QuadIntersector.cxx | 2 +- vtkm/rendering/raytracing/SphereIntersector.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vtkm/rendering/raytracing/QuadIntersector.cxx b/vtkm/rendering/raytracing/QuadIntersector.cxx index aac900cdb..639671940 100644 --- a/vtkm/rendering/raytracing/QuadIntersector.cxx +++ b/vtkm/rendering/raytracing/QuadIntersector.cxx @@ -387,7 +387,7 @@ public: invDeltaScalar = 1.f / minScalar; } typedef void ControlSignature(FieldIn<>, - FieldInOut<>, + FieldOut<>, WholeArrayIn, WholeArrayIn<>); typedef void ExecutionSignature(_1, _2, _3, _4); diff --git a/vtkm/rendering/raytracing/SphereIntersector.cxx b/vtkm/rendering/raytracing/SphereIntersector.cxx index 22bc05d1f..021b62c85 100644 --- a/vtkm/rendering/raytracing/SphereIntersector.cxx +++ b/vtkm/rendering/raytracing/SphereIntersector.cxx @@ -275,7 +275,7 @@ public: invDeltaScalar = 1.f / minScalar; } typedef void ControlSignature(FieldIn<>, - FieldInOut<>, + FieldOut<>, WholeArrayIn, WholeArrayIn<>); typedef void ExecutionSignature(_1, _2, _3, _4); From 20d02fdec202adaf8450aec93775c526bc0cab3b Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 12 Jun 2018 10:38:32 -0400 Subject: [PATCH 08/36] Support pointers in vtkm::exec::Fetch classes --- vtkm/VecFromPortalPermute.h | 55 +++++++++++++++++++++- vtkm/exec/arg/FetchTagArrayDirectIn.h | 28 +++++++++-- vtkm/exec/arg/FetchTagArrayTopologyMapIn.h | 11 +++++ 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/vtkm/VecFromPortalPermute.h b/vtkm/VecFromPortalPermute.h index 286c45029..b2f07bc5f 100644 --- a/vtkm/VecFromPortalPermute.h +++ b/vtkm/VecFromPortalPermute.h @@ -75,10 +75,55 @@ public: } private: - const IndexVecType* Indices; + const IndexVecType* const Indices; PortalType Portal; }; +template +class VecFromPortalPermute +{ +public: + using ComponentType = typename std::remove_const::type; + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + VecFromPortalPermute() {} + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal) + : Indices(indices) + , Portal(portal) + { + } + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const + { + vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents()); + for (vtkm::IdComponent index = 0; index < numComponents; index++) + { + dest[index] = (*this)[index]; + } + } + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + ComponentType operator[](vtkm::IdComponent index) const + { + return this->Portal->Get((*this->Indices)[index]); + } + +private: + const IndexVecType* const Indices; + const PortalType* const Portal; +}; + template struct TypeTraits> { @@ -134,6 +179,14 @@ inline VTKM_EXEC VecFromPortalPermute make_VecFromPort return VecFromPortalPermute(index, portal); } +template +inline VTKM_EXEC VecFromPortalPermute make_VecFromPortalPermute( + const IndexVecType* index, + const PortalType* const portal) +{ + return VecFromPortalPermute(index, portal); +} + } // namespace vtkm #endif //vtk_m_VecFromPortalPermute_h diff --git a/vtkm/exec/arg/FetchTagArrayDirectIn.h b/vtkm/exec/arg/FetchTagArrayDirectIn.h index f5df7e34f..54bc25bed 100644 --- a/vtkm/exec/arg/FetchTagArrayDirectIn.h +++ b/vtkm/exec/arg/FetchTagArrayDirectIn.h @@ -40,23 +40,43 @@ struct FetchTagArrayDirectIn { }; + +VTKM_SUPPRESS_EXEC_WARNINGS +template +inline VTKM_EXEC T load(const U& u, vtkm::Id v) +{ + return u.Get(v); +} + +VTKM_SUPPRESS_EXEC_WARNINGS +template +inline VTKM_EXEC T load(const U* u, vtkm::Id v) +{ + return u->Get(v); +} + template struct Fetch { - using ValueType = typename ExecObjectType::ValueType; + //need to remove pointer type from ThreadIdicesType + using ET = typename std::remove_const::type>::type; + using PortalType = + typename std::conditional::value, const ET*, const ET&>::type; + + using ValueType = typename ET::ValueType; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC - ValueType Load(const ThreadIndicesType& indices, const ExecObjectType& arrayPortal) const + ValueType Load(const ThreadIndicesType& indices, PortalType arrayPortal) const { - return arrayPortal.Get(indices.GetInputIndex()); + return load(arrayPortal, indices.GetInputIndex()); } VTKM_EXEC - void Store(const ThreadIndicesType&, const ExecObjectType&, const ValueType&) const + void Store(const ThreadIndicesType&, PortalType, const ValueType&) const { // Store is a no-op for this fetch. } diff --git a/vtkm/exec/arg/FetchTagArrayTopologyMapIn.h b/vtkm/exec/arg/FetchTagArrayTopologyMapIn.h index 873a4460c..5c08e355d 100644 --- a/vtkm/exec/arg/FetchTagArrayTopologyMapIn.h +++ b/vtkm/exec/arg/FetchTagArrayTopologyMapIn.h @@ -85,6 +85,17 @@ struct FetchArrayTopologyMapInImplementation // least as far as the returned VecFromPortalPermute is used. return ValueType(indices.GetIndicesFromPointer(), field); } + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC + static ValueType Load(const ThreadIndicesType& indices, const FieldExecObjectType* const field) + { + // It is important that we give the VecFromPortalPermute (ValueType) a + // pointer that will stay around during the time the Vec is valid. Thus, we + // should make sure that indices is a reference that goes up the stack at + // least as far as the returned VecFromPortalPermute is used. + return ValueType(indices.GetIndicesFromPointer(), field); + } }; static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<1> make_VecAxisAlignedPointCoordinates( From 6e1cbaa16ad1baf70bed307550934b84f8c9cc5c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Nov 2018 11:20:30 -0500 Subject: [PATCH 09/36] Add StorageVirtual and ArrayHandleVirtual to vtkm::cont --- vtkm/CMakeLists.txt | 1 + vtkm/VecFromVirtPortal.h | 79 +++++++++++ vtkm/cont/ArrayHandleVirtual.h | 203 ++++++++++++++++++++++++++ vtkm/cont/ArrayHandleVirtual.hxx | 71 ++++++++++ vtkm/cont/CMakeLists.txt | 7 +- vtkm/cont/ErrorBadType.cxx | 37 +++++ vtkm/cont/ErrorBadType.h | 8 ++ vtkm/cont/StorageVirtual.cxx | 211 ++++++++++++++++++++++++++++ vtkm/cont/StorageVirtual.h | 175 +++++++++++++++++++++++ vtkm/cont/internal/CMakeLists.txt | 1 + vtkm/cont/internal/TransferInfo.cxx | 68 +++++++++ vtkm/cont/internal/TransferInfo.h | 74 ++++++++++ vtkm/internal/ArrayPortalHelpers.h | 56 ++++++++ vtkm/internal/ArrayPortalVirtual.h | 144 +++++++++++++++++++ vtkm/internal/CMakeLists.txt | 2 + 15 files changed, 1136 insertions(+), 1 deletion(-) create mode 100644 vtkm/VecFromVirtPortal.h create mode 100644 vtkm/cont/ArrayHandleVirtual.h create mode 100644 vtkm/cont/ArrayHandleVirtual.hxx create mode 100644 vtkm/cont/ErrorBadType.cxx create mode 100644 vtkm/cont/StorageVirtual.cxx create mode 100644 vtkm/cont/StorageVirtual.h create mode 100644 vtkm/cont/internal/TransferInfo.cxx create mode 100644 vtkm/cont/internal/TransferInfo.h create mode 100644 vtkm/internal/ArrayPortalHelpers.h create mode 100644 vtkm/internal/ArrayPortalVirtual.h diff --git a/vtkm/CMakeLists.txt b/vtkm/CMakeLists.txt index aa3551dd8..fd2b95648 100644 --- a/vtkm/CMakeLists.txt +++ b/vtkm/CMakeLists.txt @@ -58,6 +58,7 @@ set(headers VecAxisAlignedPointCoordinates.h VecFromPortal.h VecFromPortalPermute.h + VecFromVirtPortal.h VectorAnalysis.h VecTraits.h VecVariable.h diff --git a/vtkm/VecFromVirtPortal.h b/vtkm/VecFromVirtPortal.h new file mode 100644 index 000000000..75ba9e10c --- /dev/null +++ b/vtkm/VecFromVirtPortal.h @@ -0,0 +1,79 @@ +//============================================================================ +// 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. +// +// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2015 UT-Battelle, LLC. +// Copyright 2015 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_VecFromVirtPortal_h +#define vtk_m_VecFromVirtPortal_h + +#include + +#include +#include + +namespace vtkm +{ + +/// \brief A short variable-length array from a window in an ArrayPortal. +/// +/// The \c VecFromPortal class is a Vec-like class that holds an array portal +/// and exposes a small window of that portal as if it were a \c Vec. +/// +template +class VTKM_ALWAYS_EXPORT VecFromVirtPortal +{ + using RefType = vtkm::internal::ArrayPortalValueReference>; + +public: + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + VecFromVirtPortal(const vtkm::ArrayPortalRef* portal, + vtkm::IdComponent numComponents, + vtkm::Id offset) + : Portal(portal) + , NumComponents(numComponents) + , Offset(offset) + { + } + + VTKM_EXEC_CONT + vtkm::IdComponent GetNumberOfComponents() const { return this->NumComponents; } + + template + VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const + { + vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents); + for (vtkm::IdComponent index = 0; index < numComponents; index++) + { + dest[index] = this->Portal->Get(index + this->Offset); + } + } + + VTKM_SUPPRESS_EXEC_WARNINGS + VTKM_EXEC_CONT + RefType operator[](vtkm::IdComponent index) const + { + return RefType(*this->Portal, index + this->Offset); + } + +private: + const vtkm::ArrayPortalRef* Portal = nullptr; + vtkm::IdComponent NumComponents = 0; + vtkm::Id Offset = 0; +}; +} +#endif diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h new file mode 100644 index 000000000..e30afd9bf --- /dev/null +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -0,0 +1,203 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleVirtual_h +#define vtk_m_cont_ArrayHandleVirtual_h + +#include + +#include +#include + +#include + +#include + +namespace vtkm +{ +namespace cont +{ + +/// Specialization of ArrayHandle for virtual storage. +template +class VTKM_ALWAYS_EXPORT ArrayHandle + : public vtkm::cont::internal::ArrayHandleBase +{ +public: + using StorageTag = vtkm::cont::StorageTagVirtual; + using StorageType = vtkm::cont::internal::Storage; + + using ValueType = T; + + using PortalControl = vtkm::ArrayPortalRef; + using PortalConstControl = vtkm::ArrayPortalRef; + + template + struct ExecutionTypes + { + using Portal = vtkm::ArrayPortalRef; + using PortalConst = vtkm::ArrayPortalRef; + }; + + ///construct an invlaid virtual array handle that has a nullptr storage + ArrayHandle() + : Storage(nullptr){}; + + ///Move existing shared_ptr of vtkm::cont::StorageVirtual to be + ///owned by this ArrayHandleVirtual. + ///This is generally how derived class construct a valid ArrayHandleVirtual + template + explicit ArrayHandle(std::shared_ptr&& storage) noexcept + : Storage(std::move(storage)) + { + using is_base = std::is_base_of; + static_assert(is_base::value, + "Storage for ArrayHandleVirtual needs to derive from vtkm::cont::StorageVirual"); + } + + ///Move existing unique_ptr of vtkm::cont::StorageVirtual to be + ///owned by this ArrayHandleVirtual. + ///This is how a derived class construct a valid ArrayHandleVirtual + template + explicit ArrayHandle(std::unique_ptr&& storage) noexcept + : Storage(std::move(storage)) + { + using is_base = std::is_base_of; + static_assert(is_base::value, + "Storage for ArrayHandleVirtual needs to derive from vtkm::cont::StorageVirual"); + } + + ///copy another existing virtual array handle + ArrayHandle(const ArrayHandle& src) = default; + + ///move from one virtual array handle to another + ArrayHandle(ArrayHandle&& src) noexcept + : Storage(std::move(src.Storage)) + { + } + + VTKM_CONT ArrayHandle& operator=( + const ArrayHandle& src) = default; + VTKM_CONT ArrayHandle& operator=( + ArrayHandle&& src) noexcept + { + this->Storage = std::move(src.Storage); + return *this; + } + + /// Returns true if this array's storage matches the type passed in. + /// + template + VTKM_CONT bool IsType() const + { + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + //We need to go long the way to find the StorageType + //as StorageType is private on lots of derived ArrayHandles + //See Issue #314 + + using VT = typename ArrayHandleType::ValueType; + static_assert( + std::is_same::value, + "ArrayHandleVirtual can only be casted to an ArrayHandle of the same ValueType."); + + using ST = typename ArrayHandleType::StorageTag; + return this->Storage->IsType(typeid(vtkm::cont::internal::Storage)); + } + + /// Returns a view on the internal storage of the ArrayHandleVirtual + /// + VTKM_CONT const StorageType* GetStorage() const { return this->Storage.get(); } + + /// Returns a new instance of an ArrayHandleVirtual with the same storage + /// + VTKM_CONT ArrayHandle NewInstance() const + { + return (this->Storage) + ? ArrayHandle(this->Storage->NewInstance()) + : ArrayHandle(); + } + + // Return a ArrayPortalRef that wraps the real virtual portal. We need a stack object for + // the following reasons: + // 1. Device Adapter algorithms only support const AH& and not const AH* + // 2. Devices will want to get the length of a portal before execution, but for CUDA + // we can't ask this information of the portal as it only valid on the device, instead + // we have to store this information also in the ref wrapper + vtkm::ArrayPortalRef PrepareForInput(vtkm::cont::DeviceAdapterId devId) const + { + return make_ArrayPortalRef( + static_cast*>(this->Storage->PrepareForInput(devId)), + this->GetNumberOfValues()); + } + + vtkm::ArrayPortalRef PrepareForOutput(vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId) + { + return make_ArrayPortalRef(static_cast*>( + this->Storage->PrepareForOutput(numberOfValues, devId)), + numberOfValues); + } + + vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); } + + /// Releases any resources being used in the execution environment (that are + /// not being shared by the control environment). + /// + void ReleaseResourcesExecution() { return this->Storage->ReleaseResourcesExecution(); } + + /// Releases all resources in both the control and execution environments. + /// + void ReleaseResources() { return this->Storage->ReleaseResources(); } + + /// Get the array portal of the control array. + /// Since worklet invocations are asynchronous and this routine is a synchronization point, + /// exceptions maybe thrown for errors from previously executed worklets. + /// + PortalControl GetPortalControl() + { + return make_ArrayPortalRef( + static_cast*>(this->Storage->GetPortalControl()), + this->GetNumberOfValues()); + } + + /// Get the array portal of the control array. + /// Since worklet invocations are asynchronous and this routine is a synchronization point, + /// exceptions maybe thrown for errors from previously executed worklets. + /// + PortalConstControl GetPortalConstControl() const + { + return make_ArrayPortalRef( + static_cast*>(this->Storage->GetPortalConstControl()), + this->GetNumberOfValues()); + } + +protected: + std::shared_ptr Storage = nullptr; +}; + +template +using ArrayHandleVirtual = vtkm::cont::ArrayHandle; +} +} //namespace vtkm::cont + + +#include + + +#endif diff --git a/vtkm/cont/ArrayHandleVirtual.hxx b/vtkm/cont/ArrayHandleVirtual.hxx new file mode 100644 index 000000000..a63469c6d --- /dev/null +++ b/vtkm/cont/ArrayHandleVirtual.hxx @@ -0,0 +1,71 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleVirtual_hxx +#define vtk_m_cont_ArrayHandleVirtual_hxx + +#include + +#include + +namespace vtkm +{ +namespace cont +{ +namespace detail +{ +template +struct TransferToDevice +{ + template + bool operator()(DeviceAdapterTag devId, Payload&& payload, Args&&... args) const + { + using TransferType = cont::internal::VirtualObjectTransfer; + + + //construct all new transfer payload + auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); + auto transfer = std::make_shared(host.get()); + auto device = transfer->PrepareForExecution(true); + + payload.updateDevice(devId, std::move(host), device, std::static_pointer_cast(transfer)); + + return true; + } +}; +} + +template +inline void make_transferToDevice(vtkm::cont::DeviceAdapterId devId, Args&&... args) +{ + vtkm::cont::TryExecuteOnDevice( + devId, detail::TransferToDevice{}, std::forward(args)...); +} + +template +inline void make_hostPortal(Payload&& payload, Args&&... args) +{ + auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); + payload.updateHost(std::move(host)); +} +} +} // namespace vtkm::virts + + +#endif diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 8b915ccd9..dfdbb7ec6 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -40,6 +40,7 @@ set(headers ArrayHandleTransform.h ArrayHandleUniformPointCoordinates.h ArrayHandleView.h + ArrayHandleVirtual.h ArrayHandleVirtualCoordinates.h ArrayHandleZip.h ArrayPortal.h @@ -100,6 +101,7 @@ set(headers Storage.h StorageBasic.h StorageImplicit.h + StorageVirtual.h StorageListTag.h Timer.h TryExecute.h @@ -109,6 +111,7 @@ set(headers set(template_sources ArrayHandle.hxx + ArrayHandleVirtual.hxx ArrayRangeCompute.hxx BoundingIntervalHierarchy.hxx CellSetExplicit.hxx @@ -136,6 +139,7 @@ set(sources DynamicArrayHandle.cxx EnvironmentTracker.cxx ErrorBadDevice.cxx + ErrorBadType.cxx Field.cxx FieldRangeCompute.cxx FieldRangeGlobalCompute.cxx @@ -143,7 +147,7 @@ set(sources internal/ArrayManagerExecutionShareWithControl.cxx internal/DeviceAdapterTag.cxx internal/SimplePolymorphicContainer.cxx - internal/SimplePolymorphicContainer.cxx + internal/TransferInfo.cxx internal/VirtualObjectTransfer.cxx Initialize.cxx Logging.cxx @@ -151,6 +155,7 @@ set(sources RuntimeDeviceInformation.cxx RuntimeDeviceTracker.cxx StorageBasic.cxx + StorageVirtual.cxx TryExecute.cxx ) diff --git a/vtkm/cont/ErrorBadType.cxx b/vtkm/cont/ErrorBadType.cxx new file mode 100644 index 000000000..693f3d52d --- /dev/null +++ b/vtkm/cont/ErrorBadType.cxx @@ -0,0 +1,37 @@ +//============================================================================ +// 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. +// +// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2016 UT-Battelle, LLC. +// Copyright 2016 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ + +#include + +#include + +namespace vtkm +{ +namespace cont +{ + +void throwFailedDynamicCast(const std::string& baseType, const std::string& derivedType) +{ //Should we support typeid() instead of className? + + const std::string msg = "Cast failed: " + baseType + " --> " + derivedType; + throw vtkm::cont::ErrorBadType(msg); +} +} +} diff --git a/vtkm/cont/ErrorBadType.h b/vtkm/cont/ErrorBadType.h index 5d28d35ee..4c8c7884f 100644 --- a/vtkm/cont/ErrorBadType.h +++ b/vtkm/cont/ErrorBadType.h @@ -42,6 +42,14 @@ public: }; VTKM_SILENCE_WEAK_VTABLE_WARNING_END + +/// Throws an ErrorBadType exception with the following message: +/// Cast failed: \c baseType --> \c derivedType". +/// This is generally caused by asking for a casting of a ArrayHandleVariant +/// with an insufficient type list. +// +VTKM_CONT_EXPORT void throwFailedDynamicCast(const std::string& baseType, + const std::string& derivedType); } } // namespace vtkm::cont diff --git a/vtkm/cont/StorageVirtual.cxx b/vtkm/cont/StorageVirtual.cxx new file mode 100644 index 000000000..367251e5f --- /dev/null +++ b/vtkm/cont/StorageVirtual.cxx @@ -0,0 +1,211 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#include "StorageVirtual.h" + +#include + +namespace vtkm +{ +namespace cont +{ +namespace internal +{ + + +//-------------------------------------------------------------------- +Storage::Storage( + const Storage& src) + : HostUpToDate(src.HostUpToDate) + , DeviceUpToDate(src.DeviceUpToDate) + , DeviceTransferState(src.DeviceTransferState) +{ +} + +//-------------------------------------------------------------------- +Storage::Storage( + Storage&& src) noexcept + : HostUpToDate(src.HostUpToDate), + DeviceUpToDate(src.DeviceUpToDate), + DeviceTransferState(std::move(src.DeviceTransferState)) +{ +} + +//-------------------------------------------------------------------- +Storage& Storage:: +operator=(const Storage& src) +{ + this->HostUpToDate = src.HostUpToDate; + this->DeviceUpToDate = src.DeviceUpToDate; + this->DeviceTransferState = src.DeviceTransferState; + return *this; +} + +//-------------------------------------------------------------------- +Storage& Storage:: +operator=(Storage&& src) noexcept +{ + this->HostUpToDate = src.HostUpToDate; + this->DeviceUpToDate = src.DeviceUpToDate; + this->DeviceTransferState = std::move(src.DeviceTransferState); + return *this; +} + +//-------------------------------------------------------------------- +Storage::~Storage() +{ +} + +//-------------------------------------------------------------------- +void Storage::ReleaseResourcesExecution() +{ + this->DeviceTransferState->releaseDevice(); + this->DeviceUpToDate = false; +} + +//-------------------------------------------------------------------- +void Storage::ReleaseResources() +{ + this->DeviceTransferState->releaseAll(); + this->HostUpToDate = false; + this->DeviceUpToDate = false; +} + +//-------------------------------------------------------------------- +bool Storage::IsSameType(const std::type_info& other) const +{ + return typeid(*this) == other; +} + +//-------------------------------------------------------------------- +std::unique_ptr> +Storage::NewInstance() const +{ + return this->MakeNewInstance(); +} + +//-------------------------------------------------------------------- +const vtkm::internal::PortalVirtualBase* +Storage::PrepareForInput( + vtkm::cont::DeviceAdapterId devId) const +{ + if (devId == vtkm::cont::DeviceAdapterTagUndefined()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED"); + } + if (devId == vtkm::cont::DeviceAdapterTagError()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR"); + } + + const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate); + + if (needsUpload) + { //Either transfer state is pointing to another device, or has + //had the execution resources released. Either way we + //need to re-transfer the execution information + auto* payload = this->DeviceTransferState.get(); + this->TransferPortalForInput(*payload, devId); + this->HostUpToDate = false; + this->DeviceUpToDate = true; + } + return this->DeviceTransferState->devicePtr(); +} + +//-------------------------------------------------------------------- +const vtkm::internal::PortalVirtualBase* +Storage::PrepareForOutput(vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId) +{ + if (devId == vtkm::cont::DeviceAdapterTagUndefined()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED"); + } + if (devId == vtkm::cont::DeviceAdapterTagError()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR"); + } + + const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate); + if (needsUpload) + { + this->TransferPortalForOutput(*(this->DeviceTransferState), numberOfValues, devId); + this->HostUpToDate = false; + this->DeviceUpToDate = true; + } + return this->DeviceTransferState->devicePtr(); +} + +//-------------------------------------------------------------------- +const vtkm::internal::PortalVirtualBase* +Storage::GetPortalControl() +{ + if (!this->HostUpToDate) + { + //we need to prepare for input and grab the host ptr + auto* payload = this->DeviceTransferState.get(); + this->ControlPortalForOutput(*payload); + } + + this->DeviceUpToDate = false; + this->HostUpToDate = true; + return this->DeviceTransferState->hostPtr(); +} + +//-------------------------------------------------------------------- +const vtkm::internal::PortalVirtualBase* +Storage::GetPortalConstControl() const +{ + if (!this->HostUpToDate) + { + //we need to prepare for input and grab the host ptr + vtkm::cont::internal::TransferInfoArray* payload = this->DeviceTransferState.get(); + this->ControlPortalForInput(*payload); + } + //We need to mark the device out of date after the conditions + //as they can modify the state of the device + this->DeviceUpToDate = false; + this->HostUpToDate = true; + return this->DeviceTransferState->hostPtr(); +} + +//-------------------------------------------------------------------- +DeviceAdapterId Storage::GetDeviceAdapterId() const noexcept +{ + return this->DeviceTransferState->deviceId(); +} + +//-------------------------------------------------------------------- +void Storage::ControlPortalForOutput( + vtkm::cont::internal::TransferInfoArray&) +{ + throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support output."); +} + +//-------------------------------------------------------------------- +void Storage::TransferPortalForOutput( + vtkm::cont::internal::TransferInfoArray&, + vtkm::Id, + vtkm::cont::DeviceAdapterId) +{ + throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support output."); +} +} +} +} diff --git a/vtkm/cont/StorageVirtual.h b/vtkm/cont/StorageVirtual.h new file mode 100644 index 000000000..beb50623a --- /dev/null +++ b/vtkm/cont/StorageVirtual.h @@ -0,0 +1,175 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_StorageVirtual_h +#define vtk_m_cont_StorageVirtual_h + +#include + +#include +#include +#include +#include + +#include + +namespace vtkm +{ +namespace cont +{ + +struct StorageTagVirtual +{ +}; + +namespace internal +{ + +template <> +class VTKM_CONT_EXPORT Storage +{ +public: + /// \brief construct storage that VTK-m is responsible for + Storage() = default; + Storage(const Storage& src); + Storage(Storage&& src) noexcept; + Storage& operator=(const Storage& src); + Storage& operator=(Storage&& src) noexcept; + + virtual ~Storage(); + + /// Releases any resources being used in the execution environment (that are + /// not being shared by the control environment). + /// + /// Only needs to overridden by subclasses such as Zip that have member + /// variables that themselves have execution memory + virtual void ReleaseResourcesExecution(); + + /// Releases all resources in both the control and execution environments. + /// + /// Only needs to overridden by subclasses such as Zip that have member + /// variables that themselves have execution memory + virtual void ReleaseResources(); + + /// Returns the number of entries in the array. + /// + virtual vtkm::Id GetNumberOfValues() const = 0; + + /// \brief Allocates an array large enough to hold the given number of values. + /// + /// The allocation may be done on an already existing array, but can wipe out + /// any data already in the array. This method can throw + /// ErrorBadAllocation if the array cannot be allocated or + /// ErrorBadValue if the allocation is not feasible (for example, the + /// array storage is read-only). + /// + void Allocate(vtkm::Id numberOfValues) + { + std::cout << "StorageVirtual::Allocate(" << numberOfValues << ") Not Implemented!" << std::endl; + } //return this->DoAllocate(numberOfValues); } + + /// \brief Reduces the size of the array without changing its values. + /// + /// This method allows you to resize the array without reallocating it. The + /// number of entries in the array is changed to \c numberOfValues. The data + /// in the array (from indices 0 to \c numberOfValues - 1) are the same, but + /// \c numberOfValues must be equal or less than the preexisting size + /// (returned from GetNumberOfValues). That is, this method can only be used + /// to shorten the array, not lengthen. + void Shrink(vtkm::Id numberOfValues) + { + std::cout << "StorageVirtual::Shrink(" << numberOfValues << ") Not Implemented!." << std::endl; + } //return this->DoShrink(numberOfValues); } + + /// Determines if storage types matches the type passed in. + /// + bool IsType(const std::type_info& other) const { return this->IsSameType(other); } + + /// \brief Create a new storage of the same type as this storage. + /// + /// This method creates a new storage that is the same type as this one and + /// returns a unique_ptr for it. This method is convenient when + /// creating output arrays that should be the same type as some input array. + /// + std::unique_ptr> NewInstance() const; + + template + const DerivedStorage* Cast() const + { + const DerivedStorage* derived = dynamic_cast(this); + if (!derived) + { + VTKM_LOG_CAST_FAIL(*this, DerivedStorage); + throwFailedDynamicCast("StorageVirtual", vtkm::cont::TypeName()); + } + VTKM_LOG_CAST_SUCC(*this, derived); + return derived; + } + + const vtkm::internal::PortalVirtualBase* PrepareForInput(vtkm::cont::DeviceAdapterId devId) const; + + const vtkm::internal::PortalVirtualBase* PrepareForOutput(vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId); + + //This needs to cause a host side sync! + //This needs to work before we execute on a device + const vtkm::internal::PortalVirtualBase* GetPortalControl(); + + //This needs to cause a host side sync! + //This needs to work before we execute on a device + const vtkm::internal::PortalVirtualBase* GetPortalConstControl() const; + + /// Returns the DeviceAdapterId for the current device. If there is no device + /// with an up-to-date copy of the data, VTKM_DEVICE_ADAPTER_UNDEFINED is + /// returned. + DeviceAdapterId GetDeviceAdapterId() const noexcept; + +private: + //Memory management routines + // virtual void DoAllocate(vtkm::Id numberOfValues) = 0; + // virtual void DoShrink(vtkm::Id numberOfValues) = 0; + + //RTTI routines + virtual bool IsSameType(const std::type_info&) const; + virtual std::unique_ptr> MakeNewInstance() + const = 0; + + //Portal routines + virtual void ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const = 0; + virtual void ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload); + virtual void TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::DeviceAdapterId devId) const = 0; + virtual void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId); + + //These might need to exist in TransferInfoArray + mutable bool HostUpToDate = false; + mutable bool DeviceUpToDate = false; + std::shared_ptr DeviceTransferState = + std::make_shared(); +}; + +} // namespace internal + +using StorageVirtual = internal::Storage; +} +} // namespace vtkm::cont + +#endif diff --git a/vtkm/cont/internal/CMakeLists.txt b/vtkm/cont/internal/CMakeLists.txt index 89161a117..9401e288c 100644 --- a/vtkm/cont/internal/CMakeLists.txt +++ b/vtkm/cont/internal/CMakeLists.txt @@ -45,6 +45,7 @@ set(headers ReverseConnectivityBuilder.h SimplePolymorphicContainer.h StorageError.h + TransferInfo.h VirtualObjectTransfer.h VirtualObjectTransferShareWithControl.h ) diff --git a/vtkm/cont/internal/TransferInfo.cxx b/vtkm/cont/internal/TransferInfo.cxx new file mode 100644 index 000000000..f9783a655 --- /dev/null +++ b/vtkm/cont/internal/TransferInfo.cxx @@ -0,0 +1,68 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#include + +#include + +namespace vtkm +{ +namespace cont +{ +namespace internal +{ + +bool TransferInfoArray::valid(vtkm::cont::DeviceAdapterId devId) const noexcept +{ + return this->DeviceId == devId; +} + +void TransferInfoArray::updateHost( + std::unique_ptr&& host) noexcept +{ + this->Host = std::move(host); +} + +void TransferInfoArray::updateDevice(vtkm::cont::DeviceAdapterId devId, + std::unique_ptr&& hostCopy, + const vtkm::internal::PortalVirtualBase* device, + const std::shared_ptr& deviceState) noexcept +{ + this->HostCopyOfDevice = std::move(hostCopy); + this->DeviceId = devId; + this->Device = device; + this->DeviceTransferState = deviceState; +} + +void TransferInfoArray::releaseDevice() +{ + this->DeviceId = vtkm::cont::DeviceAdapterTagUndefined{}; + this->Device = nullptr; //The device transfer state own this pointer + this->DeviceTransferState = nullptr; //release the device transfer state + this->HostCopyOfDevice.release(); //we own this pointer so release it +} + +void TransferInfoArray::releaseAll() +{ + this->Host.release(); //we own this pointer so release it + this->releaseDevice(); +} +} +} +} diff --git a/vtkm/cont/internal/TransferInfo.h b/vtkm/cont/internal/TransferInfo.h new file mode 100644 index 000000000..5669a7fc3 --- /dev/null +++ b/vtkm/cont/internal/TransferInfo.h @@ -0,0 +1,74 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_internal_TransferInfo_h +#define vtk_m_cont_internal_TransferInfo_h + +#include + +#include +#include +#include + +#include + +namespace vtkm +{ + +namespace internal +{ +class PortalVirtualBase; +} + +namespace cont +{ +namespace internal +{ + +struct VTKM_CONT_EXPORT TransferInfoArray +{ + bool valid(vtkm::cont::DeviceAdapterId tagValue) const noexcept; + + void updateHost(std::unique_ptr&& host) noexcept; + void updateDevice( + vtkm::cont::DeviceAdapterId id, + std::unique_ptr&& host_copy, //NOT the same as host version + const vtkm::internal::PortalVirtualBase* device, + const std::shared_ptr& state) noexcept; + void releaseDevice(); + void releaseAll(); + + const vtkm::internal::PortalVirtualBase* hostPtr() const noexcept { return this->Host.get(); } + const vtkm::internal::PortalVirtualBase* devicePtr() const noexcept { return this->Device; } + vtkm::cont::DeviceAdapterId deviceId() const noexcept { return this->DeviceId; } + + std::shared_ptr& state() noexcept { return this->DeviceTransferState; } + +private: + vtkm::cont::DeviceAdapterId DeviceId = vtkm::cont::DeviceAdapterTagUndefined{}; + std::unique_ptr Host = nullptr; + std::unique_ptr HostCopyOfDevice = nullptr; + const vtkm::internal::PortalVirtualBase* Device = nullptr; + std::shared_ptr DeviceTransferState = nullptr; +}; +} +} +} + +#endif diff --git a/vtkm/internal/ArrayPortalHelpers.h b/vtkm/internal/ArrayPortalHelpers.h new file mode 100644 index 000000000..ee6a30949 --- /dev/null +++ b/vtkm/internal/ArrayPortalHelpers.h @@ -0,0 +1,56 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_internal_ArrayPortalHelpers_h +#define vtk_m_internal_ArrayPortalHelpers_h + + +#include +#include + +namespace vtkm +{ +namespace internal +{ + +template +struct PortalSupportsGets +{ + template ().Get(vtkm::Id{}))> + static std::true_type has(int); + template + static std::false_type has(...); + using type = decltype(has(0)); +}; + +template +struct PortalSupportsSets +{ + template ().Set(vtkm::Id{}, + std::declval()))> + static std::true_type has(int); + template + static std::false_type has(...); + using type = decltype(has(0)); +}; +} +} // namespace vtkm::internal + +#endif //vtk_m_internal_ArrayPortalHelpers_h diff --git a/vtkm/internal/ArrayPortalVirtual.h b/vtkm/internal/ArrayPortalVirtual.h new file mode 100644 index 000000000..be36ed7e7 --- /dev/null +++ b/vtkm/internal/ArrayPortalVirtual.h @@ -0,0 +1,144 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_internal_ArrayPortalVirtual_h +#define vtk_m_internal_ArrayPortalVirtual_h + + +#include +#include + +#include +#include + +namespace vtkm +{ +namespace internal +{ + +class VTKM_ALWAYS_EXPORT PortalVirtualBase +{ +public: + VTKM_EXEC_CONT PortalVirtualBase() noexcept {} + + VTKM_EXEC_CONT virtual ~PortalVirtualBase() noexcept { + //we implement this as we need a destructor with cuda markup. + //Using =default causes cuda free errors inside VirtualObjectTransferCuda + }; +}; + +} // namespace internal + +template +class VTKM_ALWAYS_EXPORT ArrayPortalVirtual : public internal::PortalVirtualBase +{ +public: + using ValueType = T; + + //use parents constructor + using PortalVirtualBase::PortalVirtualBase; + + VTKM_EXEC_CONT virtual ~ArrayPortalVirtual() = default; + + VTKM_EXEC_CONT virtual T Get(vtkm::Id index) const noexcept = 0; + + VTKM_EXEC_CONT virtual void Set(vtkm::Id, const T&) const noexcept {} +}; + + +template +class VTKM_ALWAYS_EXPORT ArrayPortalWrapper final + : public vtkm::ArrayPortalVirtual +{ + using T = typename PortalT::ValueType; + +public: + ArrayPortalWrapper(const PortalT& p) noexcept : ArrayPortalVirtual(), Portal(p) {} + + VTKM_EXEC + T Get(vtkm::Id index) const noexcept + { + using call_supported_t = typename internal::PortalSupportsGets::type; + return this->Get(call_supported_t(), index); + } + + VTKM_EXEC + void Set(vtkm::Id index, const T& value) const noexcept + { + using call_supported_t = typename internal::PortalSupportsSets::type; + this->Set(call_supported_t(), index, value); + } + +private: + // clang-format off + VTKM_EXEC inline T Get(std::true_type, vtkm::Id index) const noexcept { return this->Portal.Get(index); } + VTKM_EXEC inline T Get(std::false_type, vtkm::Id) const noexcept { return T{}; } + VTKM_EXEC inline void Set(std::true_type, vtkm::Id index, const T& value) const noexcept { this->Portal.Set(index, value); } + VTKM_EXEC inline void Set(std::false_type, vtkm::Id, const T&) const noexcept {} + // clang-format on + + + PortalT Portal; +}; + + +template +class VTKM_ALWAYS_EXPORT ArrayPortalRef +{ +public: + using ValueType = T; + + ArrayPortalRef() noexcept : Portal(nullptr), NumberOfValues(0) {} + + ArrayPortalRef(const ArrayPortalVirtual* portal, vtkm::Id numValues) noexcept + : Portal(portal), + NumberOfValues(numValues) + { + } + + //Currently this needs to be valid on both the host and device for cuda, so we can't + //call the underlying portal as that uses device virtuals and the method will fail. + //We need to seriously look at the interaction of portals and iterators for device + //adapters and determine a better approach as iterators are really fat + VTKM_EXEC_CONT inline vtkm::Id GetNumberOfValues() const noexcept { return this->NumberOfValues; } + + //This isn't valid on the host for cuda + VTKM_EXEC_CONT inline T Get(vtkm::Id index) const noexcept { return this->Portal->Get(index); } + + //This isn't valid on the host for + VTKM_EXEC_CONT inline void Set(vtkm::Id index, const T& t) const noexcept + { + this->Portal->Set(index, t); + } + + const ArrayPortalVirtual* Portal; + vtkm::Id NumberOfValues; +}; + +template +inline ArrayPortalRef make_ArrayPortalRef(const ArrayPortalVirtual* portal, + vtkm::Id numValues) noexcept +{ + return ArrayPortalRef(portal, numValues); +} + + +} // namespace vtkm + +#endif diff --git a/vtkm/internal/CMakeLists.txt b/vtkm/internal/CMakeLists.txt index a04b220c1..71971b6a6 100755 --- a/vtkm/internal/CMakeLists.txt +++ b/vtkm/internal/CMakeLists.txt @@ -56,8 +56,10 @@ unset(VTKM_NO_ASSERT) set(headers + ArrayPortalHelpers.h ArrayPortalUniformPointCoordinates.h ArrayPortalValueReference.h + ArrayPortalVirtual.h Assume.h brigand.hpp ConfigureFor32.h From 90223b390c956a7dfec27cbd51fa448f3e4e974d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Nov 2018 11:22:09 -0500 Subject: [PATCH 10/36] Add ArrayHandleAny to vtkm::cont --- vtkm/cont/ArrayHandleAny.h | 129 ++++++++++++++++++++++++++++++++ vtkm/cont/ArrayHandleAny.hxx | 141 +++++++++++++++++++++++++++++++++++ vtkm/cont/CMakeLists.txt | 2 + 3 files changed, 272 insertions(+) create mode 100644 vtkm/cont/ArrayHandleAny.h create mode 100644 vtkm/cont/ArrayHandleAny.hxx diff --git a/vtkm/cont/ArrayHandleAny.h b/vtkm/cont/ArrayHandleAny.h new file mode 100644 index 000000000..54ea1ff29 --- /dev/null +++ b/vtkm/cont/ArrayHandleAny.h @@ -0,0 +1,129 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleAny_h +#define vtk_m_cont_ArrayHandleAny_h + +#include + +#include + +#include +#include +#include + +namespace vtkm +{ +namespace cont +{ +template +class VTKM_ALWAYS_EXPORT StorageAny final : public vtkm::cont::StorageVirtual +{ +public: + VTKM_CONT + StorageAny(const vtkm::cont::ArrayHandle& ah); + + VTKM_CONT + ~StorageAny() = default; + + const vtkm::cont::ArrayHandle& GetHandle() const { return this->Handle; } + + vtkm::Id GetNumberOfValues() const { return this->Handle.GetNumberOfValues(); } + + void ReleaseResourcesExecution(); + void ReleaseResources(); + +private: + // StorageAny is meant to be seamless when it comes to IsType so we will match + // when either the type_info is 'StorageAny' or 'Storage'. That is why + // we need to override the default implementation. + bool IsSameType(const std::type_info& other) const + { + //We don't wan to check just 'S' as that just the tag + using ST = typename vtkm::cont::internal::Storage; + return other == typeid(ST) || other == typeid(*this); + } + + std::unique_ptr MakeNewInstance() const + { + return std::unique_ptr(new StorageAny{ vtkm::cont::ArrayHandle{} }); + } + + + void ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const; + void ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload); + + void TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::DeviceAdapterId devId) const; + + void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId); + + + vtkm::cont::ArrayHandle Handle; +}; + +/// ArrayHandleAny is a specialization of ArrayHandle. +template +class VTKM_ALWAYS_EXPORT ArrayHandleAny final : public vtkm::cont::ArrayHandleVirtual +{ +public: + template + VTKM_CONT ArrayHandleAny(const vtkm::cont::ArrayHandle& ah) + : vtkm::cont::ArrayHandleVirtual(std::make_shared>(ah)) + { + } + + ~ArrayHandleAny() = default; +}; + +/// A convenience function for creating an ArrayHandleAny. +template +VTKM_CONT vtkm::cont::ArrayHandleAny make_ArrayHandleAny(const vtkm::cont::ArrayHandle& ah) +{ + return vtkm::cont::ArrayHandleAny(ah); +} + + +template +void CastAndCall(vtkm::cont::ArrayHandleVirtual> coords, + Functor&& f, + Args&&... args) +{ + using HandleType = ArrayHandleUniformPointCoordinates; + using T = typename HandleType::ValueType; + using S = typename HandleType::StorageTag; + if (coords.IsType()) + { + const vtkm::cont::StorageVirtual* storage = coords.GetStorage(); + auto* any = storage->Cast>(); + f(any->GetHandle(), std::forward(args)...); + } + else + { + f(coords, std::forward(args)...); + } +} +} +} //namespace vtkm::cont + + + +#endif //vtk_m_cont_ArrayHandleAny_h diff --git a/vtkm/cont/ArrayHandleAny.hxx b/vtkm/cont/ArrayHandleAny.hxx new file mode 100644 index 000000000..ff623da3c --- /dev/null +++ b/vtkm/cont/ArrayHandleAny.hxx @@ -0,0 +1,141 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleAny_hxx +#define vtk_m_cont_ArrayHandleAny_hxx + +#include +#include + +namespace vtkm +{ +namespace cont +{ + +VTKM_CONT +template +StorageAny::StorageAny(const vtkm::cont::ArrayHandle& ah) + : vtkm::cont::StorageVirtual() + , Handle(ah) +{ +} + +/// release execution side resources +template +void StorageAny::ReleaseResourcesExecution() +{ + vtkm::cont::StorageVirtual::ReleaseResourcesExecution(); + this->Handle.ReleaseResourcesExecution(); +} + +/// release control side resources +template +void StorageAny::ReleaseResources() +{ + vtkm::cont::StorageVirtual::ReleaseResources(); + this->Handle.ReleaseResources(); +} + +namespace detail +{ +struct PortalWrapperToDevice +{ + template + bool operator()(DeviceAdapterTag device, + Handle&& handle, + vtkm::cont::internal::TransferInfoArray& payload) const + { + auto portal = handle.PrepareForInput(device); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::detail::TransferToDevice transfer; + return transfer(device, payload, portal); + } + template + bool operator()(DeviceAdapterTag device, + Handle&& handle, + vtkm::Id numberOfValues, + vtkm::cont::internal::TransferInfoArray& payload) const + { + auto portal = handle.PrepareForOutput(numberOfValues, device); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::detail::TransferToDevice transfer; + return transfer(device, payload, portal); + } +}; +} + +template +void StorageAny::ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const +{ + auto portal = this->Handle.GetPortalConstControl(); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::make_hostPortal(payload, portal); +} + +namespace detail +{ +template +void make_writableHostPortal(std::true_type, + vtkm::cont::internal::TransferInfoArray& payload, + HandleType& handle) +{ + auto portal = handle.GetPortalControl(); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::make_hostPortal(payload, portal); +} +template +void make_writableHostPortal(std::false_type, + vtkm::cont::internal::TransferInfoArray& payload, + HandleType&) +{ + payload.updateHost(nullptr); + throw vtkm::cont::ErrorBadValue( + "ArrayHandleAny was bound to an ArrayHandle that doesn't support output."); +} +} + +template +void StorageAny::ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload) +{ + using HT = vtkm::cont::ArrayHandle; + constexpr auto isWriteable = typename vtkm::cont::internal::IsWriteableArrayHandle::type{}; + + detail::make_writableHostPortal(isWriteable, payload, this->Handle); +} + +template +void StorageAny::TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::DeviceAdapterId devId) const +{ + vtkm::cont::TryExecuteOnDevice(devId, detail::PortalWrapperToDevice(), this->Handle, payload); +} + + +template +void StorageAny::TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId) +{ + vtkm::cont::TryExecuteOnDevice( + devId, detail::PortalWrapperToDevice(), this->Handle, numberOfValues, payload); +} +} +} // namespace vtkm::cont + +#endif //vtk_m_cont_ArrayHandleAny_hxx diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index dfdbb7ec6..ed591c181 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -22,6 +22,7 @@ set(headers Algorithm.h ArrayCopy.h ArrayHandle.h + ArrayHandleAny.h ArrayHandleCast.h ArrayHandleCartesianProduct.h ArrayHandleCompositeVector.h @@ -111,6 +112,7 @@ set(headers set(template_sources ArrayHandle.hxx + ArrayHandleAny.hxx ArrayHandleVirtual.hxx ArrayRangeCompute.hxx BoundingIntervalHierarchy.hxx From 3d67a0082240f36656470ab06de068e940758d56 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Nov 2018 11:24:59 -0500 Subject: [PATCH 11/36] Add ArrayHandleVariant to vtkm::cont which will replace DynamicArrayhandle --- vtkm/cont/ArrayHandleVariant.cxx | 57 +++ vtkm/cont/ArrayHandleVariant.h | 373 ++++++++++++++++++ vtkm/cont/CMakeLists.txt | 2 + .../internal/ArrayHandleVariantContainer.h | 213 ++++++++++ vtkm/cont/internal/CMakeLists.txt | 1 + 5 files changed, 646 insertions(+) create mode 100644 vtkm/cont/ArrayHandleVariant.cxx create mode 100644 vtkm/cont/ArrayHandleVariant.h create mode 100644 vtkm/cont/internal/ArrayHandleVariantContainer.h diff --git a/vtkm/cont/ArrayHandleVariant.cxx b/vtkm/cont/ArrayHandleVariant.cxx new file mode 100644 index 000000000..d128fe354 --- /dev/null +++ b/vtkm/cont/ArrayHandleVariant.cxx @@ -0,0 +1,57 @@ +//============================================================================ +// 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. +// +// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2015 UT-Battelle, LLC. +// Copyright 2015 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ + +#include +#include + +#include +#include + +namespace vtkm +{ +namespace cont +{ +namespace internal +{ + +ArrayHandleVariantContainerBase::ArrayHandleVariantContainerBase() +{ +} + +ArrayHandleVariantContainerBase::~ArrayHandleVariantContainerBase() +{ +} +} + +namespace detail +{ +void ThrowCastAndCallException(const vtkm::cont::internal::ArrayHandleVariantContainerBase& ref, + const std::type_info& type) +{ + std::ostringstream out; + out << "Could not find appropriate cast for array in CastAndCall1.\n" + "Array: "; + ref.PrintSummary(out); + out << "TypeList: " << type.name() << "\n"; + throw vtkm::cont::ErrorBadValue(out.str()); +} +} +} +} // namespace vtkm::cont::detail diff --git a/vtkm/cont/ArrayHandleVariant.h b/vtkm/cont/ArrayHandleVariant.h new file mode 100644 index 000000000..adc429757 --- /dev/null +++ b/vtkm/cont/ArrayHandleVariant.h @@ -0,0 +1,373 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleVariant_h +#define vtk_m_cont_ArrayHandleVariant_h + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +namespace vtkm +{ +namespace cont +{ +/// \brief Holds an array handle without having to specify template parameters. +/// +/// \c ArrayHandleVariant holds an \c ArrayHandle or \c ArrayHandleVirtual +/// object using runtime polymorphism to manage different value types and +/// storage rather than compile-time templates. This adds a programming +/// convenience that helps avoid a proliferation of templates. It also provides +/// the management necessary to interface VTK-m with data sources where types +/// will not be known until runtime. +/// +/// To interface between the runtime polymorphism and the templated algorithms +/// in VTK-m, \c ArrayHandleVariant contains a method named \c CastAndCall that +/// will determine the correct type from some known list of types. It returns +/// an ArrayHandleVirtual which type erases the storage type by using polymorphism. +/// This mechanism is used internally by VTK-m's worklet invocation +/// mechanism to determine the type when running algorithms. +/// +/// By default, \c ArrayHandleVariant will assume that the value type in the +/// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST_TAG +/// This list can be changed by using the \c ResetTypes. It is +/// worthwhile to match these lists closely to the possible types that might be +/// used. If a type is missing you will get a runtime error. If there are more +/// types than necessary, then the template mechanism will create a lot of +/// object code that is never used, and keep in mind that the number of +/// combinations grows exponentially when using multiple \c ArrayHandleVariant +/// objects. +/// +/// The actual implementation of \c ArrayHandleVariant is in a templated class +/// named \c ArrayHandleVariantBase, which is templated on the list of +/// component types. +/// +template +class VTKM_ALWAYS_EXPORT ArrayHandleVariantBase +{ +public: + VTKM_CONT + ArrayHandleVariantBase() = default; + + template + VTKM_CONT ArrayHandleVariantBase(const vtkm::cont::ArrayHandle& array) + : ArrayContainer(std::make_shared>( + vtkm::cont::ArrayHandleAny{ array })) + { + } + + template + explicit VTKM_CONT ArrayHandleVariantBase( + const vtkm::cont::ArrayHandle& array) + : ArrayContainer(std::make_shared>(array)) + { + } + + template + VTKM_CONT explicit ArrayHandleVariantBase(const ArrayHandleVariantBase& src) + : ArrayContainer(internal::variant::GetContainer::Extract(src)) + { + } + + VTKM_CONT ArrayHandleVariantBase(const ArrayHandleVariantBase& src) = default; + VTKM_CONT ArrayHandleVariantBase(ArrayHandleVariantBase&& src) noexcept = default; + + VTKM_CONT + ~ArrayHandleVariantBase() {} + + VTKM_CONT + ArrayHandleVariantBase& operator=(const ArrayHandleVariantBase& src) = + default; + + VTKM_CONT + ArrayHandleVariantBase& operator=(ArrayHandleVariantBase&& src) noexcept = + default; + + + /// Returns true if this array matches the array handle type passed in. + /// + template + VTKM_CONT bool IsType() + { + return internal::variant::IsType(this->ArrayContainer.get()); + } + + /// Returns true if this array matches the ValueType type passed in. + /// + template + VTKM_CONT bool IsVirtualType() + { + return internal::variant::IsVirtualType(this->ArrayContainer.get()); + } + + /// Returns this array cast to the given \c ArrayHandle type. Throws \c + /// ErrorBadType if the cast does not work. Use \c IsType + /// to check if the cast can happen. + /// + template + VTKM_CONT ArrayHandleType Cast() const + { + return internal::variant::Cast(this->ArrayContainer.get()); + } + + /// Returns this array cast to a \c ArrayHandleVirtual of the given type. Throws \c + /// ErrorBadType if the cast does not work. + /// + template + VTKM_CONT vtkm::cont::ArrayHandleVirtual AsVirtual() const + { + return internal::variant::Cast>(this->ArrayContainer.get()); + } + + /// Given a references to an ArrayHandle object, casts this array to the + /// ArrayHandle's type and sets the given ArrayHandle to this array. Throws + /// \c ErrorBadType if the cast does not work. Use \c + /// ArrayHandleType to check if the cast can happen. + /// + /// Note that this is a shallow copy. The data are not copied and a change + /// in the data in one array will be reflected in the other. + /// + template + VTKM_CONT void CopyTo(ArrayHandleType& array) const + { + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + array = this->Cast(); + } + + /// Changes the types to try casting to when resolving this variant array, + /// which is specified with a list tag like those in TypeListTag.h. Since C++ + /// does not allow you to actually change the template arguments, this method + /// returns a new variant array object. This method is particularly useful to + /// narrow down (or expand) the types when using an array of particular + /// constraints. + /// + template + VTKM_CONT ArrayHandleVariantBase ResetTypes(NewTypeList = NewTypeList()) const + { + VTKM_IS_LIST_TAG(NewTypeList); + return ArrayHandleVariantBase(*this); + } + + /// Attempts to cast the held array to a specific value type, + /// then call the given functor with the cast array. The types + /// tried in the cast are those in the lists defined by the TypeList. + /// By default \c ArrayHandleVariant set this to VTKM_DEFAULT_TYPE_LIST_TAG. + /// + template + VTKM_CONT void CastAndCall(Functor&& f, Args&&...) const; + + /// \brief Create a new array of the same type as this array. + /// + /// This method creates a new array that is the same type as this one and + /// returns a new variant array handle for it. This method is convenient when + /// creating output arrays that should be the same type as some input array. + /// + VTKM_CONT + ArrayHandleVariantBase NewInstance() const + { + ArrayHandleVariantBase instance; + instance.ArrayContainer = this->ArrayContainer->NewInstance(); + return instance; + } + + /// Releases any resources being used in the execution environment (that are + /// not being shared by the control environment). + /// + void ReleaseResourcesExecution() { return this->ArrayContainer->ReleaseResourcesExecution(); } + + + /// Releases all resources in both the control and execution environments. + /// + void ReleaseResources() { return this->ArrayContainer->ReleaseResources(); } + + /// \brief Get the number of components in each array value. + /// + /// This method will query the array type for the number of components in + /// each value of the array. The number of components is determined by + /// the \c VecTraits::NUM_COMPONENTS trait class. + /// + VTKM_CONT + vtkm::IdComponent GetNumberOfComponents() const + { + return this->ArrayContainer->GetNumberOfComponents(); + } + + /// \brief Get the number of values in the array. + /// + VTKM_CONT + vtkm::Id GetNumberOfValues() const { return this->ArrayContainer->GetNumberOfValues(); } + + VTKM_CONT + void PrintSummary(std::ostream& out) const { this->ArrayContainer->PrintSummary(out); } + +private: + friend struct internal::variant::GetContainer; + std::shared_ptr ArrayContainer; +}; + +using ArrayHandleVariant = vtkm::cont::ArrayHandleVariantBase; + +namespace detail +{ + +struct ArrayHandleVariantTry +{ + template + void operator()(T, + Functor&& f, + bool& called, + const vtkm::cont::internal::ArrayHandleVariantContainerBase& container, + Args&&... args) const + { + if (!called && vtkm::cont::internal::variant::IsVirtualType(&container)) + { + called = true; + const auto* derived = + static_cast*>(&container); + VTKM_LOG_CAST_SUCC(container, derived); + f(derived->Array, std::forward(args)...); + } + } +}; + +VTKM_CONT_EXPORT void ThrowCastAndCallException( + const vtkm::cont::internal::ArrayHandleVariantContainerBase&, + const std::type_info&); +} // namespace detail + + + +template +template +VTKM_CONT void ArrayHandleVariantBase::CastAndCall(Functor&& f, Args&&... args) const +{ + bool called = false; + const auto& ref = *this->ArrayContainer; + vtkm::ListForEach(detail::ArrayHandleVariantTry{}, + TypeList{}, + std::forward(f), + called, + ref, + std::forward(args)...); + if (!called) + { + // throw an exception + VTKM_LOG_CAST_FAIL(*this, TypeList); + detail::ThrowCastAndCallException(ref, typeid(TypeList)); + } +} + +namespace internal +{ + +template +struct DynamicTransformTraits> +{ + using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; +}; + +} // namespace internal +} // namespace cont +} // namespace vtkm + +//============================================================================= +// Specializations of serialization related classes +namespace diy +{ + +namespace internal +{ + +struct ArrayHandleVariantSerializeFunctor +{ + template + void operator()(const ArrayHandleType& ah, BinaryBuffer& bb) const + { + diy::save(bb, vtkm::cont::TypeString::Get()); + diy::save(bb, ah); + } +}; + +struct ArrayHandleVariantDeserializeFunctor +{ + template + void operator()(T, + vtkm::cont::ArrayHandleVariantBase& dh, + const std::string& typeString, + bool& success, + BinaryBuffer& bb) const + { + using ArrayHandleType = vtkm::cont::ArrayHandleVirtual; + + if (!success && (typeString == vtkm::cont::TypeString::Get())) + { + ArrayHandleType ah; + diy::load(bb, ah); + dh = vtkm::cont::ArrayHandleVariantBase(ah); + success = true; + } + } +}; + +} // internal + +template +struct Serialization> +{ +private: + using Type = vtkm::cont::ArrayHandleVariantBase; + +public: + static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj) + { + vtkm::cont::CastAndCall(obj, internal::ArrayHandleVariantSerializeFunctor{}, bb); + } + + static VTKM_CONT void load(BinaryBuffer& bb, Type& obj) + { + std::string typeString; + diy::load(bb, typeString); + + bool success = false; + vtkm::ListForEach( + internal::ArrayHandleVariantDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb); + + if (!success) + { + throw vtkm::cont::ErrorBadType( + "Error deserializing ArrayHandleVariant. Message TypeString: " + typeString); + } + } +}; + +} // diy + + +#endif //vtk_m_virts_ArrayHandleVariant_h diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index ed591c181..4c59873b0 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -40,6 +40,7 @@ set(headers ArrayHandleSwizzle.h ArrayHandleTransform.h ArrayHandleUniformPointCoordinates.h + ArrayHandleVariant.h ArrayHandleView.h ArrayHandleVirtual.h ArrayHandleVirtualCoordinates.h @@ -127,6 +128,7 @@ set(template_sources set(sources ArrayHandle.cxx + ArrayHandleVariant.cxx AssignerMultiBlock.cxx BoundsCompute.cxx BoundsGlobalCompute.cxx diff --git a/vtkm/cont/internal/ArrayHandleVariantContainer.h b/vtkm/cont/internal/ArrayHandleVariantContainer.h new file mode 100644 index 000000000..6444e1f8a --- /dev/null +++ b/vtkm/cont/internal/ArrayHandleVariantContainer.h @@ -0,0 +1,213 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_ArrayHandleVariantContainer_h +#define vtk_m_cont_ArrayHandleVariantContainer_h + +#include + +#include + +#include +#include + + +namespace vtkm +{ +namespace cont +{ + +// Forward declaration needed for GetContainer +template +class ArrayHandleVariantBase; + +namespace internal +{ + +/// \brief Base class for ArrayHandleVariantContainer +/// +struct VTKM_CONT_EXPORT ArrayHandleVariantContainerBase +{ + ArrayHandleVariantContainerBase(); + + // This must exist so that subclasses are destroyed correctly. + virtual ~ArrayHandleVariantContainerBase(); + + virtual vtkm::Id GetNumberOfValues() const = 0; + virtual vtkm::IdComponent GetNumberOfComponents() const = 0; + + virtual void ReleaseResourcesExecution() = 0; + virtual void ReleaseResources() = 0; + + virtual void PrintSummary(std::ostream& out) const = 0; + + virtual std::shared_ptr NewInstance() const = 0; + + virtual const vtkm::cont::StorageVirtual* GetStorage() const = 0; +}; + +/// \brief ArrayHandle container that can use C++ run-time type information. +/// +/// The \c ArrayHandleVariantContainer is similar to the +/// \c SimplePolymorphicContainer in that it can contain an object of an +/// unknown type. However, this class specifically holds ArrayHandle objects +/// (with different template parameters) so that it can polymorphically answer +/// simple questions about the object. +/// +template +struct VTKM_ALWAYS_EXPORT ArrayHandleVariantContainer final : public ArrayHandleVariantContainerBase +{ + vtkm::cont::ArrayHandleVirtual Array; + + ArrayHandleVariantContainer() + : Array() + { + } + + ArrayHandleVariantContainer(const vtkm::cont::ArrayHandleVirtual& array) + : Array(array) + { + } + + ~ArrayHandleVariantContainer() = default; + + vtkm::Id GetNumberOfValues() const { return this->Array.GetNumberOfValues(); } + + vtkm::IdComponent GetNumberOfComponents() const { return vtkm::VecTraits::NUM_COMPONENTS; } + + + void ReleaseResourcesExecution() { this->Array.ReleaseResourcesExecution(); } + void ReleaseResources() { this->Array.ReleaseResources(); } + + void PrintSummary(std::ostream& out) const + { + vtkm::cont::printSummary_ArrayHandle(this->Array, out); + } + + std::shared_ptr NewInstance() const + { + return std::make_shared>(this->Array.NewInstance()); + } + + const vtkm::cont::StorageVirtual* GetStorage() const { return this->Array.GetStorage(); } +}; + +namespace variant +{ + +// One instance of a template class cannot access the private members of +// another instance of a template class. However, I want to be able to copy +// construct a ArrayHandleVariant from another ArrayHandleVariant of any other +// type. Since you cannot partially specialize friendship, use this accessor +// class to get at the internals for the copy constructor. +struct GetContainer +{ + template + VTKM_CONT static const std::shared_ptr& Extract( + const vtkm::cont::ArrayHandleVariantBase& src) + { + return src.ArrayContainer; + } +}; + +template +VTKM_CONT bool IsType(const ArrayHandleVariantContainerBase* container) +{ //container could be nullptr + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + if (!container) + { + return false; + } + using VT = typename ArrayHandleType::ValueType; + using ST = typename ArrayHandleType::StorageTag; + + const vtkm::cont::StorageVirtual* storage = container->GetStorage(); + return storage->IsType(typeid(vtkm::cont::internal::Storage)); +} + +template +VTKM_CONT bool IsVirtualType(const ArrayHandleVariantContainerBase* container) +{ + if (container == nullptr) + { //you can't use typeid on nullptr of polymorphic types + return false; + } + return typeid(ArrayHandleVariantContainer) == typeid(*container); +} + + +template +struct VTKM_ALWAYS_EXPORT Caster +{ + vtkm::cont::ArrayHandle operator()(const ArrayHandleVariantContainerBase* container) const + { + using ArrayHandleType = vtkm::cont::ArrayHandle; + if (!IsType(container)) + { + VTKM_LOG_CAST_FAIL(container, ArrayHandleType); + throwFailedDynamicCast(vtkm::cont::TypeName(container), + vtkm::cont::TypeName()); + } + + //we know the storage isn't a virtual but another storage type + //that means that the container holds a vtkm::cont::ArrayHandleAny + const auto* any = static_cast*>(container->GetStorage()); + VTKM_LOG_CAST_SUCC(container, *any); + return any->GetHandle(); + } +}; + +template +struct VTKM_ALWAYS_EXPORT Caster +{ + vtkm::cont::ArrayHandle operator()( + const ArrayHandleVariantContainerBase* container) const + { + if (!IsVirtualType(container)) + { + VTKM_LOG_CAST_FAIL(container, vtkm::cont::ArrayHandleVirtual); + throwFailedDynamicCast(vtkm::cont::TypeName(container), + vtkm::cont::TypeName>()); + } + + // Technically, this method returns a copy of the \c ArrayHandle. But + // because \c ArrayHandle acts like a shared pointer, it is valid to + // do the copy. + const auto* derived = static_cast*>(container); + VTKM_LOG_CAST_SUCC(container, derived->Array); + return derived->Array; + } +}; + + +template +VTKM_CONT ArrayHandleType Cast(const ArrayHandleVariantContainerBase* container) +{ //container could be nullptr + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + using Type = typename ArrayHandleType::ValueType; + using Storage = typename ArrayHandleType::StorageTag; + auto ret = Caster{}(container); + return ArrayHandleType(std::move(ret)); +} +} +} +} +} //namespace vtkm::cont::internal::variant + +#endif diff --git a/vtkm/cont/internal/CMakeLists.txt b/vtkm/cont/internal/CMakeLists.txt index 9401e288c..b52c0f283 100644 --- a/vtkm/cont/internal/CMakeLists.txt +++ b/vtkm/cont/internal/CMakeLists.txt @@ -23,6 +23,7 @@ set(headers ArrayHandleBasicImpl.h ArrayHandleBasicImpl.hxx ArrayHandleExecutionManager.h + ArrayHandleVariantContainer.h ArrayManagerExecution.h ArrayManagerExecutionShareWithControl.h ArrayPortalFromIterators.h From ef83adf3bd24f88f72d2cce9c0869b14e0405b27 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Nov 2018 11:40:39 -0500 Subject: [PATCH 12/36] Field, CoordinateSystem, VirtualCoordinates all use the new virtual code --- vtkm/cont/ArrayHandleVirtual.h | 159 +++-- vtkm/cont/ArrayHandleVirtualCoordinates.h | 619 ++---------------- vtkm/cont/CellSet.h | 2 +- vtkm/cont/CoordinateSystem.cxx | 33 +- vtkm/cont/CoordinateSystem.h | 39 +- vtkm/cont/CoordinateSystem.hxx | 14 +- vtkm/cont/DataSet.h | 15 +- vtkm/cont/DataSetFieldAdd.h | 6 +- vtkm/cont/Field.cxx | 30 +- vtkm/cont/Field.h | 162 ++--- vtkm/cont/FieldRangeCompute.cxx | 4 +- vtkm/cont/FieldRangeCompute.h | 37 +- vtkm/cont/FieldRangeCompute.hxx | 14 +- vtkm/cont/FieldRangeGlobalCompute.cxx | 6 +- vtkm/cont/FieldRangeGlobalCompute.h | 35 +- vtkm/cont/FieldRangeGlobalCompute.hxx | 14 +- vtkm/cont/MultiBlock.cxx | 1 - vtkm/cont/MultiBlock.h | 1 - .../cont/testing/UnitTestMoveConstructors.cxx | 34 +- 19 files changed, 339 insertions(+), 886 deletions(-) diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index e30afd9bf..6c78ca114 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -59,6 +59,12 @@ public: ArrayHandle() : Storage(nullptr){}; + + /// virtual destructor, as required to make sure derived classes that + /// might have member variables are properly cleaned up. + // + virtual ~ArrayHandle() = default; + ///Move existing shared_ptr of vtkm::cont::StorageVirtual to be ///owned by this ArrayHandleVirtual. ///This is generally how derived class construct a valid ArrayHandleVirtual @@ -107,23 +113,20 @@ public: VTKM_CONT bool IsType() const { VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - //We need to go long the way to find the StorageType - //as StorageType is private on lots of derived ArrayHandles - //See Issue #314 - using VT = typename ArrayHandleType::ValueType; static_assert( std::is_same::value, "ArrayHandleVirtual can only be casted to an ArrayHandle of the same ValueType."); + //We need to determine if we are checking that `ArrayHandleType` + //is a virtual array handle since that is an easy check. + //Or if we have to go ask the storage if they are holding + // using ST = typename ArrayHandleType::StorageTag; - return this->Storage->IsType(typeid(vtkm::cont::internal::Storage)); + using is_base = std::is_same; + return this->IsSameType(is_base{}); } - /// Returns a view on the internal storage of the ArrayHandleVirtual - /// - VTKM_CONT const StorageType* GetStorage() const { return this->Storage.get(); } - /// Returns a new instance of an ArrayHandleVirtual with the same storage /// VTKM_CONT ArrayHandle NewInstance() const @@ -133,37 +136,9 @@ public: : ArrayHandle(); } - // Return a ArrayPortalRef that wraps the real virtual portal. We need a stack object for - // the following reasons: - // 1. Device Adapter algorithms only support const AH& and not const AH* - // 2. Devices will want to get the length of a portal before execution, but for CUDA - // we can't ask this information of the portal as it only valid on the device, instead - // we have to store this information also in the ref wrapper - vtkm::ArrayPortalRef PrepareForInput(vtkm::cont::DeviceAdapterId devId) const - { - return make_ArrayPortalRef( - static_cast*>(this->Storage->PrepareForInput(devId)), - this->GetNumberOfValues()); - } - - vtkm::ArrayPortalRef PrepareForOutput(vtkm::Id numberOfValues, - vtkm::cont::DeviceAdapterId devId) - { - return make_ArrayPortalRef(static_cast*>( - this->Storage->PrepareForOutput(numberOfValues, devId)), - numberOfValues); - } - - vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); } - - /// Releases any resources being used in the execution environment (that are - /// not being shared by the control environment). + /// Returns a view on the internal storage of the ArrayHandleVirtual /// - void ReleaseResourcesExecution() { return this->Storage->ReleaseResourcesExecution(); } - - /// Releases all resources in both the control and execution environments. - /// - void ReleaseResources() { return this->Storage->ReleaseResources(); } + VTKM_CONT const StorageType* GetStorage() const { return this->Storage.get(); } /// Get the array portal of the control array. /// Since worklet invocations are asynchronous and this routine is a synchronization point, @@ -187,8 +162,114 @@ public: this->GetNumberOfValues()); } + /// Returns the number of entries in the array. + /// + vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); } + + /// \brief Allocates an array large enough to hold the given number of values. + /// + /// The allocation may be done on an already existing array, but can wipe out + /// any data already in the array. This method can throw + /// ErrorBadAllocation if the array cannot be allocated or + /// ErrorBadValue if the allocation is not feasible (for example, the + /// array storage is read-only). + /// + VTKM_CONT + void Allocate(vtkm::Id numberOfValues) { return this->Storage->Allocate(numberOfValues); } + + /// \brief Reduces the size of the array without changing its values. + /// + /// This method allows you to resize the array without reallocating it. The + /// number of entries in the array is changed to \c numberOfValues. The data + /// in the array (from indices 0 to \c numberOfValues - 1) are the same, but + /// \c numberOfValues must be equal or less than the preexisting size + /// (returned from GetNumberOfValues). That is, this method can only be used + /// to shorten the array, not lengthen. + void Shrink(vtkm::Id numberOfValues) { return this->Storage->Shrink(numberOfValues); } + + /// Releases any resources being used in the execution environment (that are + /// not being shared by the control environment). + /// + void ReleaseResourcesExecution() { return this->Storage->ReleaseResourcesExecution(); } + + /// Releases all resources in both the control and execution environments. + /// + void ReleaseResources() { return this->Storage->ReleaseResources(); } + + /// Prepares this array to be used as an input to an operation in the + /// execution environment. If necessary, copies data to the execution + /// environment. Can throw an exception if this array does not yet contain + /// any data. Returns a portal that can be used in code running in the + /// execution environment. + /// + /// Return a ArrayPortalRef that wraps the real virtual portal. We need a stack object for + /// the following reasons: + /// 1. Device Adapter algorithms only support const AH& and not const AH* + /// 2. Devices will want to get the length of a portal before execution, but for CUDA + /// we can't ask this information of the portal as it only valid on the device, instead + /// we have to store this information also in the ref wrapper + vtkm::ArrayPortalRef PrepareForInput(vtkm::cont::DeviceAdapterId devId) const + { + return make_ArrayPortalRef( + static_cast*>(this->Storage->PrepareForInput(devId)), + this->GetNumberOfValues()); + } + + /// Prepares (allocates) this array to be used as an output from an operation + /// in the execution environment. The internal state of this class is set to + /// have valid data in the execution array with the assumption that the array + /// will be filled soon (i.e. before any other methods of this object are + /// called). Returns a portal that can be used in code running in the + /// execution environment. + /// + vtkm::ArrayPortalRef PrepareForOutput(vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId) + { + return make_ArrayPortalRef(static_cast*>( + this->Storage->PrepareForOutput(numberOfValues, devId)), + numberOfValues); + } + + /// Prepares this array to be used in an in-place operation (both as input + /// and output) in the execution environment. If necessary, copies data to + /// the execution environment. Can throw an exception if this array does not + /// yet contain any data. Returns a portal that can be used in code running + /// in the execution environment. + /// + vtkm::ArrayPortalRef PrepareForInPlace(vtkm::cont::DeviceAdapterId devId) + { + return make_ArrayPortalRef( + static_cast*>(this->Storage->PrepareForInput(devId)), + this->GetNumberOfValues()); + } + + /// Returns the DeviceAdapterId for the current device. If there is no device + /// with an up-to-date copy of the data, VTKM_DEVICE_ADAPTER_UNDEFINED is + /// returned. + VTKM_CONT + DeviceAdapterId GetDeviceAdapterId() const { return this->Storage->GetDeviceAdapterId(); } + protected: std::shared_ptr Storage = nullptr; + +private: + template + bool IsSameType(std::true_type vtkmNotUsed(inheritsFromArrayHandleVirtual)) const + { + //All classes that derive from ArrayHandleVirtual have virtual methods so we can use + //typeid directly + return typeid(*this) == typeid(ArrayHandleType); + } + + template + bool IsSameType(std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const + { + //We need to go long the way to find the StorageType + //as StorageType is private on lots of derived ArrayHandles + //See Issue #314 + using ST = typename ArrayHandleType::StorageTag; + return this->Storage->IsType(typeid(vtkm::cont::internal::Storage)); + } }; template diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index f99543b70..ed0aa7c2d 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -20,17 +20,16 @@ #ifndef vtk_m_cont_ArrayHandleVirtualCoordinates_h #define vtk_m_cont_ArrayHandleVirtualCoordinates_h -#include +#include +#include + #include +#include #include + #include #include #include -#include -#include - -#include -#include #include #include @@ -40,473 +39,57 @@ namespace vtkm namespace cont { -namespace internal -{ - -//============================================================================= -class VTKM_ALWAYS_EXPORT CoordinatesPortalBase : public VirtualObjectBase -{ -public: - VTKM_EXEC_CONT virtual vtkm::Vec Get(vtkm::Id i) const = 0; - VTKM_EXEC_CONT virtual void Set(vtkm::Id i, - const vtkm::Vec& val) const = 0; -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesPortalImpl : public CoordinatesPortalBase -{ -public: - VTKM_CONT CoordinatesPortalImpl() = default; - VTKM_CONT explicit CoordinatesPortalImpl(const PortalType& portal) - : Portal(portal) - { - } - - VTKM_CONT void SetPortal(const PortalType& portal) { this->Portal = portal; } - - VTKM_EXEC_CONT vtkm::Vec Get(vtkm::Id i) const override - { - auto val = this->Portal.Get(i); - return { static_cast(val[0]), - static_cast(val[1]), - static_cast(val[2]) }; - } - - VTKM_EXEC_CONT void Set(vtkm::Id i, const vtkm::Vec& val) const override - { - using VecType = typename PortalType::ValueType; - using ComponentType = typename vtkm::VecTraits::ComponentType; - - this->Portal.Set(i, - { static_cast(val[0]), - static_cast(val[1]), - static_cast(val[2]) }); - } - -private: - PortalType Portal; -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesPortalImpl : public CoordinatesPortalBase -{ -public: - VTKM_CONT CoordinatesPortalImpl() = default; - VTKM_CONT explicit CoordinatesPortalImpl(const PortalType&) {} - VTKM_CONT void SetPortal(const PortalType&) {} - VTKM_EXEC_CONT vtkm::Vec Get(vtkm::Id) const override { return {}; } - VTKM_EXEC_CONT void Set(vtkm::Id, const vtkm::Vec&) const override {} -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesPortal - : public CoordinatesPortalImpl -{ -public: - VTKM_CONT CoordinatesPortal() = default; - VTKM_CONT explicit CoordinatesPortal(const PortalType& portal) - : CoordinatesPortalImpl(portal) - { - } -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesPortalConst : public CoordinatesPortalBase -{ -public: - VTKM_CONT CoordinatesPortalConst() = default; - VTKM_CONT explicit CoordinatesPortalConst(const PortalType& portal) - : Portal(portal) - { - } - - VTKM_CONT void SetPortal(const PortalType& portal) { this->Portal = portal; } - - VTKM_EXEC_CONT vtkm::Vec Get(vtkm::Id i) const override - { - auto val = this->Portal.Get(i); - return { static_cast(val[0]), - static_cast(val[1]), - static_cast(val[2]) }; - } - - VTKM_EXEC_CONT void Set(vtkm::Id, const vtkm::Vec&) const override {} - -private: - PortalType Portal; -}; - -class VTKM_ALWAYS_EXPORT ArrayPortalVirtualCoordinates +/// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle. +class VTKM_CONT_EXPORT ArrayHandleVirtualCoordinates final + : public vtkm::cont::ArrayHandleVirtual> { public: using ValueType = vtkm::Vec; + using StorageTag = vtkm::cont::StorageTagVirtual; - VTKM_EXEC_CONT ArrayPortalVirtualCoordinates() - : NumberOfValues(0) - , VirtualPortal(nullptr) + using NonDefaultCoord = typename std::conditional::value, + vtkm::Vec, + vtkm::Vec>::type; + + ArrayHandleVirtualCoordinates() + : vtkm::cont::ArrayHandleVirtual() { } - VTKM_EXEC_CONT ArrayPortalVirtualCoordinates(vtkm::Id numberOfValues, - const CoordinatesPortalBase* virtualPortal) - : NumberOfValues(numberOfValues) - , VirtualPortal(virtualPortal) - { - } - - VTKM_EXEC_CONT vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; } - - VTKM_EXEC_CONT ValueType Get(vtkm::Id i) const { return this->VirtualPortal->Get(i); } - - VTKM_EXEC_CONT void Set(vtkm::Id i, const ValueType& val) const - { - this->VirtualPortal->Set(i, val); - } - -private: - vtkm::Id NumberOfValues; - const CoordinatesPortalBase* VirtualPortal; -}; - -//============================================================================= -class VTKM_ALWAYS_EXPORT CoordinatesArrayHandleBase -{ -public: - using Portal = ArrayPortalVirtualCoordinates; - using PortalConst = ArrayPortalVirtualCoordinates; - - virtual ~CoordinatesArrayHandleBase() = default; - - VTKM_CONT virtual vtkm::Id GetNumberOfValues() const = 0; - - VTKM_CONT virtual Portal GetPortalControl() = 0; - VTKM_CONT virtual PortalConst GetPortalConstControl() = 0; - VTKM_CONT virtual void Allocate(vtkm::Id numberOfValues) = 0; - VTKM_CONT virtual void Shrink(vtkm::Id numberOfValues) = 0; - VTKM_CONT virtual void ReleaseResources() = 0; - VTKM_CONT virtual void ReleaseResourcesExecution() = 0; - - VTKM_CONT virtual PortalConst PrepareForInput(vtkm::cont::DeviceAdapterId deviceId) = 0; - VTKM_CONT virtual Portal PrepareForOutput(vtkm::Id numberOfValues, - vtkm::cont::DeviceAdapterId deviceId) = 0; - VTKM_CONT virtual Portal PrepareForInPlace(vtkm::cont::DeviceAdapterId deviceId) = 0; -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesArrayHandleArrayWrapper : public CoordinatesArrayHandleBase -{ -public: - VTKM_CONT explicit CoordinatesArrayHandleArrayWrapper(const ArrayHandleType& array) - : Array(array) - { - } - - VTKM_CONT const ArrayHandleType& GetArray() const { return this->Array; } - -protected: - ArrayHandleType Array; -}; - -template -class VTKM_ALWAYS_EXPORT CoordinatesArrayHandle - : public CoordinatesArrayHandleArrayWrapper -{ -public: - static_assert(std::is_same::value, "error"); - - using Portal = CoordinatesArrayHandleBase::Portal; - using PortalConst = CoordinatesArrayHandleBase::PortalConst; - - VTKM_CONT explicit CoordinatesArrayHandle(const ArrayHandleType& array) - : CoordinatesArrayHandleArrayWrapper(array) - { - } - - VTKM_CONT vtkm::Id GetNumberOfValues() const override { return this->Array.GetNumberOfValues(); } - - VTKM_CONT Portal GetPortalControl() override - { - this->ControlPortal.SetPortal(this->Array.GetPortalControl()); - return Portal(this->GetNumberOfValues(), &this->ControlPortal); - } - - VTKM_CONT PortalConst GetPortalConstControl() override - { - this->ControlConstPortal.SetPortal(this->Array.GetPortalConstControl()); - return PortalConst(this->GetNumberOfValues(), &this->ControlConstPortal); - } - - VTKM_CONT void Allocate(vtkm::Id numberOfValues) override - { - this->Array.Allocate(numberOfValues); - } - - VTKM_CONT void Shrink(vtkm::Id numberOfValues) override { this->Array.Shrink(numberOfValues); } - - VTKM_CONT void ReleaseResources() override { this->Array.ReleaseResources(); } - - VTKM_CONT void ReleaseResourcesExecution() override { this->Array.ReleaseResourcesExecution(); } - - VTKM_CONT PortalConst PrepareForInput(vtkm::cont::DeviceAdapterId deviceId) override - { - - PortalConst portal; - bool success = vtkm::cont::TryExecuteOnDevice( - deviceId, PrepareForInputFunctor(), DeviceList(), this, portal); - if (!success) - { - throwFailedRuntimeDeviceTransfer("ArrayHandleVirtualCoordinates", deviceId); - } - return portal; - } - - VTKM_CONT Portal PrepareForOutput(vtkm::Id numberOfValues, - vtkm::cont::DeviceAdapterId deviceId) override - { - Portal portal; - bool success = vtkm::cont::TryExecuteOnDevice( - deviceId, PrepareForOutputFunctor(), DeviceList(), this, numberOfValues, portal); - if (!success) - { - throwFailedRuntimeDeviceTransfer("ArrayHandleVirtualCoordinates", deviceId); - } - return portal; - } - - VTKM_CONT Portal PrepareForInPlace(vtkm::cont::DeviceAdapterId deviceId) override - { - Portal portal; - bool success = vtkm::cont::TryExecuteOnDevice( - deviceId, PrepareForInPlaceFunctor(), DeviceList(), this, portal); - if (!success) - { - throwFailedRuntimeDeviceTransfer("ArrayHandleVirtualCoordinates", deviceId); - } - return portal; - } - -private: - struct PrepareForInputFunctor - { - template - VTKM_CONT bool operator()(DeviceAdapter device, - CoordinatesArrayHandle* instance, - PortalConst& ret) const - { - auto portal = instance->Array.PrepareForInput(device); - instance->DevicePortalHandle.Reset(new CoordinatesPortalConst(portal), - true, - vtkm::ListTagBase()); - ret = PortalConst(portal.GetNumberOfValues(), - instance->DevicePortalHandle.PrepareForExecution(device)); - return true; - } - }; - - struct PrepareForOutputFunctor - { - template - VTKM_CONT bool operator()(DeviceAdapter device, - CoordinatesArrayHandle* instance, - vtkm::Id numberOfValues, - Portal& ret) const - { - auto portal = instance->Array.PrepareForOutput(numberOfValues, device); - instance->DevicePortalHandle.Reset( - new CoordinatesPortal(portal), true, vtkm::ListTagBase()); - ret = Portal(numberOfValues, instance->DevicePortalHandle.PrepareForExecution(device)); - return true; - } - }; - - struct PrepareForInPlaceFunctor - { - template - VTKM_CONT bool operator()(DeviceAdapter device, - CoordinatesArrayHandle* instance, - Portal& ret) const - { - auto portal = instance->Array.PrepareForInPlace(device); - instance->DevicePortalHandle.Reset( - new CoordinatesPortal(portal), true, vtkm::ListTagBase()); - ret = Portal(instance->Array.GetNumberOfValues(), - instance->DevicePortalHandle.PrepareForExecution(device)); - return true; - } - }; - - CoordinatesPortal ControlPortal; - CoordinatesPortalConst ControlConstPortal; - vtkm::cont::VirtualObjectHandle DevicePortalHandle; -}; - -//============================================================================= -struct VTKM_ALWAYS_EXPORT StorageTagVirtualCoordinates -{ -}; - -template <> -class VTKM_ALWAYS_EXPORT Storage, StorageTagVirtualCoordinates> -{ -public: - using ValueType = vtkm::Vec; - using PortalType = CoordinatesArrayHandleBase::Portal; - using PortalConstType = CoordinatesArrayHandleBase::PortalConst; - - VTKM_CONT Storage() = default; - - template - VTKM_CONT explicit Storage(const ArrayHandleType& array, DeviceList) - : Array(new CoordinatesArrayHandle(array)) - { - } - - VTKM_CONT PortalType GetPortal() { return this->Array->GetPortalControl(); } - - VTKM_CONT PortalConstType GetPortalConst() const { return this->Array->GetPortalConstControl(); } - - VTKM_CONT vtkm::Id GetNumberOfValues() const { return this->Array->GetNumberOfValues(); } - - VTKM_CONT void Allocate(vtkm::Id numberOfValues) { this->Array->Allocate(numberOfValues); } - - VTKM_CONT void Shrink(vtkm::Id numberOfValues) { this->Array->Shrink(numberOfValues); } - - VTKM_CONT void ReleaseResources() { this->Array->ReleaseResources(); } - - VTKM_CONT CoordinatesArrayHandleBase* GetVirtualArray() const { return this->Array.get(); } - -private: - std::shared_ptr Array; -}; - -//============================================================================= -template -class VTKM_ALWAYS_EXPORT - ArrayTransfer, StorageTagVirtualCoordinates, DeviceAdapter> -{ -public: - using ValueType = vtkm::Vec; - using StorageType = vtkm::cont::internal::Storage; - - using PortalControl = typename StorageType::PortalType; - using PortalConstControl = typename StorageType::PortalConstType; - using PortalExecution = CoordinatesArrayHandleBase::Portal; - using PortalConstExecution = CoordinatesArrayHandleBase::PortalConst; - - VTKM_CONT - ArrayTransfer(StorageType* storage) - : Array(storage->GetVirtualArray()) - { - } - - VTKM_CONT - vtkm::Id GetNumberOfValues() const { return this->Array->GetNumberOfValues(); } - - VTKM_CONT - PortalConstExecution PrepareForInput(bool) - { - return this->Array->PrepareForInput(DeviceAdapter()); - } - - VTKM_CONT - PortalExecution PrepareForInPlace(bool) - { - return this->Array->PrepareForInPlace(DeviceAdapter()); - } - - VTKM_CONT - PortalExecution PrepareForOutput(vtkm::Id numberOfValues) - { - return this->Array->PrepareForOutput(numberOfValues, DeviceAdapter()); - } - - VTKM_CONT - void RetrieveOutputData(StorageType*) const - { - // Implementation of this method should be unnecessary. - } - - VTKM_CONT - void Shrink(vtkm::Id numberOfValues) { this->Array->Shrink(numberOfValues); } - - // ArrayTransfer should only be capable of releasing resources in the execution - // environment - VTKM_CONT - void ReleaseResources() { this->Array->ReleaseResourcesExecution(); } - -private: - CoordinatesArrayHandleBase* Array; -}; - -} // internal - -//============================================================================= -class VTKM_ALWAYS_EXPORT ArrayHandleVirtualCoordinates - : public ArrayHandle, internal::StorageTagVirtualCoordinates> -{ -public: - VTKM_ARRAY_HANDLE_SUBCLASS_NT( - ArrayHandleVirtualCoordinates, - (ArrayHandle, internal::StorageTagVirtualCoordinates>)); - - template explicit ArrayHandleVirtualCoordinates( - const vtkm::cont::ArrayHandle, StorageTag>& array, - DeviceList devices = DeviceList()) - : Superclass(typename Superclass::StorageType(array, devices)) + const vtkm::cont::ArrayHandle& ah) + : vtkm::cont::ArrayHandleVirtual(ah) { } - template - explicit ArrayHandleVirtualCoordinates( - const vtkm::cont::ArrayHandle, StorageTag>& array, - DeviceList devices = DeviceList()) - : Superclass(typename Superclass::StorageType(array, devices)) + template + explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle& ah) + : vtkm::cont::ArrayHandleVirtual( + std::make_shared>(ah)) { } - template - bool IsType() const + template + explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle& ah) + : vtkm::cont::ArrayHandleVirtual() { - return this->GetArrayHandleWrapper() != nullptr; + auto castedHandle = vtkm::cont::make_ArrayHandleCast(ah); + using ST = typename decltype(castedHandle)::StorageTag; + this->Storage = std::make_shared>(castedHandle); } + /// Returns this array cast to the given \c ArrayHandle type. Throws \c + /// ErrorBadType if the cast does not work. Use \c IsType + /// to check if the cast can happen. + /// template - bool IsSameType(const ArrayHandleType&) const + VTKM_CONT ArrayHandleType Cast() const { - return this->GetArrayHandleWrapper() != nullptr; - } - - template - const ArrayHandleType Cast() const - { - auto wrapper = this->GetArrayHandleWrapper(); - if (!wrapper) - { - VTKM_LOG_CAST_FAIL(*this, ArrayHandleType); - throw vtkm::cont::ErrorBadType("dynamic cast failed"); - } - VTKM_LOG_CAST_SUCC(*this, wrapper->GetArray()); - return ArrayHandleType(wrapper->GetArray()); - } - -private: - template - struct WrapperType - { - VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - - using ValueType = typename ArrayHandleType::ValueType; - using StorageTag = typename ArrayHandleType::StorageTag; - using BaseArrayHandleType = vtkm::cont::ArrayHandle; - using Type = internal::CoordinatesArrayHandleArrayWrapper; - }; - - template - VTKM_CONT const typename WrapperType::Type* GetArrayHandleWrapper() const - { - auto va = this->GetStorage().GetVirtualArray(); - return dynamic_cast::Type*>(va); + using T = typename ArrayHandleType::ValueType; + using S = typename ArrayHandleType::StorageTag; + const vtkm::cont::StorageVirtual* storage = this->GetStorage(); + const auto* any = storage->Cast>(); + return any->GetHandle(); } }; @@ -515,9 +98,11 @@ void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords, Functor&& f, Args&&... args) { - if (coords.IsType()) + using HandleType = ArrayHandleUniformPointCoordinates; + if (coords.IsType()) { - f(coords.Cast(), std::forward(args)...); + HandleType uniform = coords.Cast(); + f(uniform, std::forward(args)...); } else { @@ -525,113 +110,13 @@ void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords, } } -template -void CastAndCall(const typename vtkm::cont::ArrayHandleVirtualCoordinates::Superclass& coords, - Functor&& f, - Args&&... args) -{ - CastAndCall(static_cast(coords), - std::forward(f), - std::forward(args)...); -} -} -} // vtkm::cont -#ifdef VTKM_CUDA - -// Cuda seems to have a bug where it expects the template class VirtualObjectTransfer -// to be instantiated in a consistent order among all the translation units of an -// executable. Failing to do so results in random crashes and incorrect results. -// We workaroud this issue by explicitly instantiating VirtualObjectTransfer for -// all the portal types here. - -#include - -#include -#include -#include -#include -#include -#include - -namespace vtkm -{ -namespace cont -{ -namespace internal -{ - -template -struct CudaPortalTypes -{ - using PortalConst = typename ArrayHandleType::template ExecutionTypes< - vtkm::cont::DeviceAdapterTagCuda>::PortalConst; - using Portal = - typename ArrayHandleType::template ExecutionTypes::Portal; -}; - -using CudaPortalsBasicF32 = CudaPortalTypes>>; -using CudaPortalsBasicF64 = CudaPortalTypes>>; -using CudaPortalsUniformPointCoordinates = - CudaPortalTypes; -using CudaPortalsRectilinearCoords = CudaPortalTypes< - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>>; -using CudaPortalsCompositeCoords = CudaPortalTypes< - vtkm::cont::ArrayHandleCompositeVector, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>>; -} -} -} // vtkm::cont::internal - -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::cont::internal::CoordinatesPortalConst< - vtkm::cont::internal::CudaPortalsBasicF32::PortalConst>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortal); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::cont::internal::CoordinatesPortalConst< - vtkm::cont::internal::CudaPortalsBasicF64::PortalConst>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortal); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortalConst< - vtkm::cont::internal::CudaPortalsUniformPointCoordinates::PortalConst>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortal< - vtkm::cont::internal::CudaPortalsUniformPointCoordinates::Portal>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortalConst< - vtkm::cont::internal::CudaPortalsRectilinearCoords::PortalConst>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::cont::internal::CoordinatesPortal< - vtkm::cont::internal::CudaPortalsRectilinearCoords::Portal>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER( - vtkm::cont::internal::CoordinatesPortalConst< - vtkm::cont::internal::CudaPortalsCompositeCoords::PortalConst>); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::cont::internal::CoordinatesPortal< - vtkm::cont::internal::CudaPortalsCompositeCoords::Portal>); - -#endif // VTKM_CUDA - -//============================================================================= -// Specializations of serialization related classes -namespace vtkm -{ -namespace cont -{ template <> struct TypeString { static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; } }; - -template <> -struct TypeString, - vtkm::cont::internal::StorageTagVirtualCoordinates>> - : TypeString -{ -}; } } // vtkm::cont @@ -655,16 +140,23 @@ public: static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) { const auto& virtArray = static_cast(obj); + const vtkm::cont::StorageVirtual* storage = virtArray.GetStorage(); if (virtArray.IsType()) { - auto array = virtArray.Cast(); - diy::save(bb, vtkm::cont::TypeString::Get()); + using HandleType = vtkm::cont::ArrayHandleUniformPointCoordinates; + using T = typename HandleType::ValueType; + using S = typename HandleType::StorageTag; + auto array = storage->Cast>(); + diy::save(bb, vtkm::cont::TypeString::Get()); diy::save(bb, array); } else if (virtArray.IsType()) { - auto array = virtArray.Cast(); - diy::save(bb, vtkm::cont::TypeString::Get()); + using HandleType = RectilinearCoordsArrayType; + using T = typename HandleType::ValueType; + using S = typename HandleType::StorageTag; + auto array = storage->Cast>(); + diy::save(bb, vtkm::cont::TypeString::Get()); diy::save(bb, array); } else @@ -705,13 +197,6 @@ public: } }; -template <> -struct Serialization, - vtkm::cont::internal::StorageTagVirtualCoordinates>> - : Serialization -{ -}; - } // diy #endif // vtk_m_cont_ArrayHandleVirtualCoordinates_h diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index 54b0734b2..8f05fc585 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -25,8 +25,8 @@ #include #include +#include #include -#include #include namespace vtkm diff --git a/vtkm/cont/CoordinateSystem.cxx b/vtkm/cont/CoordinateSystem.cxx index a5e416492..7973ee2b0 100644 --- a/vtkm/cont/CoordinateSystem.cxx +++ b/vtkm/cont/CoordinateSystem.cxx @@ -27,10 +27,6 @@ namespace vtkm namespace cont { -using CoordinatesTypeList = vtkm::ListTagBase; -using CoordinatesStorageList = - vtkm::ListTagBase; - VTKM_CONT CoordinateSystem::CoordinateSystem() : Superclass() { @@ -38,7 +34,7 @@ VTKM_CONT CoordinateSystem::CoordinateSystem() VTKM_CONT CoordinateSystem::CoordinateSystem( std::string name, - const vtkm::cont::ArrayHandleVirtualCoordinates::Superclass& data) + const vtkm::cont::ArrayHandleVirtual>& data) : Superclass(name, Association::POINTS, data) { } @@ -64,7 +60,8 @@ vtkm::cont::ArrayHandleVirtualCoordinates CoordinateSystem::GetData() const } VTKM_CONT -void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleVirtualCoordinates::Superclass& newdata) +void CoordinateSystem::SetData( + const vtkm::cont::ArrayHandleVirtual>& newdata) { this->Superclass::SetData(newdata); } @@ -76,26 +73,6 @@ void CoordinateSystem::PrintSummary(std::ostream& out) const this->Superclass::PrintSummary(out); } -VTKM_CONT -void CoordinateSystem::GetRange(vtkm::Range* range) const -{ - this->Superclass::GetRange(range, CoordinatesTypeList(), CoordinatesStorageList()); -} - -VTKM_CONT -const vtkm::cont::ArrayHandle& CoordinateSystem::GetRange() const -{ - return this->Superclass::GetRange(CoordinatesTypeList(), CoordinatesStorageList()); -} - -VTKM_CONT -vtkm::Bounds CoordinateSystem::GetBounds() const -{ - vtkm::Range ranges[3]; - this->GetRange(ranges); - return vtkm::Bounds(ranges[0], ranges[1], ranges[2]); -} - template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem( std::string name, const vtkm::cont::ArrayHandle>&); @@ -141,12 +118,12 @@ template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem( vtkm::cont::ArrayHandle>::StorageTag>&); template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem(std::string name, - const vtkm::cont::DynamicArrayHandle&); + const vtkm::cont::ArrayHandleVariant&); template VTKM_CONT_EXPORT void CoordinateSystem::SetData( const vtkm::cont::ArrayHandle>&); template VTKM_CONT_EXPORT void CoordinateSystem::SetData( const vtkm::cont::ArrayHandle>&); -template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::DynamicArrayHandle&); +template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleVariant&); } } // namespace vtkm::cont diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index 3a303d555..abf0cdf75 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -33,17 +33,20 @@ namespace cont class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field { using Superclass = vtkm::cont::Field; + using CoordinatesTypeList = + vtkm::ListTagBase; public: VTKM_CONT CoordinateSystem(); - VTKM_CONT CoordinateSystem(std::string name, - const vtkm::cont::ArrayHandleVirtualCoordinates::Superclass& data); + VTKM_CONT CoordinateSystem( + std::string name, + const vtkm::cont::ArrayHandleVirtual>& data); - template + template VTKM_CONT CoordinateSystem(std::string name, - const vtkm::cont::DynamicArrayHandleBase& data); + const vtkm::cont::ArrayHandleVariantBase& data); template VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle& data); @@ -60,23 +63,35 @@ public: VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates GetData() const; - VTKM_CONT void SetData(const vtkm::cont::ArrayHandleVirtualCoordinates::Superclass& newdata); + VTKM_CONT void SetData( + const vtkm::cont::ArrayHandleVirtual>& newdata); - template - VTKM_CONT void SetData(const vtkm::cont::ArrayHandle& newdata); + template + VTKM_CONT void SetData(const vtkm::cont::ArrayHandle& newdata); VTKM_CONT - template - void SetData(const vtkm::cont::DynamicArrayHandleBase& newdata); + template + void SetData(const vtkm::cont::ArrayHandleVariantBase& newdata); VTKM_CONT - void GetRange(vtkm::Range* range) const; + void GetRange(vtkm::Range* range) const + { + this->Superclass::GetRange(range, CoordinatesTypeList()); + } VTKM_CONT - const vtkm::cont::ArrayHandle& GetRange() const; + const vtkm::cont::ArrayHandle& GetRange() const + { + return this->Superclass::GetRange(CoordinatesTypeList()); + } VTKM_CONT - vtkm::Bounds GetBounds() const; + vtkm::Bounds GetBounds() const + { + vtkm::Range ranges[3]; + this->GetRange(ranges); + return vtkm::Bounds(ranges[0], ranges[1], ranges[2]); + } virtual void PrintSummary(std::ostream& out) const override; diff --git a/vtkm/cont/CoordinateSystem.hxx b/vtkm/cont/CoordinateSystem.hxx index 184fedc90..f009e7192 100644 --- a/vtkm/cont/CoordinateSystem.hxx +++ b/vtkm/cont/CoordinateSystem.hxx @@ -48,22 +48,22 @@ struct MakeArrayHandleVirtualCoordinatesFunctor } }; -template +template VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates MakeArrayHandleVirtualCoordinates( - const vtkm::cont::DynamicArrayHandleBase& array) + const vtkm::cont::ArrayHandleVariantBase& array) { vtkm::cont::ArrayHandleVirtualCoordinates output; - vtkm::cont::CastAndCall(array.ResetTypeList(vtkm::TypeListTagFieldVec3{}), + vtkm::cont::CastAndCall(array.ResetTypes(vtkm::TypeListTagFieldVec3{}), MakeArrayHandleVirtualCoordinatesFunctor{}, output); return output; } } // namespace detail -template +template VTKM_CONT CoordinateSystem::CoordinateSystem( std::string name, - const vtkm::cont::DynamicArrayHandleBase& data) + const vtkm::cont::ArrayHandleVariantBase& data) : Superclass(name, Association::POINTS, detail::MakeArrayHandleVirtualCoordinates(data)) { } @@ -81,9 +81,9 @@ VTKM_CONT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleSetData(vtkm::cont::ArrayHandleVirtualCoordinates(newdata)); } -template +template VTKM_CONT void CoordinateSystem::SetData( - const vtkm::cont::DynamicArrayHandleBase& newdata) + const vtkm::cont::ArrayHandleVariantBase& newdata) { this->SetData(detail::MakeArrayHandleVirtualCoordinates(newdata)); } diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index 555d7c41a..80c06cff2 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -23,9 +23,9 @@ #include #include +#include #include #include -#include #include #include #include @@ -193,7 +193,6 @@ namespace cont { template struct SerializableDataSet { @@ -212,12 +211,11 @@ struct SerializableDataSet namespace diy { -template -struct Serialization< - vtkm::cont::SerializableDataSet> +template +struct Serialization> { private: - using Type = vtkm::cont::SerializableDataSet; + using Type = vtkm::cont::SerializableDataSet; public: static VTKM_CONT void save(BinaryBuffer& bb, const Type& serializable) @@ -242,8 +240,7 @@ public: diy::save(bb, numberOfFields); for (vtkm::IdComponent i = 0; i < numberOfFields; ++i) { - diy::save( - bb, vtkm::cont::SerializableField(dataset.GetField(i))); + diy::save(bb, vtkm::cont::SerializableField(dataset.GetField(i))); } } @@ -274,7 +271,7 @@ public: diy::load(bb, numberOfFields); for (vtkm::IdComponent i = 0; i < numberOfFields; ++i) { - vtkm::cont::SerializableField field; + vtkm::cont::SerializableField field; diy::load(bb, field); dataset.AddField(field.Field); } diff --git a/vtkm/cont/DataSetFieldAdd.h b/vtkm/cont/DataSetFieldAdd.h index 8e5a04924..ae99538ae 100644 --- a/vtkm/cont/DataSetFieldAdd.h +++ b/vtkm/cont/DataSetFieldAdd.h @@ -38,7 +38,7 @@ public: VTKM_CONT static void AddPointField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::DynamicArrayHandle& field) + const vtkm::cont::ArrayHandleVariant& field) { dataSet.AddField(Field(fieldName, vtkm::cont::Field::Association::POINTS, field)); } @@ -74,7 +74,7 @@ public: VTKM_CONT static void AddCellField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::DynamicArrayHandle& field, + const vtkm::cont::ArrayHandleVariant& field, const std::string& cellSetName) { dataSet.AddField( @@ -119,7 +119,7 @@ public: VTKM_CONT static void AddCellField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::DynamicArrayHandle& field, + const vtkm::cont::ArrayHandleVariant& field, vtkm::Id cellSetIndex = 0) { std::string cellSetName = dataSet.GetCellSet(cellSetIndex).GetName(); diff --git a/vtkm/cont/Field.cxx b/vtkm/cont/Field.cxx index ae5977f78..20093a89a 100644 --- a/vtkm/cont/Field.cxx +++ b/vtkm/cont/Field.cxx @@ -18,7 +18,7 @@ // this software. //============================================================================ -#include +#include "Field.h" namespace vtkm { @@ -27,7 +27,7 @@ namespace cont /// constructors for points / whole mesh VTKM_CONT -Field::Field(std::string name, Association association, const vtkm::cont::DynamicArrayHandle& data) +Field::Field(std::string name, Association association, const vtkm::cont::ArrayHandleVariant& data) : Name(name) , FieldAssociation(association) , AssocCellSetName() @@ -45,7 +45,7 @@ VTKM_CONT Field::Field(std::string name, Association association, const std::string& cellSetName, - const vtkm::cont::DynamicArrayHandle& data) + const vtkm::cont::ArrayHandleVariant& data) : Name(name) , FieldAssociation(association) , AssocCellSetName(cellSetName) @@ -62,7 +62,7 @@ VTKM_CONT Field::Field(std::string name, Association association, vtkm::IdComponent logicalDim, - const vtkm::cont::DynamicArrayHandle& data) + const vtkm::cont::ArrayHandleVariant& data) : Name(name) , FieldAssociation(association) , AssocCellSetName() @@ -155,36 +155,18 @@ Field::~Field() { } -VTKM_CONT -const vtkm::cont::ArrayHandle& Field::GetRange() const -{ - return this->GetRange(VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); -} VTKM_CONT -void Field::GetRange(vtkm::Range* range) const -{ - this->GetRange(range, VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); -} - -VTKM_CONT -const vtkm::cont::DynamicArrayHandle& Field::GetData() const +const vtkm::cont::ArrayHandleVariant& Field::GetData() const { return this->Data; } VTKM_CONT -vtkm::cont::DynamicArrayHandle& Field::GetData() +vtkm::cont::ArrayHandleVariant& Field::GetData() { this->ModifiedFlag = true; return this->Data; } - -VTKM_CONT -const vtkm::cont::ArrayHandle& Field::GetRange(VTKM_DEFAULT_TYPE_LIST_TAG, - VTKM_DEFAULT_STORAGE_LIST_TAG) const -{ - return this->GetRangeImpl(VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); -} } } // namespace vtkm::cont diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index 66abbe658..a75accfe5 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -26,9 +26,10 @@ #include #include +#include #include #include -#include +#include namespace vtkm { @@ -38,26 +39,18 @@ namespace cont namespace internal { -class ComputeRange +struct ComputeRange { -public: - ComputeRange(ArrayHandle& range) - : Range(&range) - { - } - template - void operator()(const ArrayHandleType& input) const + void operator()(const ArrayHandleType& input, vtkm::cont::ArrayHandle& range) const { - *this->Range = vtkm::cont::ArrayRangeCompute(input); + range = vtkm::cont::ArrayRangeCompute(input); } - -private: - vtkm::cont::ArrayHandle* Range; }; } // namespace internal + /// A \c Field encapsulates an array on some piece of the mesh, such as /// the points, a cell set, a point logical dimension, or the whole mesh. /// @@ -78,11 +71,13 @@ public: /// constructors for points / whole mesh VTKM_CONT - Field(std::string name, Association association, const vtkm::cont::DynamicArrayHandle& data); + Field(std::string name, Association association, const vtkm::cont::ArrayHandleVariant& data); template - VTKM_CONT Field(std::string name, Association association, const ArrayHandle& data) - : Field(name, association, vtkm::cont::DynamicArrayHandle{ data }) + VTKM_CONT Field(std::string name, + Association association, + const vtkm::cont::ArrayHandle& data) + : Field(name, association, vtkm::cont::ArrayHandleVariant{ data }) { } @@ -91,14 +86,14 @@ public: Field(std::string name, Association association, const std::string& cellSetName, - const vtkm::cont::DynamicArrayHandle& data); + const vtkm::cont::ArrayHandleVariant& data); template VTKM_CONT Field(std::string name, Association association, const std::string& cellSetName, const vtkm::cont::ArrayHandle& data) - : Field(name, association, cellSetName, vtkm::cont::DynamicArrayHandle{ data }) + : Field(name, association, cellSetName, vtkm::cont::ArrayHandleVariant{ data }) { } @@ -107,14 +102,14 @@ public: Field(std::string name, Association association, vtkm::IdComponent logicalDim, - const vtkm::cont::DynamicArrayHandle& data); + const vtkm::cont::ArrayHandleVariant& data); template VTKM_CONT Field(std::string name, Association association, vtkm::IdComponent logicalDim, const vtkm::cont::ArrayHandle& data) - : Field(name, association, logicalDim, vtkm::cont::DynamicArrayHandle{ data }) + : Field(name, association, logicalDim, vtkm::cont::ArrayHandleVariant{ data }) { } @@ -126,40 +121,19 @@ public: VTKM_CONT Field& operator=(const vtkm::cont::Field& src); VTKM_CONT Field& operator=(vtkm::cont::Field&& src) noexcept; - VTKM_CONT - const std::string& GetName() const { return this->Name; } + VTKM_CONT const std::string& GetName() const { return this->Name; } + VTKM_CONT Association GetAssociation() const { return this->FieldAssociation; } + VTKM_CONT std::string GetAssocCellSet() const { return this->AssocCellSetName; } + VTKM_CONT vtkm::IdComponent GetAssocLogicalDim() const { return this->AssocLogicalDim; } + const vtkm::cont::ArrayHandleVariant& GetData() const; + vtkm::cont::ArrayHandleVariant& GetData(); - VTKM_CONT - Association GetAssociation() const { return this->FieldAssociation; } - VTKM_CONT - std::string GetAssocCellSet() const { return this->AssocCellSetName; } - - VTKM_CONT - vtkm::IdComponent GetAssocLogicalDim() const { return this->AssocLogicalDim; } - - template - VTKM_CONT const vtkm::cont::ArrayHandle& GetRange(TypeList, StorageList) const + template + VTKM_CONT void GetRange(vtkm::Range* range, TypeList) const { - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - return this->GetRangeImpl(TypeList(), StorageList()); - } - - VTKM_CONT - const vtkm::cont::ArrayHandle& GetRange(VTKM_DEFAULT_TYPE_LIST_TAG, - VTKM_DEFAULT_STORAGE_LIST_TAG) const; - - template - VTKM_CONT void GetRange(vtkm::Range* range, TypeList, StorageList) const - { - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - this->GetRange(TypeList(), StorageList()); - - vtkm::Id length = this->Range.GetNumberOfValues(); + this->GetRangeImpl(TypeList()); + const vtkm::Id length = this->Range.GetNumberOfValues(); for (vtkm::Id i = 0; i < length; ++i) { range[i] = this->Range.GetPortalConstControl().Get(i); @@ -169,28 +143,19 @@ public: template VTKM_CONT const vtkm::cont::ArrayHandle& GetRange(TypeList) const { - VTKM_IS_LIST_TAG(TypeList); - - return this->GetRange(TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return this->GetRangeImpl(TypeList()); } - template - VTKM_CONT void GetRange(vtkm::Range* range, TypeList) const + VTKM_CONT + const vtkm::cont::ArrayHandle& GetRange() const { - VTKM_IS_LIST_TAG(TypeList); + return this->GetRangeImpl(VTKM_DEFAULT_TYPE_LIST_TAG()); + }; - this->GetRange(range, TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); - } - - VTKM_CONT - const vtkm::cont::ArrayHandle& GetRange() const; - - VTKM_CONT - void GetRange(vtkm::Range* range) const; - - const vtkm::cont::DynamicArrayHandle& GetData() const; - - vtkm::cont::DynamicArrayHandle& GetData(); + VTKM_CONT void GetRange(vtkm::Range* range) const + { + return this->GetRange(range, VTKM_DEFAULT_TYPE_LIST_TAG()); + }; template VTKM_CONT void SetData(const vtkm::cont::ArrayHandle& newdata) @@ -200,27 +165,19 @@ public: } VTKM_CONT - void SetData(const vtkm::cont::DynamicArrayHandle& newdata) + void SetData(const vtkm::cont::ArrayHandleVariant& newdata) { this->Data = newdata; this->ModifiedFlag = true; } - template - VTKM_CONT void CopyData(const T* ptr, vtkm::Id nvals) - { - this->Data = vtkm::cont::make_ArrayHandle(ptr, nvals, true); - this->ModifiedFlag = true; - } - VTKM_CONT virtual void PrintSummary(std::ostream& out) const; VTKM_CONT virtual void ReleaseResourcesExecution() { - // TODO: Call ReleaseResourcesExecution on the data when - // the DynamicArrayHandle class is able to do so. + this->Data.ReleaseResourcesExecution(); this->Range.ReleaseResourcesExecution(); } @@ -231,20 +188,19 @@ private: std::string AssocCellSetName; ///< only populate if assoc is cells vtkm::IdComponent AssocLogicalDim; ///< only populate if assoc is logical dim - vtkm::cont::DynamicArrayHandle Data; + vtkm::cont::ArrayHandleVariant Data; mutable vtkm::cont::ArrayHandle Range; mutable bool ModifiedFlag = true; - template - VTKM_CONT const vtkm::cont::ArrayHandle& GetRangeImpl(TypeList, StorageList) const + template + VTKM_CONT const vtkm::cont::ArrayHandle& GetRangeImpl(TypeList) const { VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); if (this->ModifiedFlag) { - internal::ComputeRange computeRange(this->Range); - this->Data.ResetTypeAndStorageLists(TypeList(), StorageList()).CastAndCall(computeRange); + vtkm::cont::CastAndCall( + this->Data.ResetTypes(TypeList()), internal::ComputeRange{}, this->Range); this->ModifiedFlag = false; } @@ -255,7 +211,7 @@ private: template void CastAndCall(const vtkm::cont::Field& field, Functor&& f, Args&&... args) { - field.GetData().CastAndCall(std::forward(f), std::forward(args)...); + vtkm::cont::CastAndCall(field.GetData(), std::forward(f), std::forward(args)...); } //@{ @@ -325,15 +281,21 @@ vtkm::cont::Field make_Field(std::string name, } //@} +} // namespace cont +} // namespace vtkm + + +namespace vtkm +{ +namespace cont +{ namespace internal { - template <> struct DynamicTransformTraits { using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; }; - } // namespace internal } // namespace cont } // namespace vtkm @@ -344,9 +306,7 @@ namespace vtkm { namespace cont { - -template +template struct SerializableField { SerializableField() = default; @@ -358,17 +318,17 @@ struct SerializableField vtkm::cont::Field Field; }; -} -} // vtkm::cont +} // namespace cont +} // namespace vtkm namespace diy { -template -struct Serialization> +template +struct Serialization> { private: - using Type = vtkm::cont::SerializableField; + using Type = vtkm::cont::SerializableField; public: static VTKM_CONT void save(BinaryBuffer& bb, const Type& serializable) @@ -385,7 +345,7 @@ public: { diy::save(bb, field.GetAssocLogicalDim()); } - diy::save(bb, field.GetData().ResetTypeAndStorageLists(TypeList{}, StorageList{})); + diy::save(bb, field.GetData().ResetTypes(TypeList{})); } static VTKM_CONT void load(BinaryBuffer& bb, Type& serializable) @@ -398,26 +358,26 @@ public: diy::load(bb, assocVal); auto assoc = static_cast(assocVal); - vtkm::cont::DynamicArrayHandleBase data; + vtkm::cont::ArrayHandleVariantBase data; if (assoc == vtkm::cont::Field::Association::CELL_SET) { std::string assocCellSetName; diy::load(bb, assocCellSetName); diy::load(bb, data); field = - vtkm::cont::Field(name, assoc, assocCellSetName, vtkm::cont::DynamicArrayHandle(data)); + vtkm::cont::Field(name, assoc, assocCellSetName, vtkm::cont::ArrayHandleVariant(data)); } else if (assoc == vtkm::cont::Field::Association::LOGICAL_DIM) { vtkm::IdComponent assocLogicalDim; diy::load(bb, assocLogicalDim); diy::load(bb, data); - field = vtkm::cont::Field(name, assoc, assocLogicalDim, vtkm::cont::DynamicArrayHandle(data)); + field = vtkm::cont::Field(name, assoc, assocLogicalDim, vtkm::cont::ArrayHandleVariant(data)); } else { diy::load(bb, data); - field = vtkm::cont::Field(name, assoc, vtkm::cont::DynamicArrayHandle(data)); + field = vtkm::cont::Field(name, assoc, vtkm::cont::ArrayHandleVariant(data)); } } }; diff --git a/vtkm/cont/FieldRangeCompute.cxx b/vtkm/cont/FieldRangeCompute.cxx index 9cf5c518e..29cfd4750 100644 --- a/vtkm/cont/FieldRangeCompute.cxx +++ b/vtkm/cont/FieldRangeCompute.cxx @@ -34,7 +34,7 @@ vtkm::cont::ArrayHandle FieldRangeCompute(const vtkm::cont::DataSet vtkm::cont::Field::Association assoc) { return vtkm::cont::detail::FieldRangeComputeImpl( - dataset, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + dataset, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG()); } //----------------------------------------------------------------------------- @@ -44,7 +44,7 @@ vtkm::cont::ArrayHandle FieldRangeCompute(const vtkm::cont::MultiBl vtkm::cont::Field::Association assoc) { return vtkm::cont::detail::FieldRangeComputeImpl( - multiblock, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + multiblock, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG()); } } } // namespace vtkm::cont diff --git a/vtkm/cont/FieldRangeCompute.h b/vtkm/cont/FieldRangeCompute.h index 233d543c0..2a971483c 100644 --- a/vtkm/cont/FieldRangeCompute.h +++ b/vtkm/cont/FieldRangeCompute.h @@ -47,20 +47,6 @@ vtkm::cont::ArrayHandle FieldRangeCompute( const std::string& name, vtkm::cont::Field::Association assoc = vtkm::cont::Field::Association::ANY); -template -VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( - const vtkm::cont::DataSet& dataset, - const std::string& name, - vtkm::cont::Field::Association assoc, - TypeList, - StorageList) -{ - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - return vtkm::cont::detail::FieldRangeComputeImpl(dataset, name, assoc, TypeList(), StorageList()); -} - template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( const vtkm::cont::DataSet& dataset, @@ -69,9 +55,9 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( TypeList) { VTKM_IS_LIST_TAG(TypeList); - return vtkm::cont::detail::FieldRangeComputeImpl( - dataset, name, assoc, TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return vtkm::cont::detail::FieldRangeComputeImpl(dataset, name, assoc, TypeList()); } + //@} //{@ @@ -88,21 +74,6 @@ vtkm::cont::ArrayHandle FieldRangeCompute( const std::string& name, vtkm::cont::Field::Association assoc = vtkm::cont::Field::Association::ANY); -template -VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( - const vtkm::cont::MultiBlock& multiblock, - const std::string& name, - vtkm::cont::Field::Association assoc, - TypeList, - StorageList) -{ - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - return vtkm::cont::detail::FieldRangeComputeImpl( - multiblock, name, assoc, TypeList(), StorageList()); -} - template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( const vtkm::cont::MultiBlock& multiblock, @@ -111,9 +82,9 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute( TypeList) { VTKM_IS_LIST_TAG(TypeList); - return vtkm::cont::detail::FieldRangeComputeImpl( - multiblock, name, assoc, TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return vtkm::cont::detail::FieldRangeComputeImpl(multiblock, name, assoc, TypeList()); } + //@} } } // namespace vtkm::cont diff --git a/vtkm/cont/FieldRangeCompute.hxx b/vtkm/cont/FieldRangeCompute.hxx index 954d0f9ba..aef17a839 100644 --- a/vtkm/cont/FieldRangeCompute.hxx +++ b/vtkm/cont/FieldRangeCompute.hxx @@ -29,13 +29,12 @@ namespace cont namespace detail { -template +template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeComputeImpl( const vtkm::cont::DataSet& dataset, const std::string& name, vtkm::cont::Field::Association assoc, - TypeList, - StorageList) + TypeList) { vtkm::cont::Field field; try @@ -48,16 +47,15 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeComputeImpl( return vtkm::cont::ArrayHandle(); } - return field.GetRange(TypeList(), StorageList()); + return field.GetRange(TypeList()); } -template +template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeComputeImpl( const vtkm::cont::MultiBlock& multiblock, const std::string& name, vtkm::cont::Field::Association assoc, - TypeList, - StorageList) + TypeList) { std::vector result_vector = std::accumulate( multiblock.begin(), @@ -65,7 +63,7 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeComputeImpl( std::vector(), [&](const std::vector& accumulated_value, const vtkm::cont::DataSet& dataset) { vtkm::cont::ArrayHandle block_range = - vtkm::cont::detail::FieldRangeComputeImpl(dataset, name, assoc, TypeList(), StorageList()); + vtkm::cont::detail::FieldRangeComputeImpl(dataset, name, assoc, TypeList()); std::vector result = accumulated_value; diff --git a/vtkm/cont/FieldRangeGlobalCompute.cxx b/vtkm/cont/FieldRangeGlobalCompute.cxx index 368d83659..b39e23d02 100644 --- a/vtkm/cont/FieldRangeGlobalCompute.cxx +++ b/vtkm/cont/FieldRangeGlobalCompute.cxx @@ -45,8 +45,7 @@ vtkm::cont::ArrayHandle FieldRangeGlobalCompute(const vtkm::cont::D const std::string& name, vtkm::cont::Field::Association assoc) { - return detail::FieldRangeGlobalComputeImpl( - dataset, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return detail::FieldRangeGlobalComputeImpl(dataset, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG()); } //----------------------------------------------------------------------------- @@ -56,8 +55,7 @@ vtkm::cont::ArrayHandle FieldRangeGlobalCompute( const std::string& name, vtkm::cont::Field::Association assoc) { - return detail::FieldRangeGlobalComputeImpl( - multiblock, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return detail::FieldRangeGlobalComputeImpl(multiblock, name, assoc, VTKM_DEFAULT_TYPE_LIST_TAG()); } //----------------------------------------------------------------------------- diff --git a/vtkm/cont/FieldRangeGlobalCompute.h b/vtkm/cont/FieldRangeGlobalCompute.h index b7861436a..9c15b7248 100644 --- a/vtkm/cont/FieldRangeGlobalCompute.h +++ b/vtkm/cont/FieldRangeGlobalCompute.h @@ -45,20 +45,6 @@ vtkm::cont::ArrayHandle FieldRangeGlobalCompute( const std::string& name, vtkm::cont::Field::Association assoc = vtkm::cont::Field::Association::ANY); -template -VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( - const vtkm::cont::DataSet& dataset, - const std::string& name, - vtkm::cont::Field::Association assoc, - TypeList, - StorageList) -{ - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - return detail::FieldRangeGlobalComputeImpl(dataset, name, assoc, TypeList(), StorageList()); -} - template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( const vtkm::cont::DataSet& dataset, @@ -67,9 +53,9 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( TypeList) { VTKM_IS_LIST_TAG(TypeList); - return detail::FieldRangeGlobalComputeImpl( - dataset, name, assoc, TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return detail::FieldRangeGlobalComputeImpl(dataset, name, assoc, TypeList()); } + //@} //{@ @@ -86,20 +72,6 @@ vtkm::cont::ArrayHandle FieldRangeGlobalCompute( const std::string& name, vtkm::cont::Field::Association assoc = vtkm::cont::Field::Association::ANY); -template -VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( - const vtkm::cont::MultiBlock& multiblock, - const std::string& name, - vtkm::cont::Field::Association assoc, - TypeList, - StorageList) -{ - VTKM_IS_LIST_TAG(TypeList); - VTKM_IS_LIST_TAG(StorageList); - - return detail::FieldRangeGlobalComputeImpl(multiblock, name, assoc, TypeList(), StorageList()); -} - template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( const vtkm::cont::MultiBlock& multiblock, @@ -108,8 +80,7 @@ VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalCompute( TypeList) { VTKM_IS_LIST_TAG(TypeList); - return detail::FieldRangeGlobalComputeImpl( - multiblock, name, assoc, TypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + return detail::FieldRangeGlobalComputeImpl(multiblock, name, assoc, TypeList()); } //@} } diff --git a/vtkm/cont/FieldRangeGlobalCompute.hxx b/vtkm/cont/FieldRangeGlobalCompute.hxx index d3f7b3671..be4dc554d 100644 --- a/vtkm/cont/FieldRangeGlobalCompute.hxx +++ b/vtkm/cont/FieldRangeGlobalCompute.hxx @@ -32,27 +32,25 @@ VTKM_CONT vtkm::cont::ArrayHandle MergeRangesGlobal( const vtkm::cont::ArrayHandle& range); -template +template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalComputeImpl( const vtkm::cont::DataSet& dataset, const std::string& name, vtkm::cont::Field::Association assoc, - TypeList, - StorageList) + TypeList) { - auto lrange = vtkm::cont::FieldRangeCompute(dataset, name, assoc, TypeList(), StorageList()); + auto lrange = vtkm::cont::FieldRangeCompute(dataset, name, assoc, TypeList()); return vtkm::cont::detail::MergeRangesGlobal(lrange); } -template +template VTKM_CONT vtkm::cont::ArrayHandle FieldRangeGlobalComputeImpl( const vtkm::cont::MultiBlock& multiblock, const std::string& name, vtkm::cont::Field::Association assoc, - TypeList, - StorageList) + TypeList) { - auto lrange = vtkm::cont::FieldRangeCompute(multiblock, name, assoc, TypeList(), StorageList()); + auto lrange = vtkm::cont::FieldRangeCompute(multiblock, name, assoc, TypeList()); return vtkm::cont::detail::MergeRangesGlobal(lrange); } } diff --git a/vtkm/cont/MultiBlock.cxx b/vtkm/cont/MultiBlock.cxx index 2ce2a1c9f..11a914073 100644 --- a/vtkm/cont/MultiBlock.cxx +++ b/vtkm/cont/MultiBlock.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/vtkm/cont/MultiBlock.h b/vtkm/cont/MultiBlock.h index f6775fc20..279399bb0 100644 --- a/vtkm/cont/MultiBlock.h +++ b/vtkm/cont/MultiBlock.h @@ -25,7 +25,6 @@ #include #include #include -#include #include namespace vtkm diff --git a/vtkm/cont/testing/UnitTestMoveConstructors.cxx b/vtkm/cont/testing/UnitTestMoveConstructors.cxx index eec7c4319..de8c872ac 100644 --- a/vtkm/cont/testing/UnitTestMoveConstructors.cxx +++ b/vtkm/cont/testing/UnitTestMoveConstructors.cxx @@ -18,6 +18,7 @@ // this software. //============================================================================ #include +#include #include #include @@ -77,10 +78,32 @@ struct IsNoExceptHandle template void operator()(T) const { - is_noexcept_movable< vtkm::cont::ArrayHandle >(); + using HandleType = vtkm::cont::ArrayHandle; + using AnyType = vtkm::cont::ArrayHandleAny; + using VirtualType = vtkm::cont::ArrayHandleVirtual; + + //verify the handle type + is_noexcept_movable< HandleType >(); + is_noexcept_movable(); + is_noexcept_movable(); + + //verify the input portals of the handle + is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); + is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); + is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); + + //verify the output portals of the handle + is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); + is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); + is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); } }; - } //----------------------------------------------------------------------------- @@ -91,23 +114,22 @@ void TestContDataTypesHaveMoveSemantics() is_triv_noexcept_movable,3>>(); - //verify that ArrayHandles are noexcept movable + //verify that ArrayHandles and related portals are noexcept movable //allowing for efficient storage in containers such as std::vector vtkm::testing::Testing::TryTypes( IsNoExceptHandle{}, vtkm::TypeListTagAll{} ); - //verify the DataSet, Field, and CoordinateSystem, + //verify the DataSet, Field, CoordinateSystem, and ArrayHandleVirtualCoordinates //all have efficient storage in containers such as std::vector is_noexcept_movable(); is_noexcept_movable(); is_noexcept_movable(); - + is_noexcept_movable(); //verify the CellSetStructured, and CellSetExplicit //have efficient storage in containers such as std::vector is_noexcept_movable>(); is_noexcept_movable>(); is_noexcept_movable>(); - } From 3c6246140ddb55c16c0ed86865e0114be319ae59 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Nov 2018 10:16:59 -0500 Subject: [PATCH 13/36] ArrayRangeCompute now states it has uniform point coord optimization --- vtkm/cont/ArrayRangeCompute.cxx | 29 ----------------------------- vtkm/cont/ArrayRangeCompute.h | 17 ++++++++++------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/vtkm/cont/ArrayRangeCompute.cxx b/vtkm/cont/ArrayRangeCompute.cxx index 147bb84a7..92123604f 100644 --- a/vtkm/cont/ArrayRangeCompute.cxx +++ b/vtkm/cont/ArrayRangeCompute.cxx @@ -76,10 +76,6 @@ VTKM_ARRAY_RANGE_COMPUTE_IMPL_VEC(vtkm::UInt8, 4, vtkm::cont::StorageTagBasic); VTKM_ARRAY_RANGE_COMPUTE_IMPL_VEC(vtkm::Float32, 4, vtkm::cont::StorageTagBasic); VTKM_ARRAY_RANGE_COMPUTE_IMPL_VEC(vtkm::Float64, 4, vtkm::cont::StorageTagBasic); -VTKM_ARRAY_RANGE_COMPUTE_IMPL_VEC(vtkm::FloatDefault, - 3, - vtkm::cont::ArrayHandleVirtualCoordinates::StorageTag); - #undef VTKM_ARRAY_RANGE_COMPUTE_IMPL_T #undef VTKM_ARRAY_RANGE_COMPUTE_IMPL_VEC @@ -107,30 +103,5 @@ vtkm::cont::ArrayHandle ArrayRangeCompute( return rangeArray; } - -// Special implementation for composite vectors. -VTKM_CONT -vtkm::cont::ArrayHandle ArrayRangeCompute( - const vtkm::cont::ArrayHandle, - typename vtkm::cont::ArrayHandleCompositeVector< - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>::StorageTag>& input, - vtkm::cont::RuntimeDeviceTracker tracker) -{ - return detail::ArrayRangeComputeImpl(input, tracker); -} - -VTKM_CONT -vtkm::cont::ArrayHandle ArrayRangeCompute( - const vtkm::cont::ArrayHandle, - typename vtkm::cont::ArrayHandleCompositeVector< - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>::StorageTag>& input, - vtkm::cont::RuntimeDeviceTracker tracker) -{ - return detail::ArrayRangeComputeImpl(input, tracker); -} } } // namespace vtkm::cont diff --git a/vtkm/cont/ArrayRangeCompute.h b/vtkm/cont/ArrayRangeCompute.h index 31c14bd90..a2bde1771 100644 --- a/vtkm/cont/ArrayRangeCompute.h +++ b/vtkm/cont/ArrayRangeCompute.h @@ -52,6 +52,7 @@ VTKM_CONT vtkm::cont::ArrayHandle ArrayRangeCompute( const ArrayHandleType& input, vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); + // Precompiled versions of ArrayRangeCompute #define VTKM_ARRAY_RANGE_COMPUTE_EXPORT_T(T, Storage) \ VTKM_CONT_EXPORT \ @@ -94,17 +95,19 @@ VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt8, 4, vtkm::cont::StorageTagBasic) VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float32, 4, vtkm::cont::StorageTagBasic); VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float64, 4, vtkm::cont::StorageTagBasic); -VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::FloatDefault, - 3, - vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag); - -VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::FloatDefault, - 3, - vtkm::cont::ArrayHandleVirtualCoordinates::StorageTag); #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_T #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC +// Implementation of uniform point coordinates +VTKM_CONT_EXPORT +VTKM_CONT +vtkm::cont::ArrayHandle ArrayRangeCompute( + const vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag>& array, + vtkm::cont::RuntimeDeviceTracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); + + // Implementation of composite vectors VTKM_CONT_EXPORT VTKM_CONT From b57dc5d2894cd4244d4a59db093ea8e35ad9f6a8 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 28 Nov 2018 10:36:45 -0500 Subject: [PATCH 14/36] Update ArrayHandleVirtual to handle PrepareForInPlace. --- vtkm/cont/ArrayHandleAny.h | 2 +- vtkm/cont/ArrayHandleAny.hxx | 25 ++++++++++++++++------ vtkm/cont/ArrayHandleVirtual.h | 2 +- vtkm/cont/StorageVirtual.cxx | 38 +++++++++++++++++++++++++++------- vtkm/cont/StorageVirtual.h | 12 +++++++++++ 5 files changed, 64 insertions(+), 15 deletions(-) diff --git a/vtkm/cont/ArrayHandleAny.h b/vtkm/cont/ArrayHandleAny.h index 54ea1ff29..e36e38f63 100644 --- a/vtkm/cont/ArrayHandleAny.h +++ b/vtkm/cont/ArrayHandleAny.h @@ -73,10 +73,10 @@ private: vtkm::cont::DeviceAdapterId devId) const; void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + OutputMode mode, vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId devId); - vtkm::cont::ArrayHandle Handle; }; diff --git a/vtkm/cont/ArrayHandleAny.hxx b/vtkm/cont/ArrayHandleAny.hxx index ff623da3c..39dd60e53 100644 --- a/vtkm/cont/ArrayHandleAny.hxx +++ b/vtkm/cont/ArrayHandleAny.hxx @@ -70,12 +70,24 @@ struct PortalWrapperToDevice bool operator()(DeviceAdapterTag device, Handle&& handle, vtkm::Id numberOfValues, - vtkm::cont::internal::TransferInfoArray& payload) const + vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::StorageVirtual::OutputMode mode) const { - auto portal = handle.PrepareForOutput(numberOfValues, device); - using DerivedPortal = vtkm::ArrayPortalWrapper; - vtkm::cont::detail::TransferToDevice transfer; - return transfer(device, payload, portal); + using ACCESS_MODE = vtkm::cont::StorageVirtual::OutputMode; + if (mode == ACCESS_MODE::WRITE) + { + auto portal = handle.PrepareForOutput(numberOfValues, device); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::detail::TransferToDevice transfer; + return transfer(device, payload, portal); + } + else + { + auto portal = handle.PrepareForInPlace(device); + using DerivedPortal = vtkm::ArrayPortalWrapper; + vtkm::cont::detail::TransferToDevice transfer; + return transfer(device, payload, portal); + } } }; } @@ -129,11 +141,12 @@ void StorageAny::TransferPortalForInput(vtkm::cont::internal::TransferInfo template void StorageAny::TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::StorageVirtual::OutputMode mode, vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId devId) { vtkm::cont::TryExecuteOnDevice( - devId, detail::PortalWrapperToDevice(), this->Handle, numberOfValues, payload); + devId, detail::PortalWrapperToDevice(), this->Handle, numberOfValues, payload, mode); } } } // namespace vtkm::cont diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index 6c78ca114..4acaeb859 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -239,7 +239,7 @@ public: vtkm::ArrayPortalRef PrepareForInPlace(vtkm::cont::DeviceAdapterId devId) { return make_ArrayPortalRef( - static_cast*>(this->Storage->PrepareForInput(devId)), + static_cast*>(this->Storage->PrepareForInPlace(devId)), this->GetNumberOfValues()); } diff --git a/vtkm/cont/StorageVirtual.cxx b/vtkm/cont/StorageVirtual.cxx index 367251e5f..428fc9b30 100644 --- a/vtkm/cont/StorageVirtual.cxx +++ b/vtkm/cont/StorageVirtual.cxx @@ -122,7 +122,6 @@ Storage::PrepareForInput( //need to re-transfer the execution information auto* payload = this->DeviceTransferState.get(); this->TransferPortalForInput(*payload, devId); - this->HostUpToDate = false; this->DeviceUpToDate = true; } return this->DeviceTransferState->devicePtr(); @@ -145,7 +144,33 @@ Storage::PrepareForOutput(vtkm::Id number const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate); if (needsUpload) { - this->TransferPortalForOutput(*(this->DeviceTransferState), numberOfValues, devId); + this->TransferPortalForOutput( + *(this->DeviceTransferState), OutputMode::WRITE, numberOfValues, devId); + this->HostUpToDate = false; + this->DeviceUpToDate = true; + } + return this->DeviceTransferState->devicePtr(); +} + +//-------------------------------------------------------------------- +const vtkm::internal::PortalVirtualBase* +Storage::PrepareForInPlace(vtkm::cont::DeviceAdapterId devId) +{ + if (devId == vtkm::cont::DeviceAdapterTagUndefined()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED"); + } + if (devId == vtkm::cont::DeviceAdapterTagError()) + { + throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR"); + } + + const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate); + if (needsUpload) + { + vtkm::Id numberOfValues = this->GetNumberOfValues(); + this->TransferPortalForOutput( + *(this->DeviceTransferState), OutputMode::READ_WRITE, numberOfValues, devId); this->HostUpToDate = false; this->DeviceUpToDate = true; } @@ -178,9 +203,6 @@ Storage::GetPortalConstControl() const vtkm::cont::internal::TransferInfoArray* payload = this->DeviceTransferState.get(); this->ControlPortalForInput(*payload); } - //We need to mark the device out of date after the conditions - //as they can modify the state of the device - this->DeviceUpToDate = false; this->HostUpToDate = true; return this->DeviceTransferState->hostPtr(); } @@ -195,16 +217,18 @@ DeviceAdapterId Storage::GetDeviceAdapter void Storage::ControlPortalForOutput( vtkm::cont::internal::TransferInfoArray&) { - throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support output."); + throw vtkm::cont::ErrorBadValue( + "StorageTagVirtual by default doesn't support control side writes."); } //-------------------------------------------------------------------- void Storage::TransferPortalForOutput( vtkm::cont::internal::TransferInfoArray&, + OutputMode, vtkm::Id, vtkm::cont::DeviceAdapterId) { - throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support output."); + throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support exec side writes."); } } } diff --git a/vtkm/cont/StorageVirtual.h b/vtkm/cont/StorageVirtual.h index beb50623a..19e0b1870 100644 --- a/vtkm/cont/StorageVirtual.h +++ b/vtkm/cont/StorageVirtual.h @@ -127,6 +127,8 @@ public: const vtkm::internal::PortalVirtualBase* PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId devId); + const vtkm::internal::PortalVirtualBase* PrepareForInPlace(vtkm::cont::DeviceAdapterId devId); + //This needs to cause a host side sync! //This needs to work before we execute on a device const vtkm::internal::PortalVirtualBase* GetPortalControl(); @@ -140,6 +142,13 @@ public: /// returned. DeviceAdapterId GetDeviceAdapterId() const noexcept; + + enum struct OutputMode + { + WRITE, + READ_WRITE + }; + private: //Memory management routines // virtual void DoAllocate(vtkm::Id numberOfValues) = 0; @@ -153,9 +162,12 @@ private: //Portal routines virtual void ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const = 0; virtual void ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload); + + virtual void TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, vtkm::cont::DeviceAdapterId devId) const = 0; virtual void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + OutputMode mode, vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId devId); From 4c23f50227defc51244b6d248716784f1280da9b Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 28 Nov 2018 11:44:09 -0500 Subject: [PATCH 15/36] ArrayHandleVirtual can be used as AtomicArrayInOut tag type --- vtkm/cont/arg/TransportTagAtomicArray.h | 47 +++++++++++++++++++++++++ vtkm/cont/arg/TypeCheckTagAtomicArray.h | 9 +++++ 2 files changed, 56 insertions(+) diff --git a/vtkm/cont/arg/TransportTagAtomicArray.h b/vtkm/cont/arg/TransportTagAtomicArray.h index 0480aa630..b8e6aa709 100644 --- a/vtkm/cont/arg/TransportTagAtomicArray.h +++ b/vtkm/cont/arg/TransportTagAtomicArray.h @@ -23,7 +23,10 @@ #include #include +#include #include +#include + #include @@ -70,6 +73,50 @@ struct Transport +struct Transport, + Device> +{ + using ExecObjectType = vtkm::exec::AtomicArrayExecutionObject; + using ExecType = vtkm::cont::AtomicArray; + + template + VTKM_CONT ExecObjectType + operator()(vtkm::cont::ArrayHandle& array, + const InputDomainType&, + vtkm::Id, + vtkm::Id) const + { + using S = vtkm::cont::StorageTagBasic; + + const vtkm::cont::StorageVirtual* storage = array.GetStorage(); + if (!storage) + { + throw vtkm::cont::ErrorBadValue("ArrayHandleVirtual must not have a nullptr for storage."); + } + + if (!storage->IsType(typeid(vtkm::cont::internal::Storage))) + { +#if defined(VTKM_ENABLE_LOGGING) + using AH = vtkm::cont::ArrayHandle; + VTKM_LOG_CAST_FAIL(array, AH); +#endif + throw vtkm::cont::ErrorBadValue("Arrays being used as atomic's must always have storage that " + "is of the type StorageTagBasic."); + } + + const auto* any = static_cast*>(storage); + VTKM_LOG_CAST_SUCC(array, *any); + + // Note: we ignore the size of the domain because the randomly accessed + // array might not have the same size depending on how the user is using + // the array. + ExecType obj(any->GetHandle()); + return obj.PrepareForExecution(Device()); + } +}; } } } // namespace vtkm::cont::arg diff --git a/vtkm/cont/arg/TypeCheckTagAtomicArray.h b/vtkm/cont/arg/TypeCheckTagAtomicArray.h index 9eb653d21..7997bc340 100644 --- a/vtkm/cont/arg/TypeCheckTagAtomicArray.h +++ b/vtkm/cont/arg/TypeCheckTagAtomicArray.h @@ -26,6 +26,7 @@ #include #include +#include #include @@ -59,6 +60,14 @@ struct TypeCheck, static constexpr bool value = (vtkm::ListContains::value && vtkm::ListContains::value); }; + +template +struct TypeCheck, + vtkm::cont::ArrayHandle> +{ + static constexpr bool value = (vtkm::ListContains::value && + vtkm::ListContains::value); +}; } } } // namespace vtkm::cont::arg From 28757bda4b8f44bec442443da9b06c909b082c36 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 29 Nov 2018 09:29:07 -0500 Subject: [PATCH 16/36] ArrayHandleVirtual supports comparison operators --- vtkm/cont/ArrayHandleVirtual.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index 4acaeb859..593c2d550 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -107,6 +107,34 @@ public: return *this; } + /// Like a pointer, two \c ArrayHandles are considered equal if they point + /// to the same location in memory. + /// + VTKM_CONT + bool operator==(const ArrayHandle& rhs) const + { + return (this->Storage == rhs.Storage); + } + + VTKM_CONT + bool operator!=(const ArrayHandle& rhs) const + { + return (this->Storage != rhs.Storage); + } + + template + VTKM_CONT bool operator==(const ArrayHandle&) const + { + return false; // different valuetype and/or storage + } + + template + VTKM_CONT bool operator!=(const ArrayHandle&) const + { + return true; // different valuetype and/or storage + } + + /// Returns true if this array's storage matches the type passed in. /// template From 8deb6614098b7761a0140f1f6d7d8d8fc4e75fa4 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 6 Dec 2018 10:04:43 -0500 Subject: [PATCH 17/36] Add serialization support to ArrayHandle Virtual, Any, and Variant. --- vtkm/cont/ArrayHandleAny.h | 118 ++++++++++++++++++ vtkm/cont/ArrayHandleCast.h | 14 +-- vtkm/cont/ArrayHandleVariant.h | 4 +- vtkm/cont/ArrayHandleVirtual.h | 20 ++- vtkm/cont/ArrayHandleVirtual.hxx | 58 +++++++++ vtkm/cont/ArrayHandleVirtualCoordinates.h | 20 +-- .../internal/ArrayHandleVariantContainer.h | 3 + vtkm/cont/testing/TestingSerialization.h | 2 +- .../UnitTestSerializationArrayHandle.cxx | 61 ++++----- .../testing/UnitTestSerializationDataSet.cxx | 6 +- 10 files changed, 245 insertions(+), 61 deletions(-) diff --git a/vtkm/cont/ArrayHandleAny.h b/vtkm/cont/ArrayHandleAny.h index e36e38f63..5bda016ce 100644 --- a/vtkm/cont/ArrayHandleAny.h +++ b/vtkm/cont/ArrayHandleAny.h @@ -26,6 +26,7 @@ #include #include + #include namespace vtkm @@ -85,12 +86,19 @@ template class VTKM_ALWAYS_EXPORT ArrayHandleAny final : public vtkm::cont::ArrayHandleVirtual { public: + ///construct a valid ArrayHandleAny from an existing ArrayHandle template VTKM_CONT ArrayHandleAny(const vtkm::cont::ArrayHandle& ah) : vtkm::cont::ArrayHandleVirtual(std::make_shared>(ah)) { } + ///construct an invalid ArrayHandleAny that has a nullptr storage + VTKM_CONT ArrayHandleAny() + : vtkm::cont::ArrayHandleVirtual() + { + } + ~ArrayHandleAny() = default; }; @@ -121,9 +129,119 @@ void CastAndCall(vtkm::cont::ArrayHandleVirtual f(coords, std::forward(args)...); } } + +//============================================================================= +// Specializations of serialization related classes +template +struct TypeString> +{ + static VTKM_CONT const std::string& Get() + { + static std::string name = "AH_Any<" + TypeString::Get() + ">"; + return name; + } +}; } } //namespace vtkm::cont +#include +#include +//============================================================================= +// Specializations of serialization related classes +namespace diy +{ + +template +struct Serialization> +{ + + static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleAny& obj) + { + vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); + } + + static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleAny& obj) + { + vtkm::cont::ArrayHandle array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + } +}; + +template +struct IntAnySerializer +{ + using CountingType = vtkm::cont::ArrayHandleCounting; + using ConstantType = vtkm::cont::ArrayHandleConstant; + using BasicType = vtkm::cont::ArrayHandle; + + static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleAny& obj) + { + if (obj.template IsType()) + { + diy::save(bb, vtkm::cont::TypeString::Get()); + + using S = typename CountingType::StorageTag; + const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); + auto* any = storage->Cast>(); + diy::save(bb, any->GetHandle()); + } + else if (obj.template IsType()) + { + diy::save(bb, vtkm::cont::TypeString::Get()); + + using S = typename ConstantType::StorageTag; + const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); + auto* any = storage->Cast>(); + diy::save(bb, any->GetHandle()); + } + else + { + diy::save(bb, vtkm::cont::TypeString::Get()); + vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); + } + } + + static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleAny& obj) + { + std::string typeString; + diy::load(bb, typeString); + + if (typeString == vtkm::cont::TypeString::Get()) + { + CountingType array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + } + else if (typeString == vtkm::cont::TypeString::Get()) + { + ConstantType array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + } + else + { + vtkm::cont::ArrayHandle array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + } + } +}; + + +template <> +struct Serialization> : public IntAnySerializer +{ +}; +template <> +struct Serialization> : public IntAnySerializer +{ +}; +template <> +struct Serialization> : public IntAnySerializer +{ +}; +} #endif //vtk_m_cont_ArrayHandleAny_h diff --git a/vtkm/cont/ArrayHandleCast.h b/vtkm/cont/ArrayHandleCast.h index f975025c7..2a7a891bc 100644 --- a/vtkm/cont/ArrayHandleCast.h +++ b/vtkm/cont/ArrayHandleCast.h @@ -50,16 +50,14 @@ struct VTKM_ALWAYS_EXPORT Cast template class ArrayHandleCast : public vtkm::cont::ArrayHandleTransform, - internal::Cast> + internal::Cast> { public: VTKM_ARRAY_HANDLE_SUBCLASS( ArrayHandleCast, (ArrayHandleCast), (vtkm::cont::ArrayHandleTransform, - internal::Cast>)); + internal::Cast>)); ArrayHandleCast(const ArrayHandleType& handle) : Superclass(handle) @@ -125,9 +123,7 @@ struct TypeString> template struct TypeString> : TypeString< - vtkm::cont::ArrayHandleTransform, - vtkm::cont::internal::Cast>> + vtkm::cont::ArrayHandleTransform>> { }; } @@ -147,9 +143,7 @@ struct Serialization> template struct Serialization> : Serialization< - vtkm::cont::ArrayHandleTransform, - vtkm::cont::internal::Cast>> + vtkm::cont::ArrayHandleTransform>> { }; diff --git a/vtkm/cont/ArrayHandleVariant.h b/vtkm/cont/ArrayHandleVariant.h index adc429757..e675f610c 100644 --- a/vtkm/cont/ArrayHandleVariant.h +++ b/vtkm/cont/ArrayHandleVariant.h @@ -25,10 +25,8 @@ #include #include -#include -#include - #include + #include #include #include diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index 593c2d550..c206d994d 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -300,13 +300,25 @@ private: } }; +//============================================================================= +// Better name for the type template using ArrayHandleVirtual = vtkm::cont::ArrayHandle; + + +//============================================================================= +// Specializations of serialization related classes +template +struct TypeString> +{ + static VTKM_CONT const std::string& Get() + { + static std::string name = "AH_Virtual<" + TypeString::Get() + ">"; + return name; + } +}; } } //namespace vtkm::cont -#include - - -#endif +#endif //vtk_m_cont_ArrayHandleVirtual_h diff --git a/vtkm/cont/ArrayHandleVirtual.hxx b/vtkm/cont/ArrayHandleVirtual.hxx index a63469c6d..6a7a8b542 100644 --- a/vtkm/cont/ArrayHandleVirtual.hxx +++ b/vtkm/cont/ArrayHandleVirtual.hxx @@ -68,4 +68,62 @@ inline void make_hostPortal(Payload&& payload, Args&&... args) } // namespace vtkm::virts + +#include +//============================================================================= +// Specializations of serialization related classes +namespace diy +{ + +template +struct Serialization> +{ +private: + using Type = vtkm::cont::ArrayHandleVirtual; + using BaseType = vtkm::cont::ArrayHandle; + using BasicType = vtkm::cont::ArrayHandle; + +public: + static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) + { + if (obj.template IsType>()) + { + const auto& array = static_cast&>(obj); + diy::save(bb, vtkm::cont::TypeString>::Get()); + diy::save(bb, array); + } + else + { + diy::save(bb, vtkm::cont::TypeString::Get()); + vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); + } + } + + static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj) + { + std::string typeString; + diy::load(bb, typeString); + + if (typeString == vtkm::cont::TypeString>::Get()) + { + vtkm::cont::ArrayHandleAny array; + diy::load(bb, array); + obj = std::move(array); + } + else if (typeString == vtkm::cont::TypeString::Get()) + { + BasicType array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + } + else + { + throw vtkm::cont::ErrorBadType("Error deserializing ArrayHandleVirtual. TypeString: " + + typeString); + } + } +}; +} + + #endif diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index ed0aa7c2d..31eb548c3 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -117,9 +117,12 @@ struct TypeString { static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; } }; -} -} // vtkm::cont +} // namespace cont +} // namespace vtkm + +//============================================================================= +// Specializations of serialization related classes namespace diy { @@ -139,30 +142,29 @@ private: public: static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) { - const auto& virtArray = static_cast(obj); - const vtkm::cont::StorageVirtual* storage = virtArray.GetStorage(); - if (virtArray.IsType()) + const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); + if (obj.template IsType()) { using HandleType = vtkm::cont::ArrayHandleUniformPointCoordinates; using T = typename HandleType::ValueType; using S = typename HandleType::StorageTag; auto array = storage->Cast>(); diy::save(bb, vtkm::cont::TypeString::Get()); - diy::save(bb, array); + diy::save(bb, array->GetHandle()); } - else if (virtArray.IsType()) + else if (obj.template IsType()) { using HandleType = RectilinearCoordsArrayType; using T = typename HandleType::ValueType; using S = typename HandleType::StorageTag; auto array = storage->Cast>(); diy::save(bb, vtkm::cont::TypeString::Get()); - diy::save(bb, array); + diy::save(bb, array->GetHandle()); } else { diy::save(bb, vtkm::cont::TypeString::Get()); - vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, virtArray); + vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); } } diff --git a/vtkm/cont/internal/ArrayHandleVariantContainer.h b/vtkm/cont/internal/ArrayHandleVariantContainer.h index 6444e1f8a..92e70bbaa 100644 --- a/vtkm/cont/internal/ArrayHandleVariantContainer.h +++ b/vtkm/cont/internal/ArrayHandleVariantContainer.h @@ -23,6 +23,9 @@ #include #include +#include + +#include #include #include diff --git a/vtkm/cont/testing/TestingSerialization.h b/vtkm/cont/testing/TestingSerialization.h index fd72f58d6..d6f64b2ef 100644 --- a/vtkm/cont/testing/TestingSerialization.h +++ b/vtkm/cont/testing/TestingSerialization.h @@ -21,7 +21,7 @@ #define vtk_m_cont_testing_TestingSerialization_h #include -#include +#include #include // clang-format off diff --git a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx index 82aca7ee5..2a1cb10b3 100644 --- a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx @@ -36,7 +36,8 @@ #include #include #include -#include + +#include #include @@ -75,12 +76,10 @@ constexpr vtkm::Id ArraySize = 10; using TestTypesList = vtkm::ListTagBase>; -using TestStorageList = vtkm::ListTagBase; template -inline vtkm::cont::DynamicArrayHandleBase, - vtkm::ListTagAppendUnique> -MakeTestDynamicArrayHandle(const vtkm::cont::ArrayHandle& array) +inline vtkm::cont::ArrayHandleVariantBase> +MakeTestArrayHandleVariant(const vtkm::cont::ArrayHandle& array) { return array; } @@ -92,7 +91,7 @@ struct TestArrayHandleBasic { auto array = RandomArrayHandle::Make(ArraySize); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -106,7 +105,7 @@ struct TestArrayHandleCartesianProduct RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -116,9 +115,9 @@ struct TestArrayHandleCast void operator()(T) const { auto array = - vtkm::cont::make_ArrayHandleCast(RandomArrayHandle::Make(ArraySize), T{}); + vtkm::cont::make_ArrayHandleCast(RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -130,7 +129,7 @@ struct TestArrayHandleCompositeVector auto array = vtkm::cont::make_ArrayHandleCompositeVector(RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -142,7 +141,7 @@ struct TestArrayHandleConcatenate auto array = vtkm::cont::make_ArrayHandleConcatenate(RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -154,7 +153,7 @@ struct TestArrayHandleConstant T cval = RandomValue::Make(); auto array = vtkm::cont::make_ArrayHandleConstant(cval, ArraySize); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -167,7 +166,7 @@ struct TestArrayHandleCounting T step = RandomValue::Make(0, 5); auto array = vtkm::cont::make_ArrayHandleCounting(start, step, ArraySize); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -180,7 +179,7 @@ struct TestArrayHandleExtractComponent auto array = vtkm::cont::make_ArrayHandleExtractComponent( RandomArrayHandle::Make(ArraySize), RandomValue::Make(0, numComps - 1)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -197,21 +196,21 @@ struct TestArrayHandleGroupVec { auto array = vtkm::cont::make_ArrayHandleGroupVec<3>(flat); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); break; } case 4: { auto array = vtkm::cont::make_ArrayHandleGroupVec<4>(flat); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); break; } default: { auto array = vtkm::cont::make_ArrayHandleGroupVec<2>(flat); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); break; } } @@ -239,7 +238,7 @@ struct TestArrayHandleGroupVecVariable // cannot make a DynamicArrayHandle containing ArrayHandleGroupVecVariable // because of the variable number of components of its values. - // RunTest(MakeTestDynamicArrayHandle(array)); + // RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -270,7 +269,7 @@ struct TestArrayHandleImplicit ImplicitFunctor functor(RandomValue::Make(2, 9)); auto array = vtkm::cont::make_ArrayHandleImplicit(functor, ArraySize); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -279,7 +278,7 @@ void TestArrayHandleIndex() auto size = RandomValue::Make(2, 10); auto array = vtkm::cont::ArrayHandleIndex(size); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } struct TestArrayHandlePermutation @@ -296,7 +295,7 @@ struct TestArrayHandlePermutation RandomArrayHandle::Make(ArraySize, 0, ArraySize - 1), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -307,7 +306,7 @@ struct TestArrayHandleReverse { auto array = vtkm::cont::make_ArrayHandleReverse(RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; @@ -330,7 +329,7 @@ struct TestArrayHandleSwizzle auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), map2s[RandomValue::Make(0, 5)]); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); break; } case 3: @@ -339,13 +338,14 @@ struct TestArrayHandleSwizzle auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), map3s[RandomValue::Make(0, 5)]); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); break; } } } }; + struct TestArrayHandleTransform { struct TransformFunctor @@ -362,7 +362,7 @@ struct TestArrayHandleTransform template VTKM_EXEC_CONT T operator()(const T& in) const { - return in / T{ 2 }; + return static_cast(in / T{ 2 }); } }; @@ -372,7 +372,7 @@ struct TestArrayHandleTransform auto array = vtkm::cont::make_ArrayHandleTransform(RandomArrayHandle::Make(ArraySize), TransformFunctor{}); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } template @@ -381,7 +381,7 @@ struct TestArrayHandleTransform auto array = vtkm::cont::make_ArrayHandleTransform( RandomArrayHandle::Make(ArraySize), TransformFunctor{}, InverseTransformFunctor{}); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } template @@ -404,7 +404,7 @@ void TestArrayHandleUniformPointCoordinates() { auto array = MakeRandomArrayHandleUniformPointCoordinates(); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } void TestArrayHandleVirtualCoordinates() @@ -432,7 +432,7 @@ void TestArrayHandleVirtualCoordinates() } RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } struct TestArrayHandleZip @@ -443,10 +443,11 @@ struct TestArrayHandleZip auto array = vtkm::cont::make_ArrayHandleZip(RandomArrayHandle::Make(ArraySize), vtkm::cont::ArrayHandleIndex(ArraySize)); RunTest(array); - RunTest(MakeTestDynamicArrayHandle(array)); + RunTest(MakeTestArrayHandleVariant(array)); } }; + //----------------------------------------------------------------------------- void TestArrayHandleSerialization() { diff --git a/vtkm/cont/testing/UnitTestSerializationDataSet.cxx b/vtkm/cont/testing/UnitTestSerializationDataSet.cxx index 7e253294f..0310a4aad 100644 --- a/vtkm/cont/testing/UnitTestSerializationDataSet.cxx +++ b/vtkm/cont/testing/UnitTestSerializationDataSet.cxx @@ -26,20 +26,18 @@ namespace { using FieldTypeList = vtkm::ListTagBase; -using FieldStorageList = VTKM_DEFAULT_STORAGE_LIST_TAG; using CellSetTypes = vtkm::ListTagBase, vtkm::cont::CellSetSingleType<>, vtkm::cont::CellSetStructured<1>, vtkm::cont::CellSetStructured<2>, vtkm::cont::CellSetStructured<3>>; -using DataSetWrapper = - vtkm::cont::SerializableDataSet; +using DataSetWrapper = vtkm::cont::SerializableDataSet; VTKM_CONT void TestEqualDataSet(const DataSetWrapper& ds1, const DataSetWrapper& ds2) { auto result = vtkm::cont::testing::test_equal_DataSets( - ds1.DataSet, ds2.DataSet, CellSetTypes{}, FieldTypeList{}, FieldStorageList{}); + ds1.DataSet, ds2.DataSet, CellSetTypes{}, FieldTypeList{}); VTKM_TEST_ASSERT(result, result.GetMergedMessage()); } From 0c72555ee191ac04df128b78bbf16de07e92a72e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Nov 2018 10:37:50 -0500 Subject: [PATCH 18/36] Update vtkm/cont/testing to work with ArrayHandleVariant --- vtkm/cont/testing/CMakeLists.txt | 2 +- vtkm/cont/testing/Testing.h | 34 ++--- vtkm/cont/testing/TestingComputeRange.h | 4 +- ...dle.cxx => UnitTestArrayHandleVariant.cxx} | 143 +++++++----------- vtkm/cont/testing/UnitTestMultiBlock.cxx | 2 - 5 files changed, 72 insertions(+), 113 deletions(-) rename vtkm/cont/testing/{UnitTestDynamicArrayHandle.cxx => UnitTestArrayHandleVariant.cxx} (68%) diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index b31c07284..4ee74b64b 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -55,6 +55,7 @@ set(unit_tests UnitTestArrayHandleTransform.cxx UnitTestArrayHandleUniformPointCoordinates.cxx UnitTestArrayHandleConcatenate.cxx + UnitTestArrayHandleVariant.cxx UnitTestArrayPortalToIterators.cxx UnitTestCellLocator.cxx UnitTestCellSetExplicit.cxx @@ -68,7 +69,6 @@ set(unit_tests UnitTestDataSetUniform.cxx UnitTestDeviceAdapterAlgorithmDependency.cxx UnitTestDeviceAdapterAlgorithmGeneral.cxx - UnitTestDynamicArrayHandle.cxx UnitTestDynamicCellSet.cxx UnitTestFieldRangeCompute.cxx UnitTestLogging.cxx diff --git a/vtkm/cont/testing/Testing.h b/vtkm/cont/testing/Testing.h index e1624ab90..1c45a78ab 100644 --- a/vtkm/cont/testing/Testing.h +++ b/vtkm/cont/testing/Testing.h @@ -27,10 +27,10 @@ #include #include +#include #include #include #include -#include #include @@ -216,28 +216,28 @@ struct TestEqualArrayHandle } } - template + template VTKM_CONT void operator()( const vtkm::cont::ArrayHandle& array1, - const vtkm::cont::DynamicArrayHandleBase& array2, + const vtkm::cont::ArrayHandleVariantBase& array2, TestEqualResult& result) const { array2.CastAndCall(*this, array1, result); } - template + template VTKM_CONT void operator()( - const vtkm::cont::DynamicArrayHandleBase& array1, + const vtkm::cont::ArrayHandleVariantBase& array1, const vtkm::cont::ArrayHandle& array2, TestEqualResult& result) const { array1.CastAndCall(*this, array2, result); } - template + template VTKM_CONT void operator()( - const vtkm::cont::DynamicArrayHandleBase& array1, - const vtkm::cont::DynamicArrayHandleBase& array2, + const vtkm::cont::ArrayHandleVariantBase& array1, + const vtkm::cont::ArrayHandleVariantBase& array2, TestEqualResult& result) const { array2.CastAndCall(*this, array1, result); @@ -359,12 +359,10 @@ inline VTKM_CONT TestEqualResult test_equal_CellSets(const CellSet1& cellset1, return result; } -template +template inline VTKM_CONT TestEqualResult test_equal_Fields(const vtkm::cont::Field& f1, const vtkm::cont::Field& f2, - FieldTypeList fTtypes = FieldTypeList(), - FieldStorageList fStypes = FieldStorageList()) + FieldTypeList fTtypes = FieldTypeList()) { TestEqualResult result; @@ -397,8 +395,8 @@ inline VTKM_CONT TestEqualResult test_equal_Fields(const vtkm::cont::Field& f1, } } - result = test_equal_ArrayHandles(f1.GetData().ResetTypeAndStorageLists(fTtypes, fStypes), - f2.GetData().ResetTypeAndStorageLists(fTtypes, fStypes)); + result = test_equal_ArrayHandles(f1.GetData().ResetTypes(fTtypes), + f2.GetData().ResetTypes(fTtypes)); if (!result) { result.PushMessage("data doesn't match"); @@ -408,13 +406,11 @@ inline VTKM_CONT TestEqualResult test_equal_Fields(const vtkm::cont::Field& f1, } template + typename FieldTypeList = VTKM_DEFAULT_TYPE_LIST_TAG> inline VTKM_CONT TestEqualResult test_equal_DataSets(const vtkm::cont::DataSet& ds1, const vtkm::cont::DataSet& ds2, CellSetTypes ctypes = CellSetTypes(), - FieldTypeList fTtypes = FieldTypeList(), - FieldStorageList fStypes = FieldStorageList()) + FieldTypeList fTtypes = FieldTypeList()) { TestEqualResult result; if (ds1.GetNumberOfCoordinateSystems() != ds2.GetNumberOfCoordinateSystems()) @@ -458,7 +454,7 @@ inline VTKM_CONT TestEqualResult test_equal_DataSets(const vtkm::cont::DataSet& } for (vtkm::IdComponent i = 0; i < ds1.GetNumberOfFields(); ++i) { - result = test_equal_Fields(ds1.GetField(i), ds2.GetField(i), fTtypes, fStypes); + result = test_equal_Fields(ds1.GetField(i), ds2.GetField(i), fTtypes); if (!result) { result.PushMessage( diff --git a/vtkm/cont/testing/TestingComputeRange.h b/vtkm/cont/testing/TestingComputeRange.h index 8e923b7c6..5b9335302 100644 --- a/vtkm/cont/testing/TestingComputeRange.h +++ b/vtkm/cont/testing/TestingComputeRange.h @@ -26,7 +26,7 @@ #include #include -// Required for implementation of ArrayRangeCompute for "odd" arrays +// Required for implementation of ArrayRangeCompute for virtual arrays #include #include @@ -94,7 +94,7 @@ private: vtkm::cont::make_Field("TestField", vtkm::cont::Field::Association::POINTS, fieldData, nvals); vtkm::Range result[NumberOfComponents]; - field.GetRange(result, CustomTypeList(), VTKM_DEFAULT_STORAGE_LIST_TAG()); + field.GetRange(result, CustomTypeList()); for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) { diff --git a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx b/vtkm/cont/testing/UnitTestArrayHandleVariant.cxx similarity index 68% rename from vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx rename to vtkm/cont/testing/UnitTestArrayHandleVariant.cxx index dc7389183..843777fb4 100644 --- a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestArrayHandleVariant.cxx @@ -18,10 +18,11 @@ // this software. //============================================================================ -#include +#include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -45,7 +47,7 @@ namespace vtkm { -// DynamicArrayHandle requires its value type to have a defined VecTraits +// ArrayHandleVariant requires its value type to have a defined VecTraits // class. One of the tests is to use an "unusual" array of std::string // (which is pretty pointless but might tease out some assumptions). // Make an implementation here. Because I am lazy, this is only a partial @@ -108,22 +110,21 @@ struct TestValueFunctor struct CheckFunctor { - template - void operator()(vtkm::cont::ArrayHandle array, bool& called) const + template + void operator()(const vtkm::cont::ArrayHandleVirtual& array, bool& called) const { called = true; std::cout << " Checking for type: " << typeid(T).name() << std::endl; VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size."); - typename vtkm::cont::ArrayHandle::PortalConstControl portal = - array.GetPortalConstControl(); + auto portal = array.GetPortalConstControl(); CheckPortal(portal); } }; -template -void BasicDynamicArrayChecks(const vtkm::cont::DynamicArrayHandleBase& array, +template +void BasicArrayVariantChecks(const vtkm::cont::ArrayHandleVariantBase& array, vtkm::IdComponent numComponents) { VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, @@ -132,9 +133,9 @@ void BasicDynamicArrayChecks(const vtkm::cont::DynamicArrayHandleBase -void CheckDynamicArray(vtkm::cont::DynamicArrayHandleBase array, +template +void CheckArrayVariant(const vtkm::cont::ArrayHandleVariantBase& array, vtkm::IdComponent numComponents) { - BasicDynamicArrayChecks(array, numComponents); + BasicArrayVariantChecks(array, numComponents); bool called = false; CastAndCall(array, CheckFunctor(), called); @@ -157,7 +158,7 @@ void CheckDynamicArray(vtkm::cont::DynamicArrayHandleBase } template -vtkm::cont::DynamicArrayHandle CreateDynamicArray(T) +vtkm::cont::ArrayHandleVariant CreateArrayVariant(T) { // Declared static to prevent going out of scope. static T buffer[ARRAY_SIZE]; @@ -166,7 +167,7 @@ vtkm::cont::DynamicArrayHandle CreateDynamicArray(T) buffer[index] = TestValue(index, T()); } - return vtkm::cont::DynamicArrayHandle(vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE)); + return vtkm::cont::ArrayHandleVariant(vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE)); } template @@ -174,29 +175,32 @@ void CheckCastToArrayHandle(const ArrayHandleType& array) { VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - vtkm::cont::DynamicArrayHandle dynamicArray = array; - VTKM_TEST_ASSERT(!dynamicArray.IsType>(), + vtkm::cont::ArrayHandleVariant arrayVariant = array; + VTKM_TEST_ASSERT(!arrayVariant.IsType>(), "Dynamic array reporting is wrong type."); ArrayHandleType castArray1; - dynamicArray.CopyTo(castArray1); - VTKM_TEST_ASSERT(dynamicArray.IsSameType(castArray1), "Did not query handle correctly."); + arrayVariant.CopyTo(castArray1); + VTKM_TEST_ASSERT(arrayVariant.IsType(), "Did not query handle correctly."); VTKM_TEST_ASSERT(array == castArray1, "Did not get back same array."); - ArrayHandleType castArray2 = - dynamicArray.CastToTypeStorage(); + ArrayHandleType castArray2 = arrayVariant.Cast(); VTKM_TEST_ASSERT(array == castArray2, "Did not get back same array."); + + using T = typename ArrayHandleType::ValueType; + vtkm::cont::ArrayHandleVirtual castArray3 = arrayVariant.AsVirtual(); + VTKM_TEST_ASSERT(castArray3.GetNumberOfValues() == castArray2.GetNumberOfValues(), + "Did not get back virtual array handle representation."); } -template -void TryNewInstance(T, DynamicArrayType originalArray) +template +void TryNewInstance(T, ArrayVariantType originalArray) { // This check should already have been performed by caller, but just in case. - CheckDynamicArray(originalArray, vtkm::VecTraits::NUM_COMPONENTS); + CheckArrayVariant(originalArray, vtkm::VecTraits::NUM_COMPONENTS); std::cout << "Create new instance of array." << std::endl; - DynamicArrayType newArray = originalArray.NewInstance(); + ArrayVariantType newArray = originalArray.NewInstance(); std::cout << "Get a static instance of the new array (which checks the type)." << std::endl; vtkm::cont::ArrayHandle staticArray; @@ -209,7 +213,7 @@ void TryNewInstance(T, DynamicArrayType originalArray) { staticArray.GetPortalControl().Set(index, TestValue(index + 100, T())); } - CheckDynamicArray(originalArray, vtkm::VecTraits::NUM_COMPONENTS); + CheckArrayVariant(originalArray, vtkm::VecTraits::NUM_COMPONENTS); std::cout << "Set the new static array to expected values and make sure the new" << std::endl << "dynamic array points to the same new values." << std::endl; @@ -217,15 +221,15 @@ void TryNewInstance(T, DynamicArrayType originalArray) { staticArray.GetPortalControl().Set(index, TestValue(index, T())); } - CheckDynamicArray(newArray, vtkm::VecTraits::NUM_COMPONENTS); + CheckArrayVariant(newArray, vtkm::VecTraits::NUM_COMPONENTS); } template void TryDefaultType(T) { - vtkm::cont::DynamicArrayHandle array = CreateDynamicArray(T()); + vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(T()); - CheckDynamicArray(array, vtkm::VecTraits::NUM_COMPONENTS); + CheckArrayVariant(array, vtkm::VecTraits::NUM_COMPONENTS); TryNewInstance(T(), array); } @@ -235,23 +239,22 @@ struct TryBasicVTKmType template void operator()(T) const { - vtkm::cont::DynamicArrayHandle array = CreateDynamicArray(T()); + vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(T()); - CheckDynamicArray(array.ResetTypeList(vtkm::TypeListTagAll()), - vtkm::VecTraits::NUM_COMPONENTS); + CheckArrayVariant(array.ResetTypes(vtkm::TypeListTagAll()), vtkm::VecTraits::NUM_COMPONENTS); - TryNewInstance(T(), array.ResetTypeList(vtkm::TypeListTagAll())); + TryNewInstance(T(), array.ResetTypes(vtkm::TypeListTagAll())); } }; void TryUnusualType() { // A string is an unlikely type to be declared elsewhere in VTK-m. - vtkm::cont::DynamicArrayHandle array = CreateDynamicArray(std::string()); + vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(std::string()); try { - CheckDynamicArray(array, 1); + CheckArrayVariant(array, 1); VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type."); } catch (vtkm::cont::ErrorBadValue&) @@ -259,35 +262,31 @@ void TryUnusualType() std::cout << " Caught exception for unrecognized type." << std::endl; } - CheckDynamicArray(array.ResetTypeList(TypeListTagString()), 1); + CheckArrayVariant(array.ResetTypes(TypeListTagString()), 1); std::cout << " Found type when type list was reset." << std::endl; } void TryUnusualStorage() { - vtkm::cont::DynamicArrayHandle array = ArrayHandleWithUnusualStorage(); + vtkm::cont::ArrayHandleVariant array = ArrayHandleWithUnusualStorage(); try { - CheckDynamicArray(array, 1); - VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized storage."); + CheckArrayVariant(array, 1); } - catch (vtkm::cont::ErrorBadValue&) + catch (...) { - std::cout << " Caught exception for unrecognized storage." << std::endl; + VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage."); } - - CheckDynamicArray(array.ResetStorageList(StorageListTagUnusual()), 1); - std::cout << " Found instance when storage list was reset." << std::endl; } void TryUnusualTypeAndStorage() { - vtkm::cont::DynamicArrayHandle array = ArrayHandleWithUnusualStorage(); + vtkm::cont::ArrayHandleVariant array = ArrayHandleWithUnusualStorage(); try { - CheckDynamicArray(array, 1); + CheckArrayVariant(array, 1); VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type/storage."); } catch (vtkm::cont::ErrorBadValue&) @@ -297,46 +296,12 @@ void TryUnusualTypeAndStorage() try { - CheckDynamicArray(array.ResetTypeList(TypeListTagString()), 1); - VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized storage."); + CheckArrayVariant(array.ResetTypes(TypeListTagString()), 1); } - catch (vtkm::cont::ErrorBadValue&) + catch (...) { - std::cout << " Caught exception for unrecognized storage." << std::endl; + VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage."); } - - try - { - CheckDynamicArray(array.ResetStorageList(StorageListTagUnusual()), 1); - VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type."); - } - catch (vtkm::cont::ErrorBadValue&) - { - std::cout << " Caught exception for unrecognized type." << std::endl; - } - - try - { - //resetting the string and tag should result in a valid array handle - CheckDynamicArray(array.ResetTypeAndStorageLists(TypeListTagString(), StorageListTagUnusual()), - 1); - } - catch (vtkm::cont::ErrorBadValue&) - { - VTKM_TEST_FAIL("ResetTypeAndStorageLists should have handled the custom type/storage."); - } - - CheckDynamicArray( - array.ResetTypeList(TypeListTagString()).ResetStorageList(StorageListTagUnusual()), 1); - std::cout << " Found instance when type and storage lists were reset." << std::endl; - - CheckDynamicArray( - array.ResetStorageList(StorageListTagUnusual()).ResetTypeList(TypeListTagString()), 1); - std::cout << " Found instance when storage and type lists were reset." << std::endl; - - CheckDynamicArray(array.ResetTypeAndStorageLists(TypeListTagString(), StorageListTagUnusual()), - 1); - std::cout << " Found instance when storage and type lists were reset." << std::endl; } void TryCastToArrayHandle() @@ -384,11 +349,11 @@ void TryCastToArrayHandle() std::cout << " Uniform point coordinates array handle." << std::endl; CheckCastToArrayHandle(vtkm::cont::ArrayHandleUniformPointCoordinates(vtkm::Id3(ARRAY_SIZE))); - std::cout << " Zip array handle." << std::endl; - CheckCastToArrayHandle(vtkm::cont::make_ArrayHandleZip(countingArray, array)); + // std::cout << " Zip array handle." << std::endl; + // CheckCastToArrayHandle(vtkm::cont::make_ArrayHandleZip(countingArray, array)); } -void TestDynamicArrayHandle() +void TestArrayHandleVariant() { std::cout << "Try common types with default type lists." << std::endl; std::cout << "*** vtkm::Id **********************" << std::endl; @@ -422,7 +387,7 @@ void TestDynamicArrayHandle() } // anonymous namespace -int UnitTestDynamicArrayHandle(int, char* []) +int UnitTestArrayHandleVariant(int, char* []) { - return vtkm::cont::testing::Testing::Run(TestDynamicArrayHandle); + return vtkm::cont::testing::Testing::Run(TestArrayHandleVariant); } diff --git a/vtkm/cont/testing/UnitTestMultiBlock.cxx b/vtkm/cont/testing/UnitTestMultiBlock.cxx index 819818a04..831346749 100644 --- a/vtkm/cont/testing/UnitTestMultiBlock.cxx +++ b/vtkm/cont/testing/UnitTestMultiBlock.cxx @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include #include From 39929d5a7ccb443317526422fbfe8cb529831d2e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Nov 2018 16:29:52 -0500 Subject: [PATCH 19/36] Update vtkm/io to work with vtkm::cont::ArrayHandleVariant --- vtkm/io/internal/VTKDataSetCells.h | 7 +- vtkm/io/reader/VTKDataSetReaderBase.h | 98 +++++++++++------------ vtkm/io/reader/VTKPolyDataReader.h | 6 +- vtkm/io/reader/VTKRectilinearGridReader.h | 8 +- 4 files changed, 56 insertions(+), 63 deletions(-) diff --git a/vtkm/io/internal/VTKDataSetCells.h b/vtkm/io/internal/VTKDataSetCells.h index a9b3de0a4..d2bb6ce39 100644 --- a/vtkm/io/internal/VTKDataSetCells.h +++ b/vtkm/io/internal/VTKDataSetCells.h @@ -60,8 +60,7 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle& connectivity, { vtkm::UInt8 shape = shapes.GetPortalConstControl().Get(i); vtkm::IdComponent numInds = numIndices.GetPortalConstControl().Get(i); - vtkm::cont::ArrayHandle::PortalConstControl connPortal = - connectivity.GetPortalConstControl(); + auto connPortal = connectivity.GetPortalConstControl(); switch (shape) { case vtkm::CELL_SHAPE_VERTEX: @@ -219,9 +218,7 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle& connectivity, inline bool IsSingleShape(const vtkm::cont::ArrayHandle& shapes) { - vtkm::cont::ArrayHandle::PortalConstControl shapesPortal = - shapes.GetPortalConstControl(); - + auto shapesPortal = shapes.GetPortalConstControl(); vtkm::UInt8 shape0 = shapesPortal.Get(0); for (vtkm::Id i = 1; i < shapes.GetNumberOfValues(); ++i) { diff --git a/vtkm/io/reader/VTKDataSetReaderBase.h b/vtkm/io/reader/VTKDataSetReaderBase.h index f357f6eb9..befa5f4c3 100644 --- a/vtkm/io/reader/VTKDataSetReaderBase.h +++ b/vtkm/io/reader/VTKDataSetReaderBase.h @@ -28,9 +28,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -93,9 +93,9 @@ struct StreamIOType using Type = vtkm::UInt16; }; -// Since Fields and DataSets store data in the default DynamicArrayHandle, convert +// Since Fields and DataSets store data in the default ArrayHandleVariant, convert // the data to the closest type supported by default. The following will -// need to be updated if DynamicArrayHandle or TypeListTagCommon changes. +// need to be updated if ArrayHandleVariant or TypeListTagCommon changes. template struct ClosestCommonType { @@ -179,7 +179,7 @@ struct ClosestFloat }; template -vtkm::cont::DynamicArrayHandle CreateDynamicArrayHandle(const std::vector& vec) +vtkm::cont::ArrayHandleVariant CreateArrayHandleVariant(const std::vector& vec) { switch (vtkm::VecTraits::NUM_COMPONENTS) { @@ -196,12 +196,13 @@ vtkm::cont::DynamicArrayHandle CreateDynamicArrayHandle(const std::vector& ve vtkm::cont::ArrayHandle output; output.Allocate(static_cast(vec.size())); + auto portal = output.GetPortalControl(); for (vtkm::Id i = 0; i < output.GetNumberOfValues(); ++i) { - output.GetPortalControl().Set(i, static_cast(vec[static_cast(i)])); + portal.Set(i, static_cast(vec[static_cast(i)])); } - return vtkm::cont::DynamicArrayHandle(output); + return vtkm::cont::ArrayHandleVariant(output); } case 2: case 3: @@ -221,6 +222,7 @@ vtkm::cont::DynamicArrayHandle CreateDynamicArrayHandle(const std::vector& ve vtkm::cont::ArrayHandle output; output.Allocate(static_cast(vec.size())); + auto portal = output.GetPortalControl(); for (vtkm::Id i = 0; i < output.GetNumberOfValues(); ++i) { CommonType outval = CommonType(); @@ -229,15 +231,15 @@ vtkm::cont::DynamicArrayHandle CreateDynamicArrayHandle(const std::vector& ve outval[j] = static_cast( vtkm::VecTraits::GetComponent(vec[static_cast(i)], j)); } - output.GetPortalControl().Set(i, outval); + portal.Set(i, outval); } - return vtkm::cont::DynamicArrayHandle(output); + return vtkm::cont::ArrayHandleVariant(output); } default: { std::cerr << "Only 1, 2, or 3 components supported. Skipping." << std::endl; - return vtkm::cont::DynamicArrayHandle(vtkm::cont::ArrayHandle()); + return vtkm::cont::ArrayHandleVariant(vtkm::cont::ArrayHandle()); } } } @@ -333,8 +335,8 @@ protected: std::size_t numPoints; this->DataFile->Stream >> numPoints >> dataType >> std::ws; - vtkm::cont::DynamicArrayHandle points; - this->DoReadDynamicArray(dataType, numPoints, 3, points); + vtkm::cont::ArrayHandleVariant points; + this->DoReadArrayVariant(dataType, numPoints, 3, points); this->DataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", points)); } @@ -352,10 +354,8 @@ protected: this->ReadArray(buffer); vtkm::Int32* buffp = &buffer[0]; - vtkm::cont::ArrayHandle::PortalControl connectivityPortal = - connectivity.GetPortalControl(); - vtkm::cont::ArrayHandle::PortalControl numIndicesPortal = - numIndices.GetPortalControl(); + auto connectivityPortal = connectivity.GetPortalControl(); + auto numIndicesPortal = numIndices.GetPortalControl(); for (vtkm::Id i = 0, connInd = 0; i < numCells; ++i) { vtkm::IdComponent numInds = static_cast(*buffp++); @@ -379,7 +379,7 @@ protected: this->ReadArray(buffer); vtkm::Int32* buffp = &buffer[0]; - vtkm::cont::ArrayHandle::PortalControl shapesPortal = shapes.GetPortalControl(); + auto shapesPortal = shapes.GetPortalControl(); for (vtkm::Id i = 0; i < numCells; ++i) { shapesPortal.Set(i, static_cast(*buffp++)); @@ -418,7 +418,7 @@ protected: { std::string name; vtkm::cont::ArrayHandle empty; - vtkm::cont::DynamicArrayHandle data(empty); + vtkm::cont::ArrayHandleVariant data(empty); this->DataFile->Stream >> tag; if (tag == "SCALARS") @@ -546,7 +546,7 @@ private: void ReadScalars(std::size_t numElements, std::string& dataName, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) { std::string dataType, lookupTableName; vtkm::IdComponent numComponents = 1; @@ -569,7 +569,7 @@ private: internal::parseAssert(tag == "LOOKUP_TABLE"); this->DataFile->Stream >> lookupTableName >> std::ws; - this->DoReadDynamicArray(dataType, numElements, numComponents, data); + this->DoReadArrayVariant(dataType, numElements, numComponents, data); } void ReadColorScalars(std::size_t numElements, std::string& dataName) @@ -592,33 +592,33 @@ private: void ReadTextureCoordinates(std::size_t numElements, std::string& dataName, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) { vtkm::IdComponent numComponents; std::string dataType; this->DataFile->Stream >> dataName >> numComponents >> dataType >> std::ws; - this->DoReadDynamicArray(dataType, numElements, numComponents, data); + this->DoReadArrayVariant(dataType, numElements, numComponents, data); } void ReadVectors(std::size_t numElements, std::string& dataName, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) { std::string dataType; this->DataFile->Stream >> dataName >> dataType >> std::ws; - this->DoReadDynamicArray(dataType, numElements, 3, data); + this->DoReadArrayVariant(dataType, numElements, 3, data); } void ReadTensors(std::size_t numElements, std::string& dataName, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) { std::string dataType; this->DataFile->Stream >> dataName >> dataType >> std::ws; - this->DoReadDynamicArray(dataType, numElements, 9, data); + this->DoReadArrayVariant(dataType, numElements, 9, data); } protected: @@ -645,16 +645,16 @@ protected: } else { - this->DoSkipDynamicArray(dataType, numTuples, numComponents); + this->DoSkipArrayVariant(dataType, numTuples, numComponents); } } } private: - class SkipDynamicArray + class SkipArrayVariant { public: - SkipDynamicArray(VTKDataSetReaderBase* reader, std::size_t numElements) + SkipArrayVariant(VTKDataSetReaderBase* reader, std::size_t numElements) : Reader(reader) , NumElements(numElements) { @@ -677,13 +677,13 @@ private: std::size_t NumElements; }; - class ReadDynamicArray : public SkipDynamicArray + class ReadArrayVariant : public SkipArrayVariant { public: - ReadDynamicArray(VTKDataSetReaderBase* reader, + ReadArrayVariant(VTKDataSetReaderBase* reader, std::size_t numElements, - vtkm::cont::DynamicArrayHandle& data) - : SkipDynamicArray(reader, numElements) + vtkm::cont::ArrayHandleVariant& data) + : SkipArrayVariant(reader, numElements) , Data(&data) { } @@ -693,7 +693,7 @@ private: { std::vector buffer(this->NumElements); this->Reader->ReadArray(buffer); - *this->Data = internal::CreateDynamicArrayHandle(buffer); + *this->Data = internal::CreateArrayHandleVariant(buffer); } template @@ -701,21 +701,21 @@ private: { std::cerr << "Support for " << numComponents << " components not implemented. Skipping." << std::endl; - SkipDynamicArray::operator()(numComponents, T()); + SkipArrayVariant::operator()(numComponents, T()); } private: - vtkm::cont::DynamicArrayHandle* Data; + vtkm::cont::ArrayHandleVariant* Data; }; //Make the Array parsing methods protected so that derived classes //can call the methods. protected: - void DoSkipDynamicArray(std::string dataType, + void DoSkipArrayVariant(std::string dataType, std::size_t numElements, vtkm::IdComponent numComponents) { - // string is unsupported for SkipDynamicArray, so it requires some + // string is unsupported for SkipArrayVariant, so it requires some // special handling if (dataType == "string") { @@ -730,18 +730,18 @@ protected: { vtkm::io::internal::DataType typeId = vtkm::io::internal::DataTypeId(dataType); vtkm::io::internal::SelectTypeAndCall( - typeId, numComponents, SkipDynamicArray(this, numElements)); + typeId, numComponents, SkipArrayVariant(this, numElements)); } } - void DoReadDynamicArray(std::string dataType, + void DoReadArrayVariant(std::string dataType, std::size_t numElements, vtkm::IdComponent numComponents, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) { vtkm::io::internal::DataType typeId = vtkm::io::internal::DataTypeId(dataType); vtkm::io::internal::SelectTypeAndCall( - typeId, numComponents, ReadDynamicArray(this, numElements, data)); + typeId, numComponents, ReadArrayVariant(this, numElements, data)); } template @@ -846,35 +846,33 @@ private: { public: PermuteCellData(const vtkm::cont::ArrayHandle& permutation, - vtkm::cont::DynamicArrayHandle& data) + vtkm::cont::ArrayHandleVariant& data) : Permutation(permutation) , Data(&data) { } template - void operator()(const vtkm::cont::ArrayHandle& handle) const + void operator()(const vtkm::cont::ArrayHandleVirtual& handle) const { if (this->Permutation.GetNumberOfValues() < 1) return; vtkm::cont::ArrayHandle out; out.Allocate(this->Permutation.GetNumberOfValues()); - vtkm::cont::ArrayHandle::PortalConstControl permutationPortal = - this->Permutation.GetPortalConstControl(); - typename vtkm::cont::ArrayHandle::PortalConstControl inPortal = - handle.GetPortalConstControl(); - typename vtkm::cont::ArrayHandle::PortalControl outPortal = out.GetPortalControl(); + auto permutationPortal = this->Permutation.GetPortalConstControl(); + auto inPortal = handle.GetPortalConstControl(); + auto outPortal = out.GetPortalControl(); for (vtkm::Id i = 0; i < out.GetNumberOfValues(); ++i) { outPortal.Set(i, inPortal.Get(permutationPortal.Get(i))); } - *this->Data = vtkm::cont::DynamicArrayHandle(out); + *this->Data = vtkm::cont::ArrayHandleVariant(out); } private: const vtkm::cont::ArrayHandle Permutation; - vtkm::cont::DynamicArrayHandle* Data; + vtkm::cont::ArrayHandleVariant* Data; }; protected: diff --git a/vtkm/io/reader/VTKPolyDataReader.h b/vtkm/io/reader/VTKPolyDataReader.h index a000c2c1c..9737a51f3 100644 --- a/vtkm/io/reader/VTKPolyDataReader.h +++ b/vtkm/io/reader/VTKPolyDataReader.h @@ -49,15 +49,13 @@ inline vtkm::cont::ArrayHandle ConcatinateArrayHandles( vtkm::cont::ArrayHandle out; out.Allocate(size); - using IteratorType = typename vtkm::cont::ArrayPortalToIterators< - typename vtkm::cont::ArrayHandle::PortalControl>::IteratorType; - IteratorType outp = vtkm::cont::ArrayPortalToIteratorBegin(out.GetPortalControl()); + auto outp = vtkm::cont::ArrayPortalToIteratorBegin(out.GetPortalControl()); for (std::size_t i = 0; i < arrays.size(); ++i) { std::copy(vtkm::cont::ArrayPortalToIteratorBegin(arrays[i].GetPortalConstControl()), vtkm::cont::ArrayPortalToIteratorEnd(arrays[i].GetPortalConstControl()), outp); - using DifferenceType = typename std::iterator_traits::difference_type; + using DifferenceType = typename std::iterator_traits::difference_type; std::advance(outp, static_cast(arrays[i].GetNumberOfValues())); } diff --git a/vtkm/io/reader/VTKRectilinearGridReader.h b/vtkm/io/reader/VTKRectilinearGridReader.h index b4184c2e8..880211058 100644 --- a/vtkm/io/reader/VTKRectilinearGridReader.h +++ b/vtkm/io/reader/VTKRectilinearGridReader.h @@ -64,7 +64,7 @@ private: //Read the points. std::string dataType; std::size_t numPoints[3]; - vtkm::cont::DynamicArrayHandle X, Y, Z; + vtkm::cont::ArrayHandleVariant X, Y, Z; // Always read coordinates as vtkm::FloatDefault std::string readDataType = vtkm::io::internal::DataTypeName::Name(); @@ -72,17 +72,17 @@ private: this->DataFile->Stream >> tag >> numPoints[0] >> dataType >> std::ws; if (tag != "X_COORDINATES") throw vtkm::io::ErrorIO("X_COORDINATES tag not found"); - this->DoReadDynamicArray(readDataType, numPoints[0], 1, X); + this->DoReadArrayVariant(readDataType, numPoints[0], 1, X); this->DataFile->Stream >> tag >> numPoints[1] >> dataType >> std::ws; if (tag != "Y_COORDINATES") throw vtkm::io::ErrorIO("Y_COORDINATES tag not found"); - this->DoReadDynamicArray(readDataType, numPoints[1], 1, Y); + this->DoReadArrayVariant(readDataType, numPoints[1], 1, Y); this->DataFile->Stream >> tag >> numPoints[2] >> dataType >> std::ws; if (tag != "Z_COORDINATES") throw vtkm::io::ErrorIO("Z_COORDINATES tag not found"); - this->DoReadDynamicArray(readDataType, numPoints[2], 1, Z); + this->DoReadArrayVariant(readDataType, numPoints[2], 1, Z); if (dim != vtkm::Id3(static_cast(numPoints[0]), static_cast(numPoints[1]), From 09383ceb5228f56176a2ba3bc6a7bd1c2b53b888 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 26 Nov 2018 10:49:25 -0500 Subject: [PATCH 20/36] Update vtkm/rendering to work with vtkm::cont::ArrayHandleVariant --- vtkm/rendering/Wireframer.h | 1 - .../rendering/raytracing/RayTracingTypeDefs.h | 69 +------------------ .../raytracing/VolumeRendererStructured.cxx | 3 +- vtkm/rendering/testing/UnitTestCanvas.cxx | 1 + .../testing/UnitTestMapperConnectivity.cxx | 1 + .../testing/UnitTestMapperCylinders.cxx | 1 + .../testing/UnitTestMapperPoints.cxx | 1 + .../rendering/testing/UnitTestMapperQuads.cxx | 1 + .../testing/UnitTestMapperRayTracer.cxx | 1 + .../testing/UnitTestMapperVolume.cxx | 1 + .../testing/UnitTestMapperWireframer.cxx | 1 + .../rendering/testing/UnitTestMultiMapper.cxx | 1 + 12 files changed, 11 insertions(+), 71 deletions(-) diff --git a/vtkm/rendering/Wireframer.h b/vtkm/rendering/Wireframer.h index 78c4ada21..57c4a445d 100644 --- a/vtkm/rendering/Wireframer.h +++ b/vtkm/rendering/Wireframer.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/vtkm/rendering/raytracing/RayTracingTypeDefs.h b/vtkm/rendering/raytracing/RayTracingTypeDefs.h index 7695fa744..dd6d0d9fa 100644 --- a/vtkm/rendering/raytracing/RayTracingTypeDefs.h +++ b/vtkm/rendering/raytracing/RayTracingTypeDefs.h @@ -27,8 +27,8 @@ #include #include #include +#include #include -#include #include namespace vtkm @@ -149,73 +149,6 @@ struct RayStatusType : vtkm::ListTagBase struct ScalarRenderingTypes : vtkm::ListTagBase { }; - -//Restrict Coordinate types to explicit for volume renderer -namespace detail -{ - -using ArrayHandleCompositeVectorFloat32_3Default = - vtkm::cont::ArrayHandleCompositeVector, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>; - -using ArrayHandleCompositeVectorFloat64_3Default = - vtkm::cont::ArrayHandleCompositeVector, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>; - -struct StructuredStorageListTagCoordinateSystem - : vtkm::ListTagBase, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>::StorageTag> -{ -}; -/* - * This would be for support of curvilinear meshes -struct StructuredStorageListTagCoordinateSystem - : vtkm::ListTagJoin< - VTKM_DEFAULT_STORAGE_LIST_TAG, - vtkm::ListTagBase, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle >::StorageTag > > -{ };*/ -} // namespace detail - - -/* - * This is a less restrictive type list for Explicit meshes -struct ExplicitCoordinatesType : vtkm::ListTagBase, - vtkm::Vec > {}; - - -struct StorageListTagExplicitCoordinateSystem - : vtkm::ListTagBase{ }; -*/ -//Super restrictive - -struct ExplicitCoordinatesType - : vtkm::ListTagBase, vtkm::Vec> -{ -}; -struct StorageListTagExplicitCoordinateSystem : vtkm::ListTagBase -{ -}; - - -using StructuredStorage = detail::StructuredStorageListTagCoordinateSystem; - -using DynamicArrayHandleStructuredCoordinateSystem = - vtkm::cont::DynamicArrayHandleBase; - -using DynamicArrayHandleExplicitCoordinateSystem = - vtkm::cont::DynamicArrayHandleBase; } } } //namespace vtkm::rendering::raytracing diff --git a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx index 157fd0a96..1f0119acf 100644 --- a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx +++ b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx @@ -751,8 +751,7 @@ void VolumeRendererStructured::SetData(const vtkm::cont::CoordinateSystem& coord const vtkm::cont::CellSetStructured<3>& cellset, const vtkm::Range& scalarRange) { - if (coords.GetData().IsSameType(CartesianArrayHandle())) - IsUniformDataSet = false; + IsUniformDataSet = !coords.GetData().IsType(); IsSceneDirty = true; SpatialExtent = coords.GetBounds(); Coordinates = coords.GetData(); diff --git a/vtkm/rendering/testing/UnitTestCanvas.cxx b/vtkm/rendering/testing/UnitTestCanvas.cxx index 4de1e61fb..03ee2699e 100644 --- a/vtkm/rendering/testing/UnitTestCanvas.cxx +++ b/vtkm/rendering/testing/UnitTestCanvas.cxx @@ -48,5 +48,6 @@ void RenderTests() int UnitTestCanvas(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperConnectivity.cxx b/vtkm/rendering/testing/UnitTestMapperConnectivity.cxx index 8e3a77e87..b1c67165e 100644 --- a/vtkm/rendering/testing/UnitTestMapperConnectivity.cxx +++ b/vtkm/rendering/testing/UnitTestMapperConnectivity.cxx @@ -61,5 +61,6 @@ void RenderTests() int UnitTestMapperConnectivity(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperCylinders.cxx b/vtkm/rendering/testing/UnitTestMapperCylinders.cxx index e40856268..8e86d70e6 100644 --- a/vtkm/rendering/testing/UnitTestMapperCylinders.cxx +++ b/vtkm/rendering/testing/UnitTestMapperCylinders.cxx @@ -79,5 +79,6 @@ void RenderTests() int UnitTestMapperCylinders(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperPoints.cxx b/vtkm/rendering/testing/UnitTestMapperPoints.cxx index 866956b62..910cef625 100644 --- a/vtkm/rendering/testing/UnitTestMapperPoints.cxx +++ b/vtkm/rendering/testing/UnitTestMapperPoints.cxx @@ -64,5 +64,6 @@ void RenderTests() int UnitTestMapperPoints(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperQuads.cxx b/vtkm/rendering/testing/UnitTestMapperQuads.cxx index dfdf9452b..6e4358ac7 100644 --- a/vtkm/rendering/testing/UnitTestMapperQuads.cxx +++ b/vtkm/rendering/testing/UnitTestMapperQuads.cxx @@ -60,5 +60,6 @@ void RenderTests() int UnitTestMapperQuads(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperRayTracer.cxx b/vtkm/rendering/testing/UnitTestMapperRayTracer.cxx index 0cdaacd94..681b3d25a 100644 --- a/vtkm/rendering/testing/UnitTestMapperRayTracer.cxx +++ b/vtkm/rendering/testing/UnitTestMapperRayTracer.cxx @@ -59,5 +59,6 @@ void RenderTests() int UnitTestMapperRayTracer(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperVolume.cxx b/vtkm/rendering/testing/UnitTestMapperVolume.cxx index 55f8da770..712dff446 100644 --- a/vtkm/rendering/testing/UnitTestMapperVolume.cxx +++ b/vtkm/rendering/testing/UnitTestMapperVolume.cxx @@ -53,5 +53,6 @@ void RenderTests() int UnitTestMapperVolume(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMapperWireframer.cxx b/vtkm/rendering/testing/UnitTestMapperWireframer.cxx index 874c5c4a9..4be48ddb4 100644 --- a/vtkm/rendering/testing/UnitTestMapperWireframer.cxx +++ b/vtkm/rendering/testing/UnitTestMapperWireframer.cxx @@ -141,5 +141,6 @@ void RenderTests() int UnitTestMapperWireframer(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } diff --git a/vtkm/rendering/testing/UnitTestMultiMapper.cxx b/vtkm/rendering/testing/UnitTestMultiMapper.cxx index dec07db22..5f389e47a 100644 --- a/vtkm/rendering/testing/UnitTestMultiMapper.cxx +++ b/vtkm/rendering/testing/UnitTestMultiMapper.cxx @@ -72,5 +72,6 @@ void RenderTests() int UnitTestMultiMapper(int, char* []) { + vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); return vtkm::cont::testing::Testing::Run(RenderTests); } From eed321aad0ab9a7f9d7249728b8ff65e9cf2eac0 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 29 Nov 2018 09:19:30 -0500 Subject: [PATCH 21/36] Update vtkm/worklet to work with ArrayHandleVariant --- vtkm/worklet/Clip.h | 2 +- vtkm/worklet/DispatcherMapField.h | 2 +- vtkm/worklet/DispatcherStreamingMapField.h | 2 +- vtkm/worklet/KernelSplatter.h | 1 - vtkm/worklet/MarchingCubes.h | 1 - vtkm/worklet/NDimsHistogram.h | 2 +- vtkm/worklet/SplitSharpEdges.h | 2 +- vtkm/worklet/SurfaceNormals.h | 19 ++++++------- vtkm/worklet/Threshold.h | 1 - vtkm/worklet/VertexClustering.h | 9 +++---- .../connectivities/ImageConnectivity.h | 6 ++--- .../particleadvection/GridEvaluators.h | 1 - vtkm/worklet/particleadvection/Integrators.h | 3 +++ .../TemporalGridEvaluators.h | 1 - .../worklet/testing/UnitTestMarchingCubes.cxx | 8 +++--- vtkm/worklet/testing/UnitTestWarpScalar.cxx | 2 +- .../testing/UnitTestWorkletMapField.cxx | 27 ++++++++++--------- .../UnitTestWorkletMapFieldExecArg.cxx | 4 +-- .../UnitTestWorkletMapFieldWholeArray.cxx | 18 ++++++------- .../tetrahedralize/TetrahedralizeExplicit.h | 1 - .../tetrahedralize/TetrahedralizeStructured.h | 1 - .../worklet/triangulate/TriangulateExplicit.h | 1 - .../triangulate/TriangulateStructured.h | 1 - 23 files changed, 52 insertions(+), 63 deletions(-) diff --git a/vtkm/worklet/Clip.h b/vtkm/worklet/Clip.h index 28533a5d1..0e6af69e5 100644 --- a/vtkm/worklet/Clip.h +++ b/vtkm/worklet/Clip.h @@ -32,10 +32,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/vtkm/worklet/DispatcherMapField.h b/vtkm/worklet/DispatcherMapField.h index 15d794b24..1c66f78cb 100644 --- a/vtkm/worklet/DispatcherMapField.h +++ b/vtkm/worklet/DispatcherMapField.h @@ -71,7 +71,7 @@ public: const InputDomainType& inputDomain = invocation.GetInputDomain(); // For a DispatcherMapField, the inputDomain must be an ArrayHandle (or - // a DynamicArrayHandle that gets cast to one). The size of the domain + // an ArrayHandleVariant that gets cast to one). The size of the domain // (number of threads/worklet instances) is equal to the size of the // array. auto numInstances = internal::scheduling_range(inputDomain); diff --git a/vtkm/worklet/DispatcherStreamingMapField.h b/vtkm/worklet/DispatcherStreamingMapField.h index 496cab67f..b88ddf157 100644 --- a/vtkm/worklet/DispatcherStreamingMapField.h +++ b/vtkm/worklet/DispatcherStreamingMapField.h @@ -244,7 +244,7 @@ public: const InputDomainType& inputDomain = invocation.GetInputDomain(); // For a DispatcherStreamingMapField, the inputDomain must be an ArrayHandle (or - // a DynamicArrayHandle that gets cast to one). The size of the domain + // an ArrayHandleVariant that gets cast to one). The size of the domain // (number of threads/worklet instances) is equal to the size of the // array. vtkm::Id fullSize = internal::scheduling_range(inputDomain); diff --git a/vtkm/worklet/KernelSplatter.h b/vtkm/worklet/KernelSplatter.h index c349d3158..2eaefb41f 100644 --- a/vtkm/worklet/KernelSplatter.h +++ b/vtkm/worklet/KernelSplatter.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/MarchingCubes.h b/vtkm/worklet/MarchingCubes.h index 7d3057b43..885880268 100644 --- a/vtkm/worklet/MarchingCubes.h +++ b/vtkm/worklet/MarchingCubes.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/NDimsHistogram.h b/vtkm/worklet/NDimsHistogram.h index 62a121df0..a1782b994 100644 --- a/vtkm/worklet/NDimsHistogram.h +++ b/vtkm/worklet/NDimsHistogram.h @@ -71,7 +71,7 @@ public: else { CastAndCall( - fieldArray.ResetTypeList(vtkm::TypeListTagScalarAll()), + fieldArray.ResetTypes(vtkm::TypeListTagScalarAll()), vtkm::worklet::histogram::ComputeBins(Bin1DIndex, numberOfBins, rangeOfValues, binDelta)); } } diff --git a/vtkm/worklet/SplitSharpEdges.h b/vtkm/worklet/SplitSharpEdges.h index 595bfdff2..8f17f99bd 100644 --- a/vtkm/worklet/SplitSharpEdges.h +++ b/vtkm/worklet/SplitSharpEdges.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include namespace vtkm diff --git a/vtkm/worklet/SurfaceNormals.h b/vtkm/worklet/SurfaceNormals.h index c6b50e0bf..7f9d47226 100644 --- a/vtkm/worklet/SurfaceNormals.h +++ b/vtkm/worklet/SurfaceNormals.h @@ -20,12 +20,14 @@ #ifndef vtk_m_worklet_SurfaceNormals_h #define vtk_m_worklet_SurfaceNormals_h + #include #include #include #include #include +#include namespace vtkm { @@ -141,11 +143,10 @@ public: } } - template - void Run( - const CellSetType& cellset, - const vtkm::cont::DynamicArrayHandleBase& points, - vtkm::cont::ArrayHandle>& normals) + template + void Run(const CellSetType& cellset, + const vtkm::cont::ArrayHandleVariantBase& points, + vtkm::cont::ArrayHandle>& normals) { if (this->Normalize) { @@ -205,13 +206,9 @@ public: vtkm::worklet::DispatcherMapTopology().Invoke(cellset, faceNormals, pointNormals); } - template + template void Run(const CellSetType& cellset, - const vtkm::cont::DynamicArrayHandleBase& - faceNormals, + const vtkm::cont::ArrayHandleVariantBase& faceNormals, vtkm::cont::ArrayHandle>& pointNormals) { vtkm::worklet::DispatcherMapTopology().Invoke(cellset, faceNormals, pointNormals); diff --git a/vtkm/worklet/Threshold.h b/vtkm/worklet/Threshold.h index 9930e8ff7..4794bc505 100644 --- a/vtkm/worklet/Threshold.h +++ b/vtkm/worklet/Threshold.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/VertexClustering.h b/vtkm/worklet/VertexClustering.h index d7ca5003a..db8445b3d 100644 --- a/vtkm/worklet/VertexClustering.h +++ b/vtkm/worklet/VertexClustering.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -84,7 +83,7 @@ struct SelectRepresentativePoint : public vtkm::worklet::WorkletReduceByKey template VTKM_CONT void operator()(const InputPointsArrayType& points, const vtkm::worklet::Keys& keys, - vtkm::cont::DynamicArrayHandle& output) const + vtkm::cont::ArrayHandleVariant& output) const { vtkm::cont::ArrayHandle out; @@ -96,11 +95,11 @@ struct SelectRepresentativePoint : public vtkm::worklet::WorkletReduceByKey }; template - VTKM_CONT static vtkm::cont::DynamicArrayHandle Run( + VTKM_CONT static vtkm::cont::ArrayHandleVariant Run( const vtkm::worklet::Keys& keys, const InputDynamicPointsArrayType& inputPoints) { - vtkm::cont::DynamicArrayHandle output; + vtkm::cont::ArrayHandleVariant output; RunTrampoline trampoline; vtkm::cont::CastAndCall(inputPoints, trampoline, keys, output); return output; @@ -380,7 +379,7 @@ public: #endif /// pass 2 : Choose a representative point from each cluster for the output: - vtkm::cont::DynamicArrayHandle repPointArray; + vtkm::cont::ArrayHandleVariant repPointArray; { vtkm::worklet::Keys keys; keys.BuildArrays(pointCidArray, vtkm::worklet::Keys::SortType::Stable); diff --git a/vtkm/worklet/connectivities/ImageConnectivity.h b/vtkm/worklet/connectivities/ImageConnectivity.h index d0f87d01f..cfe2b2e17 100644 --- a/vtkm/worklet/connectivities/ImageConnectivity.h +++ b/vtkm/worklet/connectivities/ImageConnectivity.h @@ -142,13 +142,13 @@ public: } }; - template + template void Run(const vtkm::cont::CellSetStructured<2>& input, - const vtkm::cont::DynamicArrayHandleBase& pixels, + const vtkm::cont::ArrayHandleVariantBase& pixels, OutputPortalType& componentsOut) const { using Types = vtkm::ListTagBase; - vtkm::cont::CastAndCall(pixels.ResetTypeList(Types{}), RunImpl(), input, componentsOut); + vtkm::cont::CastAndCall(pixels.ResetTypes(Types{}), RunImpl(), input, componentsOut); } template diff --git a/vtkm/worklet/particleadvection/GridEvaluators.h b/vtkm/worklet/particleadvection/GridEvaluators.h index 5a3c88892..ffeee0626 100644 --- a/vtkm/worklet/particleadvection/GridEvaluators.h +++ b/vtkm/worklet/particleadvection/GridEvaluators.h @@ -27,7 +27,6 @@ #include #include #include -#include #include diff --git a/vtkm/worklet/particleadvection/Integrators.h b/vtkm/worklet/particleadvection/Integrators.h index f8e4b9154..58576db87 100644 --- a/vtkm/worklet/particleadvection/Integrators.h +++ b/vtkm/worklet/particleadvection/Integrators.h @@ -24,7 +24,10 @@ #include #include #include + #include +#include + #include namespace vtkm diff --git a/vtkm/worklet/particleadvection/TemporalGridEvaluators.h b/vtkm/worklet/particleadvection/TemporalGridEvaluators.h index 0660e451a..76b565c97 100644 --- a/vtkm/worklet/particleadvection/TemporalGridEvaluators.h +++ b/vtkm/worklet/particleadvection/TemporalGridEvaluators.h @@ -26,7 +26,6 @@ #include #include #include -#include #include namespace vtkm diff --git a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx index 769a76259..bf6bd27f6 100644 --- a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx +++ b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -266,12 +265,11 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates)); //Set point scalar - dataSet.AddField(vtkm::cont::Field("distanceToOrigin", - vtkm::cont::Field::Association::POINTS, - vtkm::cont::DynamicArrayHandle(distanceToOrigin))); + dataSet.AddField(vtkm::cont::Field( + "distanceToOrigin", vtkm::cont::Field::Association::POINTS, distanceToOrigin)); dataSet.AddField(vtkm::cont::Field("distanceToOther", vtkm::cont::Field::Association::POINTS, - vtkm::cont::DynamicArrayHandle(distanceToOther))); + vtkm::cont::ArrayHandleVariant(distanceToOther))); CellSet cellSet("cells"); cellSet.Fill((dim + 1) * (dim + 1) * (dim + 1), HexTag::Id, HexTraits::NUM_POINTS, connectivity); diff --git a/vtkm/worklet/testing/UnitTestWarpScalar.cxx b/vtkm/worklet/testing/UnitTestWarpScalar.cxx index 13b37268c..c32386e75 100644 --- a/vtkm/worklet/testing/UnitTestWarpScalar.cxx +++ b/vtkm/worklet/testing/UnitTestWarpScalar.cxx @@ -78,7 +78,7 @@ void TestWarpScalar() vtkm::cont::ArrayHandle scaleFactorArray; auto scaleFactor = - ds.GetField("scalefactor").GetData().ResetTypeList(vtkm::TypeListTagFieldScalar()); + ds.GetField("scalefactor").GetData().ResetTypes(vtkm::TypeListTagFieldScalar()); scaleFactor.CopyTo(scaleFactorArray); auto sFAPortal = scaleFactorArray.GetPortalControl(); diff --git a/vtkm/worklet/testing/UnitTestWorkletMapField.cxx b/vtkm/worklet/testing/UnitTestWorkletMapField.cxx index 077e7d04c..b3848952f 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapField.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapField.cxx @@ -19,7 +19,8 @@ //============================================================================ #include #include -#include + +#include #include #include @@ -136,7 +137,7 @@ struct DoStaticTestWorklet }; template -struct DoDynamicTestWorklet +struct DoVariantTestWorklet { template VTKM_CONT void operator()(T) const @@ -154,25 +155,25 @@ struct DoDynamicTestWorklet vtkm::cont::ArrayHandle inoutHandle; - std::cout << "Create and run dispatcher with dynamic arrays." << std::endl; + std::cout << "Create and run dispatcher with variant arrays." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; - vtkm::cont::DynamicArrayHandle inputDynamic(inputHandle); + vtkm::cont::ArrayHandleVariant inputVariant(inputHandle); { //Verify we can pass by value vtkm::cont::ArrayCopy(inputHandle, inoutHandle); - vtkm::cont::DynamicArrayHandle outputDynamic(outputHandle); - vtkm::cont::DynamicArrayHandle inoutDynamic(inoutHandle); - dispatcher.Invoke(inputDynamic, outputDynamic, inoutDynamic); + vtkm::cont::ArrayHandleVariant outputVariant(outputHandle); + vtkm::cont::ArrayHandleVariant inoutVariant(inoutHandle); + dispatcher.Invoke(inputVariant, outputVariant, inoutVariant); CheckPortal(outputHandle.GetPortalConstControl()); CheckPortal(inoutHandle.GetPortalConstControl()); } { //Verify we can pass by pointer vtkm::cont::ArrayCopy(inputHandle, inoutHandle); - vtkm::cont::DynamicArrayHandle outputDynamic(outputHandle); - vtkm::cont::DynamicArrayHandle inoutDynamic(inoutHandle); - dispatcher.Invoke(&inputDynamic, &outputDynamic, &inoutDynamic); + vtkm::cont::ArrayHandleVariant outputVariant(outputHandle); + vtkm::cont::ArrayHandleVariant inoutVariant(inoutHandle); + dispatcher.Invoke(&inputVariant, &outputVariant, &inoutVariant); CheckPortal(outputHandle.GetPortalConstControl()); CheckPortal(inoutHandle.GetPortalConstControl()); } @@ -187,7 +188,7 @@ struct DoTestWorklet { DoStaticTestWorklet sw; sw(t); - DoDynamicTestWorklet dw; + DoVariantTestWorklet dw; dw(t); } }; @@ -207,8 +208,8 @@ void TestWorkletMapField(vtkm::cont::DeviceAdapterId id) std::cout << "--- Sending bad type to worklet." << std::endl; try { - //can only test with dynamic arrays, as static arrays will fail to compile - DoDynamicTestWorklet badWorkletTest; + //can only test with variant arrays, as static arrays will fail to compile + DoVariantTestWorklet badWorkletTest; badWorkletTest(vtkm::Vec()); VTKM_TEST_FAIL("Did not throw expected error."); } diff --git a/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx b/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx index 6bc7e44c7..74b91e3cd 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx @@ -19,7 +19,7 @@ //============================================================================ #include #include -#include +#include #include #include @@ -94,7 +94,7 @@ struct DoTestWorklet outputHandle = vtkm::cont::ArrayHandle(); outputHandle.Allocate(ARRAY_SIZE); - vtkm::cont::DynamicArrayHandle outputFieldDynamic(outputFieldArray); + vtkm::cont::ArrayHandleVariant outputFieldDynamic(outputFieldArray); dispatcher.Invoke(counting, inputHandle, outputHandle, outputFieldDynamic); std::cout << "Check dynamic array result." << std::endl; diff --git a/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx b/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx index 68bfe0b7a..568512c68 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx @@ -19,7 +19,7 @@ //============================================================================ #include #include -#include +#include #include #include @@ -83,9 +83,9 @@ struct DoTestWholeArrayWorklet // This just demonstrates that the WholeArray tags support dynamic arrays. VTKM_CONT - void CallWorklet(const vtkm::cont::DynamicArrayHandle& inArray, - const vtkm::cont::DynamicArrayHandle& inOutArray, - const vtkm::cont::DynamicArrayHandle& outArray) const + void CallWorklet(const vtkm::cont::ArrayHandleVariant& inArray, + const vtkm::cont::ArrayHandleVariant& inOutArray, + const vtkm::cont::ArrayHandleVariant& outArray) const { std::cout << "Create and run dispatcher." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; @@ -111,9 +111,9 @@ struct DoTestWholeArrayWorklet // Output arrays must be preallocated. outHandle.Allocate(ARRAY_SIZE); - this->CallWorklet(vtkm::cont::DynamicArrayHandle(inHandle), - vtkm::cont::DynamicArrayHandle(inOutHandle), - vtkm::cont::DynamicArrayHandle(outHandle)); + this->CallWorklet(vtkm::cont::ArrayHandleVariant(inHandle), + vtkm::cont::ArrayHandleVariant(inOutHandle), + vtkm::cont::ArrayHandleVariant(outHandle)); std::cout << "Check result." << std::endl; CheckPortal(inOutHandle.GetPortalConstControl()); @@ -127,7 +127,7 @@ struct DoTestAtomicArrayWorklet // This just demonstrates that the WholeArray tags support dynamic arrays. VTKM_CONT - void CallWorklet(const vtkm::cont::DynamicArrayHandle& inOutArray) const + void CallWorklet(const vtkm::cont::ArrayHandleVariant& inOutArray) const { std::cout << "Create and run dispatcher." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; @@ -142,7 +142,7 @@ struct DoTestAtomicArrayWorklet vtkm::cont::ArrayHandle inOutHandle = vtkm::cont::make_ArrayHandle(&inOutValue, 1); - this->CallWorklet(vtkm::cont::DynamicArrayHandle(inOutHandle)); + this->CallWorklet(vtkm::cont::ArrayHandleVariant(inOutHandle)); std::cout << "Check result." << std::endl; T result = inOutHandle.GetPortalConstControl().Get(0); diff --git a/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h b/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h index 213630c8f..ea0803876 100644 --- a/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h +++ b/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h b/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h index 747515d63..7ca45d3dd 100644 --- a/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h +++ b/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/triangulate/TriangulateExplicit.h b/vtkm/worklet/triangulate/TriangulateExplicit.h index ea168adab..c8d3f1950 100644 --- a/vtkm/worklet/triangulate/TriangulateExplicit.h +++ b/vtkm/worklet/triangulate/TriangulateExplicit.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/worklet/triangulate/TriangulateStructured.h b/vtkm/worklet/triangulate/TriangulateStructured.h index 06a9cde72..d5191fbe8 100644 --- a/vtkm/worklet/triangulate/TriangulateStructured.h +++ b/vtkm/worklet/triangulate/TriangulateStructured.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include From f63be1abe6183400c7ab6e315a9791183bd79da6 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 29 Nov 2018 13:37:50 -0500 Subject: [PATCH 22/36] Update vtkm/filter to work with ArrayHandleVariant --- vtkm/filter/ClipWithField.hxx | 26 ---------------- vtkm/filter/ClipWithImplicitFunction.hxx | 26 ---------------- vtkm/filter/CrossProduct.hxx | 2 +- vtkm/filter/DotProduct.hxx | 2 +- vtkm/filter/ExtractGeometry.hxx | 2 +- vtkm/filter/FieldMetadata.h | 13 +++----- vtkm/filter/Histogram.hxx | 8 ++--- vtkm/filter/MarchingCubes.hxx | 1 - vtkm/filter/PolicyBase.h | 31 ++++++------------- vtkm/filter/internal/CreateResult.h | 4 +-- .../testing/UnitTestCellMeasuresFilter.cxx | 3 +- .../testing/UnitTestClipWithFieldFilter.cxx | 3 +- ...UnitTestClipWithImplicitFunctionFilter.cxx | 5 ++- .../testing/UnitTestMarchingCubesFilter.cxx | 28 +++-------------- .../testing/UnitTestMultiBlockFilters.cxx | 1 - .../testing/UnitTestWarpScalarFilter.cxx | 17 ++-------- .../worklet/testing/UnitTestMarchingCubes.cxx | 10 +++--- 17 files changed, 38 insertions(+), 144 deletions(-) diff --git a/vtkm/filter/ClipWithField.hxx b/vtkm/filter/ClipWithField.hxx index a95f934ed..757779f08 100644 --- a/vtkm/filter/ClipWithField.hxx +++ b/vtkm/filter/ClipWithField.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -31,29 +30,6 @@ namespace vtkm namespace filter { -namespace clipwithfield -{ - -struct PointMapHelper -{ - PointMapHelper(const vtkm::worklet::Clip& worklet, vtkm::cont::DynamicArrayHandle& output) - : Worklet(worklet) - , Output(output) - { - } - - template - void operator()(const ArrayType& array) const - { - this->Output = this->Worklet.ProcessPointField(array); - } - - const vtkm::worklet::Clip& Worklet; - vtkm::cont::DynamicArrayHandle& Output; -}; - -} // end namespace clipwithfield - //----------------------------------------------------------------------------- inline VTKM_CONT ClipWithField::ClipWithField() : vtkm::filter::FilterDataSetWithField() @@ -71,8 +47,6 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( const vtkm::filter::FieldMetadata& fieldMeta, vtkm::filter::PolicyBase policy) { - using namespace clipwithfield; - if (fieldMeta.IsPointField() == false) { throw vtkm::cont::ErrorFilterExecution("Point field expected."); diff --git a/vtkm/filter/ClipWithImplicitFunction.hxx b/vtkm/filter/ClipWithImplicitFunction.hxx index 1cddf125a..62d490750 100644 --- a/vtkm/filter/ClipWithImplicitFunction.hxx +++ b/vtkm/filter/ClipWithImplicitFunction.hxx @@ -28,30 +28,6 @@ namespace vtkm { namespace filter { - -namespace clipwithimplicitfunction -{ - -struct PointMapHelper -{ - PointMapHelper(const vtkm::worklet::Clip& worklet, vtkm::cont::DynamicArrayHandle& output) - : Worklet(worklet) - , Output(output) - { - } - - template - void operator()(const ArrayType& array) const - { - this->Output = this->Worklet.ProcessPointField(array); - } - - const vtkm::worklet::Clip& Worklet; - vtkm::cont::DynamicArrayHandle& Output; -}; - -} // end namespace clipwithimplicitfunction - //----------------------------------------------------------------------------- ClipWithImplicitFunction::ClipWithImplicitFunction() @@ -64,8 +40,6 @@ inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( const vtkm::cont::DataSet& input, const vtkm::filter::PolicyBase& policy) { - using namespace clipwithimplicitfunction; - //get the cells and coordinates of the dataset const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex()); diff --git a/vtkm/filter/CrossProduct.hxx b/vtkm/filter/CrossProduct.hxx index 8094cb0b4..bb0f6661e 100644 --- a/vtkm/filter/CrossProduct.hxx +++ b/vtkm/filter/CrossProduct.hxx @@ -82,7 +82,7 @@ inline VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute( inDataSet.GetField(this->SecondaryFieldName, this->SecondaryFieldAssociation), policy, Traits()) - .ResetTypeList(TypeList()) + .ResetTypes(TypeList()) .CastAndCall(functor, field); } } diff --git a/vtkm/filter/DotProduct.hxx b/vtkm/filter/DotProduct.hxx index f71eebffb..7d8e162ad 100644 --- a/vtkm/filter/DotProduct.hxx +++ b/vtkm/filter/DotProduct.hxx @@ -83,7 +83,7 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( inDataSet.GetField(this->SecondaryFieldName, this->SecondaryFieldAssociation), policy, Traits()) - .ResetTypeList(TypeList()) + .ResetTypes(TypeList()) .CastAndCall(functor, field); } } diff --git a/vtkm/filter/ExtractGeometry.hxx b/vtkm/filter/ExtractGeometry.hxx index 0710ea19a..f2b617c5c 100644 --- a/vtkm/filter/ExtractGeometry.hxx +++ b/vtkm/filter/ExtractGeometry.hxx @@ -119,7 +119,7 @@ inline VTKM_CONT bool ExtractGeometry::DoMapField( const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::PolicyBase&) { - vtkm::cont::DynamicArrayHandle output; + vtkm::cont::ArrayHandleVariant output; if (fieldMeta.IsPointField()) { diff --git a/vtkm/filter/FieldMetadata.h b/vtkm/filter/FieldMetadata.h index 29e55b990..f5a31a86f 100644 --- a/vtkm/filter/FieldMetadata.h +++ b/vtkm/filter/FieldMetadata.h @@ -74,29 +74,26 @@ public: template VTKM_CONT vtkm::cont::Field AsField(const vtkm::cont::ArrayHandle& handle) const { - //Field only handles arrayHandles with default storage tag, so use - //dynamic array handles - vtkm::cont::DynamicArrayHandle dhandle(handle); if (this->IsCellField()) { - return vtkm::cont::Field(this->Name, this->Association, this->CellSetName, dhandle); + return vtkm::cont::Field(this->Name, this->Association, this->CellSetName, handle); } else { - return vtkm::cont::Field(this->Name, this->Association, dhandle); + return vtkm::cont::Field(this->Name, this->Association, handle); } } VTKM_CONT - vtkm::cont::Field AsField(const vtkm::cont::DynamicArrayHandle& dhandle) const + vtkm::cont::Field AsField(const vtkm::cont::ArrayHandleVariant& handle) const { if (this->IsCellField()) { - return vtkm::cont::Field(this->Name, this->Association, this->CellSetName, dhandle); + return vtkm::cont::Field(this->Name, this->Association, this->CellSetName, handle); } else { - return vtkm::cont::Field(this->Name, this->Association, dhandle); + return vtkm::cont::Field(this->Name, this->Association, handle); } } diff --git a/vtkm/filter/Histogram.hxx b/vtkm/filter/Histogram.hxx index f8b7179bd..89fce88c2 100644 --- a/vtkm/filter/Histogram.hxx +++ b/vtkm/filter/Histogram.hxx @@ -231,18 +231,14 @@ inline VTKM_CONT void Histogram::PreExecute(const vtkm::cont::MultiBlock& input, const vtkm::filter::PolicyBase&) { using TypeList = typename DerivedPolicy::FieldTypeList; - using StorageList = typename DerivedPolicy::FieldStorageList; if (this->Range.IsNonEmpty()) { this->ComputedRange = this->Range; } else { - auto handle = vtkm::cont::FieldRangeGlobalCompute(input, - this->GetActiveFieldName(), - this->GetActiveFieldAssociation(), - TypeList(), - StorageList()); + auto handle = vtkm::cont::FieldRangeGlobalCompute( + input, this->GetActiveFieldName(), this->GetActiveFieldAssociation(), TypeList()); if (handle.GetNumberOfValues() != 1) { throw vtkm::cont::ErrorFilterExecution("expecting scalar field."); diff --git a/vtkm/filter/MarchingCubes.hxx b/vtkm/filter/MarchingCubes.hxx index 853804e06..9f7da4901 100644 --- a/vtkm/filter/MarchingCubes.hxx +++ b/vtkm/filter/MarchingCubes.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/PolicyBase.h b/vtkm/filter/PolicyBase.h index bbc4db5ec..b200028a6 100644 --- a/vtkm/filter/PolicyBase.h +++ b/vtkm/filter/PolicyBase.h @@ -42,7 +42,6 @@ template struct PolicyBase { using FieldTypeList = VTKM_DEFAULT_TYPE_LIST_TAG; - using FieldStorageList = VTKM_DEFAULT_STORAGE_LIST_TAG; using StructuredCellSetList = vtkm::cont::CellSetListTagStructured; using UnstructuredCellSetList = vtkm::cont::CellSetListTagUnstructured; @@ -51,29 +50,25 @@ struct PolicyBase //----------------------------------------------------------------------------- template -VTKM_CONT vtkm::cont::DynamicArrayHandleBase -ApplyPolicy(const vtkm::cont::Field& field, const vtkm::filter::PolicyBase&) +VTKM_CONT vtkm::cont::ArrayHandleVariantBase ApplyPolicy( + const vtkm::cont::Field& field, + const vtkm::filter::PolicyBase&) { using TypeList = typename DerivedPolicy::FieldTypeList; - using StorageList = typename DerivedPolicy::FieldStorageList; - return field.GetData().ResetTypeAndStorageLists(TypeList(), StorageList()); + return field.GetData().ResetTypes(TypeList()); } //----------------------------------------------------------------------------- template -VTKM_CONT vtkm::cont::DynamicArrayHandleBase< - typename vtkm::filter::DeduceFilterFieldTypes::TypeList, - typename DerivedPolicy::FieldStorageList> +VTKM_CONT vtkm::cont::ArrayHandleVariantBase< + typename vtkm::filter::DeduceFilterFieldTypes::TypeList> ApplyPolicy(const vtkm::cont::Field& field, const vtkm::filter::PolicyBase&, const vtkm::filter::FilterTraits&) { using TypeList = typename vtkm::filter::DeduceFilterFieldTypes::TypeList; - - using StorageList = typename DerivedPolicy::FieldStorageList; - return field.GetData().ResetTypeAndStorageLists(TypeList(), StorageList()); + return field.GetData().ResetTypes(TypeList()); } //----------------------------------------------------------------------------- @@ -108,26 +103,22 @@ ApplyPolicyUnstructured(const vtkm::cont::DynamicCellSet& cellset, //----------------------------------------------------------------------------- template -VTKM_CONT vtkm::cont::SerializableField +VTKM_CONT vtkm::cont::SerializableField MakeSerializableField(const vtkm::filter::PolicyBase&) { return {}; } template -VTKM_CONT vtkm::cont::SerializableField +VTKM_CONT vtkm::cont::SerializableField MakeSerializableField(const vtkm::cont::Field& field, const vtkm::filter::PolicyBase&) { - return vtkm::cont::SerializableField{ field }; + return vtkm::cont::SerializableField{ field }; } template VTKM_CONT vtkm::cont::SerializableDataSet MakeSerializableDataSet(const vtkm::filter::PolicyBase&) { @@ -136,13 +127,11 @@ MakeSerializableDataSet(const vtkm::filter::PolicyBase&) template VTKM_CONT vtkm::cont::SerializableDataSet MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, const vtkm::filter::PolicyBase&) { return vtkm::cont::SerializableDataSet{ dataset }; } } diff --git a/vtkm/filter/internal/CreateResult.h b/vtkm/filter/internal/CreateResult.h index 821e0a378..9be6ef7fa 100644 --- a/vtkm/filter/internal/CreateResult.h +++ b/vtkm/filter/internal/CreateResult.h @@ -108,7 +108,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult( return clone; } -/// Use this function if you have a DynamicArrayHandle that holds the data +/// Use this function if you have a ArrayHandleVariant that holds the data /// for the field. You also need to specify a name and an association for the /// field. If the field is associated with a particular element set (for /// example, a cell association is associated with a cell set), the name of @@ -116,7 +116,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult( /// for \c Association::WHOLE_MESH and \c Association::POINTS associations. /// inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::DynamicArrayHandle& fieldArray, + const vtkm::cont::ArrayHandleVariant& fieldArray, const std::string& fieldName, vtkm::cont::Field::Association fieldAssociation, const std::string& elementSetName = "") diff --git a/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx b/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx index 00b6dece1..7cde3c467 100644 --- a/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx +++ b/vtkm/filter/testing/UnitTestCellMeasuresFilter.cxx @@ -20,7 +20,6 @@ #include "vtkm/filter/CellMeasures.h" -#include "vtkm/cont/DynamicArrayHandle.h" #include "vtkm/cont/testing/MakeTestDataSet.h" #include "vtkm/cont/testing/Testing.h" @@ -51,7 +50,7 @@ void TestCellMeasuresFilter(vtkm::cont::DataSet& dataset, // Check that the empty measure name above produced a field with the expected name. vols.SetCellMeasureName("measure"); - vtkm::cont::DynamicArrayHandle temp = outputData.GetField(vols.GetCellMeasureName()).GetData(); + auto temp = outputData.GetField(vols.GetCellMeasureName()).GetData(); VTKM_TEST_ASSERT(temp.GetNumberOfValues() == static_cast(expected.size()), "Output field could not be found or was improper."); diff --git a/vtkm/filter/testing/UnitTestClipWithFieldFilter.cxx b/vtkm/filter/testing/UnitTestClipWithFieldFilter.cxx index 2d31efbc1..a51ca0afb 100644 --- a/vtkm/filter/testing/UnitTestClipWithFieldFilter.cxx +++ b/vtkm/filter/testing/UnitTestClipWithFieldFilter.cxx @@ -20,7 +20,6 @@ #include -#include #include #include @@ -80,7 +79,7 @@ void TestClipExplicit() VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 1, "Wrong number of fields in the output dataset"); - vtkm::cont::DynamicArrayHandle temp = outputData.GetField("scalars").GetData(); + auto temp = outputData.GetField("scalars").GetData(); vtkm::cont::ArrayHandle resultArrayHandle; temp.CopyTo(resultArrayHandle); diff --git a/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx b/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx index fe81da422..fd2cb5d1d 100644 --- a/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx +++ b/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx @@ -20,7 +20,6 @@ #include -#include #include #include @@ -76,7 +75,7 @@ void TestClipStructured() VTKM_TEST_ASSERT(outputData.GetCellSet().GetNumberOfCells() == 8, "Wrong number of cells in the output dataset"); - vtkm::cont::DynamicArrayHandle temp = outputData.GetField("scalars").GetData(); + vtkm::cont::ArrayHandleVariant temp = outputData.GetField("scalars").GetData(); vtkm::cont::ArrayHandle resultArrayHandle; temp.CopyTo(resultArrayHandle); @@ -116,7 +115,7 @@ void TestClipStructuredInverted() VTKM_TEST_ASSERT(outputData.GetCellSet().GetNumberOfCells() == 4, "Wrong number of cells in the output dataset"); - vtkm::cont::DynamicArrayHandle temp = outputData.GetField("scalars").GetData(); + vtkm::cont::ArrayHandleVariant temp = outputData.GetField("scalars").GetData(); vtkm::cont::ArrayHandle resultArrayHandle; temp.CopyTo(resultArrayHandle); diff --git a/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx b/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx index 8ef970a33..0b5e244a8 100644 --- a/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx +++ b/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -229,22 +228,7 @@ public: class PolicyRadiantDataSet : public vtkm::filter::PolicyBase { - using DataHandleType = MakeRadiantDataSet::DataArrayHandle; - using CountingHandleType = MakeRadiantDataSet::ConnectivityArrayHandle; - - using TransformHandleType = - vtkm::cont::ArrayHandleTransform, - CubeGridConnectivity>; - public: - struct TypeListTagRadiantTypes : vtkm::ListTagBase - { - }; - - using FieldStorageList = TypeListTagRadiantTypes; - struct TypeListTagRadiantCellSetTypes : vtkm::ListTagBase { }; @@ -281,12 +265,10 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates)); //Set point scalar - dataSet.AddField(vtkm::cont::Field("distanceToOrigin", - vtkm::cont::Field::Association::POINTS, - vtkm::cont::DynamicArrayHandle(distanceToOrigin))); - dataSet.AddField(vtkm::cont::Field("distanceToOther", - vtkm::cont::Field::Association::POINTS, - vtkm::cont::DynamicArrayHandle(distanceToOther))); + dataSet.AddField(vtkm::cont::Field( + "distanceToOrigin", vtkm::cont::Field::Association::POINTS, distanceToOrigin)); + dataSet.AddField( + vtkm::cont::Field("distanceToOther", vtkm::cont::Field::Association::POINTS, distanceToOther)); CellSet cellSet("cells"); cellSet.Fill(coordinates.GetNumberOfValues(), HexTag::Id, HexTraits::NUM_POINTS, connectivity); @@ -384,7 +366,7 @@ void TestMarchingCubesCustomPolicy() //custom field type mc.SetActiveField("distanceToOrigin"); mc.SetFieldsToPass({ "distanceToOrigin", "distanceToOther" }); - vtkm::cont::DataSet outputData = mc.Execute(dataSet, PolicyRadiantDataSet()); + vtkm::cont::DataSet outputData = mc.Execute(dataSet, PolicyRadiantDataSet{}); VTKM_TEST_ASSERT(outputData.GetNumberOfCellSets() == 1, "Wrong number of cellsets in the output dataset"); diff --git a/vtkm/filter/testing/UnitTestMultiBlockFilters.cxx b/vtkm/filter/testing/UnitTestMultiBlockFilters.cxx index 218c16258..56a729b28 100644 --- a/vtkm/filter/testing/UnitTestMultiBlockFilters.cxx +++ b/vtkm/filter/testing/UnitTestMultiBlockFilters.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx b/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx index 04c59f1a0..be668295c 100644 --- a/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx +++ b/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx @@ -64,19 +64,6 @@ vtkm::cont::DataSet MakeWarpScalarTestDataSet() return dataSet; } -class PolicyWarpScalar : public vtkm::filter::PolicyBase -{ -public: - using vecType = vtkm::Vec; - struct TypeListTagWarpScalarTags - : vtkm::ListTagBase::StorageTag, - vtkm::cont::ArrayHandle::StorageTag, - vtkm::cont::ArrayHandle::StorageTag> - { - }; - using FieldStorageList = TypeListTagWarpScalarTags; -}; - void CheckResult(const vtkm::filter::WarpScalar& filter, const vtkm::cont::DataSet& result) { VTKM_TEST_ASSERT(result.HasField("warpscalar", vtkm::cont::Field::Association::POINTS), @@ -124,7 +111,7 @@ void TestWarpScalarFilter() filter.SetUseCoordinateSystemAsPrimaryField(true); filter.SetNormalField("normal"); filter.SetScalarFactorField("scalarfactor"); - vtkm::cont::DataSet result = filter.Execute(ds, PolicyWarpScalar()); + vtkm::cont::DataSet result = filter.Execute(ds); CheckResult(filter, result); } @@ -134,7 +121,7 @@ void TestWarpScalarFilter() filter.SetPrimaryField("vec1"); filter.SetNormalField("normal"); filter.SetScalarFactorField("scalarfactor"); - vtkm::cont::DataSet result = filter.Execute(ds, PolicyWarpScalar()); + vtkm::cont::DataSet result = filter.Execute(ds); CheckResult(filter, result); } } diff --git a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx index bf6bd27f6..a38b8638d 100644 --- a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx +++ b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx @@ -286,7 +286,7 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp void TestMarchingCubesUniformGrid() { - std::cout << "Testing MarchingCubes filter on a uniform grid" << std::endl; + std::cout << "Testing MarchingCubes worklet on a uniform grid" << std::endl; vtkm::Id3 dims(4, 4, 4); vtkm::cont::DataSet dataSet = vtkm_ut_mc_worklet::MakeIsosurfaceTestDataSet(dims); @@ -341,7 +341,7 @@ void TestMarchingCubesUniformGrid() void TestMarchingCubesExplicit() { - std::cout << "Testing MarchingCubes filter on explicit data" << std::endl; + std::cout << "Testing MarchingCubes worklet on explicit data" << std::endl; using DataSetGenerator = vtkm_ut_mc_worklet::MakeRadiantDataSet; using Vec3Handle = vtkm::cont::ArrayHandle>; @@ -400,11 +400,11 @@ void TestMarchingCubesExplicit() VTKM_TEST_ASSERT(result.GetNumberOfCells() == cellFieldArrayOut.GetNumberOfValues(), "Output cell data invalid"); VTKM_TEST_ASSERT(test_equal(vertices.GetNumberOfValues(), 2472), - "Wrong vertices result for MarchingCubes filter"); + "Wrong vertices result for MarchingCubes worklet"); VTKM_TEST_ASSERT(test_equal(normals.GetNumberOfValues(), 2472), - "Wrong normals result for MarchingCubes filter"); + "Wrong normals result for MarchingCubes worklet"); VTKM_TEST_ASSERT(test_equal(scalars.GetNumberOfValues(), 2472), - "Wrong scalars result for MarchingCubes filter"); + "Wrong scalars result for MarchingCubes worklet"); } void TestMarchingCubes() From 9ca4d36e2851c6585d014ed4167d427b9d291be9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 29 Nov 2018 16:54:47 -0500 Subject: [PATCH 23/36] Update benchmarking to work with ArrayHandleVariant --- benchmarking/BenchmarkFieldAlgorithms.cxx | 32 +++++++++----------- benchmarking/BenchmarkFilters.cxx | 14 +-------- benchmarking/BenchmarkTopologyAlgorithms.cxx | 11 +++---- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/benchmarking/BenchmarkFieldAlgorithms.cxx b/benchmarking/BenchmarkFieldAlgorithms.cxx index 3c14135fd..89812a478 100644 --- a/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -22,8 +22,8 @@ #include #include +#include #include -#include #include #include @@ -309,7 +309,6 @@ struct ValueTypes : vtkm::ListTagBase struct InterpValueTypes : vtkm::ListTagBase> { }; -using StorageListTag = ::vtkm::cont::StorageListTagBasic; /// This class runs a series of micro-benchmarks to measure /// performance of different field operations @@ -318,14 +317,11 @@ class BenchmarkFieldAlgorithms { using StorageTag = vtkm::cont::StorageTagBasic; - using Algorithm = vtkm::cont::DeviceAdapterAlgorithm; - using Timer = vtkm::cont::Timer; - using ValueDynamicHandle = vtkm::cont::DynamicArrayHandleBase; - using InterpDynamicHandle = vtkm::cont::DynamicArrayHandleBase; - using IdDynamicHandle = - vtkm::cont::DynamicArrayHandleBase; + using ValueVariantHandle = vtkm::cont::ArrayHandleVariantBase; + using InterpVariantHandle = vtkm::cont::ArrayHandleVariantBase; + using IdVariantHandle = vtkm::cont::ArrayHandleVariantBase; private: template @@ -402,9 +398,9 @@ private: VTKM_CONT vtkm::Float64 operator()() { - ValueDynamicHandle dstocks(this->StockPrice); - ValueDynamicHandle dstrikes(this->OptionStrike); - ValueDynamicHandle doptions(this->OptionYears); + ValueVariantHandle dstocks(this->StockPrice); + ValueVariantHandle dstrikes(this->OptionStrike); + ValueVariantHandle doptions(this->OptionYears); vtkm::cont::ArrayHandle callResultHandle, putResultHandle; const Value RISKFREE = 0.02f; @@ -488,9 +484,9 @@ private: vtkm::cont::ArrayHandle temp1; vtkm::cont::ArrayHandle temp2; - vtkm::cont::DynamicArrayHandleBase dinput(this->InputHandle); - ValueDynamicHandle dtemp1(temp1); - ValueDynamicHandle dtemp2(temp2); + vtkm::cont::ArrayHandleVariantBase dinput(this->InputHandle); + ValueVariantHandle dtemp1(temp1); + ValueVariantHandle dtemp2(temp2); Timer timer; @@ -564,7 +560,7 @@ private: { using MathTypes = vtkm::ListTagBase, vtkm::Vec>; - vtkm::cont::DynamicArrayHandleBase dinput(this->InputHandle); + vtkm::cont::ArrayHandleVariantBase dinput(this->InputHandle); vtkm::cont::ArrayHandle result; @@ -666,9 +662,9 @@ private: VTKM_CONT vtkm::Float64 operator()() { - InterpDynamicHandle dfield(this->FieldHandle); - InterpDynamicHandle dweight(this->WeightHandle); - IdDynamicHandle dedges(this->EdgePairHandle); + InterpVariantHandle dfield(this->FieldHandle); + InterpVariantHandle dweight(this->WeightHandle); + IdVariantHandle dedges(this->EdgePairHandle); vtkm::cont::ArrayHandle result; Timer timer; diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index 1d10fb7be..e022091ab 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -147,8 +147,6 @@ using FieldTypes = vtkm::ListTagBase, vtkm::Vec>; -using FieldStorage = vtkm::ListTagBase; - using StructuredCellList = vtkm::ListTagBase>; using UnstructuredCellList = @@ -158,26 +156,16 @@ using AllCellList = vtkm::ListTagJoin; using CoordinateList = vtkm::ListTagBase, vtkm::Vec>; -using CoordinateStorage = - vtkm::ListTagBase; - -using DeviceAdapters = vtkm::ListTagBase; - class BenchmarkFilterPolicy : public vtkm::filter::PolicyBase { public: using FieldTypeList = FieldTypes; - using FieldStorageList = FieldStorage; using StructuredCellSetList = StructuredCellList; using UnstructuredCellSetList = UnstructuredCellList; using AllCellSetList = AllCellList; using CoordinateTypeList = CoordinateList; - using CoordinateStorageList = CoordinateStorage; - - using DeviceAdapterList = DeviceAdapters; }; // Class implementing all filter benchmarks: @@ -852,7 +840,7 @@ public: } }; -// Get the number of components in a DynamicArrayHandle, ArrayHandle, or Field's +// Get the number of components in a ArrayHandleVariant, ArrayHandle, or Field's // ValueType. struct NumberOfComponents { diff --git a/benchmarking/BenchmarkTopologyAlgorithms.cxx b/benchmarking/BenchmarkTopologyAlgorithms.cxx index cf773b60c..7fa830629 100644 --- a/benchmarking/BenchmarkTopologyAlgorithms.cxx +++ b/benchmarking/BenchmarkTopologyAlgorithms.cxx @@ -136,7 +136,6 @@ struct ValueTypes : vtkm::ListTagBase { }; -using StorageListTag = ::vtkm::cont::StorageListTagBasic; /// This class runs a series of micro-benchmarks to measure /// performance of different field operations @@ -145,11 +144,9 @@ class BenchmarkTopologyAlgorithms { using StorageTag = vtkm::cont::StorageTagBasic; - using Algorithm = vtkm::cont::DeviceAdapterAlgorithm; - using Timer = vtkm::cont::Timer; - using ValueDynamicHandle = vtkm::cont::DynamicArrayHandleBase; + using ValueVariantHandle = vtkm::cont::ArrayHandleVariantBase; private: template @@ -245,7 +242,7 @@ private: vtkm::cont::CellSetStructured<3> cellSet; cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); - ValueDynamicHandle dinput(this->InputHandle); + ValueVariantHandle dinput(this->InputHandle); vtkm::cont::ArrayHandle result; Timer timer; @@ -324,7 +321,7 @@ private: vtkm::cont::CellSetStructured<3> cellSet; cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); - ValueDynamicHandle dinput(this->InputHandle); + ValueVariantHandle dinput(this->InputHandle); vtkm::cont::ArrayHandle result; Timer timer; @@ -372,7 +369,7 @@ private: cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); vtkm::cont::ArrayHandle result; - ValueDynamicHandle dinput(this->InputHandle); + ValueVariantHandle dinput(this->InputHandle); Timer timer; From b138798604f3fbc7ed4e89537b5de4315914c1b5 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 29 Nov 2018 17:02:00 -0500 Subject: [PATCH 24/36] Update examples to work with ArrayHandleVariant/Virtual --- examples/clipping/Clipping.cxx | 8 ++++---- examples/histogram/HistogramMPI.h | 5 ++--- examples/histogram/HistogramMPI.hxx | 10 ++++------ examples/tau_timing/TauTiming.cxx | 1 - 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/clipping/Clipping.cxx b/examples/clipping/Clipping.cxx index 09d54aff6..f1737925d 100644 --- a/examples/clipping/Clipping.cxx +++ b/examples/clipping/Clipping.cxx @@ -38,11 +38,11 @@ namespace struct FieldMapper { - vtkm::cont::DynamicArrayHandle& Output; + vtkm::cont::ArrayHandleVariant& Output; vtkm::worklet::Clip& Worklet; bool IsCellField; - FieldMapper(vtkm::cont::DynamicArrayHandle& output, + FieldMapper(vtkm::cont::ArrayHandleVariant& output, vtkm::worklet::Clip& worklet, bool isCellField) : Output(output) @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) bool invertClip = false; vtkm::cont::CellSetExplicit<> outputCellSet = clip.Run(input.GetCellSet(0), - scalarField.GetData().ResetTypeList(vtkm::TypeListTagScalarAll()), + scalarField.GetData().ResetTypes(vtkm::TypeListTagScalarAll()), clipValue, invertClip); vtkm::Float64 clipTime = timer.GetElapsedTime(); @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) continue; } - vtkm::cont::DynamicArrayHandle outField; + vtkm::cont::ArrayHandleVariant outField; FieldMapper fieldMapper(outField, clip, isCellField); inField.GetData().CastAndCall(fieldMapper); output.AddField(vtkm::cont::Field(inField.GetName(), inField.GetAssociation(), outField)); diff --git a/examples/histogram/HistogramMPI.h b/examples/histogram/HistogramMPI.h index 641924500..60e1fe5e8 100644 --- a/examples/histogram/HistogramMPI.h +++ b/examples/histogram/HistogramMPI.h @@ -64,12 +64,11 @@ public: VTKM_CONT vtkm::Range GetComputedRange() const { return this->ComputedRange; } - template + template VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy, - const DeviceAdapter& tag); + const vtkm::filter::PolicyBase& policy); //@{ /// when operating on vtkm::cont::MultiBlock, we diff --git a/examples/histogram/HistogramMPI.hxx b/examples/histogram/HistogramMPI.hxx index 732ff3cb3..c8bafc8ca 100644 --- a/examples/histogram/HistogramMPI.hxx +++ b/examples/histogram/HistogramMPI.hxx @@ -123,13 +123,12 @@ inline VTKM_CONT HistogramMPI::HistogramMPI() } //----------------------------------------------------------------------------- -template +template inline VTKM_CONT vtkm::cont::DataSet HistogramMPI::DoExecute( const vtkm::cont::DataSet&, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata&, - const vtkm::filter::PolicyBase&, - const DeviceAdapter& device) + const vtkm::filter::PolicyBase&) { vtkm::cont::ArrayHandle binArray; T delta; @@ -142,12 +141,11 @@ inline VTKM_CONT vtkm::cont::DataSet HistogramMPI::DoExecute( static_cast(this->ComputedRange.Min), static_cast(this->ComputedRange.Max), delta, - binArray, - device); + binArray); } else { - worklet.Run(field, this->NumberOfBins, this->ComputedRange, delta, binArray, device); + worklet.Run(field, this->NumberOfBins, this->ComputedRange, delta, binArray); } this->BinDelta = static_cast(delta); diff --git a/examples/tau_timing/TauTiming.cxx b/examples/tau_timing/TauTiming.cxx index 9b52d4c62..b72ed7edf 100644 --- a/examples/tau_timing/TauTiming.cxx +++ b/examples/tau_timing/TauTiming.cxx @@ -47,7 +47,6 @@ #include -#include #include static bool printProgress = true; From 0a40c620ac2a86c8673b5de06eabb825df696c7f Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 11 Dec 2018 08:56:08 -0500 Subject: [PATCH 25/36] Rename ArrayHandleVariant to VariantArrayHandle. --- benchmarking/BenchmarkFieldAlgorithms.cxx | 12 +-- benchmarking/BenchmarkFilters.cxx | 2 +- benchmarking/BenchmarkTopologyAlgorithms.cxx | 2 +- examples/clipping/Clipping.cxx | 6 +- vtkm/cont/CMakeLists.txt | 18 ++-- vtkm/cont/CellSet.h | 2 +- vtkm/cont/CoordinateSystem.cxx | 4 +- vtkm/cont/CoordinateSystem.h | 4 +- vtkm/cont/CoordinateSystem.hxx | 6 +- vtkm/cont/DataSet.h | 2 +- vtkm/cont/DataSetFieldAdd.h | 6 +- vtkm/cont/ErrorBadType.h | 2 +- vtkm/cont/Field.cxx | 10 +-- vtkm/cont/Field.h | 30 +++---- ...ndleVariant.cxx => VariantArrayHandle.cxx} | 8 +- ...ayHandleVariant.h => VariantArrayHandle.h} | 90 +++++++++---------- vtkm/cont/internal/CMakeLists.txt | 2 +- ...tainer.h => VariantArrayHandleContainer.h} | 50 +++++------ vtkm/cont/testing/CMakeLists.txt | 2 +- vtkm/cont/testing/Testing.h | 10 +-- vtkm/cont/testing/TestingSerialization.h | 2 +- .../cont/testing/UnitTestMoveConstructors.cxx | 2 +- .../UnitTestSerializationArrayHandle.cxx | 52 +++++------ ...ant.cxx => UnitTestVariantArrayHandle.cxx} | 32 +++---- vtkm/filter/ExtractGeometry.hxx | 2 +- vtkm/filter/FieldMetadata.h | 2 +- vtkm/filter/PolicyBase.h | 4 +- vtkm/filter/internal/CreateResult.h | 4 +- ...UnitTestClipWithImplicitFunctionFilter.cxx | 4 +- vtkm/io/reader/VTKDataSetReaderBase.h | 40 ++++----- vtkm/io/reader/VTKRectilinearGridReader.h | 2 +- .../rendering/raytracing/RayTracingTypeDefs.h | 2 +- vtkm/worklet/Clip.h | 2 +- vtkm/worklet/DispatcherMapField.h | 2 +- vtkm/worklet/DispatcherStreamingMapField.h | 2 +- vtkm/worklet/SurfaceNormals.h | 6 +- vtkm/worklet/VertexClustering.h | 8 +- .../connectivities/ImageConnectivity.h | 2 +- .../worklet/testing/UnitTestMarchingCubes.cxx | 2 +- .../testing/UnitTestWorkletMapField.cxx | 12 +-- .../UnitTestWorkletMapFieldExecArg.cxx | 4 +- .../UnitTestWorkletMapFieldWholeArray.cxx | 18 ++-- 42 files changed, 237 insertions(+), 237 deletions(-) rename vtkm/cont/{ArrayHandleVariant.cxx => VariantArrayHandle.cxx} (84%) rename vtkm/cont/{ArrayHandleVariant.h => VariantArrayHandle.h} (78%) rename vtkm/cont/internal/{ArrayHandleVariantContainer.h => VariantArrayHandleContainer.h} (78%) rename vtkm/cont/testing/{UnitTestArrayHandleVariant.cxx => UnitTestVariantArrayHandle.cxx} (92%) diff --git a/benchmarking/BenchmarkFieldAlgorithms.cxx b/benchmarking/BenchmarkFieldAlgorithms.cxx index 89812a478..5d98708fa 100644 --- a/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -22,10 +22,10 @@ #include #include -#include #include #include #include +#include #include #include @@ -319,9 +319,9 @@ class BenchmarkFieldAlgorithms using Timer = vtkm::cont::Timer; - using ValueVariantHandle = vtkm::cont::ArrayHandleVariantBase; - using InterpVariantHandle = vtkm::cont::ArrayHandleVariantBase; - using IdVariantHandle = vtkm::cont::ArrayHandleVariantBase; + using ValueVariantHandle = vtkm::cont::VariantArrayHandleBase; + using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase; + using IdVariantHandle = vtkm::cont::VariantArrayHandleBase; private: template @@ -484,7 +484,7 @@ private: vtkm::cont::ArrayHandle temp1; vtkm::cont::ArrayHandle temp2; - vtkm::cont::ArrayHandleVariantBase dinput(this->InputHandle); + vtkm::cont::VariantArrayHandleBase dinput(this->InputHandle); ValueVariantHandle dtemp1(temp1); ValueVariantHandle dtemp2(temp2); @@ -560,7 +560,7 @@ private: { using MathTypes = vtkm::ListTagBase, vtkm::Vec>; - vtkm::cont::ArrayHandleVariantBase dinput(this->InputHandle); + vtkm::cont::VariantArrayHandleBase dinput(this->InputHandle); vtkm::cont::ArrayHandle result; diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index e022091ab..51f0a7c39 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -840,7 +840,7 @@ public: } }; -// Get the number of components in a ArrayHandleVariant, ArrayHandle, or Field's +// Get the number of components in a VariantArrayHandle, ArrayHandle, or Field's // ValueType. struct NumberOfComponents { diff --git a/benchmarking/BenchmarkTopologyAlgorithms.cxx b/benchmarking/BenchmarkTopologyAlgorithms.cxx index 7fa830629..d8dd4d2dc 100644 --- a/benchmarking/BenchmarkTopologyAlgorithms.cxx +++ b/benchmarking/BenchmarkTopologyAlgorithms.cxx @@ -146,7 +146,7 @@ class BenchmarkTopologyAlgorithms using Timer = vtkm::cont::Timer; - using ValueVariantHandle = vtkm::cont::ArrayHandleVariantBase; + using ValueVariantHandle = vtkm::cont::VariantArrayHandleBase; private: template diff --git a/examples/clipping/Clipping.cxx b/examples/clipping/Clipping.cxx index f1737925d..02150c002 100644 --- a/examples/clipping/Clipping.cxx +++ b/examples/clipping/Clipping.cxx @@ -38,11 +38,11 @@ namespace struct FieldMapper { - vtkm::cont::ArrayHandleVariant& Output; + vtkm::cont::VariantArrayHandle& Output; vtkm::worklet::Clip& Worklet; bool IsCellField; - FieldMapper(vtkm::cont::ArrayHandleVariant& output, + FieldMapper(vtkm::cont::VariantArrayHandle& output, vtkm::worklet::Clip& worklet, bool isCellField) : Output(output) @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) continue; } - vtkm::cont::ArrayHandleVariant outField; + vtkm::cont::VariantArrayHandle outField; FieldMapper fieldMapper(outField, clip, isCellField); inField.GetData().CastAndCall(fieldMapper); output.AddField(vtkm::cont::Field(inField.GetName(), inField.GetAssociation(), outField)); diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 4c59873b0..e6d7185f1 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -23,13 +23,14 @@ set(headers ArrayCopy.h ArrayHandle.h ArrayHandleAny.h - ArrayHandleCast.h ArrayHandleCartesianProduct.h + ArrayHandleCast.h ArrayHandleCompositeVector.h + ArrayHandleConcatenate.h ArrayHandleConstant.h ArrayHandleCounting.h - ArrayHandleExtractComponent.h ArrayHandleDiscard.h + ArrayHandleExtractComponent.h ArrayHandleGroupVec.h ArrayHandleGroupVecVariable.h ArrayHandleImplicit.h @@ -40,19 +41,17 @@ set(headers ArrayHandleSwizzle.h ArrayHandleTransform.h ArrayHandleUniformPointCoordinates.h - ArrayHandleVariant.h ArrayHandleView.h ArrayHandleVirtual.h ArrayHandleVirtualCoordinates.h ArrayHandleZip.h ArrayPortal.h ArrayPortalToIterators.h - ArrayHandleConcatenate.h ArrayRangeCompute.h AssignerMultiBlock.h AtomicArray.h - BoundingIntervalHierarchyNode.h BoundingIntervalHierarchy.h + BoundingIntervalHierarchyNode.h BoundsCompute.h BoundsGlobalCompute.h CellLocator.h @@ -61,9 +60,9 @@ set(headers CellSet.h CellSetExplicit.h CellSetListTag.h + CellSetPermutation.h CellSetSingleType.h CellSetStructured.h - CellSetPermutation.h ColorTable.h ColorTableSamples.h CoordinateSystem.h @@ -83,8 +82,8 @@ set(headers ErrorBadDevice.h ErrorBadType.h ErrorBadValue.h - ErrorFilterExecution.h ErrorExecution.h + ErrorFilterExecution.h ErrorInternal.h ExecutionAndControlObjectBase.h ExecutionObjectBase.h @@ -103,11 +102,12 @@ set(headers Storage.h StorageBasic.h StorageImplicit.h - StorageVirtual.h StorageListTag.h + StorageVirtual.h Timer.h TryExecute.h TypeString.h + VariantArrayHandle.h VirtualObjectHandle.h ) @@ -128,7 +128,6 @@ set(template_sources set(sources ArrayHandle.cxx - ArrayHandleVariant.cxx AssignerMultiBlock.cxx BoundsCompute.cxx BoundsGlobalCompute.cxx @@ -161,6 +160,7 @@ set(sources StorageBasic.cxx StorageVirtual.cxx TryExecute.cxx + VariantArrayHandle.cxx ) # This list of sources has code that uses devices and so might need to be diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index 8f05fc585..ecf0965d9 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -25,9 +25,9 @@ #include #include -#include #include #include +#include namespace vtkm { diff --git a/vtkm/cont/CoordinateSystem.cxx b/vtkm/cont/CoordinateSystem.cxx index 7973ee2b0..59391569e 100644 --- a/vtkm/cont/CoordinateSystem.cxx +++ b/vtkm/cont/CoordinateSystem.cxx @@ -118,12 +118,12 @@ template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem( vtkm::cont::ArrayHandle>::StorageTag>&); template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem(std::string name, - const vtkm::cont::ArrayHandleVariant&); + const vtkm::cont::VariantArrayHandle&); template VTKM_CONT_EXPORT void CoordinateSystem::SetData( const vtkm::cont::ArrayHandle>&); template VTKM_CONT_EXPORT void CoordinateSystem::SetData( const vtkm::cont::ArrayHandle>&); -template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleVariant&); +template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::VariantArrayHandle&); } } // namespace vtkm::cont diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index abf0cdf75..72b17b3cf 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -46,7 +46,7 @@ public: template VTKM_CONT CoordinateSystem(std::string name, - const vtkm::cont::ArrayHandleVariantBase& data); + const vtkm::cont::VariantArrayHandleBase& data); template VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle& data); @@ -71,7 +71,7 @@ public: VTKM_CONT template - void SetData(const vtkm::cont::ArrayHandleVariantBase& newdata); + void SetData(const vtkm::cont::VariantArrayHandleBase& newdata); VTKM_CONT void GetRange(vtkm::Range* range) const diff --git a/vtkm/cont/CoordinateSystem.hxx b/vtkm/cont/CoordinateSystem.hxx index f009e7192..dca1ac063 100644 --- a/vtkm/cont/CoordinateSystem.hxx +++ b/vtkm/cont/CoordinateSystem.hxx @@ -50,7 +50,7 @@ struct MakeArrayHandleVirtualCoordinatesFunctor template VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates MakeArrayHandleVirtualCoordinates( - const vtkm::cont::ArrayHandleVariantBase& array) + const vtkm::cont::VariantArrayHandleBase& array) { vtkm::cont::ArrayHandleVirtualCoordinates output; vtkm::cont::CastAndCall(array.ResetTypes(vtkm::TypeListTagFieldVec3{}), @@ -63,7 +63,7 @@ VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates MakeArrayHandleVirtualCoordi template VTKM_CONT CoordinateSystem::CoordinateSystem( std::string name, - const vtkm::cont::ArrayHandleVariantBase& data) + const vtkm::cont::VariantArrayHandleBase& data) : Superclass(name, Association::POINTS, detail::MakeArrayHandleVirtualCoordinates(data)) { } @@ -83,7 +83,7 @@ VTKM_CONT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandle VTKM_CONT void CoordinateSystem::SetData( - const vtkm::cont::ArrayHandleVariantBase& newdata) + const vtkm::cont::VariantArrayHandleBase& newdata) { this->SetData(detail::MakeArrayHandleVirtualCoordinates(newdata)); } diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index 80c06cff2..1f913f4b8 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -23,12 +23,12 @@ #include #include -#include #include #include #include #include #include +#include namespace vtkm { diff --git a/vtkm/cont/DataSetFieldAdd.h b/vtkm/cont/DataSetFieldAdd.h index ae99538ae..ee2bb5586 100644 --- a/vtkm/cont/DataSetFieldAdd.h +++ b/vtkm/cont/DataSetFieldAdd.h @@ -38,7 +38,7 @@ public: VTKM_CONT static void AddPointField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::ArrayHandleVariant& field) + const vtkm::cont::VariantArrayHandle& field) { dataSet.AddField(Field(fieldName, vtkm::cont::Field::Association::POINTS, field)); } @@ -74,7 +74,7 @@ public: VTKM_CONT static void AddCellField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::ArrayHandleVariant& field, + const vtkm::cont::VariantArrayHandle& field, const std::string& cellSetName) { dataSet.AddField( @@ -119,7 +119,7 @@ public: VTKM_CONT static void AddCellField(vtkm::cont::DataSet& dataSet, const std::string& fieldName, - const vtkm::cont::ArrayHandleVariant& field, + const vtkm::cont::VariantArrayHandle& field, vtkm::Id cellSetIndex = 0) { std::string cellSetName = dataSet.GetCellSet(cellSetIndex).GetName(); diff --git a/vtkm/cont/ErrorBadType.h b/vtkm/cont/ErrorBadType.h index 4c8c7884f..0a0248f7e 100644 --- a/vtkm/cont/ErrorBadType.h +++ b/vtkm/cont/ErrorBadType.h @@ -45,7 +45,7 @@ VTKM_SILENCE_WEAK_VTABLE_WARNING_END /// Throws an ErrorBadType exception with the following message: /// Cast failed: \c baseType --> \c derivedType". -/// This is generally caused by asking for a casting of a ArrayHandleVariant +/// This is generally caused by asking for a casting of a VariantArrayHandle /// with an insufficient type list. // VTKM_CONT_EXPORT void throwFailedDynamicCast(const std::string& baseType, diff --git a/vtkm/cont/Field.cxx b/vtkm/cont/Field.cxx index 20093a89a..7e1bf3677 100644 --- a/vtkm/cont/Field.cxx +++ b/vtkm/cont/Field.cxx @@ -27,7 +27,7 @@ namespace cont /// constructors for points / whole mesh VTKM_CONT -Field::Field(std::string name, Association association, const vtkm::cont::ArrayHandleVariant& data) +Field::Field(std::string name, Association association, const vtkm::cont::VariantArrayHandle& data) : Name(name) , FieldAssociation(association) , AssocCellSetName() @@ -45,7 +45,7 @@ VTKM_CONT Field::Field(std::string name, Association association, const std::string& cellSetName, - const vtkm::cont::ArrayHandleVariant& data) + const vtkm::cont::VariantArrayHandle& data) : Name(name) , FieldAssociation(association) , AssocCellSetName(cellSetName) @@ -62,7 +62,7 @@ VTKM_CONT Field::Field(std::string name, Association association, vtkm::IdComponent logicalDim, - const vtkm::cont::ArrayHandleVariant& data) + const vtkm::cont::VariantArrayHandle& data) : Name(name) , FieldAssociation(association) , AssocCellSetName() @@ -157,13 +157,13 @@ Field::~Field() VTKM_CONT -const vtkm::cont::ArrayHandleVariant& Field::GetData() const +const vtkm::cont::VariantArrayHandle& Field::GetData() const { return this->Data; } VTKM_CONT -vtkm::cont::ArrayHandleVariant& Field::GetData() +vtkm::cont::VariantArrayHandle& Field::GetData() { this->ModifiedFlag = true; return this->Data; diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index a75accfe5..bb6ab82c1 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -26,10 +26,10 @@ #include #include -#include #include #include #include +#include namespace vtkm { @@ -71,13 +71,13 @@ public: /// constructors for points / whole mesh VTKM_CONT - Field(std::string name, Association association, const vtkm::cont::ArrayHandleVariant& data); + Field(std::string name, Association association, const vtkm::cont::VariantArrayHandle& data); template VTKM_CONT Field(std::string name, Association association, const vtkm::cont::ArrayHandle& data) - : Field(name, association, vtkm::cont::ArrayHandleVariant{ data }) + : Field(name, association, vtkm::cont::VariantArrayHandle{ data }) { } @@ -86,14 +86,14 @@ public: Field(std::string name, Association association, const std::string& cellSetName, - const vtkm::cont::ArrayHandleVariant& data); + const vtkm::cont::VariantArrayHandle& data); template VTKM_CONT Field(std::string name, Association association, const std::string& cellSetName, const vtkm::cont::ArrayHandle& data) - : Field(name, association, cellSetName, vtkm::cont::ArrayHandleVariant{ data }) + : Field(name, association, cellSetName, vtkm::cont::VariantArrayHandle{ data }) { } @@ -102,14 +102,14 @@ public: Field(std::string name, Association association, vtkm::IdComponent logicalDim, - const vtkm::cont::ArrayHandleVariant& data); + const vtkm::cont::VariantArrayHandle& data); template VTKM_CONT Field(std::string name, Association association, vtkm::IdComponent logicalDim, const vtkm::cont::ArrayHandle& data) - : Field(name, association, logicalDim, vtkm::cont::ArrayHandleVariant{ data }) + : Field(name, association, logicalDim, vtkm::cont::VariantArrayHandle{ data }) { } @@ -125,8 +125,8 @@ public: VTKM_CONT Association GetAssociation() const { return this->FieldAssociation; } VTKM_CONT std::string GetAssocCellSet() const { return this->AssocCellSetName; } VTKM_CONT vtkm::IdComponent GetAssocLogicalDim() const { return this->AssocLogicalDim; } - const vtkm::cont::ArrayHandleVariant& GetData() const; - vtkm::cont::ArrayHandleVariant& GetData(); + const vtkm::cont::VariantArrayHandle& GetData() const; + vtkm::cont::VariantArrayHandle& GetData(); template @@ -165,7 +165,7 @@ public: } VTKM_CONT - void SetData(const vtkm::cont::ArrayHandleVariant& newdata) + void SetData(const vtkm::cont::VariantArrayHandle& newdata) { this->Data = newdata; this->ModifiedFlag = true; @@ -188,7 +188,7 @@ private: std::string AssocCellSetName; ///< only populate if assoc is cells vtkm::IdComponent AssocLogicalDim; ///< only populate if assoc is logical dim - vtkm::cont::ArrayHandleVariant Data; + vtkm::cont::VariantArrayHandle Data; mutable vtkm::cont::ArrayHandle Range; mutable bool ModifiedFlag = true; @@ -358,26 +358,26 @@ public: diy::load(bb, assocVal); auto assoc = static_cast(assocVal); - vtkm::cont::ArrayHandleVariantBase data; + vtkm::cont::VariantArrayHandleBase data; if (assoc == vtkm::cont::Field::Association::CELL_SET) { std::string assocCellSetName; diy::load(bb, assocCellSetName); diy::load(bb, data); field = - vtkm::cont::Field(name, assoc, assocCellSetName, vtkm::cont::ArrayHandleVariant(data)); + vtkm::cont::Field(name, assoc, assocCellSetName, vtkm::cont::VariantArrayHandle(data)); } else if (assoc == vtkm::cont::Field::Association::LOGICAL_DIM) { vtkm::IdComponent assocLogicalDim; diy::load(bb, assocLogicalDim); diy::load(bb, data); - field = vtkm::cont::Field(name, assoc, assocLogicalDim, vtkm::cont::ArrayHandleVariant(data)); + field = vtkm::cont::Field(name, assoc, assocLogicalDim, vtkm::cont::VariantArrayHandle(data)); } else { diy::load(bb, data); - field = vtkm::cont::Field(name, assoc, vtkm::cont::ArrayHandleVariant(data)); + field = vtkm::cont::Field(name, assoc, vtkm::cont::VariantArrayHandle(data)); } } }; diff --git a/vtkm/cont/ArrayHandleVariant.cxx b/vtkm/cont/VariantArrayHandle.cxx similarity index 84% rename from vtkm/cont/ArrayHandleVariant.cxx rename to vtkm/cont/VariantArrayHandle.cxx index d128fe354..94f865c5b 100644 --- a/vtkm/cont/ArrayHandleVariant.cxx +++ b/vtkm/cont/VariantArrayHandle.cxx @@ -21,8 +21,8 @@ #include #include -#include #include +#include namespace vtkm { @@ -31,18 +31,18 @@ namespace cont namespace internal { -ArrayHandleVariantContainerBase::ArrayHandleVariantContainerBase() +VariantArrayHandleContainerBase::VariantArrayHandleContainerBase() { } -ArrayHandleVariantContainerBase::~ArrayHandleVariantContainerBase() +VariantArrayHandleContainerBase::~VariantArrayHandleContainerBase() { } } namespace detail { -void ThrowCastAndCallException(const vtkm::cont::internal::ArrayHandleVariantContainerBase& ref, +void ThrowCastAndCallException(const vtkm::cont::internal::VariantArrayHandleContainerBase& ref, const std::type_info& type) { std::ostringstream out; diff --git a/vtkm/cont/ArrayHandleVariant.h b/vtkm/cont/VariantArrayHandle.h similarity index 78% rename from vtkm/cont/ArrayHandleVariant.h rename to vtkm/cont/VariantArrayHandle.h index e675f610c..4a575fa11 100644 --- a/vtkm/cont/ArrayHandleVariant.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -17,8 +17,8 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -#ifndef vtk_m_cont_ArrayHandleVariant_h -#define vtk_m_cont_ArrayHandleVariant_h +#ifndef vtk_m_cont_VariantArrayHandle_h +#define vtk_m_cont_VariantArrayHandle_h #include @@ -31,7 +31,7 @@ #include #include -#include +#include namespace vtkm { @@ -39,7 +39,7 @@ namespace cont { /// \brief Holds an array handle without having to specify template parameters. /// -/// \c ArrayHandleVariant holds an \c ArrayHandle or \c ArrayHandleVirtual +/// \c VariantArrayHandle holds an \c ArrayHandle or \c ArrayHandleVirtual /// object using runtime polymorphism to manage different value types and /// storage rather than compile-time templates. This adds a programming /// convenience that helps avoid a proliferation of templates. It also provides @@ -47,65 +47,65 @@ namespace cont /// will not be known until runtime. /// /// To interface between the runtime polymorphism and the templated algorithms -/// in VTK-m, \c ArrayHandleVariant contains a method named \c CastAndCall that +/// in VTK-m, \c VariantArrayHandle contains a method named \c CastAndCall that /// will determine the correct type from some known list of types. It returns /// an ArrayHandleVirtual which type erases the storage type by using polymorphism. /// This mechanism is used internally by VTK-m's worklet invocation /// mechanism to determine the type when running algorithms. /// -/// By default, \c ArrayHandleVariant will assume that the value type in the +/// By default, \c VariantArrayHandle will assume that the value type in the /// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST_TAG /// This list can be changed by using the \c ResetTypes. It is /// worthwhile to match these lists closely to the possible types that might be /// used. If a type is missing you will get a runtime error. If there are more /// types than necessary, then the template mechanism will create a lot of /// object code that is never used, and keep in mind that the number of -/// combinations grows exponentially when using multiple \c ArrayHandleVariant +/// combinations grows exponentially when using multiple \c VariantArrayHandle /// objects. /// -/// The actual implementation of \c ArrayHandleVariant is in a templated class -/// named \c ArrayHandleVariantBase, which is templated on the list of +/// The actual implementation of \c VariantArrayHandle is in a templated class +/// named \c VariantArrayHandleBase, which is templated on the list of /// component types. /// template -class VTKM_ALWAYS_EXPORT ArrayHandleVariantBase +class VTKM_ALWAYS_EXPORT VariantArrayHandleBase { public: VTKM_CONT - ArrayHandleVariantBase() = default; + VariantArrayHandleBase() = default; template - VTKM_CONT ArrayHandleVariantBase(const vtkm::cont::ArrayHandle& array) - : ArrayContainer(std::make_shared>( + VTKM_CONT VariantArrayHandleBase(const vtkm::cont::ArrayHandle& array) + : ArrayContainer(std::make_shared>( vtkm::cont::ArrayHandleAny{ array })) { } template - explicit VTKM_CONT ArrayHandleVariantBase( + explicit VTKM_CONT VariantArrayHandleBase( const vtkm::cont::ArrayHandle& array) - : ArrayContainer(std::make_shared>(array)) + : ArrayContainer(std::make_shared>(array)) { } template - VTKM_CONT explicit ArrayHandleVariantBase(const ArrayHandleVariantBase& src) + VTKM_CONT explicit VariantArrayHandleBase(const VariantArrayHandleBase& src) : ArrayContainer(internal::variant::GetContainer::Extract(src)) { } - VTKM_CONT ArrayHandleVariantBase(const ArrayHandleVariantBase& src) = default; - VTKM_CONT ArrayHandleVariantBase(ArrayHandleVariantBase&& src) noexcept = default; + VTKM_CONT VariantArrayHandleBase(const VariantArrayHandleBase& src) = default; + VTKM_CONT VariantArrayHandleBase(VariantArrayHandleBase&& src) noexcept = default; VTKM_CONT - ~ArrayHandleVariantBase() {} + ~VariantArrayHandleBase() {} VTKM_CONT - ArrayHandleVariantBase& operator=(const ArrayHandleVariantBase& src) = + VariantArrayHandleBase& operator=(const VariantArrayHandleBase& src) = default; VTKM_CONT - ArrayHandleVariantBase& operator=(ArrayHandleVariantBase&& src) noexcept = + VariantArrayHandleBase& operator=(VariantArrayHandleBase&& src) noexcept = default; @@ -167,16 +167,16 @@ public: /// constraints. /// template - VTKM_CONT ArrayHandleVariantBase ResetTypes(NewTypeList = NewTypeList()) const + VTKM_CONT VariantArrayHandleBase ResetTypes(NewTypeList = NewTypeList()) const { VTKM_IS_LIST_TAG(NewTypeList); - return ArrayHandleVariantBase(*this); + return VariantArrayHandleBase(*this); } /// Attempts to cast the held array to a specific value type, /// then call the given functor with the cast array. The types /// tried in the cast are those in the lists defined by the TypeList. - /// By default \c ArrayHandleVariant set this to VTKM_DEFAULT_TYPE_LIST_TAG. + /// By default \c VariantArrayHandle set this to VTKM_DEFAULT_TYPE_LIST_TAG. /// template VTKM_CONT void CastAndCall(Functor&& f, Args&&...) const; @@ -188,9 +188,9 @@ public: /// creating output arrays that should be the same type as some input array. /// VTKM_CONT - ArrayHandleVariantBase NewInstance() const + VariantArrayHandleBase NewInstance() const { - ArrayHandleVariantBase instance; + VariantArrayHandleBase instance; instance.ArrayContainer = this->ArrayContainer->NewInstance(); return instance; } @@ -227,28 +227,28 @@ public: private: friend struct internal::variant::GetContainer; - std::shared_ptr ArrayContainer; + std::shared_ptr ArrayContainer; }; -using ArrayHandleVariant = vtkm::cont::ArrayHandleVariantBase; +using VariantArrayHandle = vtkm::cont::VariantArrayHandleBase; namespace detail { -struct ArrayHandleVariantTry +struct VariantArrayHandleTry { template void operator()(T, Functor&& f, bool& called, - const vtkm::cont::internal::ArrayHandleVariantContainerBase& container, + const vtkm::cont::internal::VariantArrayHandleContainerBase& container, Args&&... args) const { if (!called && vtkm::cont::internal::variant::IsVirtualType(&container)) { called = true; const auto* derived = - static_cast*>(&container); + static_cast*>(&container); VTKM_LOG_CAST_SUCC(container, derived); f(derived->Array, std::forward(args)...); } @@ -256,7 +256,7 @@ struct ArrayHandleVariantTry }; VTKM_CONT_EXPORT void ThrowCastAndCallException( - const vtkm::cont::internal::ArrayHandleVariantContainerBase&, + const vtkm::cont::internal::VariantArrayHandleContainerBase&, const std::type_info&); } // namespace detail @@ -264,11 +264,11 @@ VTKM_CONT_EXPORT void ThrowCastAndCallException( template template -VTKM_CONT void ArrayHandleVariantBase::CastAndCall(Functor&& f, Args&&... args) const +VTKM_CONT void VariantArrayHandleBase::CastAndCall(Functor&& f, Args&&... args) const { bool called = false; const auto& ref = *this->ArrayContainer; - vtkm::ListForEach(detail::ArrayHandleVariantTry{}, + vtkm::ListForEach(detail::VariantArrayHandleTry{}, TypeList{}, std::forward(f), called, @@ -286,7 +286,7 @@ namespace internal { template -struct DynamicTransformTraits> +struct DynamicTransformTraits> { using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; }; @@ -303,7 +303,7 @@ namespace diy namespace internal { -struct ArrayHandleVariantSerializeFunctor +struct VariantArrayHandleSerializeFunctor { template void operator()(const ArrayHandleType& ah, BinaryBuffer& bb) const @@ -313,11 +313,11 @@ struct ArrayHandleVariantSerializeFunctor } }; -struct ArrayHandleVariantDeserializeFunctor +struct VariantArrayHandleDeserializeFunctor { template void operator()(T, - vtkm::cont::ArrayHandleVariantBase& dh, + vtkm::cont::VariantArrayHandleBase& dh, const std::string& typeString, bool& success, BinaryBuffer& bb) const @@ -328,7 +328,7 @@ struct ArrayHandleVariantDeserializeFunctor { ArrayHandleType ah; diy::load(bb, ah); - dh = vtkm::cont::ArrayHandleVariantBase(ah); + dh = vtkm::cont::VariantArrayHandleBase(ah); success = true; } } @@ -337,15 +337,15 @@ struct ArrayHandleVariantDeserializeFunctor } // internal template -struct Serialization> +struct Serialization> { private: - using Type = vtkm::cont::ArrayHandleVariantBase; + using Type = vtkm::cont::VariantArrayHandleBase; public: static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj) { - vtkm::cont::CastAndCall(obj, internal::ArrayHandleVariantSerializeFunctor{}, bb); + vtkm::cont::CastAndCall(obj, internal::VariantArrayHandleSerializeFunctor{}, bb); } static VTKM_CONT void load(BinaryBuffer& bb, Type& obj) @@ -355,12 +355,12 @@ public: bool success = false; vtkm::ListForEach( - internal::ArrayHandleVariantDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb); + internal::VariantArrayHandleDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb); if (!success) { throw vtkm::cont::ErrorBadType( - "Error deserializing ArrayHandleVariant. Message TypeString: " + typeString); + "Error deserializing VariantArrayHandle. Message TypeString: " + typeString); } } }; @@ -368,4 +368,4 @@ public: } // diy -#endif //vtk_m_virts_ArrayHandleVariant_h +#endif //vtk_m_virts_VariantArrayHandle_h diff --git a/vtkm/cont/internal/CMakeLists.txt b/vtkm/cont/internal/CMakeLists.txt index b52c0f283..1a9edf83c 100644 --- a/vtkm/cont/internal/CMakeLists.txt +++ b/vtkm/cont/internal/CMakeLists.txt @@ -23,7 +23,7 @@ set(headers ArrayHandleBasicImpl.h ArrayHandleBasicImpl.hxx ArrayHandleExecutionManager.h - ArrayHandleVariantContainer.h + VariantArrayHandleContainer.h ArrayManagerExecution.h ArrayManagerExecutionShareWithControl.h ArrayPortalFromIterators.h diff --git a/vtkm/cont/internal/ArrayHandleVariantContainer.h b/vtkm/cont/internal/VariantArrayHandleContainer.h similarity index 78% rename from vtkm/cont/internal/ArrayHandleVariantContainer.h rename to vtkm/cont/internal/VariantArrayHandleContainer.h index 92e70bbaa..2499b562b 100644 --- a/vtkm/cont/internal/ArrayHandleVariantContainer.h +++ b/vtkm/cont/internal/VariantArrayHandleContainer.h @@ -17,8 +17,8 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -#ifndef vtk_m_cont_ArrayHandleVariantContainer_h -#define vtk_m_cont_ArrayHandleVariantContainer_h +#ifndef vtk_m_cont_VariantArrayHandleContainer_h +#define vtk_m_cont_VariantArrayHandleContainer_h #include @@ -38,19 +38,19 @@ namespace cont // Forward declaration needed for GetContainer template -class ArrayHandleVariantBase; +class VariantArrayHandleBase; namespace internal { -/// \brief Base class for ArrayHandleVariantContainer +/// \brief Base class for VariantArrayHandleContainer /// -struct VTKM_CONT_EXPORT ArrayHandleVariantContainerBase +struct VTKM_CONT_EXPORT VariantArrayHandleContainerBase { - ArrayHandleVariantContainerBase(); + VariantArrayHandleContainerBase(); // This must exist so that subclasses are destroyed correctly. - virtual ~ArrayHandleVariantContainerBase(); + virtual ~VariantArrayHandleContainerBase(); virtual vtkm::Id GetNumberOfValues() const = 0; virtual vtkm::IdComponent GetNumberOfComponents() const = 0; @@ -60,35 +60,35 @@ struct VTKM_CONT_EXPORT ArrayHandleVariantContainerBase virtual void PrintSummary(std::ostream& out) const = 0; - virtual std::shared_ptr NewInstance() const = 0; + virtual std::shared_ptr NewInstance() const = 0; virtual const vtkm::cont::StorageVirtual* GetStorage() const = 0; }; /// \brief ArrayHandle container that can use C++ run-time type information. /// -/// The \c ArrayHandleVariantContainer is similar to the +/// The \c VariantArrayHandleContainer is similar to the /// \c SimplePolymorphicContainer in that it can contain an object of an /// unknown type. However, this class specifically holds ArrayHandle objects /// (with different template parameters) so that it can polymorphically answer /// simple questions about the object. /// template -struct VTKM_ALWAYS_EXPORT ArrayHandleVariantContainer final : public ArrayHandleVariantContainerBase +struct VTKM_ALWAYS_EXPORT VariantArrayHandleContainer final : public VariantArrayHandleContainerBase { vtkm::cont::ArrayHandleVirtual Array; - ArrayHandleVariantContainer() + VariantArrayHandleContainer() : Array() { } - ArrayHandleVariantContainer(const vtkm::cont::ArrayHandleVirtual& array) + VariantArrayHandleContainer(const vtkm::cont::ArrayHandleVirtual& array) : Array(array) { } - ~ArrayHandleVariantContainer() = default; + ~VariantArrayHandleContainer() = default; vtkm::Id GetNumberOfValues() const { return this->Array.GetNumberOfValues(); } @@ -103,9 +103,9 @@ struct VTKM_ALWAYS_EXPORT ArrayHandleVariantContainer final : public ArrayHandle vtkm::cont::printSummary_ArrayHandle(this->Array, out); } - std::shared_ptr NewInstance() const + std::shared_ptr NewInstance() const { - return std::make_shared>(this->Array.NewInstance()); + return std::make_shared>(this->Array.NewInstance()); } const vtkm::cont::StorageVirtual* GetStorage() const { return this->Array.GetStorage(); } @@ -116,21 +116,21 @@ namespace variant // One instance of a template class cannot access the private members of // another instance of a template class. However, I want to be able to copy -// construct a ArrayHandleVariant from another ArrayHandleVariant of any other +// construct a VariantArrayHandle from another VariantArrayHandle of any other // type. Since you cannot partially specialize friendship, use this accessor // class to get at the internals for the copy constructor. struct GetContainer { template - VTKM_CONT static const std::shared_ptr& Extract( - const vtkm::cont::ArrayHandleVariantBase& src) + VTKM_CONT static const std::shared_ptr& Extract( + const vtkm::cont::VariantArrayHandleBase& src) { return src.ArrayContainer; } }; template -VTKM_CONT bool IsType(const ArrayHandleVariantContainerBase* container) +VTKM_CONT bool IsType(const VariantArrayHandleContainerBase* container) { //container could be nullptr VTKM_IS_ARRAY_HANDLE(ArrayHandleType); if (!container) @@ -145,20 +145,20 @@ VTKM_CONT bool IsType(const ArrayHandleVariantContainerBase* container) } template -VTKM_CONT bool IsVirtualType(const ArrayHandleVariantContainerBase* container) +VTKM_CONT bool IsVirtualType(const VariantArrayHandleContainerBase* container) { if (container == nullptr) { //you can't use typeid on nullptr of polymorphic types return false; } - return typeid(ArrayHandleVariantContainer) == typeid(*container); + return typeid(VariantArrayHandleContainer) == typeid(*container); } template struct VTKM_ALWAYS_EXPORT Caster { - vtkm::cont::ArrayHandle operator()(const ArrayHandleVariantContainerBase* container) const + vtkm::cont::ArrayHandle operator()(const VariantArrayHandleContainerBase* container) const { using ArrayHandleType = vtkm::cont::ArrayHandle; if (!IsType(container)) @@ -180,7 +180,7 @@ template struct VTKM_ALWAYS_EXPORT Caster { vtkm::cont::ArrayHandle operator()( - const ArrayHandleVariantContainerBase* container) const + const VariantArrayHandleContainerBase* container) const { if (!IsVirtualType(container)) { @@ -192,7 +192,7 @@ struct VTKM_ALWAYS_EXPORT Caster // Technically, this method returns a copy of the \c ArrayHandle. But // because \c ArrayHandle acts like a shared pointer, it is valid to // do the copy. - const auto* derived = static_cast*>(container); + const auto* derived = static_cast*>(container); VTKM_LOG_CAST_SUCC(container, derived->Array); return derived->Array; } @@ -200,7 +200,7 @@ struct VTKM_ALWAYS_EXPORT Caster template -VTKM_CONT ArrayHandleType Cast(const ArrayHandleVariantContainerBase* container) +VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container) { //container could be nullptr VTKM_IS_ARRAY_HANDLE(ArrayHandleType); using Type = typename ArrayHandleType::ValueType; diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index 4ee74b64b..9392f8de3 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -55,7 +55,7 @@ set(unit_tests UnitTestArrayHandleTransform.cxx UnitTestArrayHandleUniformPointCoordinates.cxx UnitTestArrayHandleConcatenate.cxx - UnitTestArrayHandleVariant.cxx + UnitTestVariantArrayHandle.cxx UnitTestArrayPortalToIterators.cxx UnitTestCellLocator.cxx UnitTestCellSetExplicit.cxx diff --git a/vtkm/cont/testing/Testing.h b/vtkm/cont/testing/Testing.h index 1c45a78ab..c4b5ec3ce 100644 --- a/vtkm/cont/testing/Testing.h +++ b/vtkm/cont/testing/Testing.h @@ -27,11 +27,11 @@ #include #include -#include #include #include #include #include +#include // clang-format off @@ -219,7 +219,7 @@ struct TestEqualArrayHandle template VTKM_CONT void operator()( const vtkm::cont::ArrayHandle& array1, - const vtkm::cont::ArrayHandleVariantBase& array2, + const vtkm::cont::VariantArrayHandleBase& array2, TestEqualResult& result) const { array2.CastAndCall(*this, array1, result); @@ -227,7 +227,7 @@ struct TestEqualArrayHandle template VTKM_CONT void operator()( - const vtkm::cont::ArrayHandleVariantBase& array1, + const vtkm::cont::VariantArrayHandleBase& array1, const vtkm::cont::ArrayHandle& array2, TestEqualResult& result) const { @@ -236,8 +236,8 @@ struct TestEqualArrayHandle template VTKM_CONT void operator()( - const vtkm::cont::ArrayHandleVariantBase& array1, - const vtkm::cont::ArrayHandleVariantBase& array2, + const vtkm::cont::VariantArrayHandleBase& array1, + const vtkm::cont::VariantArrayHandleBase& array2, TestEqualResult& result) const { array2.CastAndCall(*this, array1, result); diff --git a/vtkm/cont/testing/TestingSerialization.h b/vtkm/cont/testing/TestingSerialization.h index d6f64b2ef..5603c4927 100644 --- a/vtkm/cont/testing/TestingSerialization.h +++ b/vtkm/cont/testing/TestingSerialization.h @@ -21,7 +21,7 @@ #define vtk_m_cont_testing_TestingSerialization_h #include -#include +#include #include // clang-format off diff --git a/vtkm/cont/testing/UnitTestMoveConstructors.cxx b/vtkm/cont/testing/UnitTestMoveConstructors.cxx index de8c872ac..7f736c9ad 100644 --- a/vtkm/cont/testing/UnitTestMoveConstructors.cxx +++ b/vtkm/cont/testing/UnitTestMoveConstructors.cxx @@ -83,7 +83,7 @@ struct IsNoExceptHandle using VirtualType = vtkm::cont::ArrayHandleVirtual; //verify the handle type - is_noexcept_movable< HandleType >(); + is_noexcept_movable(); is_noexcept_movable(); is_noexcept_movable(); diff --git a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx index 2a1cb10b3..4186de563 100644 --- a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx @@ -37,7 +37,7 @@ #include #include -#include +#include #include @@ -78,8 +78,8 @@ using TestTypesList = vtkm::ListTagBase>; template -inline vtkm::cont::ArrayHandleVariantBase> -MakeTestArrayHandleVariant(const vtkm::cont::ArrayHandle& array) +inline vtkm::cont::VariantArrayHandleBase> +MakeTestVariantArrayHandle(const vtkm::cont::ArrayHandle& array) { return array; } @@ -91,7 +91,7 @@ struct TestArrayHandleBasic { auto array = RandomArrayHandle::Make(ArraySize); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -105,7 +105,7 @@ struct TestArrayHandleCartesianProduct RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -117,7 +117,7 @@ struct TestArrayHandleCast auto array = vtkm::cont::make_ArrayHandleCast(RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -129,7 +129,7 @@ struct TestArrayHandleCompositeVector auto array = vtkm::cont::make_ArrayHandleCompositeVector(RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -141,7 +141,7 @@ struct TestArrayHandleConcatenate auto array = vtkm::cont::make_ArrayHandleConcatenate(RandomArrayHandle::Make(ArraySize), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -153,7 +153,7 @@ struct TestArrayHandleConstant T cval = RandomValue::Make(); auto array = vtkm::cont::make_ArrayHandleConstant(cval, ArraySize); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -166,7 +166,7 @@ struct TestArrayHandleCounting T step = RandomValue::Make(0, 5); auto array = vtkm::cont::make_ArrayHandleCounting(start, step, ArraySize); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -179,7 +179,7 @@ struct TestArrayHandleExtractComponent auto array = vtkm::cont::make_ArrayHandleExtractComponent( RandomArrayHandle::Make(ArraySize), RandomValue::Make(0, numComps - 1)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -196,21 +196,21 @@ struct TestArrayHandleGroupVec { auto array = vtkm::cont::make_ArrayHandleGroupVec<3>(flat); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); break; } case 4: { auto array = vtkm::cont::make_ArrayHandleGroupVec<4>(flat); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); break; } default: { auto array = vtkm::cont::make_ArrayHandleGroupVec<2>(flat); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); break; } } @@ -238,7 +238,7 @@ struct TestArrayHandleGroupVecVariable // cannot make a DynamicArrayHandle containing ArrayHandleGroupVecVariable // because of the variable number of components of its values. - // RunTest(MakeTestArrayHandleVariant(array)); + // RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -269,7 +269,7 @@ struct TestArrayHandleImplicit ImplicitFunctor functor(RandomValue::Make(2, 9)); auto array = vtkm::cont::make_ArrayHandleImplicit(functor, ArraySize); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -278,7 +278,7 @@ void TestArrayHandleIndex() auto size = RandomValue::Make(2, 10); auto array = vtkm::cont::ArrayHandleIndex(size); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } struct TestArrayHandlePermutation @@ -295,7 +295,7 @@ struct TestArrayHandlePermutation RandomArrayHandle::Make(ArraySize, 0, ArraySize - 1), RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -306,7 +306,7 @@ struct TestArrayHandleReverse { auto array = vtkm::cont::make_ArrayHandleReverse(RandomArrayHandle::Make(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; @@ -329,7 +329,7 @@ struct TestArrayHandleSwizzle auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), map2s[RandomValue::Make(0, 5)]); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); break; } case 3: @@ -338,7 +338,7 @@ struct TestArrayHandleSwizzle auto array = make_ArrayHandleSwizzle(RandomArrayHandle>::Make(ArraySize), map3s[RandomValue::Make(0, 5)]); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); break; } } @@ -372,7 +372,7 @@ struct TestArrayHandleTransform auto array = vtkm::cont::make_ArrayHandleTransform(RandomArrayHandle::Make(ArraySize), TransformFunctor{}); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } template @@ -381,7 +381,7 @@ struct TestArrayHandleTransform auto array = vtkm::cont::make_ArrayHandleTransform( RandomArrayHandle::Make(ArraySize), TransformFunctor{}, InverseTransformFunctor{}); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } template @@ -404,7 +404,7 @@ void TestArrayHandleUniformPointCoordinates() { auto array = MakeRandomArrayHandleUniformPointCoordinates(); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } void TestArrayHandleVirtualCoordinates() @@ -432,7 +432,7 @@ void TestArrayHandleVirtualCoordinates() } RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } struct TestArrayHandleZip @@ -443,7 +443,7 @@ struct TestArrayHandleZip auto array = vtkm::cont::make_ArrayHandleZip(RandomArrayHandle::Make(ArraySize), vtkm::cont::ArrayHandleIndex(ArraySize)); RunTest(array); - RunTest(MakeTestArrayHandleVariant(array)); + RunTest(MakeTestVariantArrayHandle(array)); } }; diff --git a/vtkm/cont/testing/UnitTestArrayHandleVariant.cxx b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx similarity index 92% rename from vtkm/cont/testing/UnitTestArrayHandleVariant.cxx rename to vtkm/cont/testing/UnitTestVariantArrayHandle.cxx index 843777fb4..95a89d1a8 100644 --- a/vtkm/cont/testing/UnitTestArrayHandleVariant.cxx +++ b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx @@ -18,7 +18,7 @@ // this software. //============================================================================ -#include +#include #include @@ -47,7 +47,7 @@ namespace vtkm { -// ArrayHandleVariant requires its value type to have a defined VecTraits +// VariantArrayHandle requires its value type to have a defined VecTraits // class. One of the tests is to use an "unusual" array of std::string // (which is pretty pointless but might tease out some assumptions). // Make an implementation here. Because I am lazy, this is only a partial @@ -124,7 +124,7 @@ struct CheckFunctor }; template -void BasicArrayVariantChecks(const vtkm::cont::ArrayHandleVariantBase& array, +void BasicArrayVariantChecks(const vtkm::cont::VariantArrayHandleBase& array, vtkm::IdComponent numComponents) { VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, @@ -133,7 +133,7 @@ void BasicArrayVariantChecks(const vtkm::cont::ArrayHandleVariantBase& "Dynamic array reports unexpected number of components."); } -void CheckArrayVariant(vtkm::cont::ArrayHandleVariant array, vtkm::IdComponent numComponents) +void CheckArrayVariant(vtkm::cont::VariantArrayHandle array, vtkm::IdComponent numComponents) { BasicArrayVariantChecks(array, numComponents); @@ -145,7 +145,7 @@ void CheckArrayVariant(vtkm::cont::ArrayHandleVariant array, vtkm::IdComponent n } template -void CheckArrayVariant(const vtkm::cont::ArrayHandleVariantBase& array, +void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase& array, vtkm::IdComponent numComponents) { BasicArrayVariantChecks(array, numComponents); @@ -158,7 +158,7 @@ void CheckArrayVariant(const vtkm::cont::ArrayHandleVariantBase& array } template -vtkm::cont::ArrayHandleVariant CreateArrayVariant(T) +vtkm::cont::VariantArrayHandle CreateArrayVariant(T) { // Declared static to prevent going out of scope. static T buffer[ARRAY_SIZE]; @@ -167,7 +167,7 @@ vtkm::cont::ArrayHandleVariant CreateArrayVariant(T) buffer[index] = TestValue(index, T()); } - return vtkm::cont::ArrayHandleVariant(vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE)); + return vtkm::cont::VariantArrayHandle(vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE)); } template @@ -175,7 +175,7 @@ void CheckCastToArrayHandle(const ArrayHandleType& array) { VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - vtkm::cont::ArrayHandleVariant arrayVariant = array; + vtkm::cont::VariantArrayHandle arrayVariant = array; VTKM_TEST_ASSERT(!arrayVariant.IsType>(), "Dynamic array reporting is wrong type."); @@ -227,7 +227,7 @@ void TryNewInstance(T, ArrayVariantType originalArray) template void TryDefaultType(T) { - vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(T()); + vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T()); CheckArrayVariant(array, vtkm::VecTraits::NUM_COMPONENTS); @@ -239,7 +239,7 @@ struct TryBasicVTKmType template void operator()(T) const { - vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(T()); + vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T()); CheckArrayVariant(array.ResetTypes(vtkm::TypeListTagAll()), vtkm::VecTraits::NUM_COMPONENTS); @@ -250,7 +250,7 @@ struct TryBasicVTKmType void TryUnusualType() { // A string is an unlikely type to be declared elsewhere in VTK-m. - vtkm::cont::ArrayHandleVariant array = CreateArrayVariant(std::string()); + vtkm::cont::VariantArrayHandle array = CreateArrayVariant(std::string()); try { @@ -268,7 +268,7 @@ void TryUnusualType() void TryUnusualStorage() { - vtkm::cont::ArrayHandleVariant array = ArrayHandleWithUnusualStorage(); + vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage(); try { @@ -282,7 +282,7 @@ void TryUnusualStorage() void TryUnusualTypeAndStorage() { - vtkm::cont::ArrayHandleVariant array = ArrayHandleWithUnusualStorage(); + vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage(); try { @@ -353,7 +353,7 @@ void TryCastToArrayHandle() // CheckCastToArrayHandle(vtkm::cont::make_ArrayHandleZip(countingArray, array)); } -void TestArrayHandleVariant() +void TestVariantArrayHandle() { std::cout << "Try common types with default type lists." << std::endl; std::cout << "*** vtkm::Id **********************" << std::endl; @@ -387,7 +387,7 @@ void TestArrayHandleVariant() } // anonymous namespace -int UnitTestArrayHandleVariant(int, char* []) +int UnitTestVariantArrayHandle(int, char* []) { - return vtkm::cont::testing::Testing::Run(TestArrayHandleVariant); + return vtkm::cont::testing::Testing::Run(TestVariantArrayHandle); } diff --git a/vtkm/filter/ExtractGeometry.hxx b/vtkm/filter/ExtractGeometry.hxx index f2b617c5c..6eb6223ae 100644 --- a/vtkm/filter/ExtractGeometry.hxx +++ b/vtkm/filter/ExtractGeometry.hxx @@ -119,7 +119,7 @@ inline VTKM_CONT bool ExtractGeometry::DoMapField( const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::PolicyBase&) { - vtkm::cont::ArrayHandleVariant output; + vtkm::cont::VariantArrayHandle output; if (fieldMeta.IsPointField()) { diff --git a/vtkm/filter/FieldMetadata.h b/vtkm/filter/FieldMetadata.h index f5a31a86f..febf0c091 100644 --- a/vtkm/filter/FieldMetadata.h +++ b/vtkm/filter/FieldMetadata.h @@ -85,7 +85,7 @@ public: } VTKM_CONT - vtkm::cont::Field AsField(const vtkm::cont::ArrayHandleVariant& handle) const + vtkm::cont::Field AsField(const vtkm::cont::VariantArrayHandle& handle) const { if (this->IsCellField()) { diff --git a/vtkm/filter/PolicyBase.h b/vtkm/filter/PolicyBase.h index b200028a6..0d3d13609 100644 --- a/vtkm/filter/PolicyBase.h +++ b/vtkm/filter/PolicyBase.h @@ -50,7 +50,7 @@ struct PolicyBase //----------------------------------------------------------------------------- template -VTKM_CONT vtkm::cont::ArrayHandleVariantBase ApplyPolicy( +VTKM_CONT vtkm::cont::VariantArrayHandleBase ApplyPolicy( const vtkm::cont::Field& field, const vtkm::filter::PolicyBase&) { @@ -60,7 +60,7 @@ VTKM_CONT vtkm::cont::ArrayHandleVariantBase -VTKM_CONT vtkm::cont::ArrayHandleVariantBase< +VTKM_CONT vtkm::cont::VariantArrayHandleBase< typename vtkm::filter::DeduceFilterFieldTypes::TypeList> ApplyPolicy(const vtkm::cont::Field& field, const vtkm::filter::PolicyBase&, diff --git a/vtkm/filter/internal/CreateResult.h b/vtkm/filter/internal/CreateResult.h index 9be6ef7fa..e1481af94 100644 --- a/vtkm/filter/internal/CreateResult.h +++ b/vtkm/filter/internal/CreateResult.h @@ -108,7 +108,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult( return clone; } -/// Use this function if you have a ArrayHandleVariant that holds the data +/// Use this function if you have a VariantArrayHandle that holds the data /// for the field. You also need to specify a name and an association for the /// field. If the field is associated with a particular element set (for /// example, a cell association is associated with a cell set), the name of @@ -116,7 +116,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult( /// for \c Association::WHOLE_MESH and \c Association::POINTS associations. /// inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandleVariant& fieldArray, + const vtkm::cont::VariantArrayHandle& fieldArray, const std::string& fieldName, vtkm::cont::Field::Association fieldAssociation, const std::string& elementSetName = "") diff --git a/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx b/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx index fd2cb5d1d..a479f19c1 100644 --- a/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx +++ b/vtkm/filter/testing/UnitTestClipWithImplicitFunctionFilter.cxx @@ -75,7 +75,7 @@ void TestClipStructured() VTKM_TEST_ASSERT(outputData.GetCellSet().GetNumberOfCells() == 8, "Wrong number of cells in the output dataset"); - vtkm::cont::ArrayHandleVariant temp = outputData.GetField("scalars").GetData(); + vtkm::cont::VariantArrayHandle temp = outputData.GetField("scalars").GetData(); vtkm::cont::ArrayHandle resultArrayHandle; temp.CopyTo(resultArrayHandle); @@ -115,7 +115,7 @@ void TestClipStructuredInverted() VTKM_TEST_ASSERT(outputData.GetCellSet().GetNumberOfCells() == 4, "Wrong number of cells in the output dataset"); - vtkm::cont::ArrayHandleVariant temp = outputData.GetField("scalars").GetData(); + vtkm::cont::VariantArrayHandle temp = outputData.GetField("scalars").GetData(); vtkm::cont::ArrayHandle resultArrayHandle; temp.CopyTo(resultArrayHandle); diff --git a/vtkm/io/reader/VTKDataSetReaderBase.h b/vtkm/io/reader/VTKDataSetReaderBase.h index befa5f4c3..d9f2b2c4b 100644 --- a/vtkm/io/reader/VTKDataSetReaderBase.h +++ b/vtkm/io/reader/VTKDataSetReaderBase.h @@ -28,9 +28,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -93,9 +93,9 @@ struct StreamIOType using Type = vtkm::UInt16; }; -// Since Fields and DataSets store data in the default ArrayHandleVariant, convert +// Since Fields and DataSets store data in the default VariantArrayHandle, convert // the data to the closest type supported by default. The following will -// need to be updated if ArrayHandleVariant or TypeListTagCommon changes. +// need to be updated if VariantArrayHandle or TypeListTagCommon changes. template struct ClosestCommonType { @@ -179,7 +179,7 @@ struct ClosestFloat }; template -vtkm::cont::ArrayHandleVariant CreateArrayHandleVariant(const std::vector& vec) +vtkm::cont::VariantArrayHandle CreateVariantArrayHandle(const std::vector& vec) { switch (vtkm::VecTraits::NUM_COMPONENTS) { @@ -202,7 +202,7 @@ vtkm::cont::ArrayHandleVariant CreateArrayHandleVariant(const std::vector& ve portal.Set(i, static_cast(vec[static_cast(i)])); } - return vtkm::cont::ArrayHandleVariant(output); + return vtkm::cont::VariantArrayHandle(output); } case 2: case 3: @@ -234,12 +234,12 @@ vtkm::cont::ArrayHandleVariant CreateArrayHandleVariant(const std::vector& ve portal.Set(i, outval); } - return vtkm::cont::ArrayHandleVariant(output); + return vtkm::cont::VariantArrayHandle(output); } default: { std::cerr << "Only 1, 2, or 3 components supported. Skipping." << std::endl; - return vtkm::cont::ArrayHandleVariant(vtkm::cont::ArrayHandle()); + return vtkm::cont::VariantArrayHandle(vtkm::cont::ArrayHandle()); } } } @@ -335,7 +335,7 @@ protected: std::size_t numPoints; this->DataFile->Stream >> numPoints >> dataType >> std::ws; - vtkm::cont::ArrayHandleVariant points; + vtkm::cont::VariantArrayHandle points; this->DoReadArrayVariant(dataType, numPoints, 3, points); this->DataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", points)); @@ -418,7 +418,7 @@ protected: { std::string name; vtkm::cont::ArrayHandle empty; - vtkm::cont::ArrayHandleVariant data(empty); + vtkm::cont::VariantArrayHandle data(empty); this->DataFile->Stream >> tag; if (tag == "SCALARS") @@ -546,7 +546,7 @@ private: void ReadScalars(std::size_t numElements, std::string& dataName, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) { std::string dataType, lookupTableName; vtkm::IdComponent numComponents = 1; @@ -592,7 +592,7 @@ private: void ReadTextureCoordinates(std::size_t numElements, std::string& dataName, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) { vtkm::IdComponent numComponents; std::string dataType; @@ -603,7 +603,7 @@ private: void ReadVectors(std::size_t numElements, std::string& dataName, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) { std::string dataType; this->DataFile->Stream >> dataName >> dataType >> std::ws; @@ -613,7 +613,7 @@ private: void ReadTensors(std::size_t numElements, std::string& dataName, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) { std::string dataType; this->DataFile->Stream >> dataName >> dataType >> std::ws; @@ -682,7 +682,7 @@ private: public: ReadArrayVariant(VTKDataSetReaderBase* reader, std::size_t numElements, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) : SkipArrayVariant(reader, numElements) , Data(&data) { @@ -693,7 +693,7 @@ private: { std::vector buffer(this->NumElements); this->Reader->ReadArray(buffer); - *this->Data = internal::CreateArrayHandleVariant(buffer); + *this->Data = internal::CreateVariantArrayHandle(buffer); } template @@ -705,7 +705,7 @@ private: } private: - vtkm::cont::ArrayHandleVariant* Data; + vtkm::cont::VariantArrayHandle* Data; }; //Make the Array parsing methods protected so that derived classes @@ -737,7 +737,7 @@ protected: void DoReadArrayVariant(std::string dataType, std::size_t numElements, vtkm::IdComponent numComponents, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) { vtkm::io::internal::DataType typeId = vtkm::io::internal::DataTypeId(dataType); vtkm::io::internal::SelectTypeAndCall( @@ -846,7 +846,7 @@ private: { public: PermuteCellData(const vtkm::cont::ArrayHandle& permutation, - vtkm::cont::ArrayHandleVariant& data) + vtkm::cont::VariantArrayHandle& data) : Permutation(permutation) , Data(&data) { @@ -867,12 +867,12 @@ private: { outPortal.Set(i, inPortal.Get(permutationPortal.Get(i))); } - *this->Data = vtkm::cont::ArrayHandleVariant(out); + *this->Data = vtkm::cont::VariantArrayHandle(out); } private: const vtkm::cont::ArrayHandle Permutation; - vtkm::cont::ArrayHandleVariant* Data; + vtkm::cont::VariantArrayHandle* Data; }; protected: diff --git a/vtkm/io/reader/VTKRectilinearGridReader.h b/vtkm/io/reader/VTKRectilinearGridReader.h index 880211058..b602bcd1a 100644 --- a/vtkm/io/reader/VTKRectilinearGridReader.h +++ b/vtkm/io/reader/VTKRectilinearGridReader.h @@ -64,7 +64,7 @@ private: //Read the points. std::string dataType; std::size_t numPoints[3]; - vtkm::cont::ArrayHandleVariant X, Y, Z; + vtkm::cont::VariantArrayHandle X, Y, Z; // Always read coordinates as vtkm::FloatDefault std::string readDataType = vtkm::io::internal::DataTypeName::Name(); diff --git a/vtkm/rendering/raytracing/RayTracingTypeDefs.h b/vtkm/rendering/raytracing/RayTracingTypeDefs.h index dd6d0d9fa..59ec89a37 100644 --- a/vtkm/rendering/raytracing/RayTracingTypeDefs.h +++ b/vtkm/rendering/raytracing/RayTracingTypeDefs.h @@ -27,9 +27,9 @@ #include #include #include -#include #include #include +#include namespace vtkm { diff --git a/vtkm/worklet/Clip.h b/vtkm/worklet/Clip.h index 0e6af69e5..fe16e671f 100644 --- a/vtkm/worklet/Clip.h +++ b/vtkm/worklet/Clip.h @@ -32,13 +32,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include diff --git a/vtkm/worklet/DispatcherMapField.h b/vtkm/worklet/DispatcherMapField.h index 1c66f78cb..24d75d101 100644 --- a/vtkm/worklet/DispatcherMapField.h +++ b/vtkm/worklet/DispatcherMapField.h @@ -71,7 +71,7 @@ public: const InputDomainType& inputDomain = invocation.GetInputDomain(); // For a DispatcherMapField, the inputDomain must be an ArrayHandle (or - // an ArrayHandleVariant that gets cast to one). The size of the domain + // an VariantArrayHandle that gets cast to one). The size of the domain // (number of threads/worklet instances) is equal to the size of the // array. auto numInstances = internal::scheduling_range(inputDomain); diff --git a/vtkm/worklet/DispatcherStreamingMapField.h b/vtkm/worklet/DispatcherStreamingMapField.h index b88ddf157..87b7d81d5 100644 --- a/vtkm/worklet/DispatcherStreamingMapField.h +++ b/vtkm/worklet/DispatcherStreamingMapField.h @@ -244,7 +244,7 @@ public: const InputDomainType& inputDomain = invocation.GetInputDomain(); // For a DispatcherStreamingMapField, the inputDomain must be an ArrayHandle (or - // an ArrayHandleVariant that gets cast to one). The size of the domain + // an VariantArrayHandle that gets cast to one). The size of the domain // (number of threads/worklet instances) is equal to the size of the // array. vtkm::Id fullSize = internal::scheduling_range(inputDomain); diff --git a/vtkm/worklet/SurfaceNormals.h b/vtkm/worklet/SurfaceNormals.h index 7f9d47226..1582c8597 100644 --- a/vtkm/worklet/SurfaceNormals.h +++ b/vtkm/worklet/SurfaceNormals.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include namespace vtkm { @@ -145,7 +145,7 @@ public: template void Run(const CellSetType& cellset, - const vtkm::cont::ArrayHandleVariantBase& points, + const vtkm::cont::VariantArrayHandleBase& points, vtkm::cont::ArrayHandle>& normals) { if (this->Normalize) @@ -208,7 +208,7 @@ public: template void Run(const CellSetType& cellset, - const vtkm::cont::ArrayHandleVariantBase& faceNormals, + const vtkm::cont::VariantArrayHandleBase& faceNormals, vtkm::cont::ArrayHandle>& pointNormals) { vtkm::worklet::DispatcherMapTopology().Invoke(cellset, faceNormals, pointNormals); diff --git a/vtkm/worklet/VertexClustering.h b/vtkm/worklet/VertexClustering.h index db8445b3d..aa350e48c 100644 --- a/vtkm/worklet/VertexClustering.h +++ b/vtkm/worklet/VertexClustering.h @@ -83,7 +83,7 @@ struct SelectRepresentativePoint : public vtkm::worklet::WorkletReduceByKey template VTKM_CONT void operator()(const InputPointsArrayType& points, const vtkm::worklet::Keys& keys, - vtkm::cont::ArrayHandleVariant& output) const + vtkm::cont::VariantArrayHandle& output) const { vtkm::cont::ArrayHandle out; @@ -95,11 +95,11 @@ struct SelectRepresentativePoint : public vtkm::worklet::WorkletReduceByKey }; template - VTKM_CONT static vtkm::cont::ArrayHandleVariant Run( + VTKM_CONT static vtkm::cont::VariantArrayHandle Run( const vtkm::worklet::Keys& keys, const InputDynamicPointsArrayType& inputPoints) { - vtkm::cont::ArrayHandleVariant output; + vtkm::cont::VariantArrayHandle output; RunTrampoline trampoline; vtkm::cont::CastAndCall(inputPoints, trampoline, keys, output); return output; @@ -379,7 +379,7 @@ public: #endif /// pass 2 : Choose a representative point from each cluster for the output: - vtkm::cont::ArrayHandleVariant repPointArray; + vtkm::cont::VariantArrayHandle repPointArray; { vtkm::worklet::Keys keys; keys.BuildArrays(pointCidArray, vtkm::worklet::Keys::SortType::Stable); diff --git a/vtkm/worklet/connectivities/ImageConnectivity.h b/vtkm/worklet/connectivities/ImageConnectivity.h index cfe2b2e17..fee0d1221 100644 --- a/vtkm/worklet/connectivities/ImageConnectivity.h +++ b/vtkm/worklet/connectivities/ImageConnectivity.h @@ -144,7 +144,7 @@ public: template void Run(const vtkm::cont::CellSetStructured<2>& input, - const vtkm::cont::ArrayHandleVariantBase& pixels, + const vtkm::cont::VariantArrayHandleBase& pixels, OutputPortalType& componentsOut) const { using Types = vtkm::ListTagBase; diff --git a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx index a38b8638d..5ebd80d6c 100644 --- a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx +++ b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx @@ -269,7 +269,7 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp "distanceToOrigin", vtkm::cont::Field::Association::POINTS, distanceToOrigin)); dataSet.AddField(vtkm::cont::Field("distanceToOther", vtkm::cont::Field::Association::POINTS, - vtkm::cont::ArrayHandleVariant(distanceToOther))); + vtkm::cont::VariantArrayHandle(distanceToOther))); CellSet cellSet("cells"); cellSet.Fill((dim + 1) * (dim + 1) * (dim + 1), HexTag::Id, HexTraits::NUM_POINTS, connectivity); diff --git a/vtkm/worklet/testing/UnitTestWorkletMapField.cxx b/vtkm/worklet/testing/UnitTestWorkletMapField.cxx index b3848952f..5426b6b85 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapField.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapField.cxx @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -158,12 +158,12 @@ struct DoVariantTestWorklet std::cout << "Create and run dispatcher with variant arrays." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; - vtkm::cont::ArrayHandleVariant inputVariant(inputHandle); + vtkm::cont::VariantArrayHandle inputVariant(inputHandle); { //Verify we can pass by value vtkm::cont::ArrayCopy(inputHandle, inoutHandle); - vtkm::cont::ArrayHandleVariant outputVariant(outputHandle); - vtkm::cont::ArrayHandleVariant inoutVariant(inoutHandle); + vtkm::cont::VariantArrayHandle outputVariant(outputHandle); + vtkm::cont::VariantArrayHandle inoutVariant(inoutHandle); dispatcher.Invoke(inputVariant, outputVariant, inoutVariant); CheckPortal(outputHandle.GetPortalConstControl()); CheckPortal(inoutHandle.GetPortalConstControl()); @@ -171,8 +171,8 @@ struct DoVariantTestWorklet { //Verify we can pass by pointer vtkm::cont::ArrayCopy(inputHandle, inoutHandle); - vtkm::cont::ArrayHandleVariant outputVariant(outputHandle); - vtkm::cont::ArrayHandleVariant inoutVariant(inoutHandle); + vtkm::cont::VariantArrayHandle outputVariant(outputHandle); + vtkm::cont::VariantArrayHandle inoutVariant(inoutHandle); dispatcher.Invoke(&inputVariant, &outputVariant, &inoutVariant); CheckPortal(outputHandle.GetPortalConstControl()); CheckPortal(inoutHandle.GetPortalConstControl()); diff --git a/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx b/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx index 74b91e3cd..03c2c8a89 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapFieldExecArg.cxx @@ -19,7 +19,7 @@ //============================================================================ #include #include -#include +#include #include #include @@ -94,7 +94,7 @@ struct DoTestWorklet outputHandle = vtkm::cont::ArrayHandle(); outputHandle.Allocate(ARRAY_SIZE); - vtkm::cont::ArrayHandleVariant outputFieldDynamic(outputFieldArray); + vtkm::cont::VariantArrayHandle outputFieldDynamic(outputFieldArray); dispatcher.Invoke(counting, inputHandle, outputHandle, outputFieldDynamic); std::cout << "Check dynamic array result." << std::endl; diff --git a/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx b/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx index 568512c68..4ff5bc5bc 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapFieldWholeArray.cxx @@ -19,7 +19,7 @@ //============================================================================ #include #include -#include +#include #include #include @@ -83,9 +83,9 @@ struct DoTestWholeArrayWorklet // This just demonstrates that the WholeArray tags support dynamic arrays. VTKM_CONT - void CallWorklet(const vtkm::cont::ArrayHandleVariant& inArray, - const vtkm::cont::ArrayHandleVariant& inOutArray, - const vtkm::cont::ArrayHandleVariant& outArray) const + void CallWorklet(const vtkm::cont::VariantArrayHandle& inArray, + const vtkm::cont::VariantArrayHandle& inOutArray, + const vtkm::cont::VariantArrayHandle& outArray) const { std::cout << "Create and run dispatcher." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; @@ -111,9 +111,9 @@ struct DoTestWholeArrayWorklet // Output arrays must be preallocated. outHandle.Allocate(ARRAY_SIZE); - this->CallWorklet(vtkm::cont::ArrayHandleVariant(inHandle), - vtkm::cont::ArrayHandleVariant(inOutHandle), - vtkm::cont::ArrayHandleVariant(outHandle)); + this->CallWorklet(vtkm::cont::VariantArrayHandle(inHandle), + vtkm::cont::VariantArrayHandle(inOutHandle), + vtkm::cont::VariantArrayHandle(outHandle)); std::cout << "Check result." << std::endl; CheckPortal(inOutHandle.GetPortalConstControl()); @@ -127,7 +127,7 @@ struct DoTestAtomicArrayWorklet // This just demonstrates that the WholeArray tags support dynamic arrays. VTKM_CONT - void CallWorklet(const vtkm::cont::ArrayHandleVariant& inOutArray) const + void CallWorklet(const vtkm::cont::VariantArrayHandle& inOutArray) const { std::cout << "Create and run dispatcher." << std::endl; vtkm::worklet::DispatcherMapField dispatcher; @@ -142,7 +142,7 @@ struct DoTestAtomicArrayWorklet vtkm::cont::ArrayHandle inOutHandle = vtkm::cont::make_ArrayHandle(&inOutValue, 1); - this->CallWorklet(vtkm::cont::ArrayHandleVariant(inOutHandle)); + this->CallWorklet(vtkm::cont::VariantArrayHandle(inOutHandle)); std::cout << "Check result." << std::endl; T result = inOutHandle.GetPortalConstControl().Get(0); From 7eb1e31b11eff4ee4f0d970a691b2612729442b1 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 11 Dec 2018 09:20:22 -0500 Subject: [PATCH 26/36] Remove vtkm::cont::DynamicArrayHandle. --- vtkm/cont/CMakeLists.txt | 2 - vtkm/cont/DynamicArrayHandle.cxx | 53 -- vtkm/cont/DynamicArrayHandle.h | 579 ------------------ .../testing/UnitTestDynamicTransform.cxx | 35 +- .../UnitTestSerializationArrayHandle.cxx | 2 +- vtkm/filter/ZFPCompressor1D.hxx | 1 - vtkm/filter/ZFPCompressor2D.hxx | 1 - vtkm/filter/ZFPCompressor3D.hxx | 1 - vtkm/filter/ZFPDecompressor1D.hxx | 1 - vtkm/filter/ZFPDecompressor2D.hxx | 1 - vtkm/filter/ZFPDecompressor3D.hxx | 1 - vtkm/filter/testing/UnitTestZFP.cxx | 1 - 12 files changed, 26 insertions(+), 652 deletions(-) delete mode 100644 vtkm/cont/DynamicArrayHandle.cxx delete mode 100644 vtkm/cont/DynamicArrayHandle.h diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index e6d7185f1..8ee151f75 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -74,7 +74,6 @@ set(headers DeviceAdapter.h DeviceAdapterAlgorithm.h DeviceAdapterListTag.h - DynamicArrayHandle.h DynamicCellSet.h EnvironmentTracker.h Error.h @@ -139,7 +138,6 @@ set(sources DataSetBuilderExplicit.cxx DataSetBuilderRectilinear.cxx DataSetBuilderUniform.cxx - DynamicArrayHandle.cxx EnvironmentTracker.cxx ErrorBadDevice.cxx ErrorBadType.cxx diff --git a/vtkm/cont/DynamicArrayHandle.cxx b/vtkm/cont/DynamicArrayHandle.cxx deleted file mode 100644 index 0d7ce827d..000000000 --- a/vtkm/cont/DynamicArrayHandle.cxx +++ /dev/null @@ -1,53 +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. -// -// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). -// Copyright 2015 UT-Battelle, LLC. -// Copyright 2015 Los Alamos National Security. -// -// Under the terms of Contract DE-NA0003525 with NTESS, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ - -#include -#include -#include - -namespace vtkm -{ -namespace cont -{ -namespace detail -{ - -PolymorphicArrayHandleContainerBase::PolymorphicArrayHandleContainerBase() -{ -} - -PolymorphicArrayHandleContainerBase::~PolymorphicArrayHandleContainerBase() -{ -} - -void ThrowCastAndCallException(PolymorphicArrayHandleContainerBase* ptr, - const std::type_info* type, - const std::type_info* storage) -{ - std::ostringstream out; - out << "Could not find appropriate cast for array in CastAndCall1.\n" - "Array: "; - ptr->PrintSummary(out); - out << "TypeList: " << type->name() << "\nStorageList: " << storage->name() << "\n"; - throw vtkm::cont::ErrorBadValue(out.str()); -} -} -} -} // namespace vtkm::cont::detail diff --git a/vtkm/cont/DynamicArrayHandle.h b/vtkm/cont/DynamicArrayHandle.h deleted file mode 100644 index 1ec1a24ec..000000000 --- a/vtkm/cont/DynamicArrayHandle.h +++ /dev/null @@ -1,579 +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. -// -// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). -// Copyright 2014 UT-Battelle, LLC. -// Copyright 2014 Los Alamos National Security. -// -// Under the terms of Contract DE-NA0003525 with NTESS, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ -#ifndef vtk_m_cont_DynamicArrayHandle_h -#define vtk_m_cont_DynamicArrayHandle_h - -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include - -namespace vtkm -{ - -template struct ListCrossProduct; - -namespace cont -{ - -// Forward declaration -template -class DynamicArrayHandleBase; - -namespace detail -{ - -/// \brief Base class for PolymorphicArrayHandleContainer -/// -struct VTKM_CONT_EXPORT PolymorphicArrayHandleContainerBase -{ - PolymorphicArrayHandleContainerBase(); - - // This must exist so that subclasses are destroyed correctly. - virtual ~PolymorphicArrayHandleContainerBase(); - - virtual vtkm::IdComponent GetNumberOfComponents() const = 0; - virtual vtkm::Id GetNumberOfValues() const = 0; - - virtual void PrintSummary(std::ostream& out) const = 0; - - virtual std::shared_ptr NewInstance() const = 0; -}; - -/// \brief ArrayHandle container that can use C++ run-time type information. -/// -/// The \c PolymorphicArrayHandleContainer is similar to the -/// \c SimplePolymorphicContainer in that it can contain an object of an -/// unknown type. However, this class specifically holds ArrayHandle objects -/// (with different template parameters) so that it can polymorphically answer -/// simple questions about the object. -/// -template -struct VTKM_ALWAYS_EXPORT PolymorphicArrayHandleContainer - : public PolymorphicArrayHandleContainerBase -{ - using ArrayHandleType = vtkm::cont::ArrayHandle; - - ArrayHandleType Array; - - VTKM_CONT - PolymorphicArrayHandleContainer() - : Array() - { - } - - VTKM_CONT - PolymorphicArrayHandleContainer(const ArrayHandleType& array) - : Array(array) - { - } - - virtual vtkm::IdComponent GetNumberOfComponents() const - { - return vtkm::VecTraits::NUM_COMPONENTS; - } - - virtual vtkm::Id GetNumberOfValues() const { return this->Array.GetNumberOfValues(); } - - virtual void PrintSummary(std::ostream& out) const - { - vtkm::cont::printSummary_ArrayHandle(this->Array, out); - } - - virtual std::shared_ptr NewInstance() const - { - return std::shared_ptr( - new PolymorphicArrayHandleContainer()); - } -}; - -// One instance of a template class cannot access the private members of -// another instance of a template class. However, I want to be able to copy -// construct a DynamicArrayHandle from another DynamicArrayHandle of any other -// type. Since you cannot partially specialize friendship, use this accessor -// class to get at the internals for the copy constructor. -struct DynamicArrayHandleCopyHelper -{ - template - VTKM_CONT static const std::shared_ptr& - GetArrayHandleContainer(const vtkm::cont::DynamicArrayHandleBase& src) - { - return src.ArrayContainer; - } -}; - -// A simple function to downcast an ArrayHandle encapsulated in a -// PolymorphicArrayHandleContainerBase to the given type of ArrayHandle. If the -// conversion cannot be done, nullptr is returned. -template -VTKM_CONT vtkm::cont::ArrayHandle* DynamicArrayHandleTryCast( - vtkm::cont::detail::PolymorphicArrayHandleContainerBase* arrayContainer) -{ - vtkm::cont::detail::PolymorphicArrayHandleContainer* downcastContainer = nullptr; - downcastContainer = dynamic_cast(arrayContainer); - if (downcastContainer != nullptr) - { - return &downcastContainer->Array; - } - else - { - return nullptr; - } -} - -template -VTKM_CONT vtkm::cont::ArrayHandle* DynamicArrayHandleTryCast( - const std::shared_ptr& arrayContainer) -{ - return detail::DynamicArrayHandleTryCast(arrayContainer.get()); -} - -} // namespace detail - -/// \brief Holds an array handle without having to specify template parameters. -/// -/// \c DynamicArrayHandle holds an \c ArrayHandle object using runtime -/// polymorphism to manage different value types and storage rather than -/// compile-time templates. This adds a programming convenience that helps -/// avoid a proliferation of templates. It also provides the management -/// necessary to interface VTK-m with data sources where types will not be -/// known until runtime. -/// -/// To interface between the runtime polymorphism and the templated algorithms -/// in VTK-m, \c DynamicArrayHandle contains a method named \c CastAndCall that -/// will determine the correct type from some known list of types and storage -/// objects. This mechanism is used internally by VTK-m's worklet invocation -/// mechanism to determine the type when running algorithms. -/// -/// By default, \c DynamicArrayHandle will assume that the value type in the -/// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST_TAG -/// and the storage matches one of the tags specified by \c -/// VTKM_DEFAULT_STORAGE_LIST_TAG. These lists can be changed by using the \c -/// ResetTypeList and \c ResetStorageList methods, respectively. It is -/// worthwhile to match these lists closely to the possible types that might be -/// used. If a type is missing you will get a runtime error. If there are more -/// types than necessary, then the template mechanism will create a lot of -/// object code that is never used, and keep in mind that the number of -/// combinations grows exponentially when using multiple \c DynamicArrayHandle -/// objects. -/// -/// The actual implementation of \c DynamicArrayHandle is in a templated class -/// named \c DynamicArrayHandleBase, which is templated on the list of -/// component types and storage types. \c DynamicArrayHandle is really just a -/// typedef of \c DynamicArrayHandleBase with the default type and storage -/// lists. -/// -template -class VTKM_ALWAYS_EXPORT DynamicArrayHandleBase -{ -public: - VTKM_CONT - DynamicArrayHandleBase() {} - - template - VTKM_CONT DynamicArrayHandleBase(const vtkm::cont::ArrayHandle& array) - : ArrayContainer(new vtkm::cont::detail::PolymorphicArrayHandleContainer(array)) - { - } - - VTKM_CONT - DynamicArrayHandleBase(const DynamicArrayHandleBase& src) - : ArrayContainer(src.ArrayContainer) - { - } - - template - VTKM_CONT explicit DynamicArrayHandleBase( - const DynamicArrayHandleBase& src) - : ArrayContainer(detail::DynamicArrayHandleCopyHelper::GetArrayHandleContainer(src)) - { - } - - VTKM_CONT - ~DynamicArrayHandleBase() {} - - VTKM_CONT - vtkm::cont::DynamicArrayHandleBase& operator=( - const vtkm::cont::DynamicArrayHandleBase& src) - { - this->ArrayContainer = src.ArrayContainer; - return *this; - } - - /// Returns true if this array is of the provided type and uses the provided - /// storage. - /// - template - VTKM_CONT bool IsTypeAndStorage() const - { - return (detail::DynamicArrayHandleTryCast(this->ArrayContainer) != nullptr); - } - - /// Returns true if this array matches the array handle type passed in. - /// - template - VTKM_CONT bool IsType() - { - VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - using ValueType = typename ArrayHandleType::ValueType; - using StorageTag = typename ArrayHandleType::StorageTag; - return this->IsTypeAndStorage(); - } - - /// Returns true if the array held in this object is the same (or equivalent) - /// type as the object given. - /// - template - VTKM_CONT bool IsSameType(const ArrayHandleType&) - { - VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - return this->IsType(); - } - - /// Returns this array cast to an ArrayHandle object of the given type and - /// storage. Throws \c ErrorBadType if the cast does not work. Use - /// \c IsTypeAndStorage to check if the cast can happen. - /// - /// - template - VTKM_CONT vtkm::cont::ArrayHandle CastToTypeStorage() const - { - vtkm::cont::ArrayHandle* downcastArray = - detail::DynamicArrayHandleTryCast(this->ArrayContainer); - if (downcastArray == nullptr) - { - VTKM_LOG_CAST_FAIL(*this, decltype(downcastArray)); - throw vtkm::cont::ErrorBadType("Bad cast of dynamic array."); - } - // Technically, this method returns a copy of the \c ArrayHandle. But - // because \c ArrayHandle acts like a shared pointer, it is valid to - // do the copy. - VTKM_LOG_CAST_SUCC(*this, *downcastArray); - return *downcastArray; - } - - /// Returns this array cast to the given \c ArrayHandle type. Throws \c - /// ErrorBadType if the cast does not work. Use \c IsType - /// to check if the cast can happen. - /// - template - VTKM_CONT ArrayHandleType Cast() const - { - VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - using ValueType = typename ArrayHandleType::ValueType; - using StorageTag = typename ArrayHandleType::StorageTag; - // Technically, this method returns a copy of the \c ArrayHandle. But - // because \c ArrayHandle acts like a shared pointer, it is valid to - // do the copy. - return this->CastToTypeStorage(); - } - - /// Given a references to an ArrayHandle object, casts this array to the - /// ArrayHandle's type and sets the given ArrayHandle to this array. Throws - /// \c ErrorBadType if the cast does not work. Use \c - /// ArrayHandleType to check if the cast can happen. - /// - /// Note that this is a shallow copy. The data are not copied and a change - /// in the data in one array will be reflected in the other. - /// - template - VTKM_CONT void CopyTo(ArrayHandleType& array) const - { - VTKM_IS_ARRAY_HANDLE(ArrayHandleType); - array = this->Cast(); - } - - /// Changes the types to try casting to when resolving this dynamic array, - /// which is specified with a list tag like those in TypeListTag.h. Since C++ - /// does not allow you to actually change the template arguments, this method - /// returns a new dynamic array object. This method is particularly useful to - /// narrow down (or expand) the types when using an array of particular - /// constraints. - /// - template - VTKM_CONT DynamicArrayHandleBase ResetTypeList( - NewTypeList = NewTypeList()) const - { - VTKM_IS_LIST_TAG(NewTypeList); - return DynamicArrayHandleBase(*this); - } - - /// Changes the array storage types to try casting to when resolving this - /// dynamic array, which is specified with a list tag like those in - /// StorageListTag.h. Since C++ does not allow you to actually change the - /// template arguments, this method returns a new dynamic array object. This - /// method is particularly useful to narrow down (or expand) the types when - /// using an array of particular constraints. - /// - template - VTKM_CONT DynamicArrayHandleBase ResetStorageList( - NewStorageList = NewStorageList()) const - { - VTKM_IS_LIST_TAG(NewStorageList); - return DynamicArrayHandleBase(*this); - } - - /// Changes the value, and array storage types to try casting to when - /// resolving this dynamic array. Since C++ does not allow you to actually - /// change the template arguments, this method returns a new dynamic array - /// object. This method is particularly useful when you have both custom - /// types and traits. - /// - template - VTKM_CONT DynamicArrayHandleBase ResetTypeAndStorageLists( - NewTypeList = NewTypeList(), - NewStorageList = NewStorageList()) const - { - VTKM_IS_LIST_TAG(NewTypeList); - VTKM_IS_LIST_TAG(NewStorageList); - return DynamicArrayHandleBase(*this); - } - - /// Attempts to cast the held array to a specific value type and storage, - /// then call the given functor with the cast array. The types and storage - /// tried in the cast are those in the lists defined by the TypeList and - /// StorageList, respectively. The default \c DynamicArrayHandle sets these - /// two lists to VTKM_DEFAULT_TYPE_LIST_TAG and VTK_DEFAULT_STORAGE_LIST_TAG, - /// respectively. - /// - template - VTKM_CONT void CastAndCall(Functor&& f, Args&&...) const; - - /// \brief Create a new array of the same type as this array. - /// - /// This method creates a new array that is the same type as this one and - /// returns a new dynamic array handle for it. This method is convenient when - /// creating output arrays that should be the same type as some input array. - /// - VTKM_CONT - DynamicArrayHandleBase NewInstance() const - { - DynamicArrayHandleBase newArray; - newArray.ArrayContainer = this->ArrayContainer->NewInstance(); - return newArray; - } - - /// \brief Get the number of components in each array value. - /// - /// This method will query the array type for the number of components in - /// each value of the array. The number of components is determined by - /// the \c VecTraits::NUM_COMPONENTS trait class. - /// - VTKM_CONT - vtkm::IdComponent GetNumberOfComponents() const - { - return this->ArrayContainer->GetNumberOfComponents(); - } - - /// \brief Get the number of values in the array. - /// - VTKM_CONT - vtkm::Id GetNumberOfValues() const { return this->ArrayContainer->GetNumberOfValues(); } - - VTKM_CONT - void PrintSummary(std::ostream& out) const { this->ArrayContainer->PrintSummary(out); } - -private: - std::shared_ptr ArrayContainer; - - friend struct detail::DynamicArrayHandleCopyHelper; -}; - -using DynamicArrayHandle = - vtkm::cont::DynamicArrayHandleBase; - -namespace detail -{ - -struct DynamicArrayHandleTry -{ - template - void operator()(brigand::list, - Functor&& f, - bool& called, - const PolymorphicArrayHandleContainerBase* const container, - Args&&... args) const - { - if (!called) - { - using downcastType = const vtkm::cont::detail::PolymorphicArrayHandleContainer* const; - downcastType downcastContainer = dynamic_cast(container); - if (downcastContainer) - { - VTKM_LOG_CAST_SUCC(*container, *downcastContainer); - f(downcastContainer->Array, std::forward(args)...); - called = true; - } - } - } -}; - -VTKM_CONT_EXPORT void ThrowCastAndCallException(PolymorphicArrayHandleContainerBase*, - const std::type_info*, - const std::type_info*); -} // namespace detail - - -template -struct IsUndefinedStorage -{ -}; -template -struct IsUndefinedStorage> : vtkm::cont::internal::IsInValidArrayHandle -{ -}; - -template -struct ListTagDynamicTypes : vtkm::detail::ListRoot -{ - using crossProduct = typename vtkm::ListCrossProduct; - // using list = typename crossProduct::list; - using list = ::brigand::remove_if>; -}; - - -template -template -VTKM_CONT void DynamicArrayHandleBase::CastAndCall(Functor&& f, - Args&&... args) const -{ - //For optimizations we should compile once the cross product for the default types - //and make it extern - using crossProduct = ListTagDynamicTypes; - - bool called = false; - auto* ptr = this->ArrayContainer.get(); - vtkm::ListForEach(detail::DynamicArrayHandleTry{}, - crossProduct{}, - std::forward(f), - called, - ptr, - std::forward(args)...); - if (!called) - { - // throw an exception - VTKM_LOG_CAST_FAIL(*this, crossProduct); - detail::ThrowCastAndCallException(ptr, &typeid(TypeList), &typeid(StorageList)); - } -} - -namespace internal -{ - -template -struct DynamicTransformTraits> -{ - using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; -}; - -} // namespace internal -} - -} // namespace vtkm::cont - - -//============================================================================= -// Specializations of serialization related classes -namespace diy -{ - -namespace internal -{ - -struct DynamicArrayHandleSerializeFunctor -{ - template - void operator()(const ArrayHandleType& ah, BinaryBuffer& bb) const - { - diy::save(bb, vtkm::cont::TypeString::Get()); - diy::save(bb, ah); - } -}; - -template -struct DynamicArrayHandleDeserializeFunctor -{ - template - void operator()(brigand::list, - vtkm::cont::DynamicArrayHandleBase& dh, - const std::string& typeString, - bool& success, - BinaryBuffer& bb) const - { - using ArrayHandleType = vtkm::cont::ArrayHandle; - - if (!success && (typeString == vtkm::cont::TypeString::Get())) - { - ArrayHandleType ah; - diy::load(bb, ah); - dh = vtkm::cont::DynamicArrayHandleBase(ah); - success = true; - } - } -}; - -} // internal - -template -struct Serialization> -{ -private: - using Type = vtkm::cont::DynamicArrayHandleBase; - -public: - static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj) - { - obj.CastAndCall(internal::DynamicArrayHandleSerializeFunctor{}, bb); - } - - static VTKM_CONT void load(BinaryBuffer& bb, Type& obj) - { - using CrossProduct = vtkm::cont::ListTagDynamicTypes; - - std::string typeString; - diy::load(bb, typeString); - - bool success = false; - vtkm::ListForEach(internal::DynamicArrayHandleDeserializeFunctor{}, - CrossProduct{}, - obj, - typeString, - success, - bb); - - if (!success) - { - throw vtkm::cont::ErrorBadType( - "Error deserializing DynamicArrayHandle. Message TypeString: " + typeString); - } - } -}; - -} // diy - -#endif //vtk_m_cont_DynamicArrayHandle_h diff --git a/vtkm/cont/internal/testing/UnitTestDynamicTransform.cxx b/vtkm/cont/internal/testing/UnitTestDynamicTransform.cxx index 1639a51d6..814157dd4 100644 --- a/vtkm/cont/internal/testing/UnitTestDynamicTransform.cxx +++ b/vtkm/cont/internal/testing/UnitTestDynamicTransform.cxx @@ -21,8 +21,8 @@ #include "vtkm/cont/internal/DynamicTransform.h" #include "vtkm/cont/ArrayHandle.h" -#include "vtkm/cont/DynamicArrayHandle.h" #include "vtkm/cont/DynamicCellSet.h" +#include "vtkm/cont/VariantArrayHandle.h" #include "vtkm/internal/FunctionInterface.h" @@ -31,7 +31,7 @@ namespace vtkm { -// DynamicArrayHandle requires its value type to have a defined VecTraits +// VariantArrayHandle requires its value type to have a defined VecTraits // class. One of the tests is to use an "unusual" array of std::string // (which is pretty pointless but might tease out some assumptions). // Make an implementation here. Because I am lazy, this is only a partial @@ -71,10 +71,15 @@ struct ScalarFunctor struct ArrayHandleScalarFunctor { template - void operator()(const vtkm::cont::ArrayHandle&) const + void operator()(const vtkm::cont::ArrayHandleVirtual&) const { VTKM_TEST_FAIL("Called wrong form of functor operator."); } + void operator()(const vtkm::cont::ArrayHandleVirtual&) const + { + std::cout << " In ArrayHandleVirtual functor." << std::endl; + g_FunctionCalls++; + } void operator()(const vtkm::cont::ArrayHandle&) const { std::cout << " In ArrayHandle functor." << std::endl; @@ -84,9 +89,9 @@ struct ArrayHandleScalarFunctor struct ArrayHandleStringFunctor { - void operator()(const vtkm::cont::ArrayHandle&) const + void operator()(const vtkm::cont::ArrayHandleVirtual&) const { - std::cout << " In ArrayHandle functor." << std::endl; + std::cout << " In ArrayHandleVirtual functor." << std::endl; g_FunctionCalls++; } }; @@ -121,6 +126,16 @@ struct FunctionInterfaceFunctor std::cout << " In FunctionInterface<...> functor." << std::endl; g_FunctionCalls++; } + + void operator()( + const vtkm::internal::FunctionInterface, + vtkm::cont::ArrayHandleVirtual, + vtkm::cont::ArrayHandleVirtual, + vtkm::cont::CellSetStructured<3>)>&) const + { + std::cout << " In FunctionInterface<...> functor." << std::endl; + g_FunctionCalls++; + } }; void TestBasicTransform() @@ -138,13 +153,13 @@ void TestBasicTransform() TRY_TRANSFORM(transform(concreteArray, ArrayHandleScalarFunctor(), indexTag)); std::cout << " Trying scalar dynamic array." << std::endl; - vtkm::cont::DynamicArrayHandle dynamicArray = concreteArray; + vtkm::cont::VariantArrayHandle dynamicArray = concreteArray; TRY_TRANSFORM(transform(dynamicArray, ArrayHandleScalarFunctor(), indexTag)); std::cout << " Trying with unusual (string) dynamic array." << std::endl; dynamicArray = vtkm::cont::ArrayHandle(); - TRY_TRANSFORM(transform( - dynamicArray.ResetTypeList(TypeListTagString()), ArrayHandleStringFunctor(), indexTag)); + TRY_TRANSFORM( + transform(dynamicArray.ResetTypes(TypeListTagString()), ArrayHandleStringFunctor(), indexTag)); std::cout << " Trying with structured cell set." << std::endl; vtkm::cont::CellSetStructured<3> concreteCellSet; @@ -171,8 +186,8 @@ void TestFunctionTransform() TRY_TRANSFORM( vtkm::internal::make_FunctionInterface( scalarArray, - vtkm::cont::DynamicArrayHandle(scalarArray), - vtkm::cont::DynamicArrayHandle(stringArray).ResetTypeList(TypeListTagString()), + vtkm::cont::VariantArrayHandle(scalarArray), + vtkm::cont::VariantArrayHandle(stringArray).ResetTypes(TypeListTagString()), vtkm::cont::DynamicCellSet(structuredCellSet)) .DynamicTransformCont(vtkm::cont::internal::DynamicTransform(), FunctionInterfaceFunctor())); } diff --git a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx index 4186de563..c7fcb3d23 100644 --- a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx @@ -236,7 +236,7 @@ struct TestArrayHandleGroupVecVariable vtkm::cont::make_ArrayHandle(comps)); RunTest(array); - // cannot make a DynamicArrayHandle containing ArrayHandleGroupVecVariable + // cannot make a VariantArrayHandle containing ArrayHandleGroupVecVariable // because of the variable number of components of its values. // RunTest(MakeTestVariantArrayHandle(array)); } diff --git a/vtkm/filter/ZFPCompressor1D.hxx b/vtkm/filter/ZFPCompressor1D.hxx index f089eb641..90bcb2027 100644 --- a/vtkm/filter/ZFPCompressor1D.hxx +++ b/vtkm/filter/ZFPCompressor1D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/ZFPCompressor2D.hxx b/vtkm/filter/ZFPCompressor2D.hxx index 4ba890b00..2987a6ddd 100644 --- a/vtkm/filter/ZFPCompressor2D.hxx +++ b/vtkm/filter/ZFPCompressor2D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/ZFPCompressor3D.hxx b/vtkm/filter/ZFPCompressor3D.hxx index 9e78954a8..86701ea24 100644 --- a/vtkm/filter/ZFPCompressor3D.hxx +++ b/vtkm/filter/ZFPCompressor3D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/ZFPDecompressor1D.hxx b/vtkm/filter/ZFPDecompressor1D.hxx index 1c0fadd1c..aaecad963 100644 --- a/vtkm/filter/ZFPDecompressor1D.hxx +++ b/vtkm/filter/ZFPDecompressor1D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/ZFPDecompressor2D.hxx b/vtkm/filter/ZFPDecompressor2D.hxx index 27cc029a9..8c052ba81 100644 --- a/vtkm/filter/ZFPDecompressor2D.hxx +++ b/vtkm/filter/ZFPDecompressor2D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/ZFPDecompressor3D.hxx b/vtkm/filter/ZFPDecompressor3D.hxx index 9fa6ce736..650dbba71 100644 --- a/vtkm/filter/ZFPDecompressor3D.hxx +++ b/vtkm/filter/ZFPDecompressor3D.hxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/testing/UnitTestZFP.cxx b/vtkm/filter/testing/UnitTestZFP.cxx index 16f5e540f..7a46e8da8 100644 --- a/vtkm/filter/testing/UnitTestZFP.cxx +++ b/vtkm/filter/testing/UnitTestZFP.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include #include From 78e9cf092940b5ae349aa147ca1f255d11c86767 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 11 Dec 2018 14:12:47 -0500 Subject: [PATCH 27/36] ArrayRangeCompute now supports ArrayHandleVirtual --- vtkm/cont/ArrayRangeCompute.h | 14 +++++++--- vtkm/cont/ArrayRangeCompute.hxx | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/vtkm/cont/ArrayRangeCompute.h b/vtkm/cont/ArrayRangeCompute.h index a2bde1771..42a5faaa6 100644 --- a/vtkm/cont/ArrayRangeCompute.h +++ b/vtkm/cont/ArrayRangeCompute.h @@ -52,7 +52,6 @@ VTKM_CONT vtkm::cont::ArrayHandle ArrayRangeCompute( const ArrayHandleType& input, vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); - // Precompiled versions of ArrayRangeCompute #define VTKM_ARRAY_RANGE_COMPUTE_EXPORT_T(T, Storage) \ VTKM_CONT_EXPORT \ @@ -95,11 +94,19 @@ VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt8, 4, vtkm::cont::StorageTagBasic) VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float32, 4, vtkm::cont::StorageTagBasic); VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float64, 4, vtkm::cont::StorageTagBasic); - #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_T #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC -// Implementation of uniform point coordinates +VTKM_CONT +vtkm::cont::ArrayHandle ArrayRangeCompute( + const vtkm::cont::ArrayHandleVirtualCoordinates& input, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); + +VTKM_CONT +vtkm::cont::ArrayHandle ArrayRangeCompute( + const vtkm::cont::ArrayHandleVirtual>& input, + vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); + VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::ArrayHandle ArrayRangeCompute( @@ -107,7 +114,6 @@ vtkm::cont::ArrayHandle ArrayRangeCompute( vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag>& array, vtkm::cont::RuntimeDeviceTracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); - // Implementation of composite vectors VTKM_CONT_EXPORT VTKM_CONT diff --git a/vtkm/cont/ArrayRangeCompute.hxx b/vtkm/cont/ArrayRangeCompute.hxx index ff480ea9a..4502e9e4b 100644 --- a/vtkm/cont/ArrayRangeCompute.hxx +++ b/vtkm/cont/ArrayRangeCompute.hxx @@ -103,6 +103,53 @@ inline vtkm::cont::ArrayHandle ArrayRangeComputeImpl( } // namespace detail + +VTKM_CONT +inline vtkm::cont::ArrayHandle ArrayRangeCompute( + const vtkm::cont::ArrayHandleVirtualCoordinates& input, + vtkm::cont::RuntimeDeviceTracker tracker) +{ + auto array = + static_cast>&>(input); + return ArrayRangeCompute(array, tracker); +} + +VTKM_CONT +inline vtkm::cont::ArrayHandle ArrayRangeCompute( + const vtkm::cont::ArrayHandleVirtual>& input, + vtkm::cont::RuntimeDeviceTracker tracker) +{ + using UniformHandleType = ArrayHandleUniformPointCoordinates; + using RectilinearHandleType = + vtkm::cont::ArrayHandleCartesianProduct, + vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandle>; + + + if (input.IsType()) + { + using T = typename UniformHandleType::ValueType; + using S = typename UniformHandleType::StorageTag; + const vtkm::cont::StorageVirtual* storage = input.GetStorage(); + const auto* any = storage->Cast>(); + + return ArrayRangeCompute(any->GetHandle(), tracker); + } + else if (input.IsType()) + { + using T = typename RectilinearHandleType::ValueType; + using S = typename RectilinearHandleType::StorageTag; + const vtkm::cont::StorageVirtual* storage = input.GetStorage(); + const auto* any = storage->Cast>(); + + return ArrayRangeCompute(any->GetHandle(), tracker); + } + else + { + return detail::ArrayRangeComputeImpl(input, tracker); + } +} + template inline vtkm::cont::ArrayHandle ArrayRangeCompute( const ArrayHandleType& input, From 9c496e5da0d39b987ab3efd382b8e8aa88639b95 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 13 Dec 2018 09:40:38 -0500 Subject: [PATCH 28/36] Correct warning found in ArrayHandleVirtualCoordinates with cuda 8.0 --- vtkm/cont/ArrayHandleVirtualCoordinates.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index 31eb548c3..685f1c8e7 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -143,7 +143,7 @@ public: static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) { const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); - if (obj.template IsType()) + if (obj.IsType()) { using HandleType = vtkm::cont::ArrayHandleUniformPointCoordinates; using T = typename HandleType::ValueType; @@ -152,7 +152,7 @@ public: diy::save(bb, vtkm::cont::TypeString::Get()); diy::save(bb, array->GetHandle()); } - else if (obj.template IsType()) + else if (obj.IsType()) { using HandleType = RectilinearCoordsArrayType; using T = typename HandleType::ValueType; From deb4946a4175bb79da6850804efd5dc0ec87e93b Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 13 Dec 2018 13:47:39 -0500 Subject: [PATCH 29/36] Make sure vtk-m libraries under CUDA 8 are always built statically --- CMake/VTKmDeviceAdapters.cmake | 11 +++++++++++ CMake/VTKmWrappers.cmake | 25 ++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CMake/VTKmDeviceAdapters.cmake b/CMake/VTKmDeviceAdapters.cmake index 2539cd171..2d6e43cc2 100644 --- a/CMake/VTKmDeviceAdapters.cmake +++ b/CMake/VTKmDeviceAdapters.cmake @@ -134,6 +134,17 @@ if(VTKm_ENABLE_CUDA AND NOT TARGET vtkm::cuda) add_library(vtkm::cuda UNKNOWN IMPORTED GLOBAL) endif() + # Workaround issue with CUDA 8.X where virtual don't work when building + # VTK-m as shared. We don't want to force BUILD_SHARED_LIBS to a specific + # value as that could impact other projects that embed VTK-m. Instead what + # we do is make sure that libraries built by vtkm_library() are static + # if they use cuda + if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0) + set_target_properties(vtkm::cuda PROPERTIES REQUIRES_STATIC_BUILDS TRUE) + else() + set_target_properties(vtkm::cuda PROPERTIES REQUIRES_STATIC_BUILDS FALSE) + endif() + set_target_properties(vtkm::cuda PROPERTIES INTERFACE_COMPILE_OPTIONS $<$:--expt-relaxed-constexpr> ) diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index fedbaec39..7b6713da8 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -282,16 +282,31 @@ function(vtkm_library) endif() set(lib_name ${VTKm_LIB_NAME}) + if(VTKm_LIB_STATIC) + set(VTKm_LIB_type STATIC) + else() + if(VTKm_LIB_SHARED) + set(VTKm_LIB_type SHARED) + endif() + #if cuda requires static libaries force + #them no matter what + if(TARGET vtkm::cuda) + get_target_property(force_static vtkm::cuda REQUIRES_STATIC_BUILDS) + if(force_static) + set(VTKm_LIB_type STATIC) + message("Forcing ${lib_name} to be built statically as we are using CUDA 8.X, which doesn't support virtuals sufficiently in dynamic libraries.") + endif() + endif() + + endif() + + if(TARGET vtkm::cuda) vtkm_compile_as_cuda(cu_srcs ${VTKm_LIB_WRAP_FOR_CUDA}) set(VTKm_LIB_WRAP_FOR_CUDA ${cu_srcs}) endif() - if(VTKm_LIB_STATIC) - set(VTKm_LIB_type STATIC) - elseif(VTKm_LIB_SHARED) - set(VTKm_LIB_type SHARED) - endif() + add_library(${lib_name} ${VTKm_LIB_type} From 7b9fa975f29d59b77d71b166bf284925029cc1e5 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 14 Dec 2018 15:00:21 -0500 Subject: [PATCH 30/36] Rename: IsVirtualType to IsValueType. --- vtkm/cont/VariantArrayHandle.h | 6 +++--- vtkm/cont/internal/VariantArrayHandleContainer.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index 4a575fa11..78f153ac5 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -120,9 +120,9 @@ public: /// Returns true if this array matches the ValueType type passed in. /// template - VTKM_CONT bool IsVirtualType() + VTKM_CONT bool IsValueType() { - return internal::variant::IsVirtualType(this->ArrayContainer.get()); + return internal::variant::IsValueType(this->ArrayContainer.get()); } /// Returns this array cast to the given \c ArrayHandle type. Throws \c @@ -244,7 +244,7 @@ struct VariantArrayHandleTry const vtkm::cont::internal::VariantArrayHandleContainerBase& container, Args&&... args) const { - if (!called && vtkm::cont::internal::variant::IsVirtualType(&container)) + if (!called && vtkm::cont::internal::variant::IsValueType(&container)) { called = true; const auto* derived = diff --git a/vtkm/cont/internal/VariantArrayHandleContainer.h b/vtkm/cont/internal/VariantArrayHandleContainer.h index 2499b562b..ec5bd0b90 100644 --- a/vtkm/cont/internal/VariantArrayHandleContainer.h +++ b/vtkm/cont/internal/VariantArrayHandleContainer.h @@ -145,7 +145,7 @@ VTKM_CONT bool IsType(const VariantArrayHandleContainerBase* container) } template -VTKM_CONT bool IsVirtualType(const VariantArrayHandleContainerBase* container) +VTKM_CONT bool IsValueType(const VariantArrayHandleContainerBase* container) { if (container == nullptr) { //you can't use typeid on nullptr of polymorphic types @@ -182,7 +182,7 @@ struct VTKM_ALWAYS_EXPORT Caster vtkm::cont::ArrayHandle operator()( const VariantArrayHandleContainerBase* container) const { - if (!IsVirtualType(container)) + if (!IsValueType(container)) { VTKM_LOG_CAST_FAIL(container, vtkm::cont::ArrayHandleVirtual); throwFailedDynamicCast(vtkm::cont::TypeName(container), From acf825b2799add92def08a2f3e608329363a6f52 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 18 Dec 2018 15:10:55 -0500 Subject: [PATCH 31/36] Correct IsType and Cast on ArrayHandleVirtual to work on OSX. --- vtkm/cont/ArrayHandleAny.h | 10 --- vtkm/cont/ArrayHandleImplicit.h | 3 +- vtkm/cont/ArrayHandleVirtual.h | 73 ++++++++++++++++--- vtkm/cont/ArrayHandleVirtual.hxx | 32 +++++++- vtkm/cont/ArrayHandleVirtualCoordinates.h | 17 +---- vtkm/cont/StorageImplicit.h | 3 +- vtkm/cont/StorageVirtual.cxx | 6 -- vtkm/cont/StorageVirtual.h | 9 ++- vtkm/cont/arg/TransportTagAtomicArray.h | 20 ++--- .../internal/VariantArrayHandleContainer.h | 8 +- 10 files changed, 117 insertions(+), 64 deletions(-) diff --git a/vtkm/cont/ArrayHandleAny.h b/vtkm/cont/ArrayHandleAny.h index 5bda016ce..b438377e6 100644 --- a/vtkm/cont/ArrayHandleAny.h +++ b/vtkm/cont/ArrayHandleAny.h @@ -51,16 +51,6 @@ public: void ReleaseResources(); private: - // StorageAny is meant to be seamless when it comes to IsType so we will match - // when either the type_info is 'StorageAny' or 'Storage'. That is why - // we need to override the default implementation. - bool IsSameType(const std::type_info& other) const - { - //We don't wan to check just 'S' as that just the tag - using ST = typename vtkm::cont::internal::Storage; - return other == typeid(ST) || other == typeid(*this); - } - std::unique_ptr MakeNewInstance() const { return std::unique_ptr(new StorageAny{ vtkm::cont::ArrayHandle{} }); diff --git a/vtkm/cont/ArrayHandleImplicit.h b/vtkm/cont/ArrayHandleImplicit.h index a99ecf74b..5c931dca3 100644 --- a/vtkm/cont/ArrayHandleImplicit.h +++ b/vtkm/cont/ArrayHandleImplicit.h @@ -115,7 +115,8 @@ private: /// array at that position. /// template -class ArrayHandleImplicit : public detail::ArrayHandleImplicitTraits::Superclass +class VTKM_ALWAYS_EXPORT ArrayHandleImplicit + : public detail::ArrayHandleImplicitTraits::Superclass { private: using ArrayTraits = typename detail::ArrayHandleImplicitTraits; diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index c206d994d..089e13dfa 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -134,7 +134,6 @@ public: return true; // different valuetype and/or storage } - /// Returns true if this array's storage matches the type passed in. /// template @@ -155,6 +154,28 @@ public: return this->IsSameType(is_base{}); } + /// Returns this array cast to the given \c ArrayHandle type. Throws \c + /// ErrorBadType if the cast does not work. Use \c IsType + /// to check if the cast can happen. + /// + template + VTKM_CONT ArrayHandleType Cast() const + { + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + using VT = typename ArrayHandleType::ValueType; + static_assert( + std::is_same::value, + "ArrayHandleVirtual can only be casted to an ArrayHandle of the same ValueType."); + + //We need to determine if we are checking that `ArrayHandleType` + //is a virtual array handle since that is an easy check. + //Or if we have to go ask the storage if they are holding + // + using ST = typename ArrayHandleType::StorageTag; + using is_base = std::is_same; + return this->CastToType(is_base{}); + } + /// Returns a new instance of an ArrayHandleVirtual with the same storage /// VTKM_CONT ArrayHandle NewInstance() const @@ -285,19 +306,36 @@ private: bool IsSameType(std::true_type vtkmNotUsed(inheritsFromArrayHandleVirtual)) const { //All classes that derive from ArrayHandleVirtual have virtual methods so we can use - //typeid directly - return typeid(*this) == typeid(ArrayHandleType); + //typeid directly. + //needs optimizations based on platform. !OSX can use typeid + return nullptr != dynamic_cast(this); } template - bool IsSameType(std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const + bool IsSameType(std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const; + + template + ArrayHandleType CastToType(std::true_type vtkmNotUsed(inheritsFromArrayHandleVirtual)) const { - //We need to go long the way to find the StorageType - //as StorageType is private on lots of derived ArrayHandles - //See Issue #314 - using ST = typename ArrayHandleType::StorageTag; - return this->Storage->IsType(typeid(vtkm::cont::internal::Storage)); + //All classes that derive from ArrayHandleVirtual have virtual methods so we can use + //dynamic_cast directly + if (!this->Storage) + { + VTKM_LOG_CAST_FAIL(*this, ArrayHandleType); + throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeName()); + } + const ArrayHandleType* derived = dynamic_cast(this); + if (!derived) + { + VTKM_LOG_CAST_FAIL(*this, ArrayHandleType); + throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeName()); + } + VTKM_LOG_CAST_SUCC(*this, derived); + return *derived; } + + template + ArrayHandleType CastToType(std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const; }; //============================================================================= @@ -306,6 +344,23 @@ template using ArrayHandleVirtual = vtkm::cont::ArrayHandle; +//============================================================================= +// Free function casting helpers + +template +VTKM_CONT inline bool IsType(const vtkm::cont::ArrayHandleVirtual& virtHandle) +{ + return virtHandle.template IsType(); +} + +template +VTKM_CONT inline ArrayHandleType Cast(const vtkm::cont::ArrayHandleVirtual& virtHandle) +{ + return virtHandle.template Cast(); +} + + + //============================================================================= // Specializations of serialization related classes template diff --git a/vtkm/cont/ArrayHandleVirtual.hxx b/vtkm/cont/ArrayHandleVirtual.hxx index 6a7a8b542..fb27ed85e 100644 --- a/vtkm/cont/ArrayHandleVirtual.hxx +++ b/vtkm/cont/ArrayHandleVirtual.hxx @@ -22,12 +22,43 @@ #include +#include #include namespace vtkm { namespace cont { + +template +template +bool ArrayHandle::IsSameType( + std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const +{ + if (!this->Storage) + { + return false; + } + using S = typename ArrayHandleType::StorageTag; + return this->Storage->template IsType>(); +} + +template +template +ArrayHandleType ArrayHandle::CastToType( + std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const +{ + if (!this->Storage) + { + VTKM_LOG_CAST_FAIL(*this, ArrayHandleType); + throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeName()); + } + using S = typename ArrayHandleType::StorageTag; + const auto* any = this->Storage->template Cast>(); + return any->GetHandle(); +} + + namespace detail { template @@ -69,7 +100,6 @@ inline void make_hostPortal(Payload&& payload, Args&&... args) -#include //============================================================================= // Specializations of serialization related classes namespace diy diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index 685f1c8e7..e825ba0c2 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -40,7 +40,7 @@ namespace cont { /// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle. -class VTKM_CONT_EXPORT ArrayHandleVirtualCoordinates final +class VTKM_ALWAYS_EXPORT ArrayHandleVirtualCoordinates final : public vtkm::cont::ArrayHandleVirtual> { public: @@ -77,20 +77,6 @@ public: using ST = typename decltype(castedHandle)::StorageTag; this->Storage = std::make_shared>(castedHandle); } - - /// Returns this array cast to the given \c ArrayHandle type. Throws \c - /// ErrorBadType if the cast does not work. Use \c IsType - /// to check if the cast can happen. - /// - template - VTKM_CONT ArrayHandleType Cast() const - { - using T = typename ArrayHandleType::ValueType; - using S = typename ArrayHandleType::StorageTag; - const vtkm::cont::StorageVirtual* storage = this->GetStorage(); - const auto* any = storage->Cast>(); - return any->GetHandle(); - } }; template @@ -111,7 +97,6 @@ void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords, } - template <> struct TypeString { diff --git a/vtkm/cont/StorageImplicit.h b/vtkm/cont/StorageImplicit.h index a9749adf5..17efb60ee 100644 --- a/vtkm/cont/StorageImplicit.h +++ b/vtkm/cont/StorageImplicit.h @@ -53,7 +53,8 @@ namespace internal { template -class Storage> +class VTKM_ALWAYS_EXPORT + Storage> { using ClassType = Storage>; diff --git a/vtkm/cont/StorageVirtual.cxx b/vtkm/cont/StorageVirtual.cxx index 428fc9b30..2c440f328 100644 --- a/vtkm/cont/StorageVirtual.cxx +++ b/vtkm/cont/StorageVirtual.cxx @@ -87,12 +87,6 @@ void Storage::ReleaseResources() this->DeviceUpToDate = false; } -//-------------------------------------------------------------------- -bool Storage::IsSameType(const std::type_info& other) const -{ - return typeid(*this) == other; -} - //-------------------------------------------------------------------- std::unique_ptr> Storage::NewInstance() const diff --git a/vtkm/cont/StorageVirtual.h b/vtkm/cont/StorageVirtual.h index 19e0b1870..fab29a3d5 100644 --- a/vtkm/cont/StorageVirtual.h +++ b/vtkm/cont/StorageVirtual.h @@ -34,7 +34,7 @@ namespace vtkm namespace cont { -struct StorageTagVirtual +struct VTKM_ALWAYS_EXPORT StorageTagVirtual { }; @@ -99,7 +99,11 @@ public: /// Determines if storage types matches the type passed in. /// - bool IsType(const std::type_info& other) const { return this->IsSameType(other); } + template + bool IsType() const + { //needs optimizations based on platform. !OSX can use typeid + return nullptr != dynamic_cast(this); + } /// \brief Create a new storage of the same type as this storage. /// @@ -155,7 +159,6 @@ private: // virtual void DoShrink(vtkm::Id numberOfValues) = 0; //RTTI routines - virtual bool IsSameType(const std::type_info&) const; virtual std::unique_ptr> MakeNewInstance() const = 0; diff --git a/vtkm/cont/arg/TransportTagAtomicArray.h b/vtkm/cont/arg/TransportTagAtomicArray.h index b8e6aa709..8cad6225f 100644 --- a/vtkm/cont/arg/TransportTagAtomicArray.h +++ b/vtkm/cont/arg/TransportTagAtomicArray.h @@ -89,31 +89,23 @@ struct TransportIsType(typeid(vtkm::cont::internal::Storage))) + using ArrayHandleType = vtkm::cont::ArrayHandle; + const bool is_type = vtkm::cont::IsType(array); + if (!is_type) { #if defined(VTKM_ENABLE_LOGGING) - using AH = vtkm::cont::ArrayHandle; - VTKM_LOG_CAST_FAIL(array, AH); + VTKM_LOG_CAST_FAIL(array, ArrayHandleType); #endif throw vtkm::cont::ErrorBadValue("Arrays being used as atomic's must always have storage that " "is of the type StorageTagBasic."); } - const auto* any = static_cast*>(storage); - VTKM_LOG_CAST_SUCC(array, *any); + ArrayHandleType handle = vtkm::cont::Cast(array); // Note: we ignore the size of the domain because the randomly accessed // array might not have the same size depending on how the user is using // the array. - ExecType obj(any->GetHandle()); + ExecType obj(handle); return obj.PrepareForExecution(Device()); } }; diff --git a/vtkm/cont/internal/VariantArrayHandleContainer.h b/vtkm/cont/internal/VariantArrayHandleContainer.h index ec5bd0b90..b7d453285 100644 --- a/vtkm/cont/internal/VariantArrayHandleContainer.h +++ b/vtkm/cont/internal/VariantArrayHandleContainer.h @@ -137,11 +137,11 @@ VTKM_CONT bool IsType(const VariantArrayHandleContainerBase* container) { return false; } + using VT = typename ArrayHandleType::ValueType; using ST = typename ArrayHandleType::StorageTag; - const vtkm::cont::StorageVirtual* storage = container->GetStorage(); - return storage->IsType(typeid(vtkm::cont::internal::Storage)); + return storage->IsType>(); } template @@ -151,7 +151,9 @@ VTKM_CONT bool IsValueType(const VariantArrayHandleContainerBase* container) { //you can't use typeid on nullptr of polymorphic types return false; } - return typeid(VariantArrayHandleContainer) == typeid(*container); + + //needs optimizations based on platform. !OSX can use typeid + return (nullptr != dynamic_cast*>(container)); } From 1f2abbc9c46f65f749c90931e28a5aeeed124e78 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 21 Dec 2018 14:03:38 -0500 Subject: [PATCH 32/36] vtkm::cont::IsType and vtkm::cont::Cast support VariantArrayHandle --- vtkm/cont/VariantArrayHandle.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index 78f153ac5..9230c6208 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -112,7 +112,7 @@ public: /// Returns true if this array matches the array handle type passed in. /// template - VTKM_CONT bool IsType() + VTKM_CONT bool IsType() const { return internal::variant::IsType(this->ArrayContainer.get()); } @@ -120,7 +120,7 @@ public: /// Returns true if this array matches the ValueType type passed in. /// template - VTKM_CONT bool IsValueType() + VTKM_CONT bool IsValueType() const { return internal::variant::IsValueType(this->ArrayContainer.get()); } @@ -232,6 +232,24 @@ private: using VariantArrayHandle = vtkm::cont::VariantArrayHandleBase; + +//============================================================================= +// Free function casting helpers + +template +VTKM_CONT inline bool IsType(const vtkm::cont::VariantArrayHandleBase& variant) +{ + return variant.template IsType(); +} + +template +VTKM_CONT inline ArrayHandleType Cast(const vtkm::cont::VariantArrayHandleBase& variant) +{ + return variant.template Cast(); +} + + + namespace detail { From bef70820c9883cf82b16ac88c55df99b7577c46b Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 21 Dec 2018 16:29:41 -0500 Subject: [PATCH 33/36] Update new worklets to work with ArrayHandleVariant --- vtkm/worklet/testing/UnitTestZFPCompressor.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vtkm/worklet/testing/UnitTestZFPCompressor.cxx b/vtkm/worklet/testing/UnitTestZFPCompressor.cxx index 83666f71c..7ced86f73 100644 --- a/vtkm/worklet/testing/UnitTestZFPCompressor.cxx +++ b/vtkm/worklet/testing/UnitTestZFPCompressor.cxx @@ -64,7 +64,7 @@ void Test1D(int rate) vtkm::worklet::ZFP1DCompressor compressor; vtkm::worklet::ZFP1DDecompressor decompressor; - if (dynField.IsSameType(Handle64())) + if (vtkm::cont::IsType(dynField)) { vtkm::cont::ArrayHandle handle; const vtkm::Id size = dynField.Cast().GetNumberOfValues(); @@ -101,7 +101,7 @@ void Test2D(int rate) vtkm::worklet::ZFP2DCompressor compressor; vtkm::worklet::ZFP2DDecompressor decompressor; - if (dynField.IsSameType(Handle64())) + if (vtkm::cont::IsType(dynField)) { vtkm::cont::ArrayHandle handle; const vtkm::Id size = dynField.Cast().GetNumberOfValues(); @@ -141,7 +141,7 @@ void Test3D(int rate) vtkm::worklet::ZFPCompressor compressor; vtkm::worklet::ZFPDecompressor decompressor; - if (dynField.IsSameType(Handle64())) + if (vtkm::cont::IsType(dynField)) { vtkm::cont::ArrayHandle handle; const vtkm::Id size = dynField.Cast().GetNumberOfValues(); From 7a5e32be73d891b92795c1d5dcad4dab06cb5aa6 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 24 Dec 2018 14:28:46 -0500 Subject: [PATCH 34/36] Update VTKmCompilerFlags to suppress stack-size-warnings on CUDA 9+ This will allow better suppression of cuda stack size warnings for developers and build machines. --- CMake/VTKmCompilerFlags.cmake | 17 +++++++++++++++-- CTestCustom.cmake.in | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMake/VTKmCompilerFlags.cmake b/CMake/VTKmCompilerFlags.cmake index edd28d1ff..4ee473698 100644 --- a/CMake/VTKmCompilerFlags.cmake +++ b/CMake/VTKmCompilerFlags.cmake @@ -101,7 +101,7 @@ if(VTKM_COMPILER_IS_MSVC) #Setup MSVC warnings with CUDA and CXX target_compile_options(vtkm_developer_flags INTERFACE $<$:-wd4702 -wd4505>) if(TARGET vtkm::cuda) - target_compile_options(vtkm_developer_flags INTERFACE $<$:-Xcompiler=-wd4702,-wd4505 -Xcudafe=--display_error_number,--diag_suppress=1394,--diag_suppress=766>) + target_compile_options(vtkm_developer_flags INTERFACE $<$:-Xcompiler=-wd4702,-wd4505 -Xcudafe=--diag_suppress=1394,--diag_suppress=766>) endif() if(MSVC_VERSION LESS 1900) @@ -124,7 +124,7 @@ elseif(VTKM_COMPILER_IS_ICC) elseif(VTKM_COMPILER_IS_GNU OR VTKM_COMPILER_IS_CLANG) set(cxx_flags -Wall -Wno-long-long -Wcast-align -Wconversion -Wchar-subscripts -Wextra -Wpointer-arith -Wformat -Wformat-security -Wshadow -Wunused-parameter -fno-common) - set(cuda_flags -Xcudafe=--display_error_number -Xcompiler=-Wall,-Wno-unknown-pragmas,-Wno-unused-local-typedefs,-Wno-unused-local-typedefs,-Wno-unused-function,-Wno-long-long,-Wcast-align,-Wconversion,-Wchar-subscripts,-Wpointer-arith,-Wformat,-Wformat-security,-Wshadow,-Wunused-parameter,-fno-common) + set(cuda_flags -Xcompiler=-Wall,-Wno-unknown-pragmas,-Wno-unused-local-typedefs,-Wno-unused-local-typedefs,-Wno-unused-function,-Wno-long-long,-Wcast-align,-Wconversion,-Wchar-subscripts,-Wpointer-arith,-Wformat,-Wformat-security,-Wshadow,-Wunused-parameter,-fno-common) #GCC 5, 6 don't properly handle strict-overflow suppression through pragma's. #Instead of suppressing around the location of the strict-overflow you @@ -142,6 +142,19 @@ elseif(VTKM_COMPILER_IS_GNU OR VTKM_COMPILER_IS_CLANG) endif() endif() +#common warnings for all platforms when building cuda +if(TARGET vtkm::cuda) + if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER 8.99.0) + #nvcc 9 introduced specific controls to disable the stack size warning + #otherwise we let the warning occur. We have to set this in CMAKE_CUDA_FLAGS + #as it is passed to the device link step, unlike compile_options + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xnvlink=--suppress-stack-size-warning") + endif() + + set(display_error_nums -Xcudafe=--display_error_number) + target_compile_options(vtkm_developer_flags INTERFACE $<$:${suppress_nvlink_stack_size_warnings} ${display_error_nums}>) +endif() + if(NOT VTKm_INSTALL_ONLY_LIBRARIES) install(TARGETS vtkm_compiler_flags vtkm_developer_flags EXPORT ${VTKm_EXPORT_NAME}) endif() diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in index 2e7045da1..061b6c75f 100644 --- a/CTestCustom.cmake.in +++ b/CTestCustom.cmake.in @@ -37,6 +37,7 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION "CONTRIBUTING.md.*warning" "CodingConventions.md.*warning" + # disable PTX warning about recursive functions. These look like they can't be silenced # without disabling all PTX warnings, show hide them on the dashboard. # We explicitly only suppress specific worklets so we can see when new recursive @@ -45,4 +46,13 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION "ptxas warning : Stack size for entry function.*BoundingIntervalHierarchy.*" "ptxas warning : Stack size for entry function.*CoordinatesPortal.*" "ptxas warning : Stack size for entry function.*CellRangesExtracter.*" + + # disable nvlink warnings about virtual functions. The Stack size warnings can only + # be silenced in CUDA >=9, without disabling all nvlink warnings. + "nvlink warning : Stack size for entry function.*NearestNeighborSearch.*" + "nvlink warning : Stack size for entry function.*ArrayPortalRef.*" + "nvlink warning : Stack size for entry function.*ArrayPortalWrapper.*" + "nvlink warning : .*ArrayPortalWrapper.* has address taken but no possible call to it" + "nvlink warning : .*ArrayPortalVirtual.* has address taken but no possible call to it" + ) From 3445047f9e57f61c9d05ff4eb7e259050b386faa Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 24 Dec 2018 14:29:12 -0500 Subject: [PATCH 35/36] Refactor vtkm::cont::ArrayHandleAny into vtkm::cont::ArrayHandleVirtual ArrayHandleVirtual can automatically be constructed from any ArrayHandle. In the cases where the input ArrayHandle doesn't derived from ArrayHandleVirtual, it will automatically construct StorageAny to hold the array. --- vtkm/cont/ArrayHandleAny.h | 237 ------------------ vtkm/cont/ArrayHandleVirtual.h | 94 ++++++- vtkm/cont/ArrayHandleVirtual.hxx | 127 +++++----- vtkm/cont/ArrayHandleVirtualCoordinates.h | 4 +- vtkm/cont/ArrayRangeCompute.h | 8 +- vtkm/cont/ArrayRangeCompute.hxx | 19 +- vtkm/cont/CMakeLists.txt | 5 +- vtkm/cont/StorageAny.h | 74 ++++++ .../{ArrayHandleAny.hxx => StorageAny.hxx} | 18 +- vtkm/cont/StorageVirtual.hxx | 71 ++++++ vtkm/cont/VariantArrayHandle.h | 2 +- vtkm/cont/arg/TransportTagAtomicArray.h | 2 +- .../internal/VariantArrayHandleContainer.h | 3 +- vtkm/cont/testing/CMakeLists.txt | 1 + .../testing/UnitTestArrayHandleVirtual.cxx | 208 +++++++++++++++ .../cont/testing/UnitTestMoveConstructors.cxx | 8 - .../testing/UnitTestVariantArrayHandle.cxx | 1 - 17 files changed, 542 insertions(+), 340 deletions(-) delete mode 100644 vtkm/cont/ArrayHandleAny.h create mode 100644 vtkm/cont/StorageAny.h rename vtkm/cont/{ArrayHandleAny.hxx => StorageAny.hxx} (93%) create mode 100644 vtkm/cont/StorageVirtual.hxx create mode 100644 vtkm/cont/testing/UnitTestArrayHandleVirtual.cxx diff --git a/vtkm/cont/ArrayHandleAny.h b/vtkm/cont/ArrayHandleAny.h deleted file mode 100644 index b438377e6..000000000 --- a/vtkm/cont/ArrayHandleAny.h +++ /dev/null @@ -1,237 +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. -// -// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). -// Copyright 2014 UT-Battelle, LLC. -// Copyright 2014 Los Alamos National Security. -// -// Under the terms of Contract DE-NA0003525 with NTESS, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ -#ifndef vtk_m_cont_ArrayHandleAny_h -#define vtk_m_cont_ArrayHandleAny_h - -#include - -#include - -#include -#include - -#include - -namespace vtkm -{ -namespace cont -{ -template -class VTKM_ALWAYS_EXPORT StorageAny final : public vtkm::cont::StorageVirtual -{ -public: - VTKM_CONT - StorageAny(const vtkm::cont::ArrayHandle& ah); - - VTKM_CONT - ~StorageAny() = default; - - const vtkm::cont::ArrayHandle& GetHandle() const { return this->Handle; } - - vtkm::Id GetNumberOfValues() const { return this->Handle.GetNumberOfValues(); } - - void ReleaseResourcesExecution(); - void ReleaseResources(); - -private: - std::unique_ptr MakeNewInstance() const - { - return std::unique_ptr(new StorageAny{ vtkm::cont::ArrayHandle{} }); - } - - - void ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const; - void ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload); - - void TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, - vtkm::cont::DeviceAdapterId devId) const; - - void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, - OutputMode mode, - vtkm::Id numberOfValues, - vtkm::cont::DeviceAdapterId devId); - - vtkm::cont::ArrayHandle Handle; -}; - -/// ArrayHandleAny is a specialization of ArrayHandle. -template -class VTKM_ALWAYS_EXPORT ArrayHandleAny final : public vtkm::cont::ArrayHandleVirtual -{ -public: - ///construct a valid ArrayHandleAny from an existing ArrayHandle - template - VTKM_CONT ArrayHandleAny(const vtkm::cont::ArrayHandle& ah) - : vtkm::cont::ArrayHandleVirtual(std::make_shared>(ah)) - { - } - - ///construct an invalid ArrayHandleAny that has a nullptr storage - VTKM_CONT ArrayHandleAny() - : vtkm::cont::ArrayHandleVirtual() - { - } - - ~ArrayHandleAny() = default; -}; - -/// A convenience function for creating an ArrayHandleAny. -template -VTKM_CONT vtkm::cont::ArrayHandleAny make_ArrayHandleAny(const vtkm::cont::ArrayHandle& ah) -{ - return vtkm::cont::ArrayHandleAny(ah); -} - - -template -void CastAndCall(vtkm::cont::ArrayHandleVirtual> coords, - Functor&& f, - Args&&... args) -{ - using HandleType = ArrayHandleUniformPointCoordinates; - using T = typename HandleType::ValueType; - using S = typename HandleType::StorageTag; - if (coords.IsType()) - { - const vtkm::cont::StorageVirtual* storage = coords.GetStorage(); - auto* any = storage->Cast>(); - f(any->GetHandle(), std::forward(args)...); - } - else - { - f(coords, std::forward(args)...); - } -} - -//============================================================================= -// Specializations of serialization related classes -template -struct TypeString> -{ - static VTKM_CONT const std::string& Get() - { - static std::string name = "AH_Any<" + TypeString::Get() + ">"; - return name; - } -}; -} -} //namespace vtkm::cont - - -#include -#include - -//============================================================================= -// Specializations of serialization related classes -namespace diy -{ - -template -struct Serialization> -{ - - static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleAny& obj) - { - vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); - } - - static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleAny& obj) - { - vtkm::cont::ArrayHandle array; - diy::load(bb, array); - obj = std::move(vtkm::cont::ArrayHandleAny{ array }); - } -}; - -template -struct IntAnySerializer -{ - using CountingType = vtkm::cont::ArrayHandleCounting; - using ConstantType = vtkm::cont::ArrayHandleConstant; - using BasicType = vtkm::cont::ArrayHandle; - - static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleAny& obj) - { - if (obj.template IsType()) - { - diy::save(bb, vtkm::cont::TypeString::Get()); - - using S = typename CountingType::StorageTag; - const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); - auto* any = storage->Cast>(); - diy::save(bb, any->GetHandle()); - } - else if (obj.template IsType()) - { - diy::save(bb, vtkm::cont::TypeString::Get()); - - using S = typename ConstantType::StorageTag; - const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); - auto* any = storage->Cast>(); - diy::save(bb, any->GetHandle()); - } - else - { - diy::save(bb, vtkm::cont::TypeString::Get()); - vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); - } - } - - static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleAny& obj) - { - std::string typeString; - diy::load(bb, typeString); - - if (typeString == vtkm::cont::TypeString::Get()) - { - CountingType array; - diy::load(bb, array); - obj = std::move(vtkm::cont::ArrayHandleAny{ array }); - } - else if (typeString == vtkm::cont::TypeString::Get()) - { - ConstantType array; - diy::load(bb, array); - obj = std::move(vtkm::cont::ArrayHandleAny{ array }); - } - else - { - vtkm::cont::ArrayHandle array; - diy::load(bb, array); - obj = std::move(vtkm::cont::ArrayHandleAny{ array }); - } - } -}; - - -template <> -struct Serialization> : public IntAnySerializer -{ -}; -template <> -struct Serialization> : public IntAnySerializer -{ -}; -template <> -struct Serialization> : public IntAnySerializer -{ -}; -} -#endif //vtk_m_cont_ArrayHandleAny_h diff --git a/vtkm/cont/ArrayHandleVirtual.h b/vtkm/cont/ArrayHandleVirtual.h index 089e13dfa..11893e02e 100644 --- a/vtkm/cont/ArrayHandleVirtual.h +++ b/vtkm/cont/ArrayHandleVirtual.h @@ -23,8 +23,10 @@ #include #include +#include #include +#include #include #include @@ -55,9 +57,38 @@ public: using PortalConst = vtkm::ArrayPortalRef; }; - ///construct an invlaid virtual array handle that has a nullptr storage - ArrayHandle() - : Storage(nullptr){}; + + ///Construct a invalid ArrayHandleVirtual that has nullptr storage + VTKM_CONT ArrayHandle() + : Storage(nullptr) + { + } + + ///Construct a valid ArrayHandleVirtual from an existing ArrayHandle + ///that doesn't derive from ArrayHandleVirtual. + ///Note left non-explicit to allow: + /// + /// std::vector> vectorOfArrays; + /// //Make basic array. + /// vtkm::cont::ArrayHandle basicArray; + /// //Fill basicArray... + /// vectorOfArrays.push_back(basicArray); + /// + /// // Make fancy array. + /// vtkm::cont::ArrayHandleCounting fancyArray(-1.0, 0.1, ARRAY_SIZE); + /// vectorOfArrays.push_back(fancyArray); + + + template + ArrayHandle(const vtkm::cont::ArrayHandle& ah) + : Storage(std::make_shared>(ah)) + { + using is_base = std::is_base_of; + static_assert(!is_base::value, "Wrong specialization for ArrayHandleVirtual selected"); + } + + ///Copy an existing ArrayHandleVirtual into this instance + ArrayHandle(const ArrayHandle& src) = default; /// virtual destructor, as required to make sure derived classes that @@ -65,6 +96,7 @@ public: // virtual ~ArrayHandle() = default; + ///Move existing shared_ptr of vtkm::cont::StorageVirtual to be ///owned by this ArrayHandleVirtual. ///This is generally how derived class construct a valid ArrayHandleVirtual @@ -89,23 +121,41 @@ public: "Storage for ArrayHandleVirtual needs to derive from vtkm::cont::StorageVirual"); } - ///copy another existing virtual array handle - ArrayHandle(const ArrayHandle& src) = default; - ///move from one virtual array handle to another ArrayHandle(ArrayHandle&& src) noexcept : Storage(std::move(src.Storage)) { } + ///move from one a non-virtual array handle to virtual array handle + template + ArrayHandle(ArrayHandle&& src) noexcept + : Storage(std::make_shared>(std::move(src))) + { + } + VTKM_CONT ArrayHandle& operator=( const ArrayHandle& src) = default; + template + VTKM_CONT ArrayHandle& operator=(const ArrayHandle& src) + { + this->Storage = std::make_shared>(src); + return *this; + } + VTKM_CONT ArrayHandle& operator=( ArrayHandle&& src) noexcept { this->Storage = std::move(src.Storage); return *this; } + template + VTKM_CONT ArrayHandle& operator=( + ArrayHandle&& src) noexcept + { + this->Storage = std::make_shared>(std::move(src)); + return *this; + } /// Like a pointer, two \c ArrayHandles are considered equal if they point /// to the same location in memory. @@ -344,6 +394,15 @@ template using ArrayHandleVirtual = vtkm::cont::ArrayHandle; +//============================================================================= +/// A convenience function for creating an ArrayHandleVirtual. +template +VTKM_CONT vtkm::cont::ArrayHandleVirtual make_ArrayHandleVirtual( + const vtkm::cont::ArrayHandle& ah) +{ + return vtkm::cont::ArrayHandleVirtual(ah); +} + //============================================================================= // Free function casting helpers @@ -359,6 +418,29 @@ VTKM_CONT inline ArrayHandleType Cast(const vtkm::cont::ArrayHandleVirtual& v return virtHandle.template Cast(); } +//============================================================================= +// Specializations of CastAndCall to help make sure ArrayHandleVirtual +// holding a ArrayHandleUniformPointCoordinates works properly +template +void CastAndCall(vtkm::cont::ArrayHandleVirtual> coords, + Functor&& f, + Args&&... args) +{ + using HandleType = ArrayHandleUniformPointCoordinates; + using T = typename HandleType::ValueType; + using S = typename HandleType::StorageTag; + if (coords.IsType()) + { + const vtkm::cont::StorageVirtual* storage = coords.GetStorage(); + auto* any = storage->Cast>(); + f(any->GetHandle(), std::forward(args)...); + } + else + { + f(coords, std::forward(args)...); + } +} + //============================================================================= diff --git a/vtkm/cont/ArrayHandleVirtual.hxx b/vtkm/cont/ArrayHandleVirtual.hxx index fb27ed85e..5891acd7b 100644 --- a/vtkm/cont/ArrayHandleVirtual.hxx +++ b/vtkm/cont/ArrayHandleVirtual.hxx @@ -21,8 +21,7 @@ #define vtk_m_cont_ArrayHandleVirtual_hxx #include - -#include +#include #include namespace vtkm @@ -57,48 +56,12 @@ ArrayHandleType ArrayHandle::CastToType( const auto* any = this->Storage->template Cast>(); return any->GetHandle(); } - - -namespace detail -{ -template -struct TransferToDevice -{ - template - bool operator()(DeviceAdapterTag devId, Payload&& payload, Args&&... args) const - { - using TransferType = cont::internal::VirtualObjectTransfer; - - - //construct all new transfer payload - auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); - auto transfer = std::make_shared(host.get()); - auto device = transfer->PrepareForExecution(true); - - payload.updateDevice(devId, std::move(host), device, std::static_pointer_cast(transfer)); - - return true; - } -}; } - -template -inline void make_transferToDevice(vtkm::cont::DeviceAdapterId devId, Args&&... args) -{ - vtkm::cont::TryExecuteOnDevice( - devId, detail::TransferToDevice{}, std::forward(args)...); -} - -template -inline void make_hostPortal(Payload&& payload, Args&&... args) -{ - auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); - payload.updateHost(std::move(host)); -} -} -} // namespace vtkm::virts +} // namespace vtkm::const +#include +#include //============================================================================= // Specializations of serialization related classes @@ -108,19 +71,46 @@ namespace diy template struct Serialization> { -private: - using Type = vtkm::cont::ArrayHandleVirtual; - using BaseType = vtkm::cont::ArrayHandle; + + static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleVirtual& obj) + { + vtkm::cont::internal::ArrayHandleDefaultSerialization(bb, obj); + } + + static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleVirtual& obj) + { + vtkm::cont::ArrayHandle array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleVirtual{ array }); + } +}; + +template +struct IntAnySerializer +{ + using CountingType = vtkm::cont::ArrayHandleCounting; + using ConstantType = vtkm::cont::ArrayHandleConstant; using BasicType = vtkm::cont::ArrayHandle; -public: - static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) + static VTKM_CONT void save(diy::BinaryBuffer& bb, const vtkm::cont::ArrayHandleVirtual& obj) { - if (obj.template IsType>()) + if (obj.template IsType()) { - const auto& array = static_cast&>(obj); - diy::save(bb, vtkm::cont::TypeString>::Get()); - diy::save(bb, array); + diy::save(bb, vtkm::cont::TypeString::Get()); + + using S = typename CountingType::StorageTag; + const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); + auto* any = storage->Cast>(); + diy::save(bb, any->GetHandle()); + } + else if (obj.template IsType()) + { + diy::save(bb, vtkm::cont::TypeString::Get()); + + using S = typename ConstantType::StorageTag; + const vtkm::cont::StorageVirtual* storage = obj.GetStorage(); + auto* any = storage->Cast>(); + diy::save(bb, any->GetHandle()); } else { @@ -129,31 +119,48 @@ public: } } - static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj) + static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::ArrayHandleVirtual& obj) { std::string typeString; diy::load(bb, typeString); - if (typeString == vtkm::cont::TypeString>::Get()) + if (typeString == vtkm::cont::TypeString::Get()) { - vtkm::cont::ArrayHandleAny array; + CountingType array; diy::load(bb, array); - obj = std::move(array); + obj = std::move(vtkm::cont::ArrayHandleVirtual{ array }); } - else if (typeString == vtkm::cont::TypeString::Get()) + else if (typeString == vtkm::cont::TypeString::Get()) { - BasicType array; + ConstantType array; diy::load(bb, array); - obj = std::move(vtkm::cont::ArrayHandleAny{ array }); + obj = std::move(vtkm::cont::ArrayHandleVirtual{ array }); } else { - throw vtkm::cont::ErrorBadType("Error deserializing ArrayHandleVirtual. TypeString: " + - typeString); + vtkm::cont::ArrayHandle array; + diy::load(bb, array); + obj = std::move(vtkm::cont::ArrayHandleVirtual{ array }); } } }; + + +template <> +struct Serialization> + : public IntAnySerializer +{ +}; +template <> +struct Serialization> + : public IntAnySerializer +{ +}; +template <> +struct Serialization> + : public IntAnySerializer +{ +}; } - #endif diff --git a/vtkm/cont/ArrayHandleVirtualCoordinates.h b/vtkm/cont/ArrayHandleVirtualCoordinates.h index e825ba0c2..f3cf5f37a 100644 --- a/vtkm/cont/ArrayHandleVirtualCoordinates.h +++ b/vtkm/cont/ArrayHandleVirtualCoordinates.h @@ -20,7 +20,6 @@ #ifndef vtk_m_cont_ArrayHandleVirtualCoordinates_h #define vtk_m_cont_ArrayHandleVirtualCoordinates_h -#include #include #include @@ -64,8 +63,7 @@ public: template explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle& ah) - : vtkm::cont::ArrayHandleVirtual( - std::make_shared>(ah)) + : vtkm::cont::ArrayHandleVirtual(ah) { } diff --git a/vtkm/cont/ArrayRangeCompute.h b/vtkm/cont/ArrayRangeCompute.h index 42a5faaa6..6dd8fbf08 100644 --- a/vtkm/cont/ArrayRangeCompute.h +++ b/vtkm/cont/ArrayRangeCompute.h @@ -97,10 +97,10 @@ VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float64, 4, vtkm::cont::StorageTagBasi #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_T #undef VTKM_ARRAY_RANGE_COMPUTE_EXPORT_VEC -VTKM_CONT -vtkm::cont::ArrayHandle ArrayRangeCompute( - const vtkm::cont::ArrayHandleVirtualCoordinates& input, - vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); +// VTKM_CONT +// vtkm::cont::ArrayHandle ArrayRangeCompute( +// const vtkm::cont::ArrayHandleVirtualCoordinates& input, +// vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker()); VTKM_CONT vtkm::cont::ArrayHandle ArrayRangeCompute( diff --git a/vtkm/cont/ArrayRangeCompute.hxx b/vtkm/cont/ArrayRangeCompute.hxx index 4502e9e4b..0b36a265b 100644 --- a/vtkm/cont/ArrayRangeCompute.hxx +++ b/vtkm/cont/ArrayRangeCompute.hxx @@ -104,15 +104,15 @@ inline vtkm::cont::ArrayHandle ArrayRangeComputeImpl( } // namespace detail -VTKM_CONT -inline vtkm::cont::ArrayHandle ArrayRangeCompute( - const vtkm::cont::ArrayHandleVirtualCoordinates& input, - vtkm::cont::RuntimeDeviceTracker tracker) -{ - auto array = - static_cast>&>(input); - return ArrayRangeCompute(array, tracker); -} +// VTKM_CONT +// inline vtkm::cont::ArrayHandle ArrayRangeCompute( +// const vtkm::cont::ArrayHandleVirtualCoordinates& input, +// vtkm::cont::RuntimeDeviceTracker tracker) +// { +// auto array = +// static_cast>&>(input); +// return ArrayRangeCompute(array, tracker); +// } VTKM_CONT inline vtkm::cont::ArrayHandle ArrayRangeCompute( @@ -125,7 +125,6 @@ inline vtkm::cont::ArrayHandle ArrayRangeCompute( vtkm::cont::ArrayHandle, vtkm::cont::ArrayHandle>; - if (input.IsType()) { using T = typename UniformHandleType::ValueType; diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 8ee151f75..89631d061 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -22,7 +22,6 @@ set(headers Algorithm.h ArrayCopy.h ArrayHandle.h - ArrayHandleAny.h ArrayHandleCartesianProduct.h ArrayHandleCast.h ArrayHandleCompositeVector.h @@ -99,6 +98,7 @@ set(headers RuntimeDeviceTracker.h Serialization.h Storage.h + StorageAny.h StorageBasic.h StorageImplicit.h StorageListTag.h @@ -112,7 +112,6 @@ set(headers set(template_sources ArrayHandle.hxx - ArrayHandleAny.hxx ArrayHandleVirtual.hxx ArrayRangeCompute.hxx BoundingIntervalHierarchy.hxx @@ -122,7 +121,9 @@ set(template_sources CoordinateSystem.hxx FieldRangeCompute.hxx FieldRangeGlobalCompute.hxx + StorageAny.hxx StorageBasic.hxx + StorageVirtual.hxx ) set(sources diff --git a/vtkm/cont/StorageAny.h b/vtkm/cont/StorageAny.h new file mode 100644 index 000000000..9539cc830 --- /dev/null +++ b/vtkm/cont/StorageAny.h @@ -0,0 +1,74 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_StorageAny_h +#define vtk_m_cont_StorageAny_h + +#include + +#include +#include + +namespace vtkm +{ +namespace cont +{ +template +class VTKM_ALWAYS_EXPORT StorageAny final : public vtkm::cont::StorageVirtual +{ +public: + VTKM_CONT + explicit StorageAny(const vtkm::cont::ArrayHandle& ah); + + explicit StorageAny(vtkm::cont::ArrayHandle&& ah) noexcept; + + VTKM_CONT + ~StorageAny() = default; + + const vtkm::cont::ArrayHandle& GetHandle() const { return this->Handle; } + + vtkm::Id GetNumberOfValues() const { return this->Handle.GetNumberOfValues(); } + + void ReleaseResourcesExecution(); + void ReleaseResources(); + +private: + std::unique_ptr MakeNewInstance() const + { + return std::unique_ptr(new StorageAny{ vtkm::cont::ArrayHandle{} }); + } + + + void ControlPortalForInput(vtkm::cont::internal::TransferInfoArray& payload) const; + void ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload); + + void TransferPortalForInput(vtkm::cont::internal::TransferInfoArray& payload, + vtkm::cont::DeviceAdapterId devId) const; + + void TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray& payload, + OutputMode mode, + vtkm::Id numberOfValues, + vtkm::cont::DeviceAdapterId devId); + + vtkm::cont::ArrayHandle Handle; +}; +} +} + +#endif //vtk_m_cont_StorageAny_h diff --git a/vtkm/cont/ArrayHandleAny.hxx b/vtkm/cont/StorageAny.hxx similarity index 93% rename from vtkm/cont/ArrayHandleAny.hxx rename to vtkm/cont/StorageAny.hxx index 39dd60e53..3a412878c 100644 --- a/vtkm/cont/ArrayHandleAny.hxx +++ b/vtkm/cont/StorageAny.hxx @@ -17,11 +17,11 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -#ifndef vtk_m_cont_ArrayHandleAny_hxx -#define vtk_m_cont_ArrayHandleAny_hxx +#ifndef vtk_m_cont_StorageAny_hxx +#define vtk_m_cont_StorageAny_hxx -#include -#include +#include +#include namespace vtkm { @@ -36,6 +36,14 @@ StorageAny::StorageAny(const vtkm::cont::ArrayHandle& ah) { } +VTKM_CONT +template +StorageAny::StorageAny(vtkm::cont::ArrayHandle&& ah) noexcept + : vtkm::cont::StorageVirtual(), + Handle(std::move(ah)) +{ +} + /// release execution side resources template void StorageAny::ReleaseResourcesExecution() @@ -151,4 +159,4 @@ void StorageAny::TransferPortalForOutput(vtkm::cont::internal::TransferInf } } // namespace vtkm::cont -#endif //vtk_m_cont_ArrayHandleAny_hxx +#endif //vtk_m_cont_StorageAny_hxx diff --git a/vtkm/cont/StorageVirtual.hxx b/vtkm/cont/StorageVirtual.hxx new file mode 100644 index 000000000..664f009e2 --- /dev/null +++ b/vtkm/cont/StorageVirtual.hxx @@ -0,0 +1,71 @@ +//============================================================================ +// 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. +// +// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_cont_StorageVirtual_hxx +#define vtk_m_cont_StorageVirtual_hxx + +#include +#include +#include + +namespace vtkm +{ +namespace cont +{ +namespace detail +{ +template +struct TransferToDevice +{ + template + bool operator()(DeviceAdapterTag devId, Payload&& payload, Args&&... args) const + { + using TransferType = cont::internal::VirtualObjectTransfer; + + + //construct all new transfer payload + auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); + auto transfer = std::make_shared(host.get()); + auto device = transfer->PrepareForExecution(true); + + payload.updateDevice(devId, std::move(host), device, std::static_pointer_cast(transfer)); + + return true; + } +}; +} + +template +inline void make_transferToDevice(vtkm::cont::DeviceAdapterId devId, Args&&... args) +{ + vtkm::cont::TryExecuteOnDevice( + devId, detail::TransferToDevice{}, std::forward(args)...); +} + +template +inline void make_hostPortal(Payload&& payload, Args&&... args) +{ + auto host = std::unique_ptr(new DerivedPortal(std::forward(args)...)); + payload.updateHost(std::move(host)); +} +} + +} // namespace vtkm::cont:: + +#endif diff --git a/vtkm/cont/VariantArrayHandle.h b/vtkm/cont/VariantArrayHandle.h index 9230c6208..9949a2ce8 100644 --- a/vtkm/cont/VariantArrayHandle.h +++ b/vtkm/cont/VariantArrayHandle.h @@ -77,7 +77,7 @@ public: template VTKM_CONT VariantArrayHandleBase(const vtkm::cont::ArrayHandle& array) : ArrayContainer(std::make_shared>( - vtkm::cont::ArrayHandleAny{ array })) + vtkm::cont::ArrayHandleVirtual{ array })) { } diff --git a/vtkm/cont/arg/TransportTagAtomicArray.h b/vtkm/cont/arg/TransportTagAtomicArray.h index 8cad6225f..bb35fb757 100644 --- a/vtkm/cont/arg/TransportTagAtomicArray.h +++ b/vtkm/cont/arg/TransportTagAtomicArray.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include diff --git a/vtkm/cont/internal/VariantArrayHandleContainer.h b/vtkm/cont/internal/VariantArrayHandleContainer.h index b7d453285..42351b757 100644 --- a/vtkm/cont/internal/VariantArrayHandleContainer.h +++ b/vtkm/cont/internal/VariantArrayHandleContainer.h @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -171,7 +170,7 @@ struct VTKM_ALWAYS_EXPORT Caster } //we know the storage isn't a virtual but another storage type - //that means that the container holds a vtkm::cont::ArrayHandleAny + //that means that the container holds a vtkm::cont::StorageAny const auto* any = static_cast*>(container->GetStorage()); VTKM_LOG_CAST_SUCC(container, *any); return any->GetHandle(); diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index 9392f8de3..5a01b1c83 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -55,6 +55,7 @@ set(unit_tests UnitTestArrayHandleTransform.cxx UnitTestArrayHandleUniformPointCoordinates.cxx UnitTestArrayHandleConcatenate.cxx + UnitTestArrayHandleVirtual.cxx UnitTestVariantArrayHandle.cxx UnitTestArrayPortalToIterators.cxx UnitTestCellLocator.cxx diff --git a/vtkm/cont/testing/UnitTestArrayHandleVirtual.cxx b/vtkm/cont/testing/UnitTestArrayHandleVirtual.cxx new file mode 100644 index 000000000..f36c7a83c --- /dev/null +++ b/vtkm/cont/testing/UnitTestArrayHandleVirtual.cxx @@ -0,0 +1,208 @@ +//============================================================================ +// 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. +// +// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2017 UT-Battelle, LLC. +// Copyright 2017 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ + +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include + +#include + +namespace UnitTestArrayHandleVirtualDetail +{ + +template +struct Test +{ + static constexpr vtkm::Id ARRAY_SIZE = 100; + static constexpr vtkm::Id NUM_KEYS = 3; + + using ArrayHandle = vtkm::cont::ArrayHandle; + using VirtHandle = vtkm::cont::ArrayHandleVirtual; + using DeviceTag = vtkm::cont::DeviceAdapterTagSerial; + using Algorithm = vtkm::cont::DeviceAdapterAlgorithm; + + void TestConstructors() + { + VirtHandle nullStorage; + VTKM_TEST_ASSERT(nullStorage.GetStorage() == nullptr, + "storage should be empty when using ArrayHandleVirtual()."); + + VirtHandle fromArrayHandle{ ArrayHandle{} }; + VTKM_TEST_ASSERT(fromArrayHandle.GetStorage() != nullptr, + "storage should be empty when using ArrayHandleVirtual()."); + VTKM_TEST_ASSERT(vtkm::cont::IsType(fromArrayHandle), + "ArrayHandleVirtual should contain a ArrayHandle."); + + VirtHandle fromVirtHandle(fromArrayHandle); + VTKM_TEST_ASSERT(fromVirtHandle.GetStorage() != nullptr, + "storage should be empty when using ArrayHandleVirtual()."); + VTKM_TEST_ASSERT(vtkm::cont::IsType(fromVirtHandle), + "ArrayHandleVirtual should contain a ArrayHandle."); + + VirtHandle fromNullPtrHandle(nullStorage); + VTKM_TEST_ASSERT(fromNullPtrHandle.GetStorage() == nullptr, + "storage should be empty when constructing from a ArrayHandleVirtual that has " + "nullptr storage."); + VTKM_TEST_ASSERT((vtkm::cont::IsType(fromNullPtrHandle) == false), + "ArrayHandleVirtual shouldn't match any type with nullptr storage."); + } + + + void TestMoveConstructors() + { + //test shared_ptr move constructor + { + vtkm::cont::ArrayHandleCounting countingHandle; + using ST = typename decltype(countingHandle)::StorageTag; + auto sharedPtr = std::make_shared>(countingHandle); + + VirtHandle virt(std::move(sharedPtr)); + VTKM_TEST_ASSERT( + vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after move constructor shared_ptr."); + } + + //test unique_ptr move constructor + { + vtkm::cont::ArrayHandleCounting countingHandle; + using ST = typename decltype(countingHandle)::StorageTag; + auto uniquePtr = std::unique_ptr>( + new vtkm::cont::StorageAny(countingHandle)); + + VirtHandle virt(std::move(uniquePtr)); + VTKM_TEST_ASSERT( + vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after move constructor unique_ptr."); + } + + //test ArrayHandle move constructor + { + ArrayHandle handle; + VirtHandle virt(std::move(handle)); + VTKM_TEST_ASSERT( + vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after move constructor ArrayHandle."); + } + + //test ArrayHandleVirtual move constructor + { + ArrayHandle handle; + VirtHandle virt(std::move(handle)); + VirtHandle virt2(std::move(virt)); + VTKM_TEST_ASSERT( + vtkm::cont::IsType(virt2), + "ArrayHandleVirtual should be valid after move constructor ArrayHandleVirtual."); + } + } + + void TestAssignmentOps() + { + //test assignment operator from ArrayHandleVirtual + { + VirtHandle virt; + virt = VirtHandle{ ArrayHandle{} }; + VTKM_TEST_ASSERT(vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after assignment op from AHV."); + } + + //test assignment operator from ArrayHandle + { + VirtHandle virt = vtkm::cont::ArrayHandleCounting{}; + virt = ArrayHandle{}; + VTKM_TEST_ASSERT(vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after assignment op from AH."); + } + + //test move assignment operator from ArrayHandleVirtual + { + VirtHandle temp{ ArrayHandle{} }; + VirtHandle virt; + virt = std::move(temp); + VTKM_TEST_ASSERT(vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after move assignment op from AHV."); + } + + //test move assignment operator from ArrayHandle + { + vtkm::cont::ArrayHandleCounting temp; + VirtHandle virt; + virt = std::move(temp); + VTKM_TEST_ASSERT(vtkm::cont::IsType(virt), + "ArrayHandleVirtual should be valid after move assignment op from AH."); + } + } + + void TestPrepareForExecution() + { + vtkm::cont::ArrayHandle handle; + handle.Allocate(50); + + VirtHandle virt(std::move(handle)); + + try + { + virt.PrepareForInput(DeviceTag()); + virt.PrepareForInPlace(DeviceTag()); + virt.PrepareForOutput(ARRAY_SIZE, DeviceTag()); + } + catch (vtkm::cont::ErrorBadValue&) + { + // un-expected failure. + VTKM_TEST_FAIL( + "Unexpected error when using Prepare* on an ArrayHandleVirtual with StorageAny."); + } + } + + void operator()() + { + TestConstructors(); + TestMoveConstructors(); + TestAssignmentOps(); + TestPrepareForExecution(); + } +}; + +void TestArrayHandleVirtual() +{ + Test()(); + Test()(); + Test()(); + Test()(); + Test()(); + Test()(); +} + +} // end namespace UnitTestArrayHandleVirtualDetail + +int UnitTestArrayHandleVirtual(int, char* []) +{ + using namespace UnitTestArrayHandleVirtualDetail; + return vtkm::cont::testing::Testing::Run(TestArrayHandleVirtual); +} diff --git a/vtkm/cont/testing/UnitTestMoveConstructors.cxx b/vtkm/cont/testing/UnitTestMoveConstructors.cxx index 7f736c9ad..dfae2e30e 100644 --- a/vtkm/cont/testing/UnitTestMoveConstructors.cxx +++ b/vtkm/cont/testing/UnitTestMoveConstructors.cxx @@ -18,7 +18,6 @@ // this software. //============================================================================ #include -#include #include #include @@ -34,7 +33,6 @@ namespace { - // clang-format off template void is_noexcept_movable() @@ -79,27 +77,21 @@ struct IsNoExceptHandle void operator()(T) const { using HandleType = vtkm::cont::ArrayHandle; - using AnyType = vtkm::cont::ArrayHandleAny; using VirtualType = vtkm::cont::ArrayHandleVirtual; //verify the handle type is_noexcept_movable(); - is_noexcept_movable(); is_noexcept_movable(); //verify the input portals of the handle is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); - is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); //verify the output portals of the handle is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); - is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); } diff --git a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx index 95a89d1a8..6672d5467 100644 --- a/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestVariantArrayHandle.cxx @@ -22,7 +22,6 @@ #include -#include #include #include #include From 19c623bfa392785fddf73b7341c7da5e973e5f95 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 24 Dec 2018 16:15:58 -0500 Subject: [PATCH 36/36] Add changelogs for ArrayHandleVirtual and VariantArrayHandle --- docs/changelog/arrayhandlevirtual.md | 45 +++++++++++++++++++ ...zip-handles-writing-to-implicit-handles.md | 9 ++++ .../cuda-separable-compilation-enabled.md | 4 ++ docs/changelog/variantarrayhandle.md | 43 ++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 docs/changelog/arrayhandlevirtual.md create mode 100644 docs/changelog/arrayhandlezip-handles-writing-to-implicit-handles.md create mode 100644 docs/changelog/cuda-separable-compilation-enabled.md create mode 100644 docs/changelog/variantarrayhandle.md diff --git a/docs/changelog/arrayhandlevirtual.md b/docs/changelog/arrayhandlevirtual.md new file mode 100644 index 000000000..e5172d648 --- /dev/null +++ b/docs/changelog/arrayhandlevirtual.md @@ -0,0 +1,45 @@ +# Add vtkm::cont::ArrayHandleVirtual + + +Added a new class named `ArrayHandleVirtual` that allows you to type erase an +ArrayHandle storage type by using virtual calls. This simplification makes +storing `Fields` and `Coordinates` significantly easier as VTK-m doesn't +need to deduce both the storage and value type when executing worklets. + +To construct an `ArrayHandleVirtual` one can do one of the following: + +```cpp +vtkm::cont::ArrayHandle pressure; +vtkm::cont::ArrayHandleConstant constant(42.0f); + + +// constrcut from an array handle +vtkm::cont::ArrayHandleVirtual v(pressure); + +// or assign from an array handle +v = constant; + +``` + +To help maintain performance `ArrayHandleVirtual` provides a collection of helper +functions/methods to query and cast back to the concrete storage and value type: +```cpp +vtkm::cont::ArrayHandleConstant constant(42.0f); +vtkm::cont::ArrayHandleVirtual v = constant; + +bool isConstant = vtkm::cont::IsType< decltype(constant) >(v); +if(isConstant) + vtkm::cont::ArrayHandleConstant t = vtkm::cont::Cast< decltype(constant) >(v); + +``` + +Lastly, a common operation of calling code using `ArrayHandleVirtual` is a desire to construct a new instance +of an existing virtual handle with the same storage type. This can be done by using the `NewInstance` method +as seen below +```cpp +vtkm::cont::ArrayHandle pressure; +vtkm::cont::ArrayHandleVirtual v = pressure; + +vtkm::cont::ArrayHandleVirtual newArray = v->NewInstance(); +bool isConstant = vtkm::cont::IsType< vtkm::cont::ArrayHandle >(newArray); //will be true +``` diff --git a/docs/changelog/arrayhandlezip-handles-writing-to-implicit-handles.md b/docs/changelog/arrayhandlezip-handles-writing-to-implicit-handles.md new file mode 100644 index 000000000..06c88c4b1 --- /dev/null +++ b/docs/changelog/arrayhandlezip-handles-writing-to-implicit-handles.md @@ -0,0 +1,9 @@ +# vtkm::cont::ArrayHandleZip provides a consistent API even with non-writable handles + +Previously ArrayHandleZip could not wrap an implicit handle and provide a consistent experience. +The primary issue was that if you tried to use the PortalType returned by GetPortalControl() you +would get a compile failure. This would occur as the PortalType returned would try to call `Set` +on an ImplicitPortal which doesn't have a set method. + +Now with this change, the `ZipPortal` use SFINAE to determine if `Set` and `Get` should call the +underlying zipped portals. diff --git a/docs/changelog/cuda-separable-compilation-enabled.md b/docs/changelog/cuda-separable-compilation-enabled.md new file mode 100644 index 000000000..6b231e88f --- /dev/null +++ b/docs/changelog/cuda-separable-compilation-enabled.md @@ -0,0 +1,4 @@ +# VTK-m now requires CUDA separable compilation to build + +With the introduction of `vtkm::cont::ArrayHandleVirtual` and the related infrastructure, vtk-m now +requires that all CUDA code be compiled using separable compilation ( -rdc ). diff --git a/docs/changelog/variantarrayhandle.md b/docs/changelog/variantarrayhandle.md new file mode 100644 index 000000000..d6466027f --- /dev/null +++ b/docs/changelog/variantarrayhandle.md @@ -0,0 +1,43 @@ +# vtkm::cont::VariantArrayHandle replaces vtkm::cont::DynamicArrayHandle + +`ArrayHandleVariant` replaces `DynamicArrayHandle` as the primary method +for holding onto a type erased `vtkm::cont::ArrayHandle`. The major difference +between the two implementations is how they handle the Storage component of +an array handle. + +`DynamicArrayHandle` approach was to find the fully deduced type of the `ArrayHandle` +meaning it would check all value and storage types it knew about until it found a match. +This cross product of values and storages would cause significant compilation times when +a `DynamicArrayHandle` had multiple storage types. + +`VariantArrayHandle` approach is to only deduce the value type of the `ArrayHandle` and +return a `vtkm::cont::ArrayHandleVirtual` which uses polymorpishm to hide the actual +storage type. This approach allows for better compile times, and for calling code +to always expect an `ArrayHandleVirtual` instead of the fully deduced type. This conversion +to `ArrayHandleVirtual` is usually done internally within VTK-m when a worklet or filter +is invoked. + +In certain cases users of `VariantArrayHandle` want to be able to access the concrete +`ArrayHandle` and not have it wrapped in a `ArrayHandleVirtual`. For those occurrences +`VariantArrayHandle` provides a collection of helper functions/methods to query and +cast back to the concrete storage and value type: +```cpp +vtkm::cont::ArrayHandleConstant constant(42.0f); +vtkm::cont::ArrayHandleVariant v(constant); + +bool isConstant = vtkm::cont::IsType< decltype(constant) >(v); +if(isConstant) + vtkm::cont::ArrayHandleConstant t = vtkm::cont::Cast< decltype(constant) >(v); + +``` + +Lastly, a common operation of calling code using `VariantArrayHandle` is a desire to construct a new instance +of an existing virtual handle with the same storage type. This can be done by using the `NewInstance` method +as seen below +```cpp +vtkm::cont::ArrayHandle pressure; +vtkm::cont::ArrayHandleVariant v(pressure); + +vtkm::cont::ArrayHandleVariant newArray = v->NewInstance(); +bool isConstant = vtkm::cont::IsType< decltype(pressure) >(newArray); //will be true +```