From a0be6837436897790517013727eb90ed42e773f5 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 6 Aug 2024 15:40:42 -0400 Subject: [PATCH] Merge pull request #17425 from tjhei/nvcc-particle-get_prop-hack fix nvcc compilation in particle handler --- include/deal.II/particles/particle_accessor.h | 27 ++++++--- include/deal.II/particles/property_pool.h | 55 +++++++++++-------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 0d0706dfbd..a4ff6dba1a 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -326,7 +326,21 @@ namespace Particles * @return An ArrayView of the properties of this particle. */ ArrayView - get_properties(); + get_properties() + { + // The implementation is up here inside the class declaration because + // NVCC (at least in 12.5 and 12.6) otherwise produce a compile error: + // + // error: no declaration matches ‘dealii::ArrayView<__remove_cv(const + // double)> dealii::Particles::ParticleAccessor::get_properties()’ + // + // See https://github.com/dealii/dealii/issues/17148 + Assert(state() == IteratorState::valid, ExcInternalError()); + + return property_pool->get_properties(get_handle()); + } + /** * Get read-access to properties of this particle. @@ -840,14 +854,9 @@ namespace Particles - template - inline ArrayView - ParticleAccessor::get_properties() - { - Assert(state() == IteratorState::valid, ExcInternalError()); - - return property_pool->get_properties(get_handle()); - } + // template + // inline ArrayView + // ParticleAccessor::get_properties() diff --git a/include/deal.II/particles/property_pool.h b/include/deal.II/particles/property_pool.h index 5ce9ce3b06..d8f868d39d 100644 --- a/include/deal.II/particles/property_pool.h +++ b/include/deal.II/particles/property_pool.h @@ -202,8 +202,36 @@ namespace Particles * Return an ArrayView to the properties that correspond to the given * handle @p handle. */ - ArrayView - get_properties(const Handle handle); + ArrayView + get_properties(const Handle handle) + { + // The implementation is up here inside the class declaration because + // NVCC (at least in 12.5 and 12.6) otherwise produce a compile error: + // + // error: no declaration matches ‘dealii::ArrayView<__remove_cv(const + // double)> dealii::Particles::PropertyPool::get_properties(Handle)’ + // + // See https://github.com/dealii/dealii/issues/17148 + + const std::vector::size_type data_index = + (handle != invalid_handle) ? handle * n_properties : 0; + + // Ideally we would need to assert that 'handle' has not been deallocated + // by searching through 'currently_available_handles'. However, this + // is expensive and this function is performance critical, so instead + // just check against the array range, and rely on the fact + // that handles are invalidated when handed over to + // deallocate_properties_array(). + Assert(data_index <= properties.size() - n_properties, + ExcMessage( + "Invalid property handle. This can happen if the " + "handle was duplicated and then one copy was deallocated " + "before trying to access the properties.")); + + return ArrayView(properties.data() + data_index, n_properties); + } + /** * Reserve the dynamic memory needed for storing the properties of @@ -455,26 +483,9 @@ namespace Particles - template - inline ArrayView - PropertyPool::get_properties(const Handle handle) - { - const std::vector::size_type data_index = - (handle != invalid_handle) ? handle * n_properties : 0; - - // Ideally we would need to assert that 'handle' has not been deallocated - // by searching through 'currently_available_handles'. However, this - // is expensive and this function is performance critical, so instead - // just check against the array range, and rely on the fact - // that handles are invalidated when handed over to - // deallocate_properties_array(). - Assert(data_index <= properties.size() - n_properties, - ExcMessage("Invalid property handle. This can happen if the " - "handle was duplicated and then one copy was deallocated " - "before trying to access the properties.")); - - return ArrayView(properties.data() + data_index, n_properties); - } + // template + // inline ArrayView + // PropertyPool::get_properties(const Handle handle) -- 2.39.5