diff --git a/include/plsm/Subpaving.h b/include/plsm/Subpaving.h index eeb2155..5e2dd77 100644 --- a/include/plsm/Subpaving.h +++ b/include/plsm/Subpaving.h @@ -37,7 +37,7 @@ struct SubpavingTester; * @test benchmark_Subpaving.cpp */ template + typename TItemData = void, typename TMemSpace = DefaultMemSpace> class Subpaving { template diff --git a/include/plsm/Tile.h b/include/plsm/Tile.h index 453c0bc..396bbc8 100644 --- a/include/plsm/Tile.h +++ b/include/plsm/Tile.h @@ -8,6 +8,79 @@ namespace plsm { +template +struct TileData +{ + //! Alias for Region + using RegionType = TRegion; + //! User data type to be mapped from Tile + using ItemType = TItem; + + KOKKOS_INLINE_FUNCTION + decltype(auto) + getItem() noexcept + { + return item; + } + + KOKKOS_INLINE_FUNCTION + decltype(auto) + getItem() const noexcept + { + return item; + } + + template + KOKKOS_INLINE_FUNCTION + void + setItem(T&& v) + { + item = std::forward(v); + } + + //! Region mapped from by this Tile + RegionType region; + //! Index of owning Zone + IdType owningZoneId{invalid}; + + static_assert(std::is_integral_v); + //! Mapped user data item + ItemType item{invalid}; +}; + +template +struct TileData +{ + //! Alias for Region + using RegionType = TRegion; + + KOKKOS_INLINE_FUNCTION + decltype(auto) + getItem() noexcept + { + return invalid; + } + + KOKKOS_INLINE_FUNCTION + decltype(auto) + getItem() const noexcept + { + return invalid; + } + + template + KOKKOS_INLINE_FUNCTION + void + setItem([[maybe_unused]] T&&) + { + } + + //! Region mapped from by this Tile + RegionType region; + //! Index of owning Zone + IdType owningZoneId{invalid}; +}; + /*! * @brief Tile is used as a non-overlapped lattice region * @@ -19,7 +92,7 @@ namespace plsm * * @test test_Tile.cpp */ -template +template class Tile { public: @@ -38,11 +111,10 @@ class Tile */ KOKKOS_INLINE_FUNCTION Tile(const RegionType& region, IdType owningZoneId) : - _region(region), _owningZoneId(owningZoneId) + _data{region, owningZoneId} { } - //!@{ /*! * @brief Get/Set the Region mapped from by this Tile */ @@ -50,16 +122,18 @@ class Tile const RegionType& getRegion() const noexcept { - return _region; + return _data.region; } + /*! + * @brief Check if this tile has a valid owning zone id + */ KOKKOS_INLINE_FUNCTION bool hasOwningZone() const noexcept { - return _owningZoneId != invalid; + return _data.owningZoneId != invalid; } - //!} //!@{ /*! @@ -69,14 +143,14 @@ class Tile IdType getOwningZoneIndex() const noexcept { - return _owningZoneId; + return _data.owningZoneId; } KOKKOS_INLINE_FUNCTION void setOwningZoneIndex(IdType id) noexcept { - _owningZoneId = id; + _data.owningZoneId = id; } //!@} @@ -87,7 +161,7 @@ class Tile bool hasData() const noexcept { - return _data != invalid; + return !isInvalid(_data.getItem()); } //!@{ @@ -95,45 +169,29 @@ class Tile * @brief Get/Set mapped data item */ KOKKOS_INLINE_FUNCTION - ItemDataType& + decltype(auto) getData() noexcept { - return _data; + return _data.getItem(); } KOKKOS_INLINE_FUNCTION - const ItemDataType& + decltype(auto) getData() const noexcept { - return _data; - } - - KOKKOS_INLINE_FUNCTION - void - setData(const ItemDataType& data) - { - _data = data; + return _data.getItem(); } + template KOKKOS_INLINE_FUNCTION void - setData(ItemDataType&& data) + setData(T&& data) { - _data = std::move(data); + _data.setItem(std::forward(data)); } //!@} private: - //! Region mapped from by this Tile - RegionType _region; - //! Index of owning Zone - IdType _owningZoneId{invalid}; - - // FIXME: Idea would be to use optional to hold arbitrary - // data in a Tile. It needs to be initialized to an invalid state. - static_assert(std::is_same::value, - "Only IdType supported for now"); - //! Mapped user data item - ItemDataType _data{invalid}; + TileData _data; }; } // namespace plsm diff --git a/include/plsm/Utility.h b/include/plsm/Utility.h index 4210202..353663d 100644 --- a/include/plsm/Utility.h +++ b/include/plsm/Utility.h @@ -16,6 +16,14 @@ using DimType = std::size_t; template inline constexpr T invalid = std::numeric_limits::max() - static_cast(1); +template +KOKKOS_INLINE_FUNCTION +constexpr bool +isInvalid(const T& val) noexcept +{ + return val == invalid; +} + //! Convention chosen to represent a wildcard value for the given type template inline constexpr T wildcard = std::numeric_limits::max(); diff --git a/test/include/plsm/RenderSubpaving.h b/test/include/plsm/RenderSubpaving.h index 5ce7592..2b4cca1 100644 --- a/test/include/plsm/RenderSubpaving.h +++ b/test/include/plsm/RenderSubpaving.h @@ -156,6 +156,7 @@ inline void renderSubpaving(Subpaving& subpaving) { std::cout << "\nNumber of Tiles: " << subpaving.getNumberOfTiles() + << "\nMemory Size: " << subpaving.getDeviceMemorySize() << std::endl; } } // namespace test diff --git a/test/unittest_Tile.cpp b/test/unittest_Tile.cpp index 06b42a3..b6d0686 100644 --- a/test/unittest_Tile.cpp +++ b/test/unittest_Tile.cpp @@ -15,7 +15,7 @@ TEMPLATE_LIST_TEST_CASE("Tile Basic", "[Tile][template]", test::IntTypes) using Ival = typename RegionType::IntervalType; RegionType r1{Ival{12}, Ival{8}}; - TileType t1{r1, 0}; + Tile t1{r1, 0}; REQUIRE(t1.hasOwningZone()); REQUIRE(t1.getOwningZoneIndex() == 0); REQUIRE(!t1.getRegion().empty());