Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-v2.0' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipFackler committed Dec 8, 2021
2 parents fc76007 + ecc98c7 commit d168f28
Show file tree
Hide file tree
Showing 15 changed files with 695 additions and 601 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(plsm
VERSION 1.1.0
VERSION 2.0.0
LANGUAGES CXX
)

Expand All @@ -26,7 +26,6 @@ set(PLSM_HEADERS
${PLSM_HEADER_DIR}/refine/PolylineDetector.h
${PLSM_HEADER_DIR}/refine/RegionDetector.h
${PLSM_HEADER_DIR}/CompactFlat.h
${PLSM_HEADER_DIR}/ContextUtility.h
${PLSM_HEADER_DIR}/EnumIndexed.h
${PLSM_HEADER_DIR}/Interval.h
${PLSM_HEADER_DIR}/IntervalRange.h
Expand Down
103 changes: 0 additions & 103 deletions include/plsm/ContextUtility.h

This file was deleted.

166 changes: 98 additions & 68 deletions include/plsm/Subpaving.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
#include <vector>

#include <Kokkos_Core.hpp>
#include <Kokkos_DualView.hpp>

#include <plsm/ContextUtility.h>
#include <plsm/EnumIndexed.h>
#include <plsm/Utility.h>
#include <plsm/Zone.h>
#include <plsm/detail/Refiner.h>
#include <plsm/detail/SubdivisionInfo.h>

namespace plsm
{
namespace test
{
template <typename>
struct SubpavingTester;
}
/*!
* @brief A set of non-overlapping "tiles" which cover the space within a given
* Region of an N-dimensional lattice
Expand All @@ -33,13 +37,20 @@ namespace plsm
* @test benchmark_Subpaving.cpp
*/
template <typename TScalar, DimType Dim, typename TEnumIndex = void,
typename TItemData = IdType>
typename TItemData = IdType, typename TMemSpace = DefaultMemSpace>
class Subpaving
{
template <typename>
friend class ::plsm::test::SubpavingTester;

template <typename TSubpaving, typename TSelector>
friend class detail::Refiner;

static_assert(Kokkos::is_memory_space<TMemSpace>{});

public:
//! The memory space for the subpaving data
using MemorySpace = TMemSpace;
//! Underlying type for scalar representation for the lattice
using ScalarType = TScalar;
//! The type to represent lattice regions
Expand All @@ -53,21 +64,30 @@ class Subpaving

//! The subdivision Zone
using ZoneType = Zone<RegionType>;
//! The type for the set of zones (host/device synchronized)
using ZonesDualView = Kokkos::DualView<ZoneType*>;
//! The type for the set of zones on the given memory space
template <typename TContext>
using ZonesView = detail::ContextualViewType<ZonesDualView, TContext>;
using ZonesView = Kokkos::View<ZoneType*, MemorySpace>;
//! Read-only random-access view of zones
using ZonesRAView =
Kokkos::View<const ZoneType*, MemorySpace, Kokkos::MemoryRandomAccess>;

//! The subpaving Tile
using TileType = Tile<RegionType, ItemDataType>;
//! The type for the set of tiles (host/device synchronized)
using TilesDualView = Kokkos::DualView<TileType*>;
//! The type for the set of tiles on the given memory space
template <typename TContext>
using TilesView = detail::ContextualViewType<TilesDualView, TContext>;
using TilesView = Kokkos::View<TileType*, MemorySpace>;
//! Read-only random-access view of tiles
using TilesRAView =
Kokkos::View<const TileType*, MemorySpace, Kokkos::MemoryRandomAccess>;

Subpaving() = delete;
using HostMirrorSpace = typename TilesView::traits::host_mirror_space;
using HostMirror =
Subpaving<TScalar, Dim, TEnumIndex, TItemData, HostMirrorSpace>;

private:
template <typename, DimType, typename, typename, typename>
friend class ::plsm::Subpaving;

public:
Subpaving() = default;

/*!
* @brief Construct from root Region and set of subdivision ratios.
Expand Down Expand Up @@ -111,6 +131,9 @@ class Subpaving
return invalid<IdType>;
}

HostMirror
makeMirrorCopy() const;

/*!
* @brief Get root region
*/
Expand All @@ -127,79 +150,53 @@ class Subpaving
getDeviceMemorySize() const noexcept;

/*!
* @brief Get tiles DualView
* @todo Rename this
* @brief Get the set of tiles
*/
TilesDualView
getTilesView()
KOKKOS_INLINE_FUNCTION
const TilesView&
getTiles() const
{
return _tiles;
}

/*!
* @brief Synchronize Tile data onto specified memory space
*/
template <typename TContext = OnHost>
void
syncTiles(TContext context = onHost)
{
detail::syncUpdate(_tiles, context);
}

/*!
* @brief Synchronize Zone data onto specified memory space
*/
template <typename TContext = OnHost>
void
syncZones(TContext context = onHost)
{
detail::syncUpdate(_zones, context);
}

/*!
* @brief Synchronize Zone and Tile data onto specified memory space
* @brief Get random-access tiles view
*/
template <typename TContext = OnHost>
void
syncAll(TContext context = onHost)
KOKKOS_INLINE_FUNCTION
const TilesRAView&
getRandomAccessTiles() const
{
syncTiles(context);
syncZones(context);
return _tilesRA;
}

/*!
* @brief Get current number of tiles held in the specified memory space
* @note This does not synchronize
* @brief Get current number of tiles
*/
template <typename TContext = OnHost>
KOKKOS_INLINE_FUNCTION
IdType
getNumberOfTiles(TContext context = onHost)
getNumberOfTiles() const
{
return static_cast<IdType>(getTiles(context).extent(0));
return static_cast<IdType>(_tiles.size());
}

/*!
* @brief Get the set of tiles in the specified memory space
* @note This does not synchronize
* @brief Get the set of zones
*/
template <typename TContext = OnHost>
KOKKOS_INLINE_FUNCTION
const TilesView<TContext>&
getTiles(TContext context = onHost) const
const ZonesView&
getZones() const
{
return detail::getContextualView(_tiles, context);
return _zones;
}

/*!
* @brief Get the set of zones in the specified memory space
* @note This does not synchronize
* @brief Get random-access zones view
*/
template <typename TContext = OnHost>
KOKKOS_INLINE_FUNCTION
const ZonesView<TContext>&
getZones(TContext context = onHost) const
const ZonesRAView&
getRandomAccessZones() const
{
return detail::getContextualView(_zones, context);
return _zonesRA;
}

/*!
Expand All @@ -222,17 +219,31 @@ class Subpaving
* @brief Perform a tree search (using the zones) for the given point, and
* return the id of the containing tile (or invalid if not found)
*/
template <typename TContext = OnHost>
KOKKOS_INLINE_FUNCTION
IdType
findTileId(const PointType& point, TContext context = onHost) const;
findTileId(const PointType& point) const;

/*! @cond */
private:
void
plot();
/*! @endcond */
setZones(const ZonesView& zones)
{
_zones = zones;
_zonesRA = _zones;
}

void
setTiles(const TilesView& tiles)
{
_tiles = tiles;
_tilesRA = _tiles;
}

void
setRefinementDepth(std::size_t depth)
{
_refinementDepth = depth;
}

private:
/*!
* @brief Check subdivision ratios for domain divisibility and copy final
* form (one per level) into device view
Expand All @@ -242,16 +253,35 @@ class Subpaving

private:
//! Zones represent the entire subdivision tree for the root region
ZonesDualView _zones;
ZonesView _zones;
ZonesRAView _zonesRA;
//! Tiles represent the (selected) leaf nodes of the tree
TilesDualView _tiles;
TilesView _tiles;
TilesRAView _tilesRA;
//! Region which fully encloses the domain of interest
RegionType _rootRegion;
//! Collection of SubdivisionInfo, one per expected refinement level
Kokkos::DualView<detail::SubdivisionInfo<Dim>*> _subdivisionInfos;
Kokkos::View<detail::SubdivisionInfo<Dim>*, MemorySpace> _subdivisionInfos;
//! Level limit
std::size_t _refinementDepth{};
};

namespace detail
{
template <typename TMemSpace, typename TSubpaving>
struct MemSpaceSubpavingHelper;

template <typename TMemSpace, typename TS, DimType Dim, typename TE,
typename TD, typename TM>
struct MemSpaceSubpavingHelper<TMemSpace, Subpaving<TS, Dim, TE, TD, TM>>
{
using Type = Subpaving<TS, Dim, TE, TD, TMemSpace>;
};
} // namespace detail

template <typename TMemSpace, typename TSubpaving>
using MemSpaceSubpaving =
typename detail::MemSpaceSubpavingHelper<TMemSpace, TSubpaving>::Type;
} // namespace plsm

#include <plsm/Subpaving.inl>
Loading

0 comments on commit d168f28

Please sign in to comment.