From 5bdd3c7bc2c524a3ddf52de8d27518d0c77c0aea Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 16 May 2023 12:36:47 -0600 Subject: [PATCH] Move ArrayHandleRuntimeVec metadata to a separate class Originally, the metadata structure used by the `ArrayHandleRuntimeVec` storage was a nested class of its `Storage`. But the `Storage` is templated on the component type, and the metadata object is the same regardless. In addition to the typical minor issue of having the compiler create several identical classes, this caused problems when pulling arrays from equivalent but technically different C types (for example, `long` is the same as either `int` or `long long`). --- vtkm/cont/ArrayHandleRuntimeVec.h | 10 ++++++---- vtkm/cont/testing/UnitTestUnknownArrayHandle.cxx | 13 +++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/vtkm/cont/ArrayHandleRuntimeVec.h b/vtkm/cont/ArrayHandleRuntimeVec.h index 8b6575796..c7ef442fc 100644 --- a/vtkm/cont/ArrayHandleRuntimeVec.h +++ b/vtkm/cont/ArrayHandleRuntimeVec.h @@ -133,6 +133,11 @@ struct VTKM_ALWAYS_EXPORT StorageTagRuntimeVec namespace internal { +struct RuntimeVecMetaData +{ + vtkm::IdComponent NumberOfComponents; +}; + template class Storage, vtkm::cont::StorageTagRuntimeVec> { @@ -152,10 +157,7 @@ class Storage, vtkm::cont::StorageTagRunti (std::is_same::value), "Used invalid ComponentsPortal type with expected ComponentsStorageTag."); - struct Info - { - vtkm::IdComponent NumberOfComponents; - }; + using Info = RuntimeVecMetaData; VTKM_CONT static std::vector ComponentsBuffers( const std::vector& buffers) diff --git a/vtkm/cont/testing/UnitTestUnknownArrayHandle.cxx b/vtkm/cont/testing/UnitTestUnknownArrayHandle.cxx index b8ae60a62..6b9f8045c 100644 --- a/vtkm/cont/testing/UnitTestUnknownArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestUnknownArrayHandle.cxx @@ -544,11 +544,10 @@ void TrySetMultiplexerArray() CheckUnknownArray, vtkm::List>(unknownArray, 1); } -template +template ::ComponentType> void TryConvertRuntimeVec() { using BasicArrayType = vtkm::cont::ArrayHandle; - using BasicComponentType = typename vtkm::VecFlat::ComponentType; constexpr vtkm::IdComponent numFlatComponents = vtkm::VecFlat::NUM_COMPONENTS; using RuntimeArrayType = vtkm::cont::ArrayHandleRuntimeVec; @@ -614,6 +613,16 @@ void TryConvertRuntimeVec() std::cout << " Vec of Vecs of Vecs." << std::endl; TryConvertRuntimeVec, 2>>(); + + std::cout << " Compatible but different C types." << std::endl; + if (sizeof(int) == sizeof(long)) + { + TryConvertRuntimeVec, long>(); + } + else // assuming sizeof(long long) == sizeof(long) + { + TryConvertRuntimeVec, long>(); + } } struct DefaultTypeFunctor