Replace static datasets with dynamically allocated versions.

The static datasets were wreaking havoc on order of destructors at exit and causing kokkos to throw an exception. This change dynamically allocates a dataset, copies the read/sourced data into it, and explicitly frees the data.
This commit is contained in:
Mark Bolstad 2022-02-17 13:09:29 -05:00 committed by Mark Bolstad
parent 16cdb00c6a
commit 19f90b96e0

@ -13,7 +13,6 @@
#include <vtkm/Math.h>
#include <vtkm/Range.h>
#include <vtkm/VecTraits.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
@ -28,21 +27,21 @@
#include <vtkm/cont/internal/OptionParser.h>
#include <vtkm/filter/CellAverage.h>
#include <vtkm/filter/Contour.h>
#include <vtkm/filter/ExternalFaces.h>
#include <vtkm/filter/FieldSelection.h>
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/PointAverage.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/entity_extraction/ExternalFaces.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/entity_extraction/ThresholdPoints.h>
#include <vtkm/filter/field_conversion/CellAverage.h>
#include <vtkm/filter/field_conversion/PointAverage.h>
#include <vtkm/filter/field_transform/WarpScalar.h>
#include <vtkm/filter/field_transform/WarpVector.h>
#include <vtkm/filter/geometry_refinement/Tetrahedralize.h>
#include <vtkm/filter/geometry_refinement/Triangulate.h>
#include <vtkm/filter/geometry_refinement/VertexClustering.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/ThresholdPoints.h>
#include <vtkm/filter/Triangulate.h>
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/VertexClustering.h>
#include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/WarpVector.h>
#include <vtkm/io/VTKDataSetReader.h>
@ -118,7 +117,7 @@ void BenchGradient(::benchmark::State& state, int options)
{
const vtkm::cont::DeviceAdapterId device = Config.Device;
vtkm::filter::vector_analysis::Gradient filter;
vtkm::filter::Gradient filter;
if (options & ScalarInput)
{
@ -128,11 +127,11 @@ void BenchGradient(::benchmark::State& state, int options)
throw vtkm::cont::ErrorInternal("A requested gradient output is "
"incompatible with scalar input.");
}
filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::Points);
filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS);
}
else
{
filter.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::Points);
filter.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::POINTS);
}
filter.SetComputeGradient(static_cast<bool>(options & Gradient));
@ -186,7 +185,7 @@ void BenchThreshold(::benchmark::State& state)
// Lookup the point scalar range
const auto range = []() -> vtkm::Range {
auto ptScalarField =
InputDataSet.GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
GetInputDataSet().GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
return ptScalarField.GetRange().ReadPortal().Get(0);
}();
@ -204,7 +203,7 @@ void BenchThreshold(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -221,7 +220,7 @@ void BenchThresholdPoints(::benchmark::State& state)
// Lookup the point scalar range
const auto range = []() -> vtkm::Range {
auto ptScalarField =
InputDataSet.GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
GetInputDataSet().GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
return ptScalarField.GetRange().ReadPortal().Get(0);
}();
@ -240,7 +239,7 @@ void BenchThresholdPoints(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -261,7 +260,7 @@ void BenchCellAverage(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -282,7 +281,7 @@ void BenchPointAverage(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -305,7 +304,7 @@ void BenchWarpScalar(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -327,7 +326,7 @@ void BenchWarpVector(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -352,7 +351,8 @@ void BenchContour(::benchmark::State& state)
// Set up some equally spaced contours, with the min/max slightly inside the
// scalar range:
const vtkm::Range scalarRange = []() -> vtkm::Range {
auto field = InputDataSet.GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
auto field =
GetInputDataSet().GetField(PointScalarsName, vtkm::cont::Field::Association::Points);
return field.GetRange().ReadPortal().Get(0);
}();
const auto step = scalarRange.Length() / static_cast<vtkm::Float64>(numIsoVals + 1);
@ -371,7 +371,7 @@ void BenchContour(::benchmark::State& state)
vtkm::cont::Timer timer{ device };
vtkm::cont::DataSet input = isStructured ? InputDataSet : UnstructuredInputDataSet;
vtkm::cont::DataSet input = isStructured ? GetInputDataSet() : GetUnstructuredInputDataSet();
for (auto _ : state)
{
@ -421,7 +421,7 @@ void BenchExternalFaces(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -447,7 +447,7 @@ void BenchTetrahedralize(::benchmark::State& state)
{
(void)_;
timer.Start();
auto result = filter.Execute(InputDataSet);
auto result = filter.Execute(GetInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -476,7 +476,7 @@ void BenchVertexClustering(::benchmark::State& state)
(void)_;
timer.Start();
auto result = filter.Execute(UnstructuredInputDataSet);
auto result = filter.Execute(GetUnstructuredInputDataSet());
::benchmark::DoNotOptimize(result);
timer.Stop();
@ -541,7 +541,7 @@ void BenchReverseConnectivityGen(::benchmark::State& state)
state.SkipWithError("ReverseConnectivityGen requires unstructured data (--use tetra).");
}
auto cellset = UnstructuredInputDataSet.GetCellSet();
auto cellset = GetUnstructuredInputDataSet().GetCellSet();
PrepareForInput functor;
for (auto _ : state)
{
@ -624,9 +624,9 @@ void FindFields()
{
if (PointScalarsName.empty())
{
for (vtkm::Id i = 0; i < InputDataSet.GetNumberOfFields(); ++i)
for (vtkm::Id i = 0; i < GetInputDataSet().GetNumberOfFields(); ++i)
{
auto field = InputDataSet.GetField(i);
auto field = GetInputDataSet().GetField(i);
if (field.GetAssociation() == vtkm::cont::Field::Association::Points &&
NumberOfComponents::Check(field) == 1)
{
@ -639,9 +639,9 @@ void FindFields()
if (CellScalarsName.empty())
{
for (vtkm::Id i = 0; i < InputDataSet.GetNumberOfFields(); ++i)
for (vtkm::Id i = 0; i < GetInputDataSet().GetNumberOfFields(); ++i)
{
auto field = InputDataSet.GetField(i);
auto field = GetInputDataSet().GetField(i);
if (field.GetAssociation() == vtkm::cont::Field::Association::Cells &&
NumberOfComponents::Check(field) == 1)
{
@ -654,9 +654,9 @@ void FindFields()
if (PointVectorsName.empty())
{
for (vtkm::Id i = 0; i < InputDataSet.GetNumberOfFields(); ++i)
for (vtkm::Id i = 0; i < GetInputDataSet().GetNumberOfFields(); ++i)
{
auto field = InputDataSet.GetField(i);
auto field = GetInputDataSet().GetField(i);
if (field.GetAssociation() == vtkm::cont::Field::Association::Points &&
NumberOfComponents::Check(field) == 3)
{
@ -674,7 +674,7 @@ void CreateMissingFields()
if (PointVectorsName.empty())
{
// Construct them from the coordinates:
auto coords = InputDataSet.GetCoordinateSystem();
auto coords = GetInputDataSet().GetCoordinateSystem();
auto bounds = coords.GetBounds();
auto points = coords.GetData();
vtkm::cont::ArrayHandle<vtkm::Vec3f> pvecs;
@ -682,7 +682,7 @@ void CreateMissingFields()
PointVectorGenerator worklet(bounds);
vtkm::worklet::DispatcherMapField<PointVectorGenerator> dispatch(worklet);
dispatch.Invoke(points, pvecs);
InputDataSet.AddField(
GetInputDataSet().AddField(
vtkm::cont::Field("GeneratedPointVectors", vtkm::cont::Field::Association::Points, pvecs));
PointVectorsName = "GeneratedPointVectors";
std::cerr << "[CreateFields] Generated point vectors '" << PointVectorsName
@ -696,8 +696,8 @@ void CreateMissingFields()
vtkm::filter::field_conversion::PointAverage avg;
avg.SetActiveField(CellScalarsName, vtkm::cont::Field::Association::Cells);
avg.SetOutputFieldName("GeneratedPointScalars");
auto outds = avg.Execute(InputDataSet);
InputDataSet.AddField(
auto outds = avg.Execute(GetInputDataSet());
GetInputDataSet().AddField(
outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::Points));
PointScalarsName = "GeneratedPointScalars";
std::cerr << "[CreateFields] Generated point scalars '" << PointScalarsName
@ -710,8 +710,8 @@ void CreateMissingFields()
vtkm::filter::vector_analysis::VectorMagnitude mag;
mag.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::Points);
mag.SetOutputFieldName("GeneratedPointScalars");
auto outds = mag.Execute(InputDataSet);
InputDataSet.AddField(
auto outds = mag.Execute(GetInputDataSet());
GetInputDataSet().AddField(
outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::Points));
PointScalarsName = "GeneratedPointScalars";
std::cerr << "[CreateFields] Generated point scalars '" << PointScalarsName
@ -725,8 +725,8 @@ void CreateMissingFields()
vtkm::filter::field_conversion::CellAverage avg;
avg.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::Points);
avg.SetOutputFieldName("GeneratedCellScalars");
auto outds = avg.Execute(InputDataSet);
InputDataSet.AddField(
auto outds = avg.Execute(GetInputDataSet());
GetInputDataSet().AddField(
outds.GetField("GeneratedCellScalars", vtkm::cont::Field::Association::Cells));
CellScalarsName = "GeneratedCellScalars";
std::cerr << "[CreateFields] Generated cell scalars '" << CellScalarsName
@ -950,7 +950,8 @@ void InitDataSet(int& argc, char** argv)
{
std::cerr << "[InitDataSet] Loading file: " << filename << "\n";
vtkm::io::VTKDataSetReader reader(filename);
InputDataSet = reader.ReadDataSet();
InputDataSet = new vtkm::cont::DataSet;
*InputDataSet = reader.ReadDataSet();
FileAsInput = true;
}
else
@ -960,7 +961,8 @@ void InitDataSet(int& argc, char** argv)
vtkm::source::Wavelet source;
source.SetExtent({ 0 }, { waveletDim - 1 });
InputDataSet = source.Execute();
InputDataSet = new vtkm::cont::DataSet;
*InputDataSet = source.Execute();
}
FindFields();
@ -970,11 +972,12 @@ void InitDataSet(int& argc, char** argv)
<< "[InitDataSet] Create UnstructuredInputDataSet from Tetrahedralized InputDataSet...\n";
vtkm::filter::geometry_refinement::Tetrahedralize tet;
tet.SetFieldsToPass(vtkm::filter::FieldSelection(vtkm::filter::FieldSelection::Mode::All));
UnstructuredInputDataSet = tet.Execute(InputDataSet);
UnstructuredInputDataSet = new vtkm::cont::DataSet;
*UnstructuredInputDataSet = tet.Execute(GetInputDataSet());
if (tetra)
{
InputDataSet = UnstructuredInputDataSet;
GetInputDataSet() = GetUnstructuredInputDataSet();
}
inputGenTimer.Stop();
@ -1004,10 +1007,12 @@ int main(int argc, char* argv[])
const std::string dataSetSummary = []() -> std::string {
std::ostringstream out;
InputDataSet.PrintSummary(out);
GetInputDataSet().PrintSummary(out);
return out.str();
}();
// handle benchmarking related args and run benchmarks:
VTKM_EXECUTE_BENCHMARKS_PREAMBLE(argc, args.data(), dataSetSummary);
delete InputDataSet;
delete UnstructuredInputDataSet;
}