mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'fallback-log'
4f0db5f2e Added log entry when a cast and call fallback is used Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Merge-request: !3242
This commit is contained in:
commit
e64a0d508f
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user