Replace bool for using shared memory with MemorySetting enum
This commit is contained in:
committed by
Patrick Niklaus
parent
70b3962c35
commit
266e65e6d2
@@ -4,6 +4,8 @@
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,7 +22,7 @@ namespace util
|
||||
* NOTE: this type is templated for future use, but will require a slight refactor to
|
||||
* configure BITSIZE and ELEMSIZE
|
||||
*/
|
||||
template <typename T, bool UseSharedMemory = false> class PackedVector
|
||||
template <typename T, osrm::storage::MemorySetting MemorySetting = osrm::storage::MemorySetting::InternalMemory> class PackedVector
|
||||
{
|
||||
static const constexpr std::size_t BITSIZE = 33;
|
||||
static const constexpr std::size_t ELEMSIZE = 64;
|
||||
@@ -120,20 +122,20 @@ template <typename T, bool UseSharedMemory = false> class PackedVector
|
||||
|
||||
std::size_t size() const { return num_elements; }
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void reserve(typename std::enable_if<!enabled, std::size_t>::type capacity)
|
||||
{
|
||||
vec.reserve(elements_to_blocks(capacity));
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void reset(typename std::enable_if<enabled, std::uint64_t>::type *ptr,
|
||||
typename std::enable_if<enabled, std::size_t>::type size)
|
||||
{
|
||||
vec.reset(ptr, size);
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void set_number_of_entries(typename std::enable_if<enabled, std::size_t>::type count)
|
||||
{
|
||||
num_elements = count;
|
||||
@@ -145,44 +147,44 @@ template <typename T, bool UseSharedMemory = false> class PackedVector
|
||||
}
|
||||
|
||||
private:
|
||||
typename util::ShM<std::uint64_t, UseSharedMemory>::vector vec;
|
||||
typename util::ShM<std::uint64_t, MemorySetting>::vector vec;
|
||||
|
||||
std::size_t num_elements = 0;
|
||||
|
||||
signed cursor = -1;
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void replace_last_elem(typename std::enable_if<enabled, std::uint64_t>::type last_elem)
|
||||
{
|
||||
vec[cursor] = last_elem;
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void replace_last_elem(typename std::enable_if<!enabled, std::uint64_t>::type last_elem)
|
||||
{
|
||||
vec.back() = last_elem;
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void add_last_elem(typename std::enable_if<enabled, std::uint64_t>::type last_elem)
|
||||
{
|
||||
vec[cursor + 1] = last_elem;
|
||||
cursor++;
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
void add_last_elem(typename std::enable_if<!enabled, std::uint64_t>::type last_elem)
|
||||
{
|
||||
vec.push_back(last_elem);
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
std::uint64_t vec_back(typename std::enable_if<enabled>::type * = nullptr)
|
||||
{
|
||||
return vec[cursor];
|
||||
}
|
||||
|
||||
template <bool enabled = UseSharedMemory>
|
||||
template <bool enabled = (MemorySetting == osrm::storage::MemorySetting::SharedMemory)>
|
||||
std::uint64_t vec_back(typename std::enable_if<!enabled>::type * = nullptr)
|
||||
{
|
||||
return vec.back();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "storage/io.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
|
||||
#include <array>
|
||||
@@ -18,13 +19,13 @@ namespace util
|
||||
* and otherwise the compiler gets confused.
|
||||
*/
|
||||
|
||||
template <unsigned BLOCK_SIZE = 16, bool USE_SHARED_MEMORY = false> class RangeTable;
|
||||
template <unsigned BLOCK_SIZE = 16, osrm::storage::MemorySetting MemorySetting = osrm::storage::MemorySetting::InternalMemory> class RangeTable;
|
||||
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
|
||||
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting>
|
||||
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, MemorySetting> &table);
|
||||
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
|
||||
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting>
|
||||
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, MemorySetting> &table);
|
||||
|
||||
/**
|
||||
* Stores adjacent ranges in a compressed format.
|
||||
@@ -35,12 +36,12 @@ std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEM
|
||||
* But each block consists of an absolute value and BLOCK_SIZE differential values.
|
||||
* So the effective block size is sizeof(unsigned) + BLOCK_SIZE.
|
||||
*/
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting> class RangeTable
|
||||
{
|
||||
public:
|
||||
using BlockT = std::array<unsigned char, BLOCK_SIZE>;
|
||||
using BlockContainerT = typename ShM<BlockT, USE_SHARED_MEMORY>::vector;
|
||||
using OffsetContainerT = typename ShM<unsigned, USE_SHARED_MEMORY>::vector;
|
||||
using BlockContainerT = typename ShM<BlockT, MemorySetting>::vector;
|
||||
using OffsetContainerT = typename ShM<unsigned, MemorySetting>::vector;
|
||||
using RangeT = range<unsigned>;
|
||||
|
||||
friend std::ostream &operator<<<>(std::ostream &out, const RangeTable &table);
|
||||
@@ -212,8 +213,8 @@ template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
|
||||
unsigned sum_lengths;
|
||||
};
|
||||
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
|
||||
unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index,
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting>
|
||||
unsigned RangeTable<BLOCK_SIZE, MemorySetting>::PrefixSumAtIndex(int index,
|
||||
const BlockT &block) const
|
||||
{
|
||||
// this loop looks inefficent, but a modern compiler
|
||||
@@ -227,8 +228,8 @@ unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index,
|
||||
return sum;
|
||||
}
|
||||
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
|
||||
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting>
|
||||
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, MemorySetting> &table)
|
||||
{
|
||||
// write number of block
|
||||
const unsigned number_of_blocks = table.diff_blocks.size();
|
||||
@@ -243,8 +244,8 @@ std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHA
|
||||
return out;
|
||||
}
|
||||
|
||||
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
|
||||
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
|
||||
template <unsigned BLOCK_SIZE, osrm::storage::MemorySetting MemorySetting>
|
||||
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, MemorySetting> &table)
|
||||
{
|
||||
// read number of block
|
||||
unsigned number_of_blocks;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
@@ -130,7 +132,7 @@ template <typename DataT> class SharedMemoryWrapper
|
||||
friend void swap(SharedMemoryWrapper<T> &, SharedMemoryWrapper<T> &) noexcept;
|
||||
};
|
||||
|
||||
template <> class SharedMemoryWrapper<bool>
|
||||
template <> class SharedMemoryWrapper<osrm::storage::MemorySetting>
|
||||
{
|
||||
private:
|
||||
unsigned *m_ptr;
|
||||
@@ -173,9 +175,9 @@ void swap(SharedMemoryWrapper<DataT> &lhs, SharedMemoryWrapper<DataT> &rhs) noex
|
||||
std::swap(lhs.m_size, rhs.m_size);
|
||||
}
|
||||
|
||||
template <typename DataT, bool UseSharedMemory> struct ShM
|
||||
template <typename DataT, osrm::storage::MemorySetting MemorySetting> struct ShM
|
||||
{
|
||||
using vector = typename std::conditional<UseSharedMemory,
|
||||
using vector = typename std::conditional<MemorySetting == osrm::storage::MemorySetting::SharedMemory,
|
||||
SharedMemoryWrapper<DataT>,
|
||||
std::vector<DataT>>::type;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -97,7 +99,7 @@ EntryT edgeToEntry(const OtherEdge &from, std::false_type)
|
||||
|
||||
} // namespace static_graph_details
|
||||
|
||||
template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
|
||||
template <typename EdgeDataT, osrm::storage::MemorySetting MemorySetting = osrm::storage::MemorySetting::InternalMemory> class StaticGraph
|
||||
{
|
||||
public:
|
||||
using InputEdge = static_graph_details::SortableEdgeWithData<EdgeDataT>;
|
||||
@@ -122,8 +124,8 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
|
||||
InitializeFromSortedEdgeRange(nodes, edges.begin(), edges.end());
|
||||
}
|
||||
|
||||
StaticGraph(typename ShM<NodeArrayEntry, UseSharedMemory>::vector node_array_,
|
||||
typename ShM<EdgeArrayEntry, UseSharedMemory>::vector edge_array_)
|
||||
StaticGraph(typename ShM<NodeArrayEntry, MemorySetting>::vector node_array_,
|
||||
typename ShM<EdgeArrayEntry, MemorySetting>::vector edge_array_)
|
||||
: node_array(std::move(node_array_)), edge_array(std::move(edge_array_))
|
||||
{
|
||||
BOOST_ASSERT(!node_array.empty());
|
||||
@@ -258,8 +260,8 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
|
||||
NodeIterator number_of_nodes;
|
||||
EdgeIterator number_of_edges;
|
||||
|
||||
typename ShM<NodeArrayEntry, UseSharedMemory>::vector node_array;
|
||||
typename ShM<EdgeArrayEntry, UseSharedMemory>::vector edge_array;
|
||||
typename ShM<NodeArrayEntry, MemorySetting>::vector node_array;
|
||||
typename ShM<EdgeArrayEntry, MemorySetting>::vector edge_array;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
#include "storage/shared_memory.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
@@ -52,7 +54,7 @@ namespace util
|
||||
// are computed, this means the internal distance metric doesn not represent meters!
|
||||
template <class EdgeDataT,
|
||||
class CoordinateListT = std::vector<Coordinate>,
|
||||
bool UseSharedMemory = false,
|
||||
osrm::storage::MemorySetting MemorySetting = osrm::storage::MemorySetting::InternalMemory,
|
||||
std::uint32_t BRANCHING_FACTOR = 128,
|
||||
std::uint32_t LEAF_PAGE_SIZE = 4096>
|
||||
class StaticRTree
|
||||
@@ -152,12 +154,12 @@ class StaticRTree
|
||||
Coordinate fixed_projected_coordinate;
|
||||
};
|
||||
|
||||
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
|
||||
typename ShM<TreeNode, MemorySetting>::vector m_search_tree;
|
||||
const CoordinateListT &m_coordinate_list;
|
||||
|
||||
boost::iostreams::mapped_file_source m_leaves_region;
|
||||
// read-only view of leaves
|
||||
typename ShM<const LeafNode, true>::vector m_leaves;
|
||||
typename ShM<const LeafNode, osrm::storage::MemorySetting::SharedMemory>::vector m_leaves;
|
||||
|
||||
public:
|
||||
StaticRTree(const StaticRTree &) = delete;
|
||||
|
||||
Reference in New Issue
Block a user