From de2f2b59badec816c9528fc5bb54527d2a631a6f Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 26 Sep 2022 10:23:26 -0600 Subject: [PATCH] Deprecate old filter base classes and supporting classes --- benchmarking/BenchmarkFilters.cxx | 1 - docs/changelog/deprecate-old-filters.md | 9 + examples/game_of_life/GameOfLife.cxx | 39 +-- examples/hello_worklet/HelloWorklet.cxx | 55 ++-- examples/histogram/CMakeLists.txt | 4 +- examples/histogram/Histogram.cxx | 5 +- .../{HistogramMPI.hxx => HistogramMPI.cxx} | 90 +++--- examples/histogram/HistogramMPI.h | 31 +-- .../multi_backend/MultiDeviceGradient.cxx | 252 ++++++++++++++++- examples/multi_backend/MultiDeviceGradient.h | 22 +- .../multi_backend/MultiDeviceGradient.hxx | 251 ----------------- examples/redistribute_points/CMakeLists.txt | 2 +- .../RedistributePoints.cxx | 259 +++++++++++++++--- .../redistribute_points/RedistributePoints.h | 236 +--------------- examples/redistribute_points/main.cxx | 60 ++++ tutorial/extract_edges.cxx | 2 +- vtkm/filter/CMakeLists.txt | 38 +-- vtkm/filter/CreateResult.h | 33 ++- vtkm/filter/FieldMetadata.h | 2 +- vtkm/filter/Filter.h | 4 +- vtkm/filter/FilterCell.h | 2 + vtkm/filter/FilterDataSet.h | 5 +- vtkm/filter/FilterDataSetWithField.h | 5 +- vtkm/filter/FilterField.h | 5 +- vtkm/filter/FilterTraits.h | 7 +- vtkm/filter/MapFieldMergeAverage.cxx | 1 - vtkm/filter/PolicyBase.h | 119 ++++---- vtkm/filter/PolicyDefault.h | 2 +- vtkm/filter/internal/CMakeLists.txt | 5 +- vtkm/filter/testing/UnitTestFieldMetadata.cxx | 2 + 30 files changed, 795 insertions(+), 753 deletions(-) create mode 100644 docs/changelog/deprecate-old-filters.md rename examples/histogram/{HistogramMPI.hxx => HistogramMPI.cxx} (75%) delete mode 100644 examples/multi_backend/MultiDeviceGradient.hxx create mode 100644 examples/redistribute_points/main.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index c1810c46b..56959078e 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -29,7 +29,6 @@ #include #include -#include #include #include #include diff --git a/docs/changelog/deprecate-old-filters.md b/docs/changelog/deprecate-old-filters.md new file mode 100644 index 000000000..8d45ad166 --- /dev/null +++ b/docs/changelog/deprecate-old-filters.md @@ -0,0 +1,9 @@ +# Old Filter Base Classes are Deprecated + +In recent versions of VTK-m, a new structure for filter classes was +introduced. All of the existing filters have been moved over to this new +structure, and the old filter class structure has been deprecated. + +This is in preparation for changed in VTK-m 2.0, where the old filter +classes will be removed and the new filter classes will have the `New` in +their name removed (so that they become simply `Filter` and `FilterField`). diff --git a/examples/game_of_life/GameOfLife.cxx b/examples/game_of_life/GameOfLife.cxx index 8cc2228c8..dc27f532d 100644 --- a/examples/game_of_life/GameOfLife.cxx +++ b/examples/game_of_life/GameOfLife.cxx @@ -19,13 +19,14 @@ #include #include +#include #include #include #include #include -#include +#include #include #include @@ -48,11 +49,6 @@ #include "LoadShaders.h" -struct GameOfLifePolicy : public vtkm::filter::PolicyBase -{ - using FieldTypeList = vtkm::List; -}; - struct UpdateLifeState : public vtkm::worklet::WorkletPointNeighborhood { using CountingHandle = vtkm::cont::ArrayHandleCounting; @@ -99,44 +95,33 @@ struct UpdateLifeState : public vtkm::worklet::WorkletPointNeighborhood }; -class GameOfLife : public vtkm::filter::FilterDataSet +class GameOfLife : public vtkm::filter::NewFilterField { public: - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) + VTKM_CONT GameOfLife() { this->SetActiveField("state", vtkm::cont::Field::Association::Points); } + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override { vtkm::cont::ArrayHandle state; vtkm::cont::ArrayHandle prevstate; vtkm::cont::ArrayHandle colors; //get the coordinate system we are using for the 2D area - const vtkm::cont::UnknownCellSet cells = input.GetCellSet(); + vtkm::cont::CellSetStructured<2> cells; + input.GetCellSet().AsCellSet(cells); //get the previous state of the game - input.GetField("state", vtkm::cont::Field::Association::Points).GetData().CopyTo(prevstate); + this->GetFieldFromDataSet(input).GetData().AsArrayHandle(prevstate); //Update the game state - this->Invoke( - UpdateLifeState{}, vtkm::filter::ApplyPolicyCellSet(cells, policy), prevstate, state, colors); + this->Invoke(UpdateLifeState{}, cells, prevstate, state, colors); //save the results - vtkm::cont::DataSet output; - output.CopyStructure(input); - + vtkm::cont::DataSet output = + this->CreateResultFieldPoint(input, this->GetActiveFieldName(), state); output.AddField(vtkm::cont::make_FieldPoint("colors", colors)); - output.AddField(vtkm::cont::make_FieldPoint("state", state)); return output; } - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet&, - const vtkm::cont::Field&, - vtkm::filter::PolicyBase) - { - return false; - } }; struct UploadData @@ -346,7 +331,7 @@ int main(int argc, char** argv) glutDisplayFunc([]() { const vtkm::Float32 c = static_cast(gTimer.GetElapsedTime()); - vtkm::cont::DataSet oData = gFilter->Execute(*gData, GameOfLifePolicy()); + vtkm::cont::DataSet oData = gFilter->Execute(*gData); gRenderer->render(oData); glutSwapBuffers(); diff --git a/examples/hello_worklet/HelloWorklet.cxx b/examples/hello_worklet/HelloWorklet.cxx index 3f103cf48..a21523cf9 100644 --- a/examples/hello_worklet/HelloWorklet.cxx +++ b/examples/hello_worklet/HelloWorklet.cxx @@ -10,8 +10,7 @@ #include -#include -#include +#include #include #include @@ -23,58 +22,56 @@ #include #include -namespace vtkm -{ -namespace worklet +namespace hello_worklet_example { struct HelloWorklet : public vtkm::worklet::WorkletMapField { using ControlSignature = void(FieldIn inVector, FieldOut outMagnitude); - VTKM_EXEC void operator()(const vtkm::Vec3f& inVector, vtkm::FloatDefault& outMagnitude) const + template + VTKM_EXEC void operator()(const vtkm::Vec& inVector, T& outMagnitude) const { outMagnitude = vtkm::Magnitude(inVector); } }; -} -} // namespace vtkm::worklet + +} // namespace hello_worklet_example namespace vtkm { namespace filter { -class HelloField : public vtkm::filter::FilterField +class HelloField : public vtkm::filter::NewFilterField { public: - // Specify that this filter operates on 3-vectors - using SupportedTypes = vtkm::TypeListFieldVec3; - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet, - const FieldType& inField, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase) + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet) { - VTKM_IS_ARRAY_HANDLE(FieldType); + // Input field + vtkm::cont::Field inField = this->GetFieldFromDataSet(inDataSet); - //construct our output - vtkm::cont::ArrayHandle outField; + // Holder for output + vtkm::cont::UnknownArrayHandle outArray; - //construct our invoker to launch worklets - vtkm::worklet::HelloWorklet mag; - this->Invoke(mag, inField, outField); //launch mag worklets + hello_worklet_example::HelloWorklet mag; + auto resolveType = [&](const auto& inputArray) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType::ComponentType; + vtkm::cont::ArrayHandle result; + this->Invoke(mag, inputArray, result); + outArray = result; + }; - //construct output field information - if (this->GetOutputFieldName().empty()) + this->CastAndCallVecField<3>(inField, resolveType); + + std::string outFieldName = this->GetOutputFieldName(); + if (outFieldName.empty()) { - this->SetOutputFieldName(fieldMetadata.GetName() + "_magnitude"); + outFieldName = inField.GetName() + "_magnitude"; } - //return the result, which is the input data with the computed field added to it - return vtkm::filter::CreateResult( - inDataSet, outField, this->GetOutputFieldName(), fieldMetadata); + return this->CreateResultField(inDataSet, outFieldName, inField.GetAssociation(), outArray); } }; } diff --git a/examples/histogram/CMakeLists.txt b/examples/histogram/CMakeLists.txt index 7eec3e52f..0667bf146 100644 --- a/examples/histogram/CMakeLists.txt +++ b/examples/histogram/CMakeLists.txt @@ -13,9 +13,9 @@ project(Histogram CXX) #Find the VTK-m package find_package(VTKm REQUIRED QUIET) if (VTKm_ENABLE_MPI) - add_executable(Histogram Histogram.cxx HistogramMPI.h HistogramMPI.hxx) + add_executable(Histogram Histogram.cxx HistogramMPI.h HistogramMPI.cxx) target_link_libraries(Histogram PRIVATE vtkm_filter MPI::MPI_CXX) vtkm_add_target_information(Histogram DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS - DEVICE_SOURCES Histogram.cxx) + DEVICE_SOURCES HistogramMPI.cxx) endif() diff --git a/examples/histogram/Histogram.cxx b/examples/histogram/Histogram.cxx index 328f22dee..461f9c69d 100644 --- a/examples/histogram/Histogram.cxx +++ b/examples/histogram/Histogram.cxx @@ -64,9 +64,8 @@ int main(int argc, char* argv[]) // tell VTK-m the communicator to use. vtkm::cont::EnvironmentTracker::SetCommunicator(world); - int rank, size; - MPI_Comm_rank(vtkmdiy::mpi::mpi_cast(world.handle()), &rank); - MPI_Comm_size(vtkmdiy::mpi::mpi_cast(world.handle()), &size); + int rank = world.rank(); + int size = world.size(); if (argc != 2) { diff --git a/examples/histogram/HistogramMPI.hxx b/examples/histogram/HistogramMPI.cxx similarity index 75% rename from examples/histogram/HistogramMPI.hxx rename to examples/histogram/HistogramMPI.cxx index fc355d43e..cb2a334c8 100644 --- a/examples/histogram/HistogramMPI.hxx +++ b/examples/histogram/HistogramMPI.cxx @@ -8,6 +8,8 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +#include "HistogramMPI.h" + #include #include @@ -102,53 +104,69 @@ public: } // namespace detail //----------------------------------------------------------------------------- -inline VTKM_CONT HistogramMPI::HistogramMPI() - : NumberOfBins(10) - , BinDelta(0) - , ComputedRange() - , Range() +VTKM_CONT vtkm::cont::DataSet HistogramMPI::DoExecute(const vtkm::cont::DataSet& input) { - this->SetOutputFieldName("histogram"); -} + const auto& fieldArray = this->GetFieldFromDataSet(input).GetData(); -//----------------------------------------------------------------------------- -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&) -{ - vtkm::cont::ArrayHandle binArray; - T delta; - - vtkm::worklet::FieldHistogram worklet; - if (this->ComputedRange.IsNonEmpty()) + if (!this->InExecutePartitions) { - worklet.Run(field, + // Handle initialization that would be done in PreExecute if the data set had partitions. + if (this->Range.IsNonEmpty()) + { + this->ComputedRange = this->Range; + } + else + { + auto handle = vtkm::cont::FieldRangeGlobalCompute( + input, this->GetActiveFieldName(), this->GetActiveFieldAssociation()); + if (handle.GetNumberOfValues() != 1) + { + throw vtkm::cont::ErrorFilterExecution("expecting scalar field."); + } + this->ComputedRange = handle.ReadPortal().Get(0); + } + } + + vtkm::cont::ArrayHandle binArray; + + auto resolveType = [&](const auto& concrete) { + using T = typename std::decay_t::ValueType; + T delta; + + vtkm::worklet::FieldHistogram worklet; + worklet.Run(concrete, this->NumberOfBins, static_cast(this->ComputedRange.Min), static_cast(this->ComputedRange.Max), delta, binArray); - } - else - { - worklet.Run(field, this->NumberOfBins, this->ComputedRange, delta, binArray); - } - this->BinDelta = static_cast(delta); + this->BinDelta = static_cast(delta); + }; + + fieldArray + .CastAndCallForTypesWithFloatFallback( + resolveType); + vtkm::cont::DataSet output; - vtkm::cont::Field rfield( - this->GetOutputFieldName(), vtkm::cont::Field::Association::WholeMesh, binArray); - output.AddField(rfield); + output.AddField( + { this->GetOutputFieldName(), vtkm::cont::Field::Association::WholeDataSet, binArray }); + + // The output is a "summary" of the input, no need to map fields return output; } +VTKM_CONT vtkm::cont::PartitionedDataSet HistogramMPI::DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& input) +{ + this->PreExecute(input); + auto result = this->NewFilter::DoExecutePartitions(input); + this->PostExecute(input, result); + return result; +} + //----------------------------------------------------------------------------- -template -inline VTKM_CONT void HistogramMPI::PreExecute(const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase&) +inline VTKM_CONT void HistogramMPI::PreExecute(const vtkm::cont::PartitionedDataSet& input) { if (this->Range.IsNonEmpty()) { @@ -167,10 +185,8 @@ inline VTKM_CONT void HistogramMPI::PreExecute(const vtkm::cont::PartitionedData } //----------------------------------------------------------------------------- -template inline VTKM_CONT void HistogramMPI::PostExecute(const vtkm::cont::PartitionedDataSet&, - vtkm::cont::PartitionedDataSet& result, - const vtkm::filter::PolicyBase&) + vtkm::cont::PartitionedDataSet& result) { // iterate and compute HistogramMPI for each local block. detail::DistributedHistogram helper(result.GetNumberOfPartitions()); @@ -182,7 +198,7 @@ inline VTKM_CONT void HistogramMPI::PostExecute(const vtkm::cont::PartitionedDat vtkm::cont::DataSet output; vtkm::cont::Field rfield(this->GetOutputFieldName(), - vtkm::cont::Field::Association::WholeMesh, + vtkm::cont::Field::Association::WholeDataSet, helper.ReduceAll(this->NumberOfBins)); output.AddField(rfield); diff --git a/examples/histogram/HistogramMPI.h b/examples/histogram/HistogramMPI.h index a63275c07..1205a982b 100644 --- a/examples/histogram/HistogramMPI.h +++ b/examples/histogram/HistogramMPI.h @@ -10,7 +10,7 @@ #ifndef vtk_m_examples_histogram_HistogramMPI_h #define vtk_m_examples_histogram_HistogramMPI_h -#include +#include namespace example { @@ -19,7 +19,7 @@ namespace example /// /// Construct a HistogramMPI with a default of 10 bins. /// -class HistogramMPI : public vtkm::filter::FilterField +class HistogramMPI : public vtkm::filter::NewFilterField { public: //currently the HistogramMPI filter only works on scalar data. @@ -29,7 +29,7 @@ public: //Construct a HistogramMPI with a default of 10 bins VTKM_CONT - HistogramMPI(); + HistogramMPI() { this->SetOutputFieldName("histogram"); } VTKM_CONT void SetNumberOfBins(vtkm::Id count) { this->NumberOfBins = count; } @@ -58,34 +58,27 @@ public: VTKM_CONT vtkm::Range GetComputedRange() const { return this->ComputedRange; } - 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); +protected: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + VTKM_CONT vtkm::cont::PartitionedDataSet DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& input) override; ///@{ /// when operating on vtkm::cont::PartitionedDataSet, we /// want to do processing across ranks as well. Just adding pre/post handles /// for the same does the trick. - template - VTKM_CONT void PreExecute(const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase& policy); - - template + VTKM_CONT void PreExecute(const vtkm::cont::PartitionedDataSet& input); VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input, - vtkm::cont::PartitionedDataSet& output, - const vtkm::filter::PolicyBase&); + vtkm::cont::PartitionedDataSet& output); ///@} private: - vtkm::Id NumberOfBins; - vtkm::Float64 BinDelta; + vtkm::Id NumberOfBins = 10; + vtkm::Float64 BinDelta = 0; vtkm::Range ComputedRange; vtkm::Range Range; + bool InExecutePartitions = false; }; } // namespace example -#include "HistogramMPI.hxx" - #endif // vtk_m_filter_Histogram_h diff --git a/examples/multi_backend/MultiDeviceGradient.cxx b/examples/multi_backend/MultiDeviceGradient.cxx index 04bac8ea1..d577b83e9 100644 --- a/examples/multi_backend/MultiDeviceGradient.cxx +++ b/examples/multi_backend/MultiDeviceGradient.cxx @@ -8,11 +8,251 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#define vtk_m_examples_multibackend_MultiDeviceGradient_cxx - #include "MultiDeviceGradient.h" -#include "MultiDeviceGradient.hxx" -template vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForExecution< - vtkm::filter::PolicyDefault>(const vtkm::cont::PartitionedDataSet&, - const vtkm::filter::PolicyBase&); +#include +#include +#include +#include +#include +#include + +#include + +namespace +{ + +void process_partition_tbb(RuntimeTaskQueue& queue) +{ + //Step 1. Set the device adapter to this thread to TBB. + //This makes sure that any vtkm::filters used by our + //task operate only on TBB. The "global" thread tracker + //is actually thread-local, so we can use that. + // + vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagTBB{}); + + while (queue.hasTasks()) + { + //Step 2. Get the task to run on TBB + auto task = queue.pop(); + + //Step 3. Run the task on TBB. We check the validity + //of the task since we could be given an empty task + //when the queue is empty and we are shutting down + if (task != nullptr) + { + task(); + } + + //Step 4. Notify the queue that we finished processing this task + queue.completedTask(); + std::cout << "finished a partition on tbb (" << std::this_thread::get_id() << ")" << std::endl; + } +} + +void process_partition_openMP(RuntimeTaskQueue& queue) +{ + //Step 1. Set the device adapter to this thread to openMP. + //This makes sure that any vtkm::filters used by our + //task operate only on openMP. The "global" thread tracker + //is actually thread-local, so we can use that. + // + vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{}); + + while (queue.hasTasks()) + { + //Step 2. Get the task to run on openMP + auto task = queue.pop(); + + //Step 3. Run the task on openMP. We check the validity + //of the task since we could be given an empty task + //when the queue is empty and we are shutting down + if (task != nullptr) + { + task(); + } + + //Step 4. Notify the queue that we finished processing this task + queue.completedTask(); + std::cout << "finished a partition on openMP (" << std::this_thread::get_id() << ")" + << std::endl; + } +} + +void process_partition_cuda(RuntimeTaskQueue& queue, int gpuId) +{ + //Step 1. Set the device adapter to this thread to cuda. + //This makes sure that any vtkm::filters used by our + //task operate only on cuda. The "global" thread tracker + //is actually thread-local, so we can use that. + // + vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagCuda{}); + (void)gpuId; + + while (queue.hasTasks()) + { + //Step 2. Get the task to run on cuda + auto task = queue.pop(); + + //Step 3. Run the task on cuda. We check the validity + //of the task since we could be given an empty task + //when the queue is empty and we are shutting down + if (task != nullptr) + { + task(); + } + + //Step 4. Notify the queue that we finished processing this task + queue.completedTask(); + std::cout << "finished a partition on cuda (" << std::this_thread::get_id() << ")" << std::endl; + } +} + +} //namespace + +//----------------------------------------------------------------------------- +VTKM_CONT MultiDeviceGradient::MultiDeviceGradient() + : ComputePointGradient(false) + , Queue() + , Workers() +{ + //Step 1. Determine the number of workers we want + auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); + const bool runOnCuda = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagCuda{}); + const bool runOnOpenMP = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagOpenMP{}); + const bool runOnTbb = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagTBB{}); + + //Note currently the virtual implementation has some issues + //In a multi-threaded environment only cuda can be used or + //all SMP backends ( Serial, TBB, OpenMP ). + //Once this issue is resolved we can enable CUDA + TBB in + //this example + + //Step 2. Launch workers that will use cuda (if enabled). + //The threads share a queue object so we need to explicitly pass it + //by reference (the std::ref call) + if (runOnCuda) + { + std::cout << "adding cuda workers" << std::endl; + try + { + vtkm::Id gpu_count = 0; + vtkm::cont::RuntimeDeviceInformation{} + .GetRuntimeConfiguration(vtkm::cont::DeviceAdapterTagCuda{}) + .GetMaxDevices(gpu_count); + for (int i = 0; i < gpu_count; ++i) + { + //The number of workers per GPU is purely arbitrary currently, + //but in general we want multiple of them so we can overlap compute + //and transfer + this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); + this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); + this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); + this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); + } + } + catch (const vtkm::cont::ErrorBadDevice& err) + { + VTKM_LOG_S(vtkm::cont::LogLevel::Error, + "Error getting CudaDeviceCount: " << err.GetMessage()); + } + } + //Step 3. Launch a worker that will use openMP (if enabled). + //The threads share a queue object so we need to explicitly pass it + //by reference (the std::ref call) + else if (runOnOpenMP) + { + std::cout << "adding a openMP worker" << std::endl; + this->Workers.emplace_back(std::bind(process_partition_openMP, std::ref(this->Queue))); + } + //Step 4. Launch a worker that will use tbb (if enabled). + //The threads share a queue object so we need to explicitly pass it + //by reference (the std::ref call) + else if (runOnTbb) + { + std::cout << "adding a tbb worker" << std::endl; + this->Workers.emplace_back(std::bind(process_partition_tbb, std::ref(this->Queue))); + } +} + +//----------------------------------------------------------------------------- +VTKM_CONT MultiDeviceGradient::~MultiDeviceGradient() +{ + this->Queue.shutdown(); + + //shutdown all workers + for (auto&& thread : this->Workers) + { + thread.join(); + } +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::PartitionedDataSet MultiDeviceGradient::DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& pds) +{ + //Step 1. Say that we have no more to submit for this PartitionedDataSet + //This is needed to happen for each execute as we want to support + //the same filter being used for multiple inputs + this->Queue.reset(); + + //Step 2. Construct the PartitionedDataSet we are going to fill. The size + //signature to PartitionedDataSet just reserves size + vtkm::cont::PartitionedDataSet output; + output.AppendPartitions( + std::vector(static_cast(pds.GetNumberOfPartitions()))); + vtkm::cont::PartitionedDataSet* outPtr = &output; + + + //Step 3. Construct the filter we want to run on each partition + vtkm::filter::vector_analysis::Gradient gradient; + gradient.SetComputePointGradient(this->GetComputePointGradient()); + gradient.SetActiveField(this->GetActiveFieldName()); + + //Step 3b. Post 1 partition up as work and block until it is + //complete. This is needed as currently constructing the virtual + //Point Coordinates is not thread safe. + auto partition = pds.cbegin(); + { + vtkm::cont::DataSet input = *partition; + this->Queue.push( //build a lambda that is the work to do + [=]() { + vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient; + + vtkm::cont::DataSet result = perThreadGrad.Execute(input); + outPtr->ReplacePartition(0, result); + }); + this->Queue.waitForAllTasksToComplete(); + partition++; + } + + vtkm::Id index = 1; + for (; partition != pds.cend(); ++partition) + { + vtkm::cont::DataSet input = *partition; + //Step 4. For each input partition construct a lambda + //and add it to the queue for workers to take. This + //will allows us to have multiple works execute in a non + //blocking manner + this->Queue.push( //build a lambda that is the work to do + [=]() { + vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient; + + vtkm::cont::DataSet result = perThreadGrad.Execute(input); + outPtr->ReplacePartition(index, result); + }); + index++; + } + + // Step 5. Wait on all workers to finish + this->Queue.waitForAllTasksToComplete(); + + return output; +} + +VTKM_CONT vtkm::cont::DataSet MultiDeviceGradient::DoExecute(const vtkm::cont::DataSet& inData) +{ + vtkm::cont::PartitionedDataSet outData = this->Execute(vtkm::cont::PartitionedDataSet(inData)); + VTKM_ASSERT(outData.GetNumberOfPartitions() == 1); + return outData.GetPartition(0); +} diff --git a/examples/multi_backend/MultiDeviceGradient.h b/examples/multi_backend/MultiDeviceGradient.h index 229682e7a..30d1a026b 100644 --- a/examples/multi_backend/MultiDeviceGradient.h +++ b/examples/multi_backend/MultiDeviceGradient.h @@ -10,7 +10,7 @@ #ifndef vtk_m_examples_multibackend_MultiDeviceGradient_h #define vtk_m_examples_multibackend_MultiDeviceGradient_h -#include +#include #include "TaskQueue.h" @@ -22,11 +22,9 @@ using RuntimeTaskQueue = TaskQueue>; /// /// The Policy used with MultiDeviceGradient must include the TBB and CUDA /// backends. -class MultiDeviceGradient : public vtkm::filter::FilterField +class MultiDeviceGradient : public vtkm::filter::NewFilterField { public: - using SupportedTypes = vtkm::List; - //Construct a MultiDeviceGradient and worker pool VTKM_CONT MultiDeviceGradient(); @@ -43,10 +41,12 @@ public: /// Will submit each block to a work queue that the threads will /// pull work from - template - VTKM_CONT vtkm::cont::PartitionedDataSet PrepareForExecution( - const vtkm::cont::PartitionedDataSet&, - const vtkm::filter::PolicyBase&); + VTKM_CONT vtkm::cont::PartitionedDataSet DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& inData) override; + + // All filters must override this method. Our implementation will just wrap this in + // a partitioned data set. + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData) override; private: bool ComputePointGradient; @@ -54,10 +54,4 @@ private: std::vector Workers; }; -#ifndef vtk_m_examples_multibackend_MultiDeviceGradient_cxx -extern template vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForExecution< - vtkm::filter::PolicyDefault>(const vtkm::cont::PartitionedDataSet&, - const vtkm::filter::PolicyBase&); -#endif - #endif diff --git a/examples/multi_backend/MultiDeviceGradient.hxx b/examples/multi_backend/MultiDeviceGradient.hxx deleted file mode 100644 index 2bbd87b26..000000000 --- a/examples/multi_backend/MultiDeviceGradient.hxx +++ /dev/null @@ -1,251 +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. -//============================================================================ - -#include -#include -#include -#include -#include -#include - -#include - -namespace -{ - -void process_partition_tbb(RuntimeTaskQueue& queue) -{ - //Step 1. Set the device adapter to this thread to TBB. - //This makes sure that any vtkm::filters used by our - //task operate only on TBB. The "global" thread tracker - //is actually thread-local, so we can use that. - // - vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagTBB{}); - - while (queue.hasTasks()) - { - //Step 2. Get the task to run on TBB - auto task = queue.pop(); - - //Step 3. Run the task on TBB. We check the validity - //of the task since we could be given an empty task - //when the queue is empty and we are shutting down - if (task != nullptr) - { - task(); - } - - //Step 4. Notify the queue that we finished processing this task - queue.completedTask(); - std::cout << "finished a partition on tbb (" << std::this_thread::get_id() << ")" << std::endl; - } -} - -void process_partition_openMP(RuntimeTaskQueue& queue) -{ - //Step 1. Set the device adapter to this thread to openMP. - //This makes sure that any vtkm::filters used by our - //task operate only on openMP. The "global" thread tracker - //is actually thread-local, so we can use that. - // - vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{}); - - while (queue.hasTasks()) - { - //Step 2. Get the task to run on openMP - auto task = queue.pop(); - - //Step 3. Run the task on openMP. We check the validity - //of the task since we could be given an empty task - //when the queue is empty and we are shutting down - if (task != nullptr) - { - task(); - } - - //Step 4. Notify the queue that we finished processing this task - queue.completedTask(); - std::cout << "finished a partition on openMP (" << std::this_thread::get_id() << ")" - << std::endl; - } -} - -void process_partition_cuda(RuntimeTaskQueue& queue, int gpuId) -{ - //Step 1. Set the device adapter to this thread to cuda. - //This makes sure that any vtkm::filters used by our - //task operate only on cuda. The "global" thread tracker - //is actually thread-local, so we can use that. - // - vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(vtkm::cont::DeviceAdapterTagCuda{}); - (void)gpuId; - - while (queue.hasTasks()) - { - //Step 2. Get the task to run on cuda - auto task = queue.pop(); - - //Step 3. Run the task on cuda. We check the validity - //of the task since we could be given an empty task - //when the queue is empty and we are shutting down - if (task != nullptr) - { - task(); - } - - //Step 4. Notify the queue that we finished processing this task - queue.completedTask(); - std::cout << "finished a partition on cuda (" << std::this_thread::get_id() << ")" << std::endl; - } -} - -} //namespace - -//----------------------------------------------------------------------------- -VTKM_CONT MultiDeviceGradient::MultiDeviceGradient() - : ComputePointGradient(false) - , Queue() - , Workers() -{ - //Step 1. Determine the number of workers we want - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - const bool runOnCuda = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagCuda{}); - const bool runOnOpenMP = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagOpenMP{}); - const bool runOnTbb = tracker.CanRunOn(vtkm::cont::DeviceAdapterTagTBB{}); - - //Note currently the virtual implementation has some issues - //In a multi-threaded environment only cuda can be used or - //all SMP backends ( Serial, TBB, OpenMP ). - //Once this issue is resolved we can enable CUDA + TBB in - //this example - - //Step 2. Launch workers that will use cuda (if enabled). - //The threads share a queue object so we need to explicitly pass it - //by reference (the std::ref call) - if (runOnCuda) - { - std::cout << "adding cuda workers" << std::endl; - try - { - vtkm::Id gpu_count = 0; - vtkm::cont::RuntimeDeviceInformation{} - .GetRuntimeConfiguration(vtkm::cont::DeviceAdapterTagCuda{}) - .GetMaxDevices(gpu_count); - for (int i = 0; i < gpu_count; ++i) - { - //The number of workers per GPU is purely arbitrary currently, - //but in general we want multiple of them so we can overlap compute - //and transfer - this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); - this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); - this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); - this->Workers.emplace_back(std::bind(process_partition_cuda, std::ref(this->Queue), i)); - } - } - catch (const vtkm::cont::ErrorBadDevice& err) - { - VTKM_LOG_S(vtkm::cont::LogLevel::Error, - "Error getting CudaDeviceCount: " << err.GetMessage()); - } - } - //Step 3. Launch a worker that will use openMP (if enabled). - //The threads share a queue object so we need to explicitly pass it - //by reference (the std::ref call) - else if (runOnOpenMP) - { - std::cout << "adding a openMP worker" << std::endl; - this->Workers.emplace_back(std::bind(process_partition_openMP, std::ref(this->Queue))); - } - //Step 4. Launch a worker that will use tbb (if enabled). - //The threads share a queue object so we need to explicitly pass it - //by reference (the std::ref call) - else if (runOnTbb) - { - std::cout << "adding a tbb worker" << std::endl; - this->Workers.emplace_back(std::bind(process_partition_tbb, std::ref(this->Queue))); - } -} - -//----------------------------------------------------------------------------- -VTKM_CONT MultiDeviceGradient::~MultiDeviceGradient() -{ - this->Queue.shutdown(); - - //shutdown all workers - for (auto&& thread : this->Workers) - { - thread.join(); - } -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForExecution( - const vtkm::cont::PartitionedDataSet& pds, - const vtkm::filter::PolicyBase&) -{ - //Step 1. Say that we have no more to submit for this PartitionedDataSet - //This is needed to happen for each execute as we want to support - //the same filter being used for multiple inputs - this->Queue.reset(); - - //Step 2. Construct the PartitionedDataSet we are going to fill. The size - //signature to PartitionedDataSet just reserves size - vtkm::cont::PartitionedDataSet output; - output.AppendPartitions( - std::vector(static_cast(pds.GetNumberOfPartitions()))); - vtkm::cont::PartitionedDataSet* outPtr = &output; - - - //Step 3. Construct the filter we want to run on each partition - vtkm::filter::vector_analysis::Gradient gradient; - gradient.SetComputePointGradient(this->GetComputePointGradient()); - gradient.SetActiveField(this->GetActiveFieldName()); - - //Step 3b. Post 1 partition up as work and block until it is - //complete. This is needed as currently constructing the virtual - //Point Coordinates is not thread safe. - auto partition = pds.cbegin(); - { - vtkm::cont::DataSet input = *partition; - this->Queue.push( //build a lambda that is the work to do - [=]() { - vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient; - - vtkm::cont::DataSet result = perThreadGrad.Execute(input); - outPtr->ReplacePartition(0, result); - }); - this->Queue.waitForAllTasksToComplete(); - partition++; - } - - vtkm::Id index = 1; - for (; partition != pds.cend(); ++partition) - { - vtkm::cont::DataSet input = *partition; - //Step 4. For each input partition construct a lambda - //and add it to the queue for workers to take. This - //will allows us to have multiple works execute in a non - //blocking manner - this->Queue.push( //build a lambda that is the work to do - [=]() { - vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient; - - vtkm::cont::DataSet result = perThreadGrad.Execute(input); - outPtr->ReplacePartition(index, result); - }); - index++; - } - - // Step 5. Wait on all workers to finish - this->Queue.waitForAllTasksToComplete(); - - return output; -} diff --git a/examples/redistribute_points/CMakeLists.txt b/examples/redistribute_points/CMakeLists.txt index 59948d79f..7b6561077 100644 --- a/examples/redistribute_points/CMakeLists.txt +++ b/examples/redistribute_points/CMakeLists.txt @@ -12,7 +12,7 @@ project(RedistributePoints CXX) #Find the VTK-m package find_package(VTKm REQUIRED QUIET) -add_executable(RedistributePoints RedistributePoints.cxx RedistributePoints.h) +add_executable(RedistributePoints RedistributePoints.cxx RedistributePoints.h main.cxx) target_link_libraries(RedistributePoints PRIVATE vtkm_filter vtkm_io) vtkm_add_target_information(RedistributePoints DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS diff --git a/examples/redistribute_points/RedistributePoints.cxx b/examples/redistribute_points/RedistributePoints.cxx index ec94f1de7..33e6f3084 100644 --- a/examples/redistribute_points/RedistributePoints.cxx +++ b/examples/redistribute_points/RedistributePoints.cxx @@ -8,53 +8,228 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include -#include +#include "RedistributePoints.h" -#include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include "RedistributePoints.h" - -#include -using std::cout; -using std::endl; - -int main(int argc, char* argv[]) +namespace example { - // Process vtk-m general args - auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice; - auto config = vtkm::cont::Initialize(argc, argv, opts); - vtkmdiy::mpi::environment env(argc, argv); - vtkmdiy::mpi::communicator comm; - vtkm::cont::EnvironmentTracker::SetCommunicator(comm); +namespace internal +{ - if (argc != 3) - { - cout << "Usage: " << endl - << "$ " << argv[0] << " [options] " << endl; - cout << config.Usage << endl; - return EXIT_FAILURE; - } - - vtkm::cont::DataSet input; - if (comm.rank() == 0) - { - vtkm::io::VTKDataSetReader reader(argv[1]); - input = reader.ReadDataSet(); - } - - example::RedistributePoints redistributor; - auto output = redistributor.Execute(input); - - std::ostringstream str; - str << argv[2] << "-" << comm.rank() << ".vtk"; - - vtkm::io::VTKDataSetWriter writer(str.str()); - writer.WriteDataSet(output); - return EXIT_SUCCESS; +static vtkmdiy::ContinuousBounds convert(const vtkm::Bounds& bds) +{ + vtkmdiy::ContinuousBounds result(3); + result.min[0] = static_cast(bds.X.Min); + result.min[1] = static_cast(bds.Y.Min); + result.min[2] = static_cast(bds.Z.Min); + result.max[0] = static_cast(bds.X.Max); + result.max[1] = static_cast(bds.Y.Max); + result.max[2] = static_cast(bds.Z.Max); + return result; } + + +template +class Redistributor +{ + const vtkmdiy::RegularDecomposer& Decomposer; + const FilterType& Filter; + + vtkm::cont::DataSet Extract(const vtkm::cont::DataSet& input, + const vtkmdiy::ContinuousBounds& bds) const + { + // extract points + vtkm::Box box(bds.min[0], bds.max[0], bds.min[1], bds.max[1], bds.min[2], bds.max[2]); + + vtkm::filter::entity_extraction::ExtractPoints extractor; + extractor.SetCompactPoints(true); + extractor.SetImplicitFunction(box); + return extractor.Execute(input); + } + + class ConcatenateFields + { + public: + explicit ConcatenateFields(vtkm::Id totalSize) + : TotalSize(totalSize) + , CurrentIdx(0) + { + } + + void Append(const vtkm::cont::Field& field) + { + VTKM_ASSERT(this->CurrentIdx + field.GetNumberOfValues() <= this->TotalSize); + + if (this->Field.GetNumberOfValues() == 0) + { + // Copy metadata + this->Field = field; + // Reset array + this->Field.SetData(field.GetData().NewInstanceBasic()); + // Preallocate array + this->Field.GetData().Allocate(this->TotalSize); + } + else + { + VTKM_ASSERT(this->Field.GetName() == field.GetName() && + this->Field.GetAssociation() == field.GetAssociation()); + } + + field.GetData().CastAndCallForTypes( + Appender{}, this->Field, this->CurrentIdx); + this->CurrentIdx += field.GetNumberOfValues(); + } + + const vtkm::cont::Field& GetResult() const { return this->Field; } + + private: + struct Appender + { + template + void operator()(const vtkm::cont::ArrayHandle& data, + vtkm::cont::Field& field, + vtkm::Id currentIdx) const + { + vtkm::cont::ArrayHandle farray = + field.GetData().template AsArrayHandle>(); + vtkm::cont::Algorithm::CopySubRange(data, 0, data.GetNumberOfValues(), farray, currentIdx); + } + }; + + vtkm::Id TotalSize; + vtkm::Id CurrentIdx; + vtkm::cont::Field Field; + }; + +public: + Redistributor(const vtkmdiy::RegularDecomposer& decomposer, + const FilterType& filter) + : Decomposer(decomposer) + , Filter(filter) + { + } + + void operator()(vtkm::cont::DataSet* block, const vtkmdiy::ReduceProxy& rp) const + { + if (rp.in_link().size() == 0) + { + if (block->GetNumberOfCoordinateSystems() > 0) + { + for (int cc = 0; cc < rp.out_link().size(); ++cc) + { + auto target = rp.out_link().target(cc); + // let's get the bounding box for the target block. + vtkmdiy::ContinuousBounds bds(3); + this->Decomposer.fill_bounds(bds, target.gid); + + auto extractedDS = this->Extract(*block, bds); + // TODO: Need a better way to serialize DataSet. See issue #725. + rp.enqueue(target, vtkm::cont::SerializableDataSet<>(extractedDS)); + } + // clear our dataset. + *block = vtkm::cont::DataSet(); + } + } + else + { + vtkm::Id numValues = 0; + std::vector receives; + for (int cc = 0; cc < rp.in_link().size(); ++cc) + { + auto target = rp.in_link().target(cc); + if (rp.incoming(target.gid).size() > 0) + { + // TODO: Need a better way to serialize DataSet. See issue #725. + vtkm::cont::SerializableDataSet<> sds; + rp.dequeue(target.gid, sds); + receives.push_back(sds.DataSet); + numValues += receives.back().GetCoordinateSystem(0).GetNumberOfPoints(); + } + } + + *block = vtkm::cont::DataSet(); + if (receives.size() == 1) + { + *block = receives[0]; + } + else if (receives.size() > 1) + { + ConcatenateFields concatCoords(numValues); + for (const auto& ds : receives) + { + concatCoords.Append(ds.GetCoordinateSystem(0)); + } + block->AddCoordinateSystem(vtkm::cont::CoordinateSystem( + concatCoords.GetResult().GetName(), concatCoords.GetResult().GetData())); + + for (vtkm::IdComponent i = 0; i < receives[0].GetNumberOfFields(); ++i) + { + ConcatenateFields concatField(numValues); + for (const auto& ds : receives) + { + concatField.Append(ds.GetField(i)); + } + block->AddField(concatField.GetResult()); + } + } + } + } +}; + +} // namespace example::internal + + +VTKM_CONT vtkm::cont::PartitionedDataSet RedistributePoints::DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& input) +{ + auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator(); + + // let's first get the global bounds of the domain + vtkm::Bounds gbounds = vtkm::cont::BoundsGlobalCompute(input); + + vtkm::cont::AssignerPartitionedDataSet assigner(input.GetNumberOfPartitions()); + vtkmdiy::RegularDecomposer decomposer( + /*dim*/ 3, internal::convert(gbounds), assigner.nblocks()); + + vtkmdiy::Master master( + comm, + /*threads*/ 1, + /*limit*/ -1, + []() -> void* { return new vtkm::cont::DataSet(); }, + [](void* ptr) { delete static_cast(ptr); }); + decomposer.decompose(comm.rank(), assigner, master); + + assert(static_cast(master.size()) == input.GetNumberOfPartitions()); + // let's populate local blocks + master.foreach ([&input](vtkm::cont::DataSet* ds, const vtkmdiy::Master::ProxyWithLink& proxy) { + auto lid = proxy.master()->lid(proxy.gid()); + *ds = input.GetPartition(lid); + }); + + internal::Redistributor redistributor(decomposer, *this); + vtkmdiy::all_to_all(master, assigner, redistributor, /*k=*/2); + + vtkm::cont::PartitionedDataSet result; + master.foreach ([&result](vtkm::cont::DataSet* ds, const vtkmdiy::Master::ProxyWithLink&) { + result.AppendPartition(*ds); + }); + + return result; +} + +vtkm::cont::DataSet RedistributePoints::DoExecute(const vtkm::cont::DataSet&) +{ + throw vtkm::cont::ErrorBadType("RedistributePoints requires PartitionedDataSet."); +} + +} // namespace example diff --git a/examples/redistribute_points/RedistributePoints.h b/examples/redistribute_points/RedistributePoints.h index 3697a7eb0..11a82b7b2 100644 --- a/examples/redistribute_points/RedistributePoints.h +++ b/examples/redistribute_points/RedistributePoints.h @@ -7,238 +7,28 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ +#ifndef example_RedistributePoints_h +#define example_RedistributePoints_h -#include -#include -#include -#include -#include -#include -#include -#include - -#include +#include namespace example { -namespace internal -{ - -static vtkmdiy::ContinuousBounds convert(const vtkm::Bounds& bds) -{ - vtkmdiy::ContinuousBounds result(3); - result.min[0] = static_cast(bds.X.Min); - result.min[1] = static_cast(bds.Y.Min); - result.min[2] = static_cast(bds.Z.Min); - result.max[0] = static_cast(bds.X.Max); - result.max[1] = static_cast(bds.Y.Max); - result.max[2] = static_cast(bds.Z.Max); - return result; -} - - -template -class Redistributor -{ - const vtkmdiy::RegularDecomposer& Decomposer; - const FilterType& Filter; - - vtkm::cont::DataSet Extract(const vtkm::cont::DataSet& input, - const vtkmdiy::ContinuousBounds& bds) const - { - // extract points - vtkm::Box box(bds.min[0], bds.max[0], bds.min[1], bds.max[1], bds.min[2], bds.max[2]); - - vtkm::filter::entity_extraction::ExtractPoints extractor; - extractor.SetCompactPoints(true); - extractor.SetImplicitFunction(box); - return extractor.Execute(input); - } - - class ConcatenateFields - { - public: - explicit ConcatenateFields(vtkm::Id totalSize) - : TotalSize(totalSize) - , CurrentIdx(0) - { - } - - void Append(const vtkm::cont::Field& field) - { - VTKM_ASSERT(this->CurrentIdx + field.GetNumberOfValues() <= this->TotalSize); - - if (this->Field.GetNumberOfValues() == 0) - { - // Copy metadata - this->Field = field; - // Reset array - this->Field.SetData(field.GetData().NewInstanceBasic()); - // Preallocate array - this->Field.GetData().Allocate(this->TotalSize); - } - else - { - VTKM_ASSERT(this->Field.GetName() == field.GetName() && - this->Field.GetAssociation() == field.GetAssociation()); - } - - field.GetData().CastAndCallForTypes( - Appender{}, this->Field, this->CurrentIdx); - this->CurrentIdx += field.GetNumberOfValues(); - } - - const vtkm::cont::Field& GetResult() const { return this->Field; } - - private: - struct Appender - { - template - void operator()(const vtkm::cont::ArrayHandle& data, - vtkm::cont::Field& field, - vtkm::Id currentIdx) const - { - vtkm::cont::ArrayHandle farray = - field.GetData().template AsArrayHandle>(); - vtkm::cont::Algorithm::CopySubRange(data, 0, data.GetNumberOfValues(), farray, currentIdx); - } - }; - - vtkm::Id TotalSize; - vtkm::Id CurrentIdx; - vtkm::cont::Field Field; - }; - -public: - Redistributor(const vtkmdiy::RegularDecomposer& decomposer, - const FilterType& filter) - : Decomposer(decomposer) - , Filter(filter) - { - } - - void operator()(vtkm::cont::DataSet* block, const vtkmdiy::ReduceProxy& rp) const - { - if (rp.in_link().size() == 0) - { - if (block->GetNumberOfCoordinateSystems() > 0) - { - for (int cc = 0; cc < rp.out_link().size(); ++cc) - { - auto target = rp.out_link().target(cc); - // let's get the bounding box for the target block. - vtkmdiy::ContinuousBounds bds(3); - this->Decomposer.fill_bounds(bds, target.gid); - - auto extractedDS = this->Extract(*block, bds); - rp.enqueue(target, vtkm::filter::MakeSerializableDataSet(extractedDS, this->Filter)); - } - // clear our dataset. - *block = vtkm::cont::DataSet(); - } - } - else - { - vtkm::Id numValues = 0; - std::vector receives; - for (int cc = 0; cc < rp.in_link().size(); ++cc) - { - auto target = rp.in_link().target(cc); - if (rp.incoming(target.gid).size() > 0) - { - auto sds = vtkm::filter::MakeSerializableDataSet(this->Filter); - rp.dequeue(target.gid, sds); - receives.push_back(sds.DataSet); - numValues += receives.back().GetCoordinateSystem(0).GetNumberOfPoints(); - } - } - - *block = vtkm::cont::DataSet(); - if (receives.size() == 1) - { - *block = receives[0]; - } - else if (receives.size() > 1) - { - ConcatenateFields concatCoords(numValues); - for (const auto& ds : receives) - { - concatCoords.Append(ds.GetCoordinateSystem(0)); - } - block->AddCoordinateSystem(vtkm::cont::CoordinateSystem( - concatCoords.GetResult().GetName(), concatCoords.GetResult().GetData())); - - for (vtkm::IdComponent i = 0; i < receives[0].GetNumberOfFields(); ++i) - { - ConcatenateFields concatField(numValues); - for (const auto& ds : receives) - { - concatField.Append(ds.GetField(i)); - } - block->AddField(concatField.GetResult()); - } - } - } - } -}; - -} // namespace example::internal - - -class RedistributePoints : public vtkm::filter::Filter +class RedistributePoints : public vtkm::filter::NewFilter { public: - VTKM_CONT - RedistributePoints() {} + VTKM_CONT RedistributePoints() {} - VTKM_CONT - ~RedistributePoints() {} + VTKM_CONT ~RedistributePoints() {} - template - VTKM_CONT vtkm::cont::PartitionedDataSet PrepareForExecution( - const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase& policy); +protected: + VTKM_CONT vtkm::cont::PartitionedDataSet DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& input) override; + + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; }; -template -inline VTKM_CONT vtkm::cont::PartitionedDataSet RedistributePoints::PrepareForExecution( - const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase&) -{ - auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator(); - - // let's first get the global bounds of the domain - vtkm::Bounds gbounds = vtkm::cont::BoundsGlobalCompute(input); - - vtkm::cont::AssignerPartitionedDataSet assigner(input.GetNumberOfPartitions()); - vtkmdiy::RegularDecomposer decomposer( - /*dim*/ 3, internal::convert(gbounds), assigner.nblocks()); - - vtkmdiy::Master master( - comm, - /*threads*/ 1, - /*limit*/ -1, - []() -> void* { return new vtkm::cont::DataSet(); }, - [](void* ptr) { delete static_cast(ptr); }); - decomposer.decompose(comm.rank(), assigner, master); - - assert(static_cast(master.size()) == input.GetNumberOfPartitions()); - // let's populate local blocks - master.foreach ([&input](vtkm::cont::DataSet* ds, const vtkmdiy::Master::ProxyWithLink& proxy) { - auto lid = proxy.master()->lid(proxy.gid()); - *ds = input.GetPartition(lid); - }); - - internal::Redistributor redistributor(decomposer, *this); - vtkmdiy::all_to_all(master, assigner, redistributor, /*k=*/2); - - vtkm::cont::PartitionedDataSet result; - master.foreach ([&result](vtkm::cont::DataSet* ds, const vtkmdiy::Master::ProxyWithLink&) { - result.AppendPartition(*ds); - }); - - return result; -} - } // namespace example + +#endif //example_RedistributePoints_h diff --git a/examples/redistribute_points/main.cxx b/examples/redistribute_points/main.cxx new file mode 100644 index 000000000..ec94f1de7 --- /dev/null +++ b/examples/redistribute_points/main.cxx @@ -0,0 +1,60 @@ +//============================================================================ +// 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. +//============================================================================ + +#include +#include +#include + +#include +#include + +#include + +#include "RedistributePoints.h" + +#include +using std::cout; +using std::endl; + +int main(int argc, char* argv[]) +{ + // Process vtk-m general args + auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice; + auto config = vtkm::cont::Initialize(argc, argv, opts); + + vtkmdiy::mpi::environment env(argc, argv); + vtkmdiy::mpi::communicator comm; + vtkm::cont::EnvironmentTracker::SetCommunicator(comm); + + if (argc != 3) + { + cout << "Usage: " << endl + << "$ " << argv[0] << " [options] " << endl; + cout << config.Usage << endl; + return EXIT_FAILURE; + } + + vtkm::cont::DataSet input; + if (comm.rank() == 0) + { + vtkm::io::VTKDataSetReader reader(argv[1]); + input = reader.ReadDataSet(); + } + + example::RedistributePoints redistributor; + auto output = redistributor.Execute(input); + + std::ostringstream str; + str << argv[2] << "-" << comm.rank() << ".vtk"; + + vtkm::io::VTKDataSetWriter writer(str.str()); + writer.WriteDataSet(output); + return EXIT_SUCCESS; +} diff --git a/tutorial/extract_edges.cxx b/tutorial/extract_edges.cxx index 35915f237..9e1a01595 100644 --- a/tutorial/extract_edges.cxx +++ b/tutorial/extract_edges.cxx @@ -20,9 +20,9 @@ #include #include -#include #include #include +#include #include #include diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 17570afdb..8fc26e60a 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -22,6 +22,7 @@ set(deprecated_headers ContourTreeUniformAugmented.h ContourTreeUniformDistributed.h CoordinateSystemTransform.h + CreateResult.h CrossProduct.h DotProduct.h Entropy.h @@ -30,6 +31,17 @@ set(deprecated_headers ExtractPoints.h ExtractStructured.h FieldToColors.h + FieldMetadata.h + FilterCell.h + FilterDataSet.h + FilterDataSet.hxx + FilterDataSetWithField.h + FilterDataSetWithField.hxx + FilterField.h + FilterField.hxx + Filter.h + Filter.hxx + FilterTraits.h GenerateIds.h GhostCellClassify.h GhostCellRemove.h @@ -55,6 +67,8 @@ set(deprecated_headers PointAverage.h PointElevation.h PointTransform.h + PolicyBase.h + PolicyDefault.h Probe.h Slice.h SplitSharpEdges.h @@ -80,30 +94,6 @@ set(deprecated_headers vtkm_declare_headers(${deprecated_headers}) -set(common_headers - CreateResult.h - FieldMetadata.h - FilterCell.h - FilterDataSet.h - FilterDataSetWithField.h - FilterField.h - Filter.h - FilterTraits.h - PolicyBase.h - PolicyDefault.h - ) - -vtkm_declare_headers(${common_headers}) - -set(common_header_template_sources - FilterDataSet.hxx - FilterDataSetWithField.hxx - FilterField.hxx - Filter.hxx - ) - -vtkm_declare_headers(${common_header_template_sources}) - set(core_headers FieldSelection.h NewFilter.h diff --git a/vtkm/filter/CreateResult.h b/vtkm/filter/CreateResult.h index 6060df28e..840609517 100644 --- a/vtkm/filter/CreateResult.h +++ b/vtkm/filter/CreateResult.h @@ -31,6 +31,7 @@ namespace filter /// Use this if you have built a \c Field object. An output /// \c DataSet will be created by adding the field to the input. +VTKM_DEPRECATED(1.9, "Use CreateResultField method in NewFilterField.") inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet, const vtkm::cont::Field& field) { @@ -45,11 +46,12 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inD /// Use this function if you have an ArrayHandle that holds the data for /// the field. You also need to specify a name for the field. template -inline VTKM_CONT vtkm::cont::DataSet CreateResult( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& fieldArray, - const std::string& fieldName, - const vtkm::filter::FieldMetadata& metaData) +VTKM_DEPRECATED(1.9, "Use CreateResultField method in NewFilterField.") +inline VTKM_CONT vtkm::cont::DataSet + CreateResult(const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::ArrayHandle& fieldArray, + const std::string& fieldName, + const vtkm::filter::FieldMetadata& metaData) { VTKM_ASSERT(!fieldName.empty()); @@ -64,6 +66,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult( /// Use this function if you have a UnknownArrayHandle that holds the data /// for the field. +VTKM_DEPRECATED(1.9, "Use CreateResultField method in NewFilterField.") inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet, const vtkm::cont::UnknownArrayHandle& fieldArray, const std::string& fieldName, @@ -83,10 +86,11 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inD /// Use this function if you want to explicit construct a Cell field and have a ArrayHandle /// that holds the data for the field. template -inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& fieldArray, - const std::string& fieldName) +VTKM_DEPRECATED(1.9, "Use CreateResultFieldCell method in NewFilterField.") +inline VTKM_CONT vtkm::cont::DataSet + CreateResultFieldCell(const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::ArrayHandle& fieldArray, + const std::string& fieldName) { VTKM_ASSERT(!fieldName.empty()); @@ -101,6 +105,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell( /// Use this function if you want to explicit construct a Cell field and have a UnknownArrayHandle /// that holds the data for the field. +VTKM_DEPRECATED(1.9, "Use CreateResultFieldCell method in NewFilterField.") inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell( const vtkm::cont::DataSet& inDataSet, const vtkm::cont::UnknownArrayHandle& fieldArray, @@ -120,10 +125,11 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell( /// Use this function if you want to explicit construct a Point field and have a ArrayHandle /// that holds the data for the field. template -inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldPoint( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& fieldArray, - const std::string& fieldName) +VTKM_DEPRECATED(1.9, "Use CreateResultFieldPoint method in NewFilterField.") +inline VTKM_CONT vtkm::cont::DataSet + CreateResultFieldPoint(const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::ArrayHandle& fieldArray, + const std::string& fieldName) { VTKM_ASSERT(!fieldName.empty()); @@ -138,6 +144,7 @@ inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldPoint( /// Use this function if you want to explicit construct a Point field and have a UnknownArrayHandle /// that holds the data for the field. +VTKM_DEPRECATED(1.9, "Use CreateResultFieldCell method in NewFilterField.") inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldPoint( const vtkm::cont::DataSet& inDataSet, const vtkm::cont::UnknownArrayHandle& fieldArray, diff --git a/vtkm/filter/FieldMetadata.h b/vtkm/filter/FieldMetadata.h index 1a41a9c25..2b6c5805a 100644 --- a/vtkm/filter/FieldMetadata.h +++ b/vtkm/filter/FieldMetadata.h @@ -19,7 +19,7 @@ namespace vtkm namespace filter { -class FieldMetadata +class VTKM_DEPRECATED(1.9) FieldMetadata { public: VTKM_CONT diff --git a/vtkm/filter/Filter.h b/vtkm/filter/Filter.h index a7eef1ebd..729fed715 100644 --- a/vtkm/filter/Filter.h +++ b/vtkm/filter/Filter.h @@ -10,6 +10,8 @@ #ifndef vtk_m_filter_Filter_h #define vtk_m_filter_Filter_h +#include + #include #include #include @@ -171,7 +173,7 @@ namespace filter /// partition. /// template -class Filter +class VTKM_DEPRECATED(1.9, "Use vtkm::filter::NewFilter.") Filter { public: VTKM_CONT diff --git a/vtkm/filter/FilterCell.h b/vtkm/filter/FilterCell.h index 0b97f08db..2025dae64 100644 --- a/vtkm/filter/FilterCell.h +++ b/vtkm/filter/FilterCell.h @@ -18,9 +18,11 @@ namespace vtkm namespace filter { +VTKM_DEPRECATED_SUPPRESS_BEGIN template using FilterCell VTKM_DEPRECATED(1.6, "Use FilterField instead of FilterCell.") = vtkm::filter::FilterField; +VTKM_DEPRECATED_SUPPRESS_END } } #endif // vtk_m_filter_CellFilter_h diff --git a/vtkm/filter/FilterDataSet.h b/vtkm/filter/FilterDataSet.h index eaabada97..cf2b3df78 100644 --- a/vtkm/filter/FilterDataSet.h +++ b/vtkm/filter/FilterDataSet.h @@ -24,8 +24,10 @@ namespace vtkm namespace filter { +VTKM_DEPRECATED_SUPPRESS_BEGIN template -class FilterDataSet : public vtkm::filter::Filter +class VTKM_DEPRECATED(1.9, "Use vtkm::filter::NewFilter.") FilterDataSet + : public vtkm::filter::Filter { public: VTKM_CONT @@ -67,6 +69,7 @@ private: friend class vtkm::filter::Filter; }; +VTKM_DEPRECATED_SUPPRESS_END } } // namespace vtkm::filter diff --git a/vtkm/filter/FilterDataSetWithField.h b/vtkm/filter/FilterDataSetWithField.h index 254a4dc62..4a93d237f 100644 --- a/vtkm/filter/FilterDataSetWithField.h +++ b/vtkm/filter/FilterDataSetWithField.h @@ -24,8 +24,10 @@ namespace vtkm namespace filter { +VTKM_DEPRECATED_SUPPRESS_BEGIN template -class FilterDataSetWithField : public vtkm::filter::Filter +class VTKM_DEPRECATED(1.9, "Use vtkm::filter::NewFilterField.") FilterDataSetWithField + : public vtkm::filter::Filter { public: VTKM_CONT @@ -109,6 +111,7 @@ private: friend class vtkm::filter::Filter; }; +VTKM_DEPRECATED_SUPPRESS_END } } // namespace vtkm::filter diff --git a/vtkm/filter/FilterField.h b/vtkm/filter/FilterField.h index 707824bdf..ffc4bc4ef 100644 --- a/vtkm/filter/FilterField.h +++ b/vtkm/filter/FilterField.h @@ -24,8 +24,10 @@ namespace vtkm namespace filter { +VTKM_DEPRECATED_SUPPRESS_BEGIN template -class FilterField : public vtkm::filter::Filter +class VTKM_DEPRECATED(1.9, "Use vtkm::filter::NewFilterField.") FilterField + : public vtkm::filter::Filter { public: VTKM_CONT @@ -112,6 +114,7 @@ private: friend class vtkm::filter::Filter; }; +VTKM_DEPRECATED_SUPPRESS_END } } // namespace vtkm::filter diff --git a/vtkm/filter/FilterTraits.h b/vtkm/filter/FilterTraits.h index f79f3d6b4..c7b85428d 100644 --- a/vtkm/filter/FilterTraits.h +++ b/vtkm/filter/FilterTraits.h @@ -11,6 +11,7 @@ #ifndef vtk_m_filter_FilterTraits_h #define vtk_m_filter_FilterTraits_h +#include #include namespace vtkm @@ -23,21 +24,21 @@ class Filter; template -struct FilterTraits +struct VTKM_DEPRECATED(1.9) FilterTraits { using InputFieldTypeList = typename Filter::SupportedTypes; using AdditionalFieldStorage = typename Filter::AdditionalFieldStorage; }; template -struct DeduceFilterFieldTypes +struct VTKM_DEPRECATED(1.9) DeduceFilterFieldTypes { using PList = typename DerivedPolicy::FieldTypeList; using TypeList = vtkm::ListIntersect; }; template -struct DeduceFilterFieldStorage +struct VTKM_DEPRECATED(1.9) DeduceFilterFieldStorage { using PList = typename DerivedPolicy::StorageList; using StorageList = vtkm::ListAppend; diff --git a/vtkm/filter/MapFieldMergeAverage.cxx b/vtkm/filter/MapFieldMergeAverage.cxx index 591b447a5..4ec13ce57 100644 --- a/vtkm/filter/MapFieldMergeAverage.cxx +++ b/vtkm/filter/MapFieldMergeAverage.cxx @@ -10,7 +10,6 @@ #include #include -#include #include namespace diff --git a/vtkm/filter/PolicyBase.h b/vtkm/filter/PolicyBase.h index 54528634e..2b3b539f6 100644 --- a/vtkm/filter/PolicyBase.h +++ b/vtkm/filter/PolicyBase.h @@ -11,6 +11,7 @@ #ifndef vtk_m_filter_PolicyBase_h #define vtk_m_filter_PolicyBase_h +#include #include #include @@ -31,7 +32,7 @@ namespace filter { template -struct PolicyBase +struct VTKM_DEPRECATED(1.9) PolicyBase { using FieldTypeList = vtkm::ListUniversal; using StorageList = VTKM_DEFAULT_STORAGE_LIST; @@ -215,13 +216,15 @@ using ArrayHandleMultiplexerForStorageList = vtkm::cont::ArrayHandleMultiplexerF /// passed to the `DoMapField` method of filters. /// template +VTKM_DEPRECATED(1.9) VTKM_CONT vtkm::cont::UncertainArrayHandle< typename std::conditional< std::is_same::value, VTKM_DEFAULT_TYPE_LIST, typename DerivedPolicy::FieldTypeList>::type, - typename DerivedPolicy::StorageList> -ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBase) + typename DerivedPolicy::StorageList> ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, + vtkm::filter::PolicyBase< + DerivedPolicy>) { // Policies are on their way out, but until they are we want to respect them. In the mean // time, respect the policy if it is defined. @@ -239,13 +242,14 @@ ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBa /// (more likely) there is a type you are going to cast it to anyway. /// template +VTKM_DEPRECATED(1.9) VTKM_CONT internal::ArrayHandleMultiplexerForStorageList< T, vtkm::ListAppend::AdditionalFieldStorage, - typename DerivedPolicy::StorageList>> -ApplyPolicyFieldOfType(const vtkm::cont::Field& field, - vtkm::filter::PolicyBase, - const FilterType&) + typename DerivedPolicy:: + StorageList>> ApplyPolicyFieldOfType(const vtkm::cont::Field& field, + vtkm::filter::PolicyBase, + const FilterType&) { using ArrayHandleMultiplexerType = internal::ArrayHandleMultiplexerForStorageList< T, @@ -261,16 +265,17 @@ ApplyPolicyFieldOfType(const vtkm::cont::Field& field, /// the active field of this filter. /// template +VTKM_DEPRECATED(1.9) VTKM_CONT vtkm::cont::UncertainArrayHandle< typename vtkm::filter::DeduceFilterFieldTypes< DerivedPolicy, typename vtkm::filter::FilterTraits::InputFieldTypeList>::TypeList, typename vtkm::filter::DeduceFilterFieldStorage< DerivedPolicy, - typename vtkm::filter::FilterTraits::AdditionalFieldStorage>::StorageList> -ApplyPolicyFieldActive(const vtkm::cont::Field& field, - vtkm::filter::PolicyBase, - vtkm::filter::FilterTraits) + typename vtkm::filter::FilterTraits::AdditionalFieldStorage>:: + StorageList> ApplyPolicyFieldActive(const vtkm::cont::Field& field, + vtkm::filter::PolicyBase, + vtkm::filter::FilterTraits) { using FilterTypes = typename vtkm::filter::FilterTraits::InputFieldTypeList; using TypeList = @@ -287,11 +292,13 @@ ApplyPolicyFieldActive(const vtkm::cont::Field& field, /// Adjusts the types of `CellSet`s to support those types specified in a policy. /// template -VTKM_CONT vtkm::cont::UncertainCellSet> -ApplyPolicyCellSet(const vtkm::cont::UnknownCellSet& cellset, - vtkm::filter::PolicyBase, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::UncertainCellSet< + vtkm::ListAppend> ApplyPolicyCellSet(const vtkm::cont::UnknownCellSet& cellset, + vtkm::filter::PolicyBase, + const vtkm::filter::Filter&) { using CellSetList = vtkm::ListAppend; @@ -315,12 +322,13 @@ VTKM_CONT vtkm::cont::UncertainCellSet A /// specified in a policy. /// template -VTKM_CONT - vtkm::cont::UncertainCellSet> - ApplyPolicyCellSetStructured(const vtkm::cont::UnknownCellSet& cellset, - vtkm::filter::PolicyBase, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::UncertainCellSet> ApplyPolicyCellSetStructured(const vtkm::cont::UnknownCellSet& cellset, + vtkm::filter::PolicyBase, + const vtkm::filter::Filter&) { using CellSetList = vtkm::ListAppend; @@ -345,12 +353,16 @@ VTKM_CONT vtkm::cont:: /// specified in a policy. /// template -VTKM_CONT vtkm::cont::UncertainCellSet< - vtkm::ListAppend> -ApplyPolicyCellSetUnstructured(const vtkm::cont::UnknownCellSet& cellset, - vtkm::filter::PolicyBase, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::UncertainCellSet> ApplyPolicyCellSetUnstructured(const vtkm::cont::UnknownCellSet& + cellset, + vtkm::filter::PolicyBase< + DerivedPolicy>, + const vtkm::filter::Filter< + DerivedFilter>&) { using CellSetList = vtkm::ListAppend; @@ -400,21 +412,27 @@ VTKM_CONT vtkm::cont::SerializableDataSet< return {}; } +// TODO: Make DataSet serializable (issue #725). template -VTKM_CONT - vtkm::cont::SerializableDataSet> - MakeSerializableDataSet(vtkm::filter::PolicyBase, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::SerializableDataSet< + typename DerivedPolicy::FieldTypeList, + vtkm::ListAppend< + typename DerivedFilter::SupportedCellSets, + typename DerivedPolicy::AllCellSetList>> MakeSerializableDataSet(vtkm::filter:: + PolicyBase, + const vtkm::filter::Filter< + DerivedFilter>&) { return {}; } template -VTKM_CONT - vtkm::cont::SerializableDataSet - MakeSerializableDataSet(const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::SerializableDataSet< + VTKM_DEFAULT_TYPE_LIST, + typename DerivedFilter::SupportedCellSets> MakeSerializableDataSet(const vtkm::filter:: + Filter&) { return {}; } @@ -433,13 +451,15 @@ VTKM_CONT vtkm::cont::SerializableDataSet< } template -VTKM_CONT - vtkm::cont::SerializableDataSet> - MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, - vtkm::filter::PolicyBase, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::SerializableDataSet< + typename DerivedPolicy::FieldTypeList, + vtkm::ListAppend< + typename DerivedFilter::SupportedCellSets, + typename DerivedPolicy:: + AllCellSetList>> MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, + vtkm::filter::PolicyBase, + const vtkm::filter::Filter&) { return vtkm::cont::SerializableDataSet -VTKM_CONT - vtkm::cont::SerializableDataSet - MakeSerializableDataSet(const vtkm::cont::DataSet& dataset, - const vtkm::filter::Filter&) +VTKM_DEPRECATED(1.9) +VTKM_CONT vtkm::cont::SerializableDataSet< + VTKM_DEFAULT_TYPE_LIST, + typename DerivedFilter::SupportedCellSets> MakeSerializableDataSet(const vtkm::cont::DataSet& + dataset, + const vtkm::filter::Filter< + DerivedFilter>&) { return vtkm::cont::SerializableDataSet{ dataset }; diff --git a/vtkm/filter/PolicyDefault.h b/vtkm/filter/PolicyDefault.h index 3a0b42cc2..985a384b5 100644 --- a/vtkm/filter/PolicyDefault.h +++ b/vtkm/filter/PolicyDefault.h @@ -18,7 +18,7 @@ namespace vtkm namespace filter { -struct PolicyDefault : vtkm::filter::PolicyBase +struct VTKM_DEPRECATED(1.9) PolicyDefault : vtkm::filter::PolicyBase { // Inherit defaults from PolicyBase }; diff --git a/vtkm/filter/internal/CMakeLists.txt b/vtkm/filter/internal/CMakeLists.txt index 5773486c2..05e3f8da9 100644 --- a/vtkm/filter/internal/CMakeLists.txt +++ b/vtkm/filter/internal/CMakeLists.txt @@ -1,3 +1,4 @@ + ##============================================================================ ## Copyright (c) Kitware, Inc. ## All rights reserved. @@ -8,9 +9,9 @@ ## PURPOSE. See the above copyright notice for more information. ##============================================================================ -set(headers +set(deprecated_headers ResolveFieldTypeAndExecute.h ResolveFieldTypeAndMap.h ) -vtkm_declare_headers(${headers}) +vtkm_declare_headers(${deprecated_headers}) diff --git a/vtkm/filter/testing/UnitTestFieldMetadata.cxx b/vtkm/filter/testing/UnitTestFieldMetadata.cxx index 54e43295b..fc5056e24 100644 --- a/vtkm/filter/testing/UnitTestFieldMetadata.cxx +++ b/vtkm/filter/testing/UnitTestFieldMetadata.cxx @@ -11,6 +11,7 @@ #include #include +VTKM_DEPRECATED_SUPPRESS_BEGIN namespace { @@ -77,3 +78,4 @@ int UnitTestFieldMetadata(int argc, char* argv[]) { return vtkm::cont::testing::Testing::Run(TestFieldMetadata, argc, argv); } +VTKM_DEPRECATED_SUPPRESS_END