Skip to content

Commit

Permalink
#11: fix "calling a constexpr __host__ function from a __host__ __dev…
Browse files Browse the repository at this point in the history
…ice__ function" warnings
  • Loading branch information
cz4rs committed Sep 18, 2024
1 parent 1cdf063 commit 272f320
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
40 changes: 22 additions & 18 deletions src/bvh/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@
#ifndef INC_BVH_TRAITS_HPP
#define INC_BVH_TRAITS_HPP

#include <Kokkos_Macros.hpp>

#include <type_traits>

namespace bvh
{
template< typename... >
using void_t = void;

template< unsigned N >
struct overload_priority
: overload_priority< N - 1 >
{
};

template<>
struct overload_priority< 0 >
{};

namespace detail
{
template< typename Element >
Expand All @@ -56,79 +60,79 @@ namespace bvh
{
return get_entity_kdop( _element );
}

template< typename Element >
constexpr auto get_kdop_impl( const Element &_element, overload_priority< 0 > )
-> decltype( _element.kdop() )
{
return _element.kdop();
}

template< typename Element >
constexpr auto get_kdop( const Element &_element )
{
return get_kdop_impl( _element, overload_priority< 1 >{} );
}

template< typename Element >
constexpr auto get_centroid_impl( const Element &_element, overload_priority< 1 > )
-> decltype( get_entity_centroid( _element ) )
{
return get_entity_centroid( _element );
}

template< typename Element >
constexpr auto get_centroid_impl( const Element &_element, overload_priority< 0 > )
-> decltype( _element.centroid() )
{
return _element.centroid();
}

template< typename Element >
constexpr auto get_centroid( const Element &_element )
{
return get_centroid_impl( _element, overload_priority< 1 >{} );
}

template< typename Element >
constexpr auto get_global_id_impl( const Element &_element, overload_priority< 1 > )
-> decltype( get_entity_global_id( _element ) )
{
return get_entity_global_id( _element );
}

template< typename Element >
constexpr auto get_global_id_impl( const Element &_element, overload_priority< 0 > )
-> decltype( _element.global_id() )
{
return _element.global_id();
}

template< typename Element >
constexpr auto get_global_id( const Element &_element )
{
return get_global_id_impl( _element, overload_priority< 1 >{} );
}
}

template< typename Element >
struct element_traits
{
using kdop_type = std::remove_cv_t< std::remove_reference_t< decltype( detail::get_kdop( std::declval< Element >() ) ) > >;
using centroid_type = std::remove_cv_t< std::remove_reference_t< decltype( detail::get_centroid( std::declval< Element >() ) ) > >;
using global_id_type = std::remove_cv_t< std::remove_reference_t< decltype( detail::get_global_id( std::declval< Element >() ) ) > >;
static constexpr kdop_type get_kdop( const Element &_element )

static constexpr KOKKOS_INLINE_FUNCTION kdop_type get_kdop( const Element &_element )
{
return detail::get_kdop( _element );
}
static constexpr centroid_type get_centroid( const Element &_element )

static constexpr KOKKOS_INLINE_FUNCTION centroid_type get_centroid( const Element &_element )
{
return detail::get_centroid( _element );
}
static constexpr global_id_type get_global_id( const Element &_element )

static constexpr KOKKOS_INLINE_FUNCTION global_id_type get_global_id( const Element &_element )
{
return detail::get_global_id( _element );
}
Expand Down
3 changes: 2 additions & 1 deletion src/bvh/util/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <type_traits>
#include "assert.hpp"
#include <array>
#include <Kokkos_Macros.hpp>
#include "../range.hpp"

namespace bvh
Expand Down Expand Up @@ -174,7 +175,7 @@ namespace bvh
constexpr index_type size_bytes() const noexcept { return m_count * sizeof( element_type ); }
constexpr bool empty() const noexcept { return m_count == 0; }

constexpr reference operator[]( index_type _idx ) const
constexpr KOKKOS_INLINE_FUNCTION reference operator[]( index_type _idx ) const
{
BVH_ASSERT( _idx < m_count );
return m_data[_idx];
Expand Down

0 comments on commit 272f320

Please sign in to comment.