Merge branch 'no-recurse-bih' of https://gitlab.kitware.com/kmorel/vtk-m into gridEval

This commit is contained in:
Dave Pugmire 2019-03-15 13:05:39 -04:00
commit 9b9742f436
11 changed files with 357 additions and 283 deletions

@ -46,7 +46,6 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
# We explicitly only suppress specific worklets so we can see when new recursive
# worklets are added
"ptxas warning : Stack size for entry function.*NearestNeighborSearch3DWorklet.*"
"ptxas warning : Stack size for entry function.*BoundingIntervalHierarchy.*"
"ptxas warning : Stack size for entry function.*CoordinatesPortal.*"
"ptxas warning : Stack size for entry function.*CellRangesExtracter.*"

@ -191,7 +191,7 @@ public:
using PortalType = vtkm::exec::internal::ArrayPortalGroupVecVariable<
typename SourceArrayHandleType::PortalControl,
typename OffsetsArrayHandleType::PortalControl>;
typename OffsetsArrayHandleType::PortalConstControl>;
using PortalConstType = vtkm::exec::internal::ArrayPortalGroupVecVariable<
typename SourceArrayHandleType::PortalConstControl,
typename OffsetsArrayHandleType::PortalConstControl>;
@ -213,7 +213,8 @@ public:
VTKM_CONT
PortalType GetPortal()
{
return PortalType(this->SourceArray.GetPortalControl(), this->OffsetsArray.GetPortalControl());
return PortalType(this->SourceArray.GetPortalControl(),
this->OffsetsArray.GetPortalConstControl());
}
VTKM_CONT

@ -1,60 +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_BoundingIntervalHierarchyNode_h
#define vtk_m_cont_BoundingIntervalHierarchyNode_h
#include <vtkm/Types.h>
namespace vtkm
{
namespace cont
{
struct BoundingIntervalHierarchyNode
{
vtkm::IdComponent Dimension;
vtkm::Id ChildIndex;
union {
struct
{
vtkm::FloatDefault LMax;
vtkm::FloatDefault RMin;
} Node;
struct
{
vtkm::Id Start;
vtkm::Id Size;
} Leaf;
};
VTKM_EXEC_CONT
BoundingIntervalHierarchyNode()
: Dimension()
, ChildIndex()
, Node{ 0, 0 }
{
}
}; // struct BoundingIntervalHierarchyNode
} // namespace cont
} // namespace vtkm
#endif // vtk_m_cont_BoundingIntervalHierarchyNode_h

@ -49,11 +49,10 @@ set(headers
ArrayRangeCompute.h
AssignerMultiBlock.h
AtomicArray.h
BoundingIntervalHierarchy.h
BoundingIntervalHierarchyNode.h
BoundsCompute.h
BoundsGlobalCompute.h
CellLocator.h
CellLocatorBoundingIntervalHierarchy.h
CellLocatorHelper.h
CellLocatorRectilinearGrid.h
CellLocatorTwoLevelUniformGrid.h
@ -115,7 +114,7 @@ set(template_sources
ArrayHandle.hxx
ArrayHandleVirtual.hxx
ArrayRangeCompute.hxx
BoundingIntervalHierarchy.hxx
CellLocatorBoundingIntervalHierarchy.hxx
CellSetExplicit.hxx
CellSetStructured.hxx
ColorTable.hxx

@ -18,16 +18,14 @@
// this software.
//============================================================================
#ifndef vtk_m_cont_BoundingIntervalHierarchy_h
#define vtk_m_cont_BoundingIntervalHierarchy_h
#ifndef vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h
#define vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h
#include <vtkm/cont/vtkm_cont_export.h>
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/BoundingIntervalHierarchyNode.h>
#include <vtkm/cont/CellLocator.h>
#include <vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h>
@ -37,7 +35,7 @@ namespace vtkm
namespace cont
{
class VTKM_ALWAYS_EXPORT BoundingIntervalHierarchy : public vtkm::cont::CellLocator
class VTKM_ALWAYS_EXPORT CellLocatorBoundingIntervalHierarchy : public vtkm::cont::CellLocator
{
private:
using IdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
@ -85,7 +83,8 @@ private:
public:
VTKM_CONT
BoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4, vtkm::IdComponent maxLeafSize = 5)
CellLocatorBoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4,
vtkm::IdComponent maxLeafSize = 5)
: NumPlanes(numPlanes)
, MaxLeafSize(maxLeafSize)
, Nodes()
@ -140,7 +139,7 @@ protected:
private:
vtkm::IdComponent NumPlanes;
vtkm::IdComponent MaxLeafSize;
vtkm::cont::ArrayHandle<BoundingIntervalHierarchyNode> Nodes;
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode> Nodes;
IdArrayHandle ProcessedCellIds;
mutable HandleType ExecHandle;
@ -152,4 +151,4 @@ private:
} // namespace cont
} // namespace vtkm
#endif // vtk_m_cont_BoundingIntervalHierarchy_h
#endif // vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h

