mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Refactor the design of CellLocator::PrepareForExecution
The try execute functor now doesn't need to be a member of the class. This helps with the separation of concerns.
This commit is contained in:
parent
6306ca66ce
commit
30aedf287f
@ -24,7 +24,6 @@ namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
CellLocator::~CellLocator() = default;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class VTKM_CONT_EXPORT CellLocator : public vtkm::cont::ExecutionObjectBase
|
||||
public:
|
||||
virtual ~CellLocator();
|
||||
|
||||
vtkm::cont::DynamicCellSet GetCellSet() const { return this->CellSet; }
|
||||
const vtkm::cont::DynamicCellSet& GetCellSet() const { return this->CellSet; }
|
||||
|
||||
void SetCellSet(const vtkm::cont::DynamicCellSet& cellSet)
|
||||
{
|
||||
@ -48,7 +48,7 @@ public:
|
||||
this->SetModified();
|
||||
}
|
||||
|
||||
vtkm::cont::CoordinateSystem GetCoordinates() const { return this->Coords; }
|
||||
const vtkm::cont::CoordinateSystem& GetCoordinates() const { return this->Coords; }
|
||||
|
||||
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/CellLocatorBoundingIntervalHierarchy.h>
|
||||
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/Types.h>
|
||||
@ -28,7 +29,6 @@
|
||||
#include <vtkm/cont/ArrayHandlePermutation.h>
|
||||
#include <vtkm/cont/ArrayHandleReverse.h>
|
||||
#include <vtkm/cont/ArrayHandleTransform.h>
|
||||
#include <vtkm/cont/CellLocatorBoundingIntervalHierarchy.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/ErrorBadDevice.h>
|
||||
#include <vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h>
|
||||
@ -455,44 +455,59 @@ void CellLocatorBoundingIntervalHierarchy::Build()
|
||||
//std::cout << "Total time: " << totalTimer.GetElapsedTime() << "\n";
|
||||
}
|
||||
|
||||
struct CellLocatorBoundingIntervalHierarchy::MakeExecObject
|
||||
namespace
|
||||
{
|
||||
using NodeArrayHandle =
|
||||
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>;
|
||||
|
||||
template <typename CellSetType, typename DeviceAdapter>
|
||||
void operator()(const CellSetType& cellset,
|
||||
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih,
|
||||
DeviceAdapter device) const
|
||||
struct CellLocatorBIHPrepareForExecutionFunctor
|
||||
{
|
||||
using ExecObjectType =
|
||||
template <typename DeviceAdapter, typename CellSetType>
|
||||
VTKM_CONT bool operator()(
|
||||
DeviceAdapter,
|
||||
const CellSetType& cellset,
|
||||
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& bihExec,
|
||||
const vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>& nodes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& processedCellIds,
|
||||
const vtkm::cont::ArrayHandleVirtualCoordinates& coords) const
|
||||
{
|
||||
using ExecutionType =
|
||||
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
|
||||
auto execObject = new ExecObjectType(
|
||||
bih.Nodes, bih.ProcessedCellIds, cellset, bih.GetCoordinates().GetData(), device);
|
||||
bih.ExecutionObjectHandle.Reset(execObject);
|
||||
}
|
||||
};
|
||||
|
||||
struct CellLocatorBoundingIntervalHierarchy::PrepareForExecutionFunctor
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter device,
|
||||
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih) const
|
||||
{
|
||||
bih.GetCellSet().CastAndCall(MakeExecObject{}, bih, device);
|
||||
ExecutionType* execObject =
|
||||
new ExecutionType(nodes, processedCellIds, cellset, coords, DeviceAdapter());
|
||||
bihExec.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct BIHCellSetCaster
|
||||
{
|
||||
template <typename CellSet, typename... Args>
|
||||
VTKM_CONT void operator()(CellSet&& cellset,
|
||||
vtkm::cont::DeviceAdapterId device,
|
||||
Args&&... args) const
|
||||
{
|
||||
//We need to go though CastAndCall first
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
device, CellLocatorBIHPrepareForExecutionFunctor(), cellset, std::forward<Args>(args)...);
|
||||
if (!success)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("BoundingIntervalHierarchy", device);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
const vtkm::exec::CellLocator* CellLocatorBoundingIntervalHierarchy::PrepareForExecution(
|
||||
vtkm::cont::DeviceAdapterId device) const
|
||||
{
|
||||
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("BoundingIntervalHierarchy", device);
|
||||
}
|
||||
this->GetCellSet().CastAndCall(BIHCellSetCaster{},
|
||||
device,
|
||||
this->ExecutionObjectHandle,
|
||||
this->Nodes,
|
||||
this->ProcessedCellIds,
|
||||
this->GetCoordinates().GetData());
|
||||
return this->ExecutionObjectHandle.PrepareForExecution(device);
|
||||
;
|
||||
}
|
||||
|
||||
} //namespace cont
|
||||
|
@ -86,9 +86,6 @@ private:
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> ProcessedCellIds;
|
||||
|
||||
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
|
||||
|
||||
struct MakeExecObject;
|
||||
struct PrepareForExecutionFunctor;
|
||||
};
|
||||
|
||||
} // namespace cont
|
||||
|
@ -55,31 +55,39 @@ void CellLocatorRectilinearGrid::Build()
|
||||
this->RowSize = celldims[0];
|
||||
}
|
||||
|
||||
struct CellLocatorRectilinearGrid::PrepareForExecutionFunctor
|
||||
namespace
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter, const CellLocatorRectilinearGrid& contLocator) const
|
||||
struct CellLocatorRectilinearGridPrepareForExecutionFunctor
|
||||
{
|
||||
auto* execObject = new vtkm::exec::CellLocatorRectilinearGrid<DeviceAdapter>(
|
||||
contLocator.PlaneSize,
|
||||
contLocator.RowSize,
|
||||
contLocator.GetCellSet().template Cast<StructuredType>(),
|
||||
contLocator.GetCoordinates().GetData().template Cast<RectilinearType>(),
|
||||
DeviceAdapter());
|
||||
contLocator.ExecutionObjectHandle.Reset(execObject);
|
||||
|
||||
template <typename DeviceAdapter, typename... Args>
|
||||
VTKM_CONT bool operator()(DeviceAdapter,
|
||||
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& execLocator,
|
||||
Args&&... args) const
|
||||
{
|
||||
using ExecutionType = vtkm::exec::CellLocatorRectilinearGrid<DeviceAdapter>;
|
||||
ExecutionType* execObject = new ExecutionType(std::forward<Args>(args)..., DeviceAdapter());
|
||||
execLocator.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const vtkm::exec::CellLocator* CellLocatorRectilinearGrid::PrepareForExecution(
|
||||
vtkm::cont::DeviceAdapterId device) const
|
||||
{
|
||||
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
device,
|
||||
CellLocatorRectilinearGridPrepareForExecutionFunctor(),
|
||||
this->ExecutionObjectHandle,
|
||||
this->PlaneSize,
|
||||
this->RowSize,
|
||||
this->GetCellSet().template Cast<StructuredType>(),
|
||||
this->GetCoordinates().GetData().template Cast<RectilinearType>());
|
||||
if (!success)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("CellLocatorRectilinearGrid", device);
|
||||
}
|
||||
return this->ExecutionObjectHandle.PrepareForExecution(device);
|
||||
}
|
||||
}
|
||||
} // vtkm::cont
|
||||
} //namespace cont
|
||||
} //namespace vtkm
|
||||
|
@ -47,8 +47,6 @@ private:
|
||||
vtkm::Id RowSize;
|
||||
|
||||
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
|
||||
|
||||
struct PrepareForExecutionFunctor;
|
||||
};
|
||||
|
||||
} //namespace cont
|
||||
|
@ -58,32 +58,41 @@ void CellLocatorUniformGrid::Build()
|
||||
static_cast<vtkm::FloatDefault>(this->Bounds.Z.Length());
|
||||
}
|
||||
|
||||
struct CellLocatorUniformGrid::PrepareForExecutionFunctor
|
||||
namespace
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter, const CellLocatorUniformGrid& contLocator) const
|
||||
struct CellLocatorUniformGridPrepareForExecutionFunctor
|
||||
{
|
||||
auto* execObject = new vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>(
|
||||
contLocator.Bounds,
|
||||
contLocator.RangeTransform,
|
||||
contLocator.CellDims,
|
||||
contLocator.GetCellSet().template Cast<StructuredType>(),
|
||||
contLocator.GetCoordinates().GetData(),
|
||||
DeviceAdapter());
|
||||
contLocator.ExecutionObjectHandle.Reset(execObject);
|
||||
|
||||
template <typename DeviceAdapter, typename... Args>
|
||||
VTKM_CONT bool operator()(DeviceAdapter,
|
||||
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& execLocator,
|
||||
Args&&... args) const
|
||||
{
|
||||
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>;
|
||||
ExecutionType* execObject = new ExecutionType(std::forward<Args>(args)..., DeviceAdapter());
|
||||
execLocator.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const vtkm::exec::CellLocator* CellLocatorUniformGrid::PrepareForExecution(
|
||||
vtkm::cont::DeviceAdapterId device) const
|
||||
{
|
||||
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
|
||||
const bool success =
|
||||
vtkm::cont::TryExecuteOnDevice(device,
|
||||
CellLocatorUniformGridPrepareForExecutionFunctor(),
|
||||
this->ExecutionObjectHandle,
|
||||
this->Bounds,
|
||||
this->RangeTransform,
|
||||
this->CellDims,
|
||||
this->GetCellSet().template Cast<StructuredType>(),
|
||||
this->GetCoordinates().GetData());
|
||||
if (!success)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", device);
|
||||
}
|
||||
return this->ExecutionObjectHandle.PrepareForExecution(device);
|
||||
}
|
||||
}
|
||||
} // vtkm::cont
|
||||
|
||||
} //namespace cont
|
||||
} //namespace vtkm
|
||||
|
@ -47,8 +47,6 @@ private:
|
||||
vtkm::Vec<vtkm::Id, 3> CellDims;
|
||||
|
||||
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
|
||||
|
||||
struct PrepareForExecutionFunctor;
|
||||
};
|
||||
}
|
||||
} // vtkm::cont
|
||||
|
@ -207,7 +207,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
VTKM_CONT virtual const HandleType PrepareForExecutionImpl(
|
||||
VTKM_CONT virtual const HandleType& PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId device) const = 0;
|
||||
};
|
||||
|
||||
@ -231,31 +231,20 @@ public:
|
||||
throw vtkm::cont::ErrorBadType("Cell set is not 3D structured type");
|
||||
}
|
||||
|
||||
struct StructuredCellFunctor
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter,
|
||||
const vtkm::cont::StructuredCellInterpolationHelper& contInterpolator,
|
||||
HandleType& execInterpolator) const
|
||||
{
|
||||
using ExecutionType = vtkm::exec::StructuredCellInterpolationHelper;
|
||||
ExecutionType* execObject =
|
||||
new ExecutionType(contInterpolator.CellDims, contInterpolator.PointDims);
|
||||
execInterpolator.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
const HandleType& PrepareForExecutionImpl(vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success =
|
||||
vtkm::cont::TryExecuteOnDevice(deviceId, StructuredCellFunctor(), *this, this->ExecHandle);
|
||||
if (!success)
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
const bool valid = tracker.CanRunOn(deviceId);
|
||||
if (!valid)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("StructuredCellInterpolationHelper", deviceId);
|
||||
}
|
||||
|
||||
using ExecutionType = vtkm::exec::StructuredCellInterpolationHelper;
|
||||
ExecutionType* execObject = new ExecutionType(this->CellDims, this->PointDims);
|
||||
this->ExecHandle.Reset(execObject);
|
||||
|
||||
return this->ExecHandle;
|
||||
}
|
||||
|
||||
@ -310,7 +299,7 @@ public:
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImpl(
|
||||
const HandleType& PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
@ -371,7 +360,7 @@ public:
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImpl(
|
||||
const HandleType& PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
|
Loading…
Reference in New Issue
Block a user