mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Compare commits
6 Commits
2dc72dde26
...
ff4c189a65
Author | SHA1 | Date | |
---|---|---|---|
|
ff4c189a65 | ||
|
31b9c44fc3 | ||
|
3440dfa9f9 | ||
|
67b0fea23a | ||
|
012853a73b | ||
|
4f0db5f2ea |
10
docs/changelog/fallback-log.md
Normal file
10
docs/changelog/fallback-log.md
Normal file
@ -0,0 +1,10 @@
|
||||
## Added log entry when a cast and call fallback is used
|
||||
|
||||
Several places in VTK-m use the `CastAndCallForTypesWithFallback` method in
|
||||
`UnknownArrayHandle`. The method works well for catching both common and
|
||||
corner cases. However, there was no way to know if the efficient direct
|
||||
method or the (supposedly) less likely fallback of copying data to a float
|
||||
array was used. VTK-m now adds a log event, registered at the "INFO" level,
|
||||
whenever data is copied to a fallback float array. This helps developers
|
||||
monitor the eficiency of their code.
|
||||
|
@ -1207,6 +1207,9 @@ VTKM_CONT void UnknownArrayHandle::CastAndCallForTypesWithFloatFallback(Functor&
|
||||
if (!called)
|
||||
{
|
||||
// Copy to a float array and try again
|
||||
VTKM_LOG_F(vtkm::cont::LogLevel::Info,
|
||||
"Cast and call from %s failed. Copying to basic float array.",
|
||||
this->GetArrayTypeName().c_str());
|
||||
vtkm::cont::UnknownArrayHandle floatArray = this->NewInstanceFloatBasic();
|
||||
floatArray.DeepCopyFrom(*this);
|
||||
vtkm::ListForEach(detail::UnknownArrayHandleTry{},
|
||||
|
@ -295,6 +295,60 @@ void TryNewInstance(vtkm::cont::UnknownArrayHandle originalArray)
|
||||
floatArray.AsArrayHandle(staticFloatArray);
|
||||
}
|
||||
|
||||
template <typename ActualT>
|
||||
struct CheckActualTypeFunctor
|
||||
{
|
||||
template <typename T, typename S>
|
||||
void operator()(const vtkm::cont::ArrayHandle<T, S>& array, bool& called) const
|
||||
{
|
||||
called = true;
|
||||
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
|
||||
auto portal = array.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
T retrieved = portal.Get(i);
|
||||
ActualT expected = TestValue(i, ActualT{});
|
||||
VTKM_TEST_ASSERT(test_equal(retrieved, expected));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void TryCastAndCallFallback()
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle array = CreateArrayUnknown(T{});
|
||||
|
||||
using FallbackTypes = vtkm::List<vtkm::FloatDefault,
|
||||
vtkm::Vec2f,
|
||||
vtkm::Vec3f,
|
||||
vtkm::Vec4f,
|
||||
vtkm::Vec<vtkm::Vec2f, 3>,
|
||||
vtkm::Vec<vtkm::Vec<vtkm::Vec4f, 3>, 2>>;
|
||||
bool called = false;
|
||||
array.CastAndCallForTypesWithFloatFallback<FallbackTypes, vtkm::cont::StorageListBasic>(
|
||||
CheckActualTypeFunctor<T>{}, called);
|
||||
VTKM_TEST_ASSERT(
|
||||
called, "The functor was never called (and apparently a bad value exception not thrown).");
|
||||
}
|
||||
|
||||
void TryCastAndCallFallback()
|
||||
{
|
||||
std::cout << " Scalar array." << std::endl;
|
||||
TryCastAndCallFallback<vtkm::Float64>();
|
||||
|
||||
std::cout << " Equivalent scalar." << std::endl;
|
||||
TryCastAndCallFallback<VTKM_UNUSED_INT_TYPE>();
|
||||
|
||||
std::cout << " Basic Vec." << std::endl;
|
||||
TryCastAndCallFallback<vtkm::Id3>();
|
||||
|
||||
std::cout << " Vec of Vecs." << std::endl;
|
||||
TryCastAndCallFallback<vtkm::Vec<vtkm::Vec2f_32, 3>>();
|
||||
|
||||
std::cout << " Vec of Vecs of Vecs." << std::endl;
|
||||
TryCastAndCallFallback<vtkm::Vec<vtkm::Vec<vtkm::Id4, 3>, 2>>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TryAsMultiplexer(vtkm::cont::UnknownArrayHandle sourceArray)
|
||||
{
|
||||
@ -660,6 +714,9 @@ void TestUnknownArrayHandle()
|
||||
std::cout << "Try AsArrayHandle" << std::endl;
|
||||
TryAsArrayHandle();
|
||||
|
||||
std::cout << "Try CastAndCall with fallback" << std::endl;
|
||||
TryCastAndCallFallback();
|
||||
|
||||
std::cout << "Try ExtractComponent" << std::endl;
|
||||
TryExtractComponent();
|
||||
|
||||
|
@ -233,33 +233,56 @@ vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet1()
|
||||
constexpr vtkm::Id nVerts = 125;
|
||||
constexpr vtkm::Id nCells = 64;
|
||||
constexpr vtkm::Float32 pointvar[nVerts] = {
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 0, 0
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 1, 0
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 2, 0
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 3, 0
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 4, 0
|
||||
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 99.0f, 90.0f, 85.0f, 0.0f, 0.0f, 95.0f, 80.0f,
|
||||
95.0f, 0.0f, 0.0f, 85.0f, 90.0f, 99.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 0, 1
|
||||
0.0f, 99.0f, 90.0f, 85.0f, 0.0f, // 0-4, 1, 1
|
||||
0.0f, 95.0f, 80.0f, 95.0f, 0.0f, // 0-4, 2, 1
|
||||
0.0f, 85.0f, 90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.0f
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 0, 4
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 1, 4
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 2, 4
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 3, 4
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f // 0-4, 4, 4
|
||||
};
|
||||
constexpr vtkm::Float32 cellvar[nCells] = {
|
||||
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f,
|
||||
8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f,
|
||||
0.0f, 1.0f, 2.0f, 3.0f, // 0-3, 0, 0
|
||||
4.0f, 5.0f, 6.0f, 7.0f, // 0-3, 1, 0
|
||||
8.0f, 9.0f, 10.0f, 11.0f, // 0-3, 2, 0
|
||||
12.0f, 13.0f, 14.0f, 15.0f, // 0-3, 3, 0
|
||||
|
||||
16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f,
|
||||
24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f,
|
||||
16.0f, 17.0f, 18.0f, 19.0f, // 0-3, 0, 1
|
||||
20.0f, 21.0f, 22.0f, 23.0f, // 0-3, 1, 1
|
||||
24.0f, 25.0f, 26.0f, 27.0f, // 0-3, 2, 1
|
||||
28.0f, 29.0f, 30.0f, 31.0f, // 0-3, 3, 1
|
||||
|
||||
32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
|
||||
40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f,
|
||||
32.0f, 33.0f, 34.0f, 35.0f, // 0-3, 0, 2
|
||||
36.0f, 37.0f, 38.0f, 39.0f, // 0-3, 1, 2
|
||||
40.0f, 41.0f, 42.0f, 43.0f, // 0-3, 2, 2
|
||||
44.0f, 45.0f, 46.0f, 47.0f, // 0-3, 3, 2
|
||||
|
||||
48.0f, 49.0f, 50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f,
|
||||
56.0f, 57.0f, 58.0f, 59.0f, 60.0f, 61.0f, 62.0f, 63.0f
|
||||
48.0f, 49.0f, 50.0f, 51.0f, // 0-3, 0, 3
|
||||
52.0f, 53.0f, 54.0f, 55.0f, // 0-3, 1, 3
|
||||
56.0f, 57.0f, 58.0f, 59.0f, // 0-3, 2, 3
|
||||
60.0f, 61.0f, 62.0f, 63.0f // 0-3, 3, 3
|
||||
};
|
||||
|
||||
dataSet.AddPointField("pointvar", pointvar, nVerts);
|
||||
|
@ -85,17 +85,23 @@ public:
|
||||
VTKM_CONT
|
||||
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
|
||||
|
||||
// Get if we should include the outer boundary on a subsample
|
||||
// (NOTE: This method is deprecated because it is not clear from either
|
||||
// the documentation or the source code what the intention of this feature
|
||||
// is. If your are using this method somewhere and think it should remain,
|
||||
// please open a merge request to "de-deprecate" it and add a test and
|
||||
// documentation of the expected behavior.)
|
||||
VTKM_DEPRECATED(2.2)
|
||||
/// @brief Specifies if the outer boundary should always be included.
|
||||
///
|
||||
/// When a subsample rate is specified, it is possible that some of the
|
||||
/// boundary samples will not be included in the sampling. If this is the
|
||||
/// case and `IncludeBoundary` is set to true, then an extra sample is
|
||||
/// set in the output and the values on the boundary are included. For example,
|
||||
/// say the input has resolution (5, 5, 1) (and the VOI matches), and the sample
|
||||
/// rate is set to (3, 3, 1). If `IncludeBoundary` is false, then the output will
|
||||
/// have the 4 points that correspond to the 3D indices (0, 0, 0), (3, 0, 0),
|
||||
/// (0, 3, 0), and (3, 3, 0) of the input. This misses the outer boundary at
|
||||
/// index 4 in the x and y directions. If `IncludeBoundary is set to true, then
|
||||
/// the output will have the 9 points that correspond to the 3D indices (0, 0, 0),
|
||||
/// (3, 0, 0), (4, 0, 0), (0, 3, 0), (3, 3, 0), (4, 3, 0), (0, 4, 0), (3, 4, 0),
|
||||
/// and (4, 4, 0) to capture this outer boundary.
|
||||
VTKM_CONT
|
||||
bool GetIncludeBoundary() const { return this->IncludeBoundary; }
|
||||
// Set if we should include the outer boundary on a subsample
|
||||
VTKM_DEPRECATED(2.2)
|
||||
/// @copydoc GetIncludeBoundary
|
||||
VTKM_CONT
|
||||
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
|
||||
|
||||
|
@ -341,7 +341,7 @@ public:
|
||||
|
||||
static void TestUniform3D7()
|
||||
{
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
std::cout << "Testing extract structured uniform, exclude boundary" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
@ -351,6 +351,7 @@ public:
|
||||
vtkm::Id3 sample(3, 3, 2);
|
||||
extract.SetVOI(range);
|
||||
extract.SetSampleRate(sample);
|
||||
extract.SetIncludeBoundary(false); // default
|
||||
|
||||
extract.SetFieldsToPass({ "pointvar", "cellvar" });
|
||||
vtkm::cont::DataSet output = extract.Execute(dataset);
|
||||
@ -371,16 +372,16 @@ public:
|
||||
"Data/Geometry mismatch for ExtractStructured filter");
|
||||
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(0) == 0.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(3) == 99.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(4) == 0.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(7) == 97.0f, "Wrong point field data");
|
||||
|
||||
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(0) == 16.0f, "Wrong cell field data");
|
||||
}
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
// This test repeates TestUniform3D7 but uses deprecated behavior.
|
||||
static void TestUniform3D8()
|
||||
{
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
std::cout << "Testing extract structured uniform, include boundary" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
@ -411,12 +412,15 @@ public:
|
||||
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(0) == 0.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(4) == 99.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(5) == 0.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(7) == 0.0f, "Wrong point field data");
|
||||
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(13) == 97.0f, "Wrong point field data");
|
||||
|
||||
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(0) == 16.0f, "Wrong cell field data");
|
||||
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(1) == 19.0f, "Wrong cell field data");
|
||||
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(2) == 28.0f, "Wrong cell field data");
|
||||
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(3) == 31.0f, "Wrong cell field data");
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
static void TestRectilinear2D()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user