@ -27,12 +27,12 @@
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/ArrayHandleReverse.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/BoundingIntervalHierarchy.h>
#include <vtkm/cont/BoundingIntervalHierarchyNode.h>
#include <vtkm/cont/CellLocatorBoundingIntervalHierarchy.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/ErrorBadDevice.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/exec/BoundingIntervalHierarchyExec.h>
#include <vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/Invoker.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
@ -63,7 +63,8 @@ using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle
BoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds, vtkm::Id numCells)
CellLocatorBoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds,
vtkm::Id numCells)
{
using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
IdArrayHandle discardKeys;
@ -78,7 +79,8 @@ BoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle
BoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes, vtkm::Id numCells)
CellLocatorBoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes,
vtkm::Id numCells)
{
// Compact segment ids, removing non-contiguous values.
using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
@ -93,7 +95,7 @@ BoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes,
}
template <typename DeviceAdapter>
VTKM_CONT void BoundingIntervalHierarchy::CalculateSplitCosts(
VTKM_CONT void CellLocatorBoundingIntervalHierarchy::CalculateSplitCosts(
RangePermutationArrayHandle& segmentRanges,
RangeArrayHandle& ranges,
CoordsArrayHandle& coords,
@ -119,7 +121,7 @@ VTKM_CONT void BoundingIntervalHierarchy::CalculateSplitCosts(
}
template <typename DeviceAdapter>
VTKM_CONT void BoundingIntervalHierarchy::CalculatePlaneSplitCost(
VTKM_CONT void CellLocatorBoundingIntervalHierarchy::CalculatePlaneSplitCost(
vtkm::IdComponent planeIndex,
vtkm::IdComponent numPlanes,
RangePermutationArrayHandle& segmentRanges,
@ -198,10 +200,10 @@ VTKM_CONT void BoundingIntervalHierarchy::CalculatePlaneSplitCost(
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle
BoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cellIds,
const IdArrayHandle& leqFlags,
const IdArrayHandle& segmentIds,
DeviceAdapter)
CellLocatorBoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cellIds,
const IdArrayHandle& leqFlags,
const IdArrayHandle& segmentIds,
DeviceAdapter)
{
using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
vtkm::worklet::Invoker invoker(DeviceAdapter{});
@ -243,14 +245,14 @@ BoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cel
return scatterIndices;
}
class BoundingIntervalHierarchy::BuildFunctor
class CellLocatorBoundingIntervalHierarchy::BuildFunctor
{
protected:
BoundingIntervalHierarchy* Self;
CellLocatorBoundingIntervalHierarchy* Self;
public:
VTKM_CONT
BuildFunctor(BoundingIntervalHierarchy* self)
BuildFunctor(CellLocatorBoundingIntervalHierarchy* self)
: Self(self)
{
}
@ -297,13 +299,16 @@ public:
vtkm::Id nodesIndexOffset = 0;
vtkm::Id numSegments = 1;
IdArrayHandle discardKeys;
IdArrayHandle segmentStarts;
IdArrayHandle segmentSizes;
segmentSizes.Allocate(1);
segmentSizes.GetPortalControl().Set(0, numCells);
Self->ProcessedCellIds.Allocate(numCells);
vtkm::Id cellIdsOffset = 0;
IdArrayHandle parentIndices;
parentIndices.Allocate(1);
parentIndices.GetPortalControl().Set(0, -1);
while (!done)
{
//std::cout << "**** Iteration " << (++iteration) << " ****\n";
@ -412,7 +417,7 @@ public:
IdArrayHandle nonSplitSegmentIndices;
Algorithms::ScanExclusive(nonSplitSegmentSizes, nonSplitSegmentIndices);
IdArrayHandle runningSplitSegmentCounts;
Algorithms::ScanExclusive(splitChoices, runningSplitSegmentCounts);
vtkm::Id numNewSegments = Algorithms::ScanExclusive(splitChoices, runningSplitSegmentCounts);
//PRINT_TIMER("4.1", s41);
//START_TIMER(s42);
@ -435,10 +440,13 @@ public:
//START_TIMER(s43);
// Make a new nodes with enough nodes for the current level, copying over the old one
vtkm::Id nodesSize = Self->Nodes.GetNumberOfValues() + numSegments;
vtkm::cont::ArrayHandle<BoundingIntervalHierarchyNode> newTree;
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode> newTree;
newTree.Allocate(nodesSize);
Algorithms::CopySubRange(Self->Nodes, 0, Self->Nodes.GetNumberOfValues(), newTree);
IdArrayHandle nextParentIndices;
nextParentIndices.Allocate(2 * numNewSegments);
CountingIdArrayHandle nodesIndices(nodesIndexOffset, 1, numSegments);
vtkm::worklet::spatialstructure::TreeLevelAdder nodesAdder(
cellIdsOffset, nodesSize, Self->MaxLeafSize);
@ -448,7 +456,9 @@ public:
nonSplitSegmentIndices,
segmentSizes,
runningSplitSegmentCounts,
newTree);
parentIndices,
newTree,
nextParentIndices);
nodesIndexOffset = nodesSize;
cellIdsOffset += doneCellIds.GetNumberOfValues();
Self->Nodes = newTree;
@ -464,6 +474,7 @@ public:
Algorithms::Unique(uniqueSegmentIds);
numSegments = uniqueSegmentIds.GetNumberOfValues();
done = segmentIds.GetNumberOfValues() == 0;
parentIndices = nextParentIndices;
//PRINT_TIMER("5.1", s51);
//std::cout << "Iteration time: " << iterationTimer.GetElapsedTime() << "\n";
}
@ -472,19 +483,20 @@ public:
}
};
class BoundingIntervalHierarchy::PrepareForExecutionFunctor
class CellLocatorBoundingIntervalHierarchy::PrepareForExecutionFunctor
{
public:
template <typename DeviceAdapter>
VTKM_CONT bool operator()(DeviceAdapter,
const vtkm::cont::BoundingIntervalHierarchy& bih,
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih,
HandleType& bihExec) const
{
vtkm::cont::DynamicCellSet cellSet = bih.GetCellSet();
if (cellSet.IsType<vtkm::cont::CellSetExplicit<>>())
{
using CellSetType = vtkm::cont::CellSetExplicit<>;
using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
@ -495,7 +507,8 @@ public:
else if (cellSet.IsType<vtkm::cont::CellSetStructured<2>>())
{
using CellSetType = vtkm::cont::CellSetStructured<2>;
using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
@ -506,7 +519,8 @@ public:
else if (cellSet.IsType<vtkm::cont::CellSetStructured<3>>())
{
using CellSetType = vtkm::cont::CellSetStructured<3>;
using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
@ -517,7 +531,8 @@ public:
else if (cellSet.IsType<vtkm::cont::CellSetSingleType<>>())
{
using CellSetType = vtkm::cont::CellSetSingleType<>;
using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
@ -534,14 +549,14 @@ public:
};
VTKM_CONT
void BoundingIntervalHierarchy::Build()
void CellLocatorBoundingIntervalHierarchy::Build()
{
BuildFunctor functor(this);
vtkm::cont::TryExecute(functor);
}
VTKM_CONT
const HandleType BoundingIntervalHierarchy::PrepareForExecutionImpl(
const HandleType CellLocatorBoundingIntervalHierarchy::PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const
{
#ifdef VTKM_CUDA

@ -1,163 +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 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.
//============================================================================
#ifndef vtk_m_cont_BoundingIntervalHierarchyExec_h
#define vtk_m_cont_BoundingIntervalHierarchyExec_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/VecFromPortalPermute.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
#include <vtkm/cont/BoundingIntervalHierarchyNode.h>
#include <vtkm/exec/CellInside.h>
#include <vtkm/exec/CellLocator.h>
#include <vtkm/exec/ParametricCoordinates.h>
namespace vtkm
{
namespace exec
{
namespace
{
using NodeArrayHandle = vtkm::cont::ArrayHandle<vtkm::cont::BoundingIntervalHierarchyNode>;
using CellIdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
} // namespace
template <typename DeviceAdapter, typename CellSetType>
class BoundingIntervalHierarchyExec : public vtkm::exec::CellLocator
{
public:
VTKM_CONT
BoundingIntervalHierarchyExec() {}
VTKM_CONT
BoundingIntervalHierarchyExec(const NodeArrayHandle& nodes,
const CellIdArrayHandle& cellIds,
const CellSetType& cellSet,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
DeviceAdapter)
: Nodes(nodes.PrepareForInput(DeviceAdapter()))
, CellIds(cellIds.PrepareForInput(DeviceAdapter()))
{
CellSet = cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType());
Coords = coords.PrepareForInput(DeviceAdapter());
}
VTKM_EXEC
void FindCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Id& cellId,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::exec::FunctorBase& worklet) const override
{
cellId = Find(0, point, parametric, worklet);
}
private:
VTKM_EXEC vtkm::Id Find(vtkm::Id index,
const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::exec::FunctorBase& worklet) const
{
const vtkm::cont::BoundingIntervalHierarchyNode& node = Nodes.Get(index);
if (node.ChildIndex < 0)
{
return FindInLeaf(point, parametric, node, worklet);
}
else
{
const vtkm::FloatDefault& c = point[node.Dimension];
vtkm::Id id1 = -1;
vtkm::Id id2 = -1;
if (c <= node.Node.LMax)
{
id1 = Find(node.ChildIndex, point, parametric, worklet);
}
if (id1 == -1 && c >= node.Node.RMin)
{
id2 = Find(node.ChildIndex + 1, point, parametric, worklet);
}
if (id1 == -1 && id2 == -1)
{
return -1;
}
else if (id1 == -1)
{
return id2;
}
else
{
return id1;
}
}
}
VTKM_EXEC vtkm::Id FindInLeaf(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::cont::BoundingIntervalHierarchyNode& node,
const vtkm::exec::FunctorBase& worklet) const
{
using IndicesType = typename CellSetPortal::IndicesType;
for (vtkm::Id i = node.Leaf.Start; i < node.Leaf.Start + node.Leaf.Size; ++i)
{
vtkm::Id cellId = CellIds.Get(i);
IndicesType cellPointIndices = CellSet.GetIndices(cellId);
vtkm::VecFromPortalPermute<IndicesType, CoordsPortal> cellPoints(&cellPointIndices, Coords);
if (IsPointInCell(point, parametric, CellSet.GetCellShape(cellId), cellPoints, worklet))
{
return cellId;
}
}
return -1;
}
template <typename CoordsType, typename CellShapeTag>
VTKM_EXEC static bool IsPointInCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
CellShapeTag cellShape,
const CoordsType& cellPoints,
const vtkm::exec::FunctorBase& worklet)
{
bool success = false;
parametric = vtkm::exec::WorldCoordinatesToParametricCoordinates(
cellPoints, point, cellShape, success, worklet);
return success && vtkm::exec::CellInside(parametric, cellShape);
}
using FromType = vtkm::TopologyElementTagPoint;
using ToType = vtkm::TopologyElementTagCell;
using NodePortal = typename NodeArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
using CellIdPortal =
typename CellIdArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
using CellSetPortal =
typename CellSetType::template ExecutionTypes<DeviceAdapter, FromType, ToType>::ExecObjectType;
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
DeviceAdapter>::PortalConst;
NodePortal Nodes;
CellIdPortal CellIds;
CellSetPortal CellSet;
CoordsPortal Coords;
}; // class BoundingIntervalHierarchyExec
} // namespace exec
} // namespace vtkm
#endif //vtk_m_cont_BoundingIntervalHierarchyExec_h

@ -19,17 +19,17 @@
##============================================================================
set(headers
BoundingIntervalHierarchyExec.h
BoundaryState.h
AtomicArrayExecutionObject.h
BoundaryState.h
CellDerivative.h
CellEdge.h
CellFace.h
CellInside.h
CellInterpolate.h
CellLocator.h
CellLocatorUniformGrid.h
CellLocatorBoundingIntervalHierarchyExec.h
CellLocatorRectilinearGrid.h
CellLocatorUniformGrid.h
CellMeasure.h
ColorTable.h
ConnectivityExplicit.h

@ -0,0 +1,272 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h
#define vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/VecFromPortalPermute.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
#include <vtkm/exec/CellInside.h>
#include <vtkm/exec/CellLocator.h>
#include <vtkm/exec/ParametricCoordinates.h>
namespace vtkm
{
namespace exec
{
struct CellLocatorBoundingIntervalHierarchyNode
{
vtkm::IdComponent Dimension;
vtkm::Id ParentIndex;
vtkm::Id ChildIndex;
union {
struct
{
vtkm::FloatDefault LMax;
vtkm::FloatDefault RMin;
} Node;
struct
{
vtkm::Id Start;
vtkm::Id Size;
} Leaf;
};
VTKM_EXEC_CONT
CellLocatorBoundingIntervalHierarchyNode()
: Dimension()
, ParentIndex()
, ChildIndex()
, Node{ 0, 0 }
{
}
}; // struct CellLocatorBoundingIntervalHierarchyNode
template <typename DeviceAdapter, typename CellSetType>
class CellLocatorBoundingIntervalHierarchyExec : public vtkm::exec::CellLocator
{
using NodeArrayHandle =
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>;
using CellIdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
public:
VTKM_CONT
CellLocatorBoundingIntervalHierarchyExec() {}
VTKM_CONT
CellLocatorBoundingIntervalHierarchyExec(const NodeArrayHandle& nodes,
const CellIdArrayHandle& cellIds,
const CellSetType& cellSet,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
DeviceAdapter)
: Nodes(nodes.PrepareForInput(DeviceAdapter()))
, CellIds(cellIds.PrepareForInput(DeviceAdapter()))
, CellSet(cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType()))
, Coords(coords.PrepareForInput(DeviceAdapter()))
{
}
VTKM_EXEC
void FindCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Id& cellId,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::exec::FunctorBase& worklet) const override
{
cellId = -1;
vtkm::Id nodeIndex = 0;
FindCellState state = FindCellState::EnterNode;
while ((cellId < 0) && !((nodeIndex == 0) && (state == FindCellState::AscendFromNode)))
{
switch (state)
{
case FindCellState::EnterNode:
this->EnterNode(state, point, cellId, nodeIndex, parametric, worklet);
break;
case FindCellState::AscendFromNode:
this->AscendFromNode(state, nodeIndex);
break;
case FindCellState::DescendLeftChild:
this->DescendLeftChild(state, point, nodeIndex);
break;
case FindCellState::DescendRightChild:
this->DescendRightChild(state, point, nodeIndex);
break;
}
}
}
private:
enum struct FindCellState
{
EnterNode,
AscendFromNode,
DescendLeftChild,
DescendRightChild
};
VTKM_EXEC
void EnterNode(FindCellState& state,
const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Id& cellId,
vtkm::Id nodeIndex,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::exec::FunctorBase& worklet) const
{
VTKM_ASSERT(state == FindCellState::EnterNode);
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
if (node.ChildIndex < 0)
{
// In a leaf node. Look for a containing cell.
cellId = this->FindInLeaf(point, parametric, node, worklet);
state = FindCellState::AscendFromNode;
}
else
{
state = FindCellState::DescendLeftChild;
}
}
VTKM_EXEC
void AscendFromNode(FindCellState& state, vtkm::Id& nodeIndex) const
{
VTKM_ASSERT(state == FindCellState::AscendFromNode);
vtkm::Id childNodeIndex = nodeIndex;
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& childNode =
this->Nodes.Get(childNodeIndex);
nodeIndex = childNode.ParentIndex;
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& parentNode =
this->Nodes.Get(nodeIndex);
if (parentNode.ChildIndex == childNodeIndex)
{
// Ascending from left child. Descend into the right child.
state = FindCellState::DescendRightChild;
}
else
{
VTKM_ASSERT(parentNode.ChildIndex + 1 == childNodeIndex);
// Ascending from right child. Ascend again. (Don't need to change state.)
}
}
VTKM_EXEC
void DescendLeftChild(FindCellState& state,
const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Id& nodeIndex) const
{
VTKM_ASSERT(state == FindCellState::DescendLeftChild);
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
const vtkm::FloatDefault& coordinate = point[node.Dimension];
if (coordinate <= node.Node.LMax)
{
// Left child does contain the point. Do the actual descent.
nodeIndex = node.ChildIndex;
state = FindCellState::EnterNode;
}
else
{
// Left child does not contain the point. Skip to the right child.
state = FindCellState::DescendRightChild;
}
}
VTKM_EXEC
void DescendRightChild(FindCellState& state,
const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Id& nodeIndex) const
{
VTKM_ASSERT(state == FindCellState::DescendRightChild);
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
const vtkm::FloatDefault& coordinate = point[node.Dimension];
if (coordinate >= node.Node.RMin)
{
// Right child does contain the point. Do the actual descent.
nodeIndex = node.ChildIndex + 1;
state = FindCellState::EnterNode;
}
else
{
// Right child does not contain the point. Skip to ascent
state = FindCellState::AscendFromNode;
}
}
VTKM_EXEC vtkm::Id FindInLeaf(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node,
const vtkm::exec::FunctorBase& worklet) const
{
using IndicesType = typename CellSetPortal::IndicesType;
for (vtkm::Id i = node.Leaf.Start; i < node.Leaf.Start + node.Leaf.Size; ++i)
{
vtkm::Id cellId = this->CellIds.Get(i);
IndicesType cellPointIndices = this->CellSet.GetIndices(cellId);
vtkm::VecFromPortalPermute<IndicesType, CoordsPortal> cellPoints(&cellPointIndices,
this->Coords);
if (IsPointInCell(point, parametric, this->CellSet.GetCellShape(cellId), cellPoints, worklet))
{
return cellId;
}
}
return -1;
}
template <typename CoordsType, typename CellShapeTag>
VTKM_EXEC static bool IsPointInCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
CellShapeTag cellShape,
const CoordsType& cellPoints,
const vtkm::exec::FunctorBase& worklet)
{
bool success = false;
parametric = vtkm::exec::WorldCoordinatesToParametricCoordinates(
cellPoints, point, cellShape, success, worklet);
return success && vtkm::exec::CellInside(parametric, cellShape);
}
using FromType = vtkm::TopologyElementTagPoint;
using ToType = vtkm::TopologyElementTagCell;
using NodePortal = typename NodeArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
using CellIdPortal =
typename CellIdArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
using CellSetPortal =
typename CellSetType::template ExecutionTypes<DeviceAdapter, FromType, ToType>::ExecObjectType;
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
DeviceAdapter>::PortalConst;
NodePortal Nodes;
CellIdPortal CellIds;
CellSetPortal CellSet;
CoordsPortal Coords;
}; // class CellLocatorBoundingIntervalHierarchyExec
} // namespace exec
} // namespace vtkm
#endif //vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h

@ -31,9 +31,9 @@
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/ArrayHandleReverse.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/BoundingIntervalHierarchyNode.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
@ -504,8 +504,15 @@ struct NonSplitIndexCalculator : public vtkm::worklet::WorkletMapField
struct TreeLevelAdder : public vtkm::worklet::WorkletMapField
{
typedef void ControlSignature(FieldIn, FieldIn, FieldIn, FieldIn, FieldIn, WholeArrayInOut);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6);
typedef void ControlSignature(FieldIn nodeIndices,
FieldIn segmentSplits,
FieldIn nonSplitSegmentIndices,
FieldIn segmentSizes,
FieldIn runningSplitSegmentCounts,
FieldIn parentIndices,
WholeArrayInOut newTree,
WholeArrayOut nextParentIndices);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, _7, _8);
using InputDomain = _1;
VTKM_CONT
@ -516,26 +523,31 @@ struct TreeLevelAdder : public vtkm::worklet::WorkletMapField
{
}
template <typename BoundingIntervalHierarchyPortal>
VTKM_EXEC void operator()(const vtkm::Id& index,
template <typename BoundingIntervalHierarchyPortal, typename NextParentPortal>
VTKM_EXEC void operator()(vtkm::Id index,
const TreeNode& split,
const vtkm::Id& start,
const vtkm::Id& count,
const vtkm::Id& numPreviousSplits,
BoundingIntervalHierarchyPortal& treePortal) const
vtkm::Id start,
vtkm::Id count,
vtkm::Id numPreviousSplits,
vtkm::Id parentIndex,
BoundingIntervalHierarchyPortal& treePortal,
NextParentPortal& nextParentPortal) const
{
vtkm::cont::BoundingIntervalHierarchyNode node;
if (count > MaxLeafSize)
vtkm::exec::CellLocatorBoundingIntervalHierarchyNode node;
node.ParentIndex = parentIndex;
if (count > this->MaxLeafSize)
{
node.Dimension = split.Dimension;
node.ChildIndex = TreeOffset + 2 * numPreviousSplits;
node.ChildIndex = this->TreeOffset + 2 * numPreviousSplits;
node.Node.LMax = split.LMax;
node.Node.RMin = split.RMin;
nextParentPortal.Set(2 * numPreviousSplits, index);
nextParentPortal.Set(2 * numPreviousSplits + 1, index);
}
else
{
node.ChildIndex = -1;
node.Leaf.Start = CellIdsOffset + start;
node.Leaf.Start = this->CellIdsOffset + start;
node.Leaf.Size = count;
}
treePortal.Set(index, node);

@ -20,8 +20,7 @@
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayHandleConcatenate.h>
#include <vtkm/cont/BoundingIntervalHierarchy.h>
#include <vtkm/cont/BoundingIntervalHierarchy.hxx>
#include <vtkm/cont/CellLocatorBoundingIntervalHierarchy.hxx>
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/internal/DeviceAdapterTag.h>
@ -81,7 +80,8 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, vtkm::IdComponen
std::cout << "Using numPlanes: " << numPlanes << "\n";
std::cout << "Building Bounding Interval Hierarchy Tree" << std::endl;
vtkm::cont::BoundingIntervalHierarchy bih = vtkm::cont::BoundingIntervalHierarchy(numPlanes, 5);
vtkm::cont::CellLocatorBoundingIntervalHierarchy bih =
vtkm::cont::CellLocatorBoundingIntervalHierarchy(numPlanes, 5);
bih.SetCellSet(cellSet);
bih.SetCoordinates(dataSet.GetCoordinateSystem());
bih.Update();