From: Timo Heister Date: Fri, 2 Aug 2024 17:28:53 +0000 (-0400) Subject: fix nvcc compilation in particle handler X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef2e9b3104ee7130a7df794e1eab32c7c8a1cf86;p=dealii.git fix nvcc compilation in particle handler nvcc at least in CUDA 12.5 and 12.6 (current) with gcc 13 is not able to match the implementation with the declaration for two get_properties() functions unless we define them inline. fixes #17148 --- 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)