Merge topic 'cell-neighborhood-deprecation-warning' into release-2.2

33373f4b2 Fix deprecation warning in WorkletCellNeighborhood

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Li-Ta Lo <ollie@lanl.gov>
Merge-request: !3266
This commit is contained in:
Kenneth Moreland 2024-10-03 20:06:26 +00:00 committed by Kitware Robot
commit c7f18cf5b9
5 changed files with 357 additions and 4 deletions

@ -0,0 +1,6 @@
## Fix deprecation warning in WorkletCellNeighborhood
There was a use of a deprecated method buried in a support class of
`WorkletCellNeighborhood`. This fixes that deprecation and also adds a
missing test for `WorkletCellNeighborhood` to prevent such things in the
future.

@ -78,7 +78,7 @@ public:
inputIndex, inputIndex,
visitIndex, visitIndex,
outputIndex, outputIndex,
vtkm::exec::BoundaryState{ detail::To3D(connectivity.FlatToLogicalToIndex(inputIndex)), vtkm::exec::BoundaryState{ detail::To3D(connectivity.FlatToLogicalVisitIndex(inputIndex)),
detail::To3D(connectivity.GetCellDimensions()) }) detail::To3D(connectivity.GetCellDimensions()) })
{ {
} }

@ -36,14 +36,15 @@ set(unit_tests
UnitTestStreamLineUniformGrid.cxx UnitTestStreamLineUniformGrid.cxx
UnitTestTriangleWinding.cxx UnitTestTriangleWinding.cxx
UnitTestWholeCellSetIn.cxx UnitTestWholeCellSetIn.cxx
UnitTestWorkletCellNeighborhood.cxx
UnitTestWorkletMapField.cxx UnitTestWorkletMapField.cxx
UnitTestWorkletMapField3d.cxx UnitTestWorkletMapField3d.cxx
UnitTestWorkletMapFieldExecArg.cxx UnitTestWorkletMapFieldExecArg.cxx
UnitTestWorkletMapFieldWholeArray.cxx UnitTestWorkletMapFieldWholeArray.cxx
UnitTestWorkletMapFieldWholeArrayAtomic.cxx UnitTestWorkletMapFieldWholeArrayAtomic.cxx
UnitTestWorkletMapPointNeighborhood.cxx
UnitTestWorkletMapTopologyExplicit.cxx UnitTestWorkletMapTopologyExplicit.cxx
UnitTestWorkletMapTopologyUniform.cxx UnitTestWorkletMapTopologyUniform.cxx
UnitTestWorkletPointNeighborhood.cxx
UnitTestWorkletReduceByKey.cxx UnitTestWorkletReduceByKey.cxx
UnitTestWaveletCompressor.cxx UnitTestWaveletCompressor.cxx
) )

