Commit 5128d5a1 authored by Abhishek Yenpure's avatar Abhishek Yenpure Committed by Kitware Robot

Merge topic 'spatialsearch'

e2dccee0 Merge branch 'master' of https://gitlab.kitware.com/vtk/vtk-m into spatialsearch
ebdad45d Removing VTKM_CONT_EXPORT for the CellLocator
e42c270f fixing -Wmissing-field-initializers for BoundingIntevalHierarchyNode
b5f2e706 Moving changes of .cxx to .hxx
e0296a24 Fixes for resolving Rob's suggestions
dcbb444a Warning fixes for BoundingIntervalHierarchy
50963290 Moving BoundingIntervalHierarchy.cxx to device sources
bf224dbb Adding VTKM_CONT_EXPORT to BoundingIntervalHierarchy
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarRobert Maynard <robert.maynard@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Merge-request: !1282
parents 290ed59c e2dccee0
......@@ -42,4 +42,7 @@ 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.*"
)
//============================================================================
// 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_BoundingIntervalHierarchy_h
#define vtk_m_cont_BoundingIntervalHierarchy_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>
namespace vtkm
{
namespace cont
{
class BoundingIntervalHierarchy : public vtkm::cont::CellLocator
{
private:
using IdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
using CoordsArrayHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
using RangeArrayHandle = vtkm::cont::ArrayHandle<vtkm::Range>;
using RangePermutationArrayHandle =
vtkm::cont::ArrayHandlePermutation<IdArrayHandle, RangeArrayHandle>;
using SplitPropertiesArrayHandle =
vtkm::cont::ArrayHandle<vtkm::worklet::spatialstructure::SplitProperties>;
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
class BuildFunctor;
class PrepareForExecutionFunctor;
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle CalculateSegmentSizes(const IdArrayHandle&, vtkm::Id);
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle GenerateSegmentIds(const IdArrayHandle&, vtkm::Id);
template <typename DeviceAdapter>
VTKM_CONT void CalculateSplitCosts(RangePermutationArrayHandle&,
RangeArrayHandle&,
CoordsArrayHandle&,
IdArrayHandle&,
SplitPropertiesArrayHandle&,
DeviceAdapter);
template <typename DeviceAdapter>
VTKM_CONT void CalculatePlaneSplitCost(vtkm::IdComponent,
vtkm::IdComponent,
RangePermutationArrayHandle&,
RangeArrayHandle&,
CoordsArrayHandle&,
IdArrayHandle&,
SplitPropertiesArrayHandle&,
vtkm::IdComponent,
DeviceAdapter);
template <typename DeviceAdapter>
VTKM_CONT IdArrayHandle CalculateSplitScatterIndices(const IdArrayHandle&,
const IdArrayHandle&,
const IdArrayHandle&,
DeviceAdapter);
public:
VTKM_CONT
BoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4, vtkm::IdComponent maxLeafSize = 5)
: NumPlanes(numPlanes)
, MaxLeafSize(maxLeafSize)
, Nodes()
, ProcessedCellIds()
{
}
VTKM_CONT
void SetNumberOfSplittingPlanes(vtkm::IdComponent numPlanes)
{
NumPlanes = numPlanes;
SetDirty();
}
VTKM_CONT
vtkm::IdComponent GetNumberOfSplittingPlanes() { return NumPlanes; }
VTKM_CONT
void SetMaxLeafSize(vtkm::IdComponent maxLeafSize)
{
MaxLeafSize = maxLeafSize;
SetDirty();
}
VTKM_CONT
vtkm::Id GetMaxLeafSize() { return MaxLeafSize; }
protected:
VTKM_CONT
void Build() override;
VTKM_CONT
virtual const HandleType PrepareForExecutionImpl(const vtkm::Int8 device) const override;
private:
vtkm::IdComponent NumPlanes;
vtkm::IdComponent MaxLeafSize;
vtkm::cont::ArrayHandle<BoundingIntervalHierarchyNode> Nodes;
IdArrayHandle ProcessedCellIds;
mutable HandleType ExecHandle;
};
} // namespace cont
} // namespace vtkm
#endif // vtk_m_cont_BoundingIntervalHierarchy_h
This diff is collapsed.
//============================================================================
// 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
......@@ -46,9 +46,12 @@ set(headers
ArrayHandleConcatenate.h
ArrayRangeCompute.h
AssignerMultiBlock.h
BoundingIntervalHierarchyNode.h
BoundingIntervalHierarchy.h
BoundsCompute.h
BoundsGlobalCompute.h
CellLocator.h
CellLocatorHelper.h
CellLocatorTwoLevelUniformGrid.h
CellSet.h
CellSetExplicit.h
......@@ -100,6 +103,7 @@ set(headers
set(template_sources
ArrayHandle.hxx
ArrayRangeCompute.hxx
BoundingIntervalHierarchy.hxx
CellSetExplicit.hxx
CellSetStructured.hxx
CoordinateSystem.hxx
......
......@@ -20,139 +20,74 @@
#ifndef vtk_m_cont_CellLocator_h
#define vtk_m_cont_CellLocator_h
#include <vtkm/cont/CellLocatorTwoLevelUniformGrid.h>
#include <vtkm/exec/ParametricCoordinates.h>
#include <vtkm/Types.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/exec/CellLocator.h>
namespace vtkm
{
namespace cont
{
class CellLocator
class CellLocator : public vtkm::cont::ExecutionObjectBase
{
private:
using StructuredCellSetList = vtkm::ListTagBase<vtkm::cont::CellSetStructured<1>,
vtkm::cont::CellSetStructured<2>,
vtkm::cont::CellSetStructured<3>>;
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
VTKM_CONT static bool IsUniformGrid(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coordinates)
public:
CellLocator()
: Dirty(true)
{
return coordinates.GetData().IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>() &&
(cellset.IsType<vtkm::cont::CellSetStructured<1>>() ||
cellset.IsType<vtkm::cont::CellSetStructured<2>>() ||
cellset.IsType<vtkm::cont::CellSetStructured<3>>());
}
public:
void SetCellSet(const vtkm::cont::DynamicCellSet& cellset) { this->CellSet = cellset; }
const vtkm::cont::DynamicCellSet& GetCellSet() const { return this->CellSet; }
vtkm::cont::DynamicCellSet GetCellSet() const { return CellSet; }
void SetCellSet(const vtkm::cont::DynamicCellSet& cellSet)
{
CellSet = cellSet;
SetDirty();
}
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords) { this->Coordinates = coords; }
const vtkm::cont::CoordinateSystem& GetCoordinates() const { return this->Coordinates; }
vtkm::cont::CoordinateSystem GetCoordinates() const { return Coords; }
/// Builds the cell locator lookup structure
///
template <typename DeviceAdapter, typename CellSetList = VTKM_DEFAULT_CELL_SET_LIST_TAG>
void Build(DeviceAdapter device, CellSetList cellSetTypes = CellSetList())
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords)
{
if (IsUniformGrid(this->CellSet, this->Coordinates))
{
// nothing to build for uniform grid
}
else
{
this->Locator.SetCellSet(this->CellSet);
this->Locator.SetCoordinates(this->Coordinates);
this->Locator.Build(device, cellSetTypes);
}
Coords = coords;
SetDirty();
}
class FindCellWorklet : public vtkm::worklet::WorkletMapField
void Update()
{
private:
template <vtkm::IdComponent DIM>
using ConnectivityType = vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
DIM>;
public:
using ControlSignature = void(FieldIn<Vec3> points,
WholeCellSetIn<> cellSet,
WholeArrayIn<Vec3> coordinates,
FieldOut<IdType> cellIds,
FieldOut<Vec3> parametricCoordinates);
using ExecutionSignature = void(_1, _2, _3, _4, _5);
template <typename CoordsPortalType, vtkm::IdComponent DIM>
VTKM_EXEC void operator()(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
const ConnectivityType<DIM>& cellset,
const CoordsPortalType& coordinates,
vtkm::Id& cellId,
vtkm::Vec<vtkm::FloatDefault, 3>& pc) const
{
auto coords = coordinates.GetPortal();
static_assert(
std::is_same<decltype(coords), vtkm::internal::ArrayPortalUniformPointCoordinates>::value,
"expecting ArrayHandleUniformPointCoordinates for coordinates");
auto cellId3 = static_cast<vtkm::Id3>((point - coords.GetOrigin()) / coords.GetSpacing());
auto cellDim = vtkm::Max(vtkm::Id3(1), coords.GetDimensions() - vtkm::Id3(1));
if (cellId3[0] < 0 || cellId3[0] >= cellDim[0] || cellId3[1] < 0 ||
cellId3[1] >= cellDim[1] || cellId3[2] < 0 || cellId3[2] >= cellDim[2])
{
cellId = -1;
}
else
{
cellId = cellId3[0] + cellDim[0] * (cellId3[1] + cellDim[1] * cellId3[2]);
auto cellPoints =
vtkm::VecAxisAlignedPointCoordinates<DIM>(coords.Get(cellId3), coords.GetSpacing());
bool success;
pc = vtkm::exec::WorldCoordinatesToParametricCoordinates(
cellPoints, point, cellset.GetCellShape(cellId), success, *this);
VTKM_ASSERT(success);
}
}
};
/// Finds the containing cells for the given array of points. Returns the cell ids
/// in the `cellIds` arrays. If a cell could not be found due to the point being
/// outside all the cells or due to numerical errors, the cell id is set to -1.
/// Parametric coordinates of the point inside the cell is returned in the
/// `parametricCoords` array.
///
template <typename PointComponentType,
typename PointStorageType,
typename DeviceAdapter,
typename CellSetList = VTKM_DEFAULT_CELL_SET_LIST_TAG>
void FindCells(
const vtkm::cont::ArrayHandle<vtkm::Vec<PointComponentType, 3>, PointStorageType>& points,
vtkm::cont::ArrayHandle<vtkm::Id>& cellIds,
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>& parametricCoords,
DeviceAdapter device,
CellSetList cellSetTypes = CellSetList()) const
if (Dirty)
Build();
Dirty = false;
}
template <typename DeviceAdapter>
VTKM_CONT const vtkm::exec::CellLocator* PrepareForExecution(DeviceAdapter) const
{
if (IsUniformGrid(this->CellSet, this->Coordinates))
{
auto coordinates =
this->Coordinates.GetData().Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
auto cellset = this->CellSet.ResetCellSetList(StructuredCellSetList());
vtkm::worklet::DispatcherMapField<FindCellWorklet, DeviceAdapter>().Invoke(
points, cellset, coordinates, cellIds, parametricCoords);
}
else
{
this->Locator.FindCells(points, cellIds, parametricCoords, device, cellSetTypes);
}
vtkm::cont::DeviceAdapterId deviceId = vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetId();
return PrepareForExecutionImpl(deviceId).PrepareForExecution(DeviceAdapter());
}
protected:
void SetDirty() { Dirty = true; }
//This is going to need a TryExecute
VTKM_CONT virtual void Build() = 0;
VTKM_CONT virtual const HandleType PrepareForExecutionImpl(const vtkm::Int8 device) const = 0;
private:
vtkm::cont::DynamicCellSet CellSet;
vtkm::cont::CoordinateSystem Coordinates;
vtkm::cont::CellLocatorTwoLevelUniformGrid Locator;
vtkm::cont::CoordinateSystem Coords;
bool Dirty;
};
}
} // vtkm::cont
} // namespace cont
} // namespace vtkm
#endif // vtk_m_cont_CellLocator_h
//============================================================================
// 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_CellLocatorHelper_h
#define vtk_m_cont_CellLocatorHelper_h
#include <vtkm/cont/CellLocatorTwoLevelUniformGrid.h>
#include <vtkm/exec/ParametricCoordinates.h>
namespace vtkm
{
namespace cont
{
class CellLocatorHelper
{
private:
using StructuredCellSetList = vtkm::ListTagBase<vtkm::cont::CellSetStructured<1>,
vtkm::cont::CellSetStructured<2>,
vtkm::cont::CellSetStructured<3>>;
VTKM_CONT static bool IsUniformGrid(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coordinates)
{
return coordinates.GetData().IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>() &&
(cellset.IsType<vtkm::cont::CellSetStructured<1>>() ||
cellset.IsType<vtkm::cont::CellSetStructured<2>>() ||
cellset.IsType<vtkm::cont::CellSetStructured<3>>());
}
public:
void SetCellSet(const vtkm::cont::DynamicCellSet& cellset) { this->CellSet = cellset; }
const vtkm::cont::DynamicCellSet& GetCellSet() const { return this->CellSet; }
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords) { this->Coordinates = coords; }
const vtkm::cont::CoordinateSystem& GetCoordinates() const { return this->Coordinates; }
/// Builds the cell locator lookup structure
///
template <typename DeviceAdapter, typename CellSetList = VTKM_DEFAULT_CELL_SET_LIST_TAG>
void Build(DeviceAdapter device, CellSetList cellSetTypes = CellSetList())
{
if (IsUniformGrid(this->CellSet, this->Coordinates))
{
// nothing to build for uniform grid
}
else
{
this->Locator.SetCellSet(this->CellSet);
this->Locator.SetCoordinates(this->Coordinates);
this->Locator.Build(device, cellSetTypes);
}
}
class FindCellWorklet : public vtkm::worklet::WorkletMapField
{
private:
template <vtkm::IdComponent DIM>
using ConnectivityType = vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
DIM>;
public:
using ControlSignature = void(FieldIn<Vec3> points,
WholeCellSetIn<> cellSet,
WholeArrayIn<Vec3> coordinates,
FieldOut<IdType> cellIds,
FieldOut<Vec3> parametricCoordinates);
using ExecutionSignature = void(_1, _2, _3, _4, _5);
template <typename CoordsPortalType, vtkm::IdComponent DIM>
VTKM_EXEC void operator()(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
const ConnectivityType<DIM>& cellset,
const CoordsPortalType& coordinates,
vtkm::Id& cellId,
vtkm::Vec<vtkm::FloatDefault, 3>& pc) const
{
auto coords = coordinates.GetPortal();
static_assert(
std::is_same<decltype(coords), vtkm::internal::ArrayPortalUniformPointCoordinates>::value,
"expecting ArrayHandleUniformPointCoordinates for coordinates");
auto cellId3 = static_cast<vtkm::Id3>((point - coords.GetOrigin()) / coords.GetSpacing());
auto cellDim = vtkm::Max(vtkm::Id3(1), coords.GetDimensions() - vtkm::Id3(1));
if (cellId3[0] < 0 || cellId3[0] >= cellDim[0] || cellId3[1] < 0 ||
cellId3[1] >= cellDim[1] || cellId3[2] < 0 || cellId3[2] >= cellDim[2])
{
cellId = -1;
}
else
{
cellId = cellId3[0] + cellDim[0] * (cellId3[1] + cellDim[1] * cellId3[2]);
auto cellPoints =
vtkm::VecAxisAlignedPointCoordinates<DIM>(coords.Get(cellId3), coords.GetSpacing());
bool success;
pc = vtkm::exec::WorldCoordinatesToParametricCoordinates(
cellPoints, point, cellset.GetCellShape(cellId), success, *this);
VTKM_ASSERT(success);
}
}
};
/// Finds the containing cells for the given array of points. Returns the cell ids
/// in the `cellIds` arrays. If a cell could not be found due to the point being
/// outside all the cells or due to numerical errors, the cell id is set to -1.
/// Parametric coordinates of the point inside the cell is returned in the
/// `parametricCoords` array.
///
template <typename PointComponentType,
typename PointStorageType,
typename DeviceAdapter,
typename CellSetList = VTKM_DEFAULT_CELL_SET_LIST_TAG>
void FindCells(
const vtkm::cont::ArrayHandle<vtkm::Vec<PointComponentType, 3>, PointStorageType>& points,
vtkm::cont::ArrayHandle<vtkm::Id>& cellIds,
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>& parametricCoords,
DeviceAdapter device,
CellSetList cellSetTypes = CellSetList()) const
{
if (IsUniformGrid(this->CellSet, this->Coordinates))
{
auto coordinates =
this->Coordinates.GetData().Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
auto cellset = this->CellSet.ResetCellSetList(StructuredCellSetList());
vtkm::worklet::DispatcherMapField<FindCellWorklet, DeviceAdapter>().Invoke(
points, cellset, coordinates, cellIds, parametricCoords);
}
else
{
this->Locator.FindCells(points, cellIds, parametricCoords, device, cellSetTypes);
}
}
private:
vtkm::cont::DynamicCellSet CellSet;
vtkm::cont::CoordinateSystem Coordinates;
vtkm::cont::CellLocatorTwoLevelUniformGrid Locator;
};
}
} // vtkm::cont
#endif // vtk_m_cont_CellLocatorHelper_h
......@@ -1053,7 +1053,7 @@ public:
if (numberOfValues <= 0)
{
output.PrepareForOutput(0, DeviceAdapterTagCuda());
return vtkm::TypeTraits<T>::ZeroInitialization();
return;
}
//We need call PrepareForInput on the input argument before invoking a
......@@ -1062,11 +1062,12 @@ public:
//use case breaks.
auto keysPortal = keys.PrepareForInput(DeviceAdapterTagCuda());
auto valuesPortal = values.PrepareForInput(DeviceAdapterTagCuda());
ScanExnclusiveByKeyPortal(keysPortal,
valuesPortal,
output.PrepareForOutput(numberOfValues, DeviceAdapterTagCuda()),
vtkm::TypeTraits<T>::ZeroInitialization(),
vtkm::Add());
ScanExclusiveByKeyPortal(keysPortal,
valuesPortal,
output.PrepareForOutput(numberOfValues, DeviceAdapterTagCuda()),
vtkm::TypeTraits<T>::ZeroInitialization(),
::thrust::equal_to<T>(),
vtkm::Add());
}
template <typename T,
......
......@@ -17,7 +17,7 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/CellLocator.h>