Replace bool for using shared memory with MemorySetting enum
This commit is contained in:
committed by
Patrick Niklaus
parent
70b3962c35
commit
266e65e6d2
@@ -10,6 +10,7 @@
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
@@ -26,24 +27,24 @@ namespace partition
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <bool UseShareMemory> class CellStorageImpl;
|
||||
template <osrm::storage::MemorySetting MemorySetting> class CellStorageImpl;
|
||||
}
|
||||
using CellStorage = detail::CellStorageImpl<false>;
|
||||
using CellStorageView = detail::CellStorageImpl<true>;
|
||||
using CellStorage = detail::CellStorageImpl<osrm::storage::MemorySetting::InternalMemory>;
|
||||
using CellStorageView = detail::CellStorageImpl<osrm::storage::MemorySetting::SharedMemory>;
|
||||
|
||||
namespace io
|
||||
{
|
||||
template <bool UseShareMemory>
|
||||
template <osrm::storage::MemorySetting MemorySetting>
|
||||
inline void read(const boost::filesystem::path &path,
|
||||
detail::CellStorageImpl<UseShareMemory> &storage);
|
||||
template <bool UseShareMemory>
|
||||
detail::CellStorageImpl<MemorySetting> &storage);
|
||||
template <osrm::storage::MemorySetting MemorySetting>
|
||||
inline void write(const boost::filesystem::path &path,
|
||||
const detail::CellStorageImpl<UseShareMemory> &storage);
|
||||
const detail::CellStorageImpl<MemorySetting> &storage);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool UseShareMemory> class CellStorageImpl
|
||||
template <osrm::storage::MemorySetting MemorySetting> class CellStorageImpl
|
||||
{
|
||||
public:
|
||||
using WeightOffset = std::uint32_t;
|
||||
@@ -65,7 +66,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
};
|
||||
|
||||
private:
|
||||
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
|
||||
template <typename T> using Vector = typename util::ShM<T, MemorySetting>::vector;
|
||||
|
||||
// Implementation of the cell view. We need a template parameter here
|
||||
// because we need to derive a read-only and read-write view from this.
|
||||
@@ -185,7 +186,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
|
||||
CellStorageImpl() {}
|
||||
|
||||
template <typename GraphT, typename = std::enable_if<!UseShareMemory>>
|
||||
template <typename GraphT, typename = std::enable_if<MemorySetting == osrm::storage::MemorySetting::InternalMemory>>
|
||||
CellStorageImpl(const partition::MultiLevelPartition &partition, const GraphT &base_graph)
|
||||
{
|
||||
// pre-allocate storge for CellData so we can have random access to it by cell id
|
||||
@@ -314,7 +315,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
weights.resize(weight_offset + 1, INVALID_EDGE_WEIGHT);
|
||||
}
|
||||
|
||||
template <typename = std::enable_if<UseShareMemory>>
|
||||
template <typename = std::enable_if<MemorySetting == osrm::storage::MemorySetting::SharedMemory>>
|
||||
CellStorageImpl(Vector<EdgeWeight> weights_,
|
||||
Vector<NodeID> source_boundary_,
|
||||
Vector<NodeID> destination_boundary_,
|
||||
@@ -339,7 +340,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
destination_boundary.empty() ? nullptr : destination_boundary.data()};
|
||||
}
|
||||
|
||||
template <typename = std::enable_if<!UseShareMemory>> Cell GetCell(LevelID level, CellID id)
|
||||
template <typename = std::enable_if<MemorySetting == osrm::storage::MemorySetting::InternalMemory>> Cell GetCell(LevelID level, CellID id)
|
||||
{
|
||||
const auto level_index = LevelIDToIndex(level);
|
||||
BOOST_ASSERT(level_index < level_to_cell_offset.size());
|
||||
@@ -350,10 +351,10 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()};
|
||||
}
|
||||
|
||||
friend void io::read<UseShareMemory>(const boost::filesystem::path &path,
|
||||
detail::CellStorageImpl<UseShareMemory> &storage);
|
||||
friend void io::write<UseShareMemory>(const boost::filesystem::path &path,
|
||||
const detail::CellStorageImpl<UseShareMemory> &storage);
|
||||
friend void io::read<MemorySetting>(const boost::filesystem::path &path,
|
||||
detail::CellStorageImpl<MemorySetting> &storage);
|
||||
friend void io::write<MemorySetting>(const boost::filesystem::path &path,
|
||||
const detail::CellStorageImpl<MemorySetting> &storage);
|
||||
|
||||
private:
|
||||
Vector<EdgeWeight> weights;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "partition/multi_level_partition.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -15,9 +16,9 @@ namespace partition
|
||||
namespace io
|
||||
{
|
||||
|
||||
template <typename EdgeDataT, bool UseSharedMemory>
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting>
|
||||
inline void read(const boost::filesystem::path &path,
|
||||
MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph)
|
||||
MultiLevelGraph<EdgeDataT, MemorySetting> &graph)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
|
||||
storage::io::FileReader reader{path, fingerprint};
|
||||
@@ -27,9 +28,9 @@ inline void read(const boost::filesystem::path &path,
|
||||
reader.DeserializeVector(graph.edge_to_level);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, bool UseSharedMemory>
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting>
|
||||
inline void write(const boost::filesystem::path &path,
|
||||
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph)
|
||||
const MultiLevelGraph<EdgeDataT, MemorySetting> &graph)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "partition/multi_level_partition.hpp"
|
||||
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include "util/static_graph.hpp"
|
||||
|
||||
#include <tbb/parallel_sort.h>
|
||||
@@ -14,24 +16,24 @@ namespace osrm
|
||||
{
|
||||
namespace partition
|
||||
{
|
||||
template <typename EdgeDataT, bool UseSharedMemory> class MultiLevelGraph;
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting> class MultiLevelGraph;
|
||||
|
||||
namespace io
|
||||
{
|
||||
template <typename EdgeDataT, bool UseSharedMemory>
|
||||
void read(const boost::filesystem::path &path, MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting>
|
||||
void read(const boost::filesystem::path &path, MultiLevelGraph<EdgeDataT, MemorySetting> &graph);
|
||||
|
||||
template <typename EdgeDataT, bool UseSharedMemory>
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting>
|
||||
void write(const boost::filesystem::path &path,
|
||||
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
|
||||
const MultiLevelGraph<EdgeDataT, MemorySetting> &graph);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, bool UseSharedMemory>
|
||||
class MultiLevelGraph : public util::StaticGraph<EdgeDataT, UseSharedMemory>
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting>
|
||||
class MultiLevelGraph : public util::StaticGraph<EdgeDataT, MemorySetting>
|
||||
{
|
||||
private:
|
||||
using SuperT = util::StaticGraph<EdgeDataT, UseSharedMemory>;
|
||||
template <typename T> using Vector = typename util::ShM<T, UseSharedMemory>::vector;
|
||||
using SuperT = util::StaticGraph<EdgeDataT, MemorySetting>;
|
||||
template <typename T> using Vector = typename util::ShM<T, MemorySetting>::vector;
|
||||
|
||||
public:
|
||||
// We limit each node to have 255 edges
|
||||
@@ -190,11 +192,11 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, UseSharedMemory>
|
||||
}
|
||||
|
||||
friend void
|
||||
io::read<EdgeDataT, UseSharedMemory>(const boost::filesystem::path &path,
|
||||
MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
|
||||
io::read<EdgeDataT, MemorySetting>(const boost::filesystem::path &path,
|
||||
MultiLevelGraph<EdgeDataT, MemorySetting> &graph);
|
||||
friend void
|
||||
io::write<EdgeDataT, UseSharedMemory>(const boost::filesystem::path &path,
|
||||
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
|
||||
io::write<EdgeDataT, MemorySetting>(const boost::filesystem::path &path,
|
||||
const MultiLevelGraph<EdgeDataT, MemorySetting> &graph);
|
||||
|
||||
Vector<EdgeOffset> node_to_edge_offset;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -25,31 +26,31 @@ namespace partition
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <bool UseShareMemory> class MultiLevelPartitionImpl;
|
||||
template <osrm::storage::MemorySetting MemorySetting> class MultiLevelPartitionImpl;
|
||||
}
|
||||
using MultiLevelPartition = detail::MultiLevelPartitionImpl<false>;
|
||||
using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<true>;
|
||||
using MultiLevelPartition = detail::MultiLevelPartitionImpl<osrm::storage::MemorySetting::InternalMemory>;
|
||||
using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<osrm::storage::MemorySetting::SharedMemory>;
|
||||
|
||||
namespace io
|
||||
{
|
||||
template <bool UseShareMemory>
|
||||
template <osrm::storage::MemorySetting MemorySetting>
|
||||
void read(const boost::filesystem::path &file,
|
||||
detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
|
||||
template <bool UseShareMemory>
|
||||
detail::MultiLevelPartitionImpl<MemorySetting> &mlp);
|
||||
template <osrm::storage::MemorySetting MemorySetting>
|
||||
void write(const boost::filesystem::path &file,
|
||||
const detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
|
||||
const detail::MultiLevelPartitionImpl<MemorySetting> &mlp);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <bool UseShareMemory> class MultiLevelPartitionImpl final
|
||||
template <osrm::storage::MemorySetting MemorySetting> class MultiLevelPartitionImpl final
|
||||
{
|
||||
// we will support at most 16 levels
|
||||
static const constexpr std::uint8_t MAX_NUM_LEVEL = 16;
|
||||
static const constexpr std::uint8_t NUM_PARTITION_BITS = sizeof(PartitionID) * CHAR_BIT;
|
||||
|
||||
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
|
||||
template <typename T> using Vector = typename util::ShM<T, MemorySetting>::vector;
|
||||
|
||||
public:
|
||||
// Contains all data necessary to describe the level hierarchy
|
||||
@@ -68,7 +69,7 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl final
|
||||
// cell_sizes is index by level (starting at 0, the base graph).
|
||||
// However level 0 always needs to have cell size 1, since it is the
|
||||
// basegraph.
|
||||
template <typename = typename std::enable_if<!UseShareMemory>>
|
||||
template <typename = typename std::enable_if<MemorySetting == osrm::storage::MemorySetting::InternalMemory>>
|
||||
MultiLevelPartitionImpl(const std::vector<std::vector<CellID>> &partitions,
|
||||
const std::vector<std::uint32_t> &lidx_to_num_cells)
|
||||
: level_data(MakeLevelData(lidx_to_num_cells))
|
||||
@@ -76,7 +77,7 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl final
|
||||
InitializePartitionIDs(partitions);
|
||||
}
|
||||
|
||||
template <typename = typename std::enable_if<UseShareMemory>>
|
||||
template <typename = typename std::enable_if<MemorySetting == osrm::storage::MemorySetting::SharedMemory>>
|
||||
MultiLevelPartitionImpl(LevelData level_data,
|
||||
Vector<PartitionID> partition_,
|
||||
Vector<CellID> cell_to_children_)
|
||||
@@ -134,9 +135,9 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl final
|
||||
return cell_to_children[offset + cell + 1];
|
||||
}
|
||||
|
||||
friend void io::read<UseShareMemory>(const boost::filesystem::path &file,
|
||||
friend void io::read<MemorySetting>(const boost::filesystem::path &file,
|
||||
MultiLevelPartitionImpl &mlp);
|
||||
friend void io::write<UseShareMemory>(const boost::filesystem::path &file,
|
||||
friend void io::write<MemorySetting>(const boost::filesystem::path &file,
|
||||
const MultiLevelPartitionImpl &mlp);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user