2018-05-04 18:42:46 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-05-04 18:42:46 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_examples_multibackend_MultiDeviceGradient_h
|
|
|
|
#define vtk_m_examples_multibackend_MultiDeviceGradient_h
|
|
|
|
|
2022-12-01 20:07:56 +00:00
|
|
|
#include <vtkm/filter/FilterField.h>
|
2018-05-04 18:42:46 +00:00
|
|
|
|
|
|
|
#include "TaskQueue.h"
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
using RuntimeTaskQueue = TaskQueue<std::function<void()>>;
|
2018-05-04 18:42:46 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
/// \brief Construct a MultiDeviceGradient for a given partitioned dataset
|
2018-05-04 18:42:46 +00:00
|
|
|
///
|
|
|
|
/// The Policy used with MultiDeviceGradient must include the TBB and CUDA
|
|
|
|
/// backends.
|
2022-12-01 20:07:56 +00:00
|
|
|
class MultiDeviceGradient : public vtkm::filter::FilterField
|
2018-05-04 18:42:46 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Construct a MultiDeviceGradient and worker pool
|
|
|
|
VTKM_CONT
|
|
|
|
MultiDeviceGradient();
|
|
|
|
|
|
|
|
//Needed so that we can shut down the worker pool properly
|
|
|
|
VTKM_CONT
|
|
|
|
~MultiDeviceGradient();
|
|
|
|
|
|
|
|
/// When this flag is on (default is off), the gradient filter will provide a
|
|
|
|
/// point based gradients, which are significantly more costly since for each
|
|
|
|
/// point we need to compute the gradient of each cell that uses it.
|
|
|
|
void SetComputePointGradient(bool enable) { ComputePointGradient = enable; }
|
|
|
|
bool GetComputePointGradient() const { return ComputePointGradient; }
|
|
|
|
|
|
|
|
/// Will submit each block to a work queue that the threads will
|
|
|
|
/// pull work from
|
2022-09-26 16:23:26 +00:00
|
|
|
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;
|
2018-05-04 18:42:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool ComputePointGradient;
|
|
|
|
RuntimeTaskQueue Queue;
|
|
|
|
std::vector<std::thread> Workers;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|