@ -0,0 +1,344 @@
//============================================================================
// 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 <vtkm/worklet/DispatcherCellNeighborhood.h>
#include <vtkm/worklet/WorkletCellNeighborhood.h>
#include <vtkm/worklet/ScatterIdentity.h>
#include <vtkm/worklet/ScatterUniform.h>
#include <vtkm/Math.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/RuntimeDeviceTracker.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace test_cellneighborhood
{
struct MaxNeighborValue : public vtkm::worklet::WorkletCellNeighborhood
{
using ControlSignature = void(FieldInNeighborhood neighbors, CellSetIn, FieldOut maxV);
using ExecutionSignature = void(Boundary, _1, _3);
//verify input domain can be something other than first parameter
using InputDomain = _2;
template <typename FieldIn, typename FieldOut>
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary,
const vtkm::exec::FieldNeighborhood<FieldIn>& inputField,
FieldOut& output) const
{
using ValueType = typename FieldIn::ValueType;
auto* nboundary = inputField.Boundary;
if (!(nboundary->IsRadiusInXBoundary(1) == boundary.IsRadiusInXBoundary(1)))
{
this->RaiseError("Got invalid XPos boundary state");
}
if (!(nboundary->IsRadiusInYBoundary(1) == boundary.IsRadiusInYBoundary(1)))
{
this->RaiseError("Got invalid YPos boundary state");
}
if (!(nboundary->IsRadiusInZBoundary(1) == boundary.IsRadiusInZBoundary(1)))
{
this->RaiseError("Got invalid ZPos boundary state");
}
if (!(nboundary->IsRadiusInBoundary(1) == boundary.IsRadiusInBoundary(1)))
{
this->RaiseError("Got invalid boundary state");
}
if (nboundary->IsRadiusInXBoundary(1) !=
(boundary.IsNeighborInXBoundary(-1) && boundary.IsNeighborInXBoundary(1)))
{
this->RaiseError("Neighbor/Radius boundary mismatch in X dimension.");
}
if (nboundary->IsRadiusInYBoundary(1) !=
(boundary.IsNeighborInYBoundary(-1) && boundary.IsNeighborInYBoundary(1)))
{
this->RaiseError("Neighbor/Radius boundary mismatch in Y dimension.");
}
if (nboundary->IsRadiusInZBoundary(1) !=
(boundary.IsNeighborInZBoundary(-1) && boundary.IsNeighborInZBoundary(1)))
{
this->RaiseError("Neighbor/Radius boundary mismatch in Z dimension.");
}
if (nboundary->IsRadiusInBoundary(1) !=
(boundary.IsNeighborInBoundary({ -1 }) && boundary.IsNeighborInBoundary({ 1 })))
{
this->RaiseError("Neighbor/Radius boundary mismatch.");
}
auto minNeighbors = boundary.MinNeighborIndices(1);
auto maxNeighbors = boundary.MaxNeighborIndices(1);
ValueType maxV = inputField.Get(0, 0, 0); //our value
for (vtkm::IdComponent k = minNeighbors[2]; k <= maxNeighbors[2]; ++k)
{
for (vtkm::IdComponent j = minNeighbors[1]; j <= maxNeighbors[1]; ++j)
{
for (vtkm::IdComponent i = minNeighbors[0]; i <= maxNeighbors[0]; ++i)
{
maxV = vtkm::Max(maxV, inputField.Get(i, j, k));
}
}
}
output = static_cast<FieldOut>(maxV);
}
};
struct ScatterIdentityNeighbor : public vtkm::worklet::WorkletCellNeighborhood
{
using ControlSignature = void(CellSetIn topology);
using ExecutionSignature = void(WorkIndex, InputIndex, OutputIndex, ThreadIndices, VisitIndex);
VTKM_CONT
ScatterIdentityNeighbor() {}
VTKM_EXEC void operator()(
const vtkm::Id& workIndex,
const vtkm::Id& inputIndex,
const vtkm::Id& outputIndex,
const vtkm::exec::arg::ThreadIndicesCellNeighborhood& vtkmNotUsed(threadIndices),
const vtkm::Id& visitIndex) const
{
if (workIndex != inputIndex)
{
this->RaiseError("Got wrong input value.");
}
if (outputIndex != workIndex)
{
this->RaiseError("Got work and output index don't match.");
}
if (visitIndex != 0)
{
this->RaiseError("Got wrong visit value1.");
}
}
using ScatterType = vtkm::worklet::ScatterIdentity;
};
struct ScatterUniformNeighbor : public vtkm::worklet::WorkletCellNeighborhood
{
using ControlSignature = void(CellSetIn topology);
using ExecutionSignature = void(WorkIndex, InputIndex, OutputIndex, ThreadIndices, VisitIndex);
VTKM_CONT
ScatterUniformNeighbor() {}
VTKM_EXEC void operator()(
const vtkm::Id& workIndex,
const vtkm::Id& inputIndex,
const vtkm::Id& outputIndex,
const vtkm::exec::arg::ThreadIndicesCellNeighborhood& vtkmNotUsed(threadIndices),
const vtkm::Id& visitIndex) const
{
if ((workIndex / 3) != inputIndex)
{
this->RaiseError("Got wrong input value.");
}
if (outputIndex != workIndex)
{
this->RaiseError("Got work and output index don't match.");
}
if ((workIndex % 3) != visitIndex)
{
this->RaiseError("Got wrong visit value2.");
}
}
using ScatterType = vtkm::worklet::ScatterUniform<3>;
};
// An example of using WorkletCellNeighborhood to iterate over a structured 3D cell
// domain rather than look at an actual neighborhood. It reduces a domain by subsampling
// every other item in the input field.
struct Subsample : public vtkm::worklet::WorkletCellNeighborhood
{
using ControlSignature =
void(WholeCellSetIn<vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint> inputTopology,
WholeArrayIn inputField,
CellSetIn outputTopology,
FieldOut sampledField);
using ExecutionSignature = void(_1, _2, Boundary, _4);
using InputDomain = _3;
template <typename InFieldPortal, typename T>
VTKM_EXEC void operator()(const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagCell,
vtkm::TopologyElementTagPoint,
3>& inputTopology,
const InFieldPortal& inFieldPortal,
const vtkm::exec::BoundaryState& boundary,
T& sample) const
{
sample =
inFieldPortal.Get(inputTopology.LogicalToFlatVisitIndex(2 * boundary.GetCenterIndex()));
}
};
} // namespace test_cellneighborhood
namespace
{
static void TestMaxNeighborValue();
static void TestScatterIdentityNeighbor();
static void TestScatterUnfiormNeighbor();
static void TestIndexing();
void TestWorkletCellNeighborhood(vtkm::cont::DeviceAdapterId id)
{
std::cout << "Testing Cell Neighborhood Worklet on device adapter: " << id.GetName() << std::endl;
vtkm::cont::ScopedRuntimeDeviceTracker deviceScope(id);
TestMaxNeighborValue();
TestScatterIdentityNeighbor();
TestScatterUnfiormNeighbor();
TestIndexing();
}
static void TestMaxNeighborValue()
{
std::cout << "Testing MaxNeighborValue worklet" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::worklet::DispatcherCellNeighborhood<::test_cellneighborhood::MaxNeighborValue> dispatcher;
vtkm::cont::ArrayHandle<vtkm::Float32> output;
vtkm::cont::DataSet dataSet3D = testDataSet.Make3DUniformDataSet0();
dispatcher.Invoke(dataSet3D.GetField("cellvar")
.GetData()
.ResetTypes<vtkm::TypeListFieldScalar, VTKM_DEFAULT_STORAGE_LIST>(),
dataSet3D.GetCellSet(),
output);
vtkm::Float32 expected3D[4] = { 100.4f, 100.4f, 100.4f, 100.4f };
for (int i = 0; i < 4; ++i)
{
VTKM_TEST_ASSERT(test_equal(output.ReadPortal().Get(i), expected3D[i]),
"Wrong result for MaxNeighborValue worklet");
}
vtkm::cont::DataSet dataSet2D = testDataSet.Make2DUniformDataSet1();
dispatcher.Invoke(dataSet2D.GetField("cellvar")
.GetData()
.ResetTypes<vtkm::TypeListFieldScalar, VTKM_DEFAULT_STORAGE_LIST>(),
dataSet2D.GetCellSet(),
output);
vtkm::Float32 expected2D[16] = { 5.0f, 6.0f, 7.0f, 7.0f, 9.0f, 10.0f, 11.0f, 11.0f,
13.0f, 14.0f, 15.0f, 15.0f, 13.0f, 14.0f, 15.0f, 15.0f };
for (int i = 0; i < 16; ++i)
{
VTKM_TEST_ASSERT(test_equal(output.ReadPortal().Get(i), expected2D[i]),
"Wrong result for MaxNeighborValue worklet");
}
}
static void TestScatterIdentityNeighbor()
{
std::cout << "Testing identity scatter with CellNeighborhood" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::worklet::DispatcherCellNeighborhood<::test_cellneighborhood::ScatterIdentityNeighbor>
dispatcher;
vtkm::cont::DataSet dataSet3D = testDataSet.Make3DUniformDataSet0();
dispatcher.Invoke(dataSet3D.GetCellSet());
vtkm::cont::DataSet dataSet2D = testDataSet.Make2DUniformDataSet0();
dispatcher.Invoke(dataSet2D.GetCellSet());
}
static void TestScatterUnfiormNeighbor()
{
std::cout << "Testing uniform scatter with CellNeighborhood" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::worklet::DispatcherCellNeighborhood<::test_cellneighborhood::ScatterUniformNeighbor>
dispatcher;
vtkm::cont::DataSet dataSet3D = testDataSet.Make3DUniformDataSet0();
dispatcher.Invoke(dataSet3D.GetCellSet());
vtkm::cont::DataSet dataSet2D = testDataSet.Make2DUniformDataSet0();
dispatcher.Invoke(dataSet2D.GetCellSet());
}
static void TestIndexing()
{
std::cout << "Testing using CellNeighborhood for 3D indexing." << std::endl;
constexpr vtkm::Id outDim = 4;
constexpr vtkm::Id inDim = outDim * 2;
vtkm::cont::CellSetStructured<3> inCellSet;
inCellSet.SetPointDimensions({ inDim + 1 });
vtkm::cont::CellSetStructured<3> outCellSet;
outCellSet.SetPointDimensions({ outDim + 1 });
vtkm::cont::ArrayHandleUniformPointCoordinates inField(vtkm::Id3{ inDim });
vtkm::cont::ArrayHandle<vtkm::Vec3f> outField;
vtkm::cont::Invoker invoke;
invoke(::test_cellneighborhood::Subsample{}, inCellSet, inField, outCellSet, outField);
VTKM_TEST_ASSERT(outField.GetNumberOfValues() == (outDim * outDim * outDim));
vtkm::Id flatIndex = 0;
vtkm::Id3 IJK;
auto outFieldPortal = outField.WritePortal();
for (IJK[2] = 0; IJK[2] < outDim; ++IJK[2])
{
for (IJK[1] = 0; IJK[1] < outDim; ++IJK[1])
{
for (IJK[0] = 0; IJK[0] < outDim; ++IJK[0])
{
vtkm::Vec3f computed = outFieldPortal.Get(flatIndex);
VTKM_TEST_ASSERT(test_equal(computed, 2 * IJK));
++flatIndex;
}
}
}
}
} // anonymous namespace
int UnitTestWorkletCellNeighborhood(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::RunOnDevice(TestWorkletCellNeighborhood, argc, argv);
}

@ -22,6 +22,7 @@
#include <vtkm/cont/DataSet.h> #include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterTag.h> #include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/Invoker.h> #include <vtkm/cont/Invoker.h>
#include <vtkm/cont/RuntimeDeviceTracker.h>
#include <vtkm/cont/testing/MakeTestDataSet.h> #include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h> #include <vtkm/cont/testing/Testing.h>
@ -222,6 +223,7 @@ void TestWorkletPointNeighborhood(vtkm::cont::DeviceAdapterId id)
{ {
std::cout << "Testing Point Neighborhood Worklet on device adapter: " << id.GetName() std::cout << "Testing Point Neighborhood Worklet on device adapter: " << id.GetName()
<< std::endl; << std::endl;
vtkm::cont::ScopedRuntimeDeviceTracker deviceScope(id);
TestMaxNeighborValue(); TestMaxNeighborValue();
TestScatterIdentityNeighbor(); TestScatterIdentityNeighbor();
@ -231,7 +233,7 @@ void TestWorkletPointNeighborhood(vtkm::cont::DeviceAdapterId id)
static void TestMaxNeighborValue() static void TestMaxNeighborValue()
{ {
std::cout << "Testing MaxPointOfCell worklet" << std::endl; std::cout << "Testing MaxNeighborValue worklet" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet; vtkm::cont::testing::MakeTestDataSet testDataSet;
@ -348,7 +350,7 @@ static void TestIndexing()
} // anonymous namespace } // anonymous namespace
int UnitTestWorkletMapPointNeighborhood(int argc, char* argv[]) int UnitTestWorkletPointNeighborhood(int argc, char* argv[])
{ {
return vtkm::cont::testing::Testing::RunOnDevice(TestWorkletPointNeighborhood, argc, argv); return vtkm::cont::testing::Testing::RunOnDevice(TestWorkletPointNeighborhood, argc, argv);
} }