From 266e65e6d2c70fc2d4af2954da7cec69e31c628f Mon Sep 17 00:00:00 2001 From: Pepijn Schoen Date: Wed, 29 Mar 2017 14:06:52 +0200 Subject: [PATCH] Replace bool for using shared memory with MemorySetting enum --- include/customizer/edge_based_graph.hpp | 10 +- .../contiguous_internalmem_datafacade.hpp | 135 +++++++++--------- include/extractor/segment_data_container.hpp | 28 ++-- include/partition/cell_storage.hpp | 33 ++--- include/partition/io.hpp | 9 +- include/partition/multi_level_graph.hpp | 28 ++-- include/partition/multi_level_partition.hpp | 27 ++-- include/storage/shared_memory.hpp | 6 + include/util/packed_vector.hpp | 24 ++-- include/util/range_table.hpp | 29 ++-- include/util/shared_memory_vector_wrapper.hpp | 8 +- include/util/static_graph.hpp | 12 +- include/util/static_rtree.hpp | 8 +- src/benchmarks/static_rtree.cpp | 2 +- src/customize/customizer.cpp | 4 +- src/storage/storage.cpp | 12 +- unit_tests/customizer/cell_customization.cpp | 2 +- unit_tests/partition/multi_level_graph.cpp | 2 +- unit_tests/util/packed_vector.cpp | 4 +- unit_tests/util/range_table.cpp | 2 +- unit_tests/util/static_graph.cpp | 4 +- unit_tests/util/static_rtree.cpp | 6 +- 22 files changed, 211 insertions(+), 184 deletions(-) diff --git a/include/customizer/edge_based_graph.hpp b/include/customizer/edge_based_graph.hpp index d3703d7fd..63e0b0fef 100644 --- a/include/customizer/edge_based_graph.hpp +++ b/include/customizer/edge_based_graph.hpp @@ -7,6 +7,8 @@ #include "util/static_graph.hpp" #include "util/typedefs.hpp" +#include "storage/shared_memory.hpp" + #include namespace osrm @@ -16,16 +18,16 @@ namespace customizer using EdgeBasedGraphEdgeData = partition::EdgeBasedGraphEdgeData; -struct MultiLevelEdgeBasedGraph : public partition::MultiLevelGraph +struct MultiLevelEdgeBasedGraph : public partition::MultiLevelGraph { - using Base = partition::MultiLevelGraph; + using Base = partition::MultiLevelGraph; using Base::Base; }; struct MultiLevelEdgeBasedGraphView - : public partition::MultiLevelGraph + : public partition::MultiLevelGraph { - using Base = partition::MultiLevelGraph; + using Base = partition::MultiLevelGraph; using Base::Base; }; diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 54e5213a7..ad1bc01a4 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -20,6 +20,7 @@ #include "partition/multi_level_partition.hpp" #include "storage/shared_datatype.hpp" +#include "storage/shared_memory.hpp" #include "util/exception.hpp" #include "util/exception_utils.hpp" @@ -61,7 +62,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::AlgorithmDataFacade { private: - using QueryGraph = util::StaticGraph; + using QueryGraph = util::StaticGraph; using GraphNode = QueryGraph::NodeArrayEntry; using GraphEdge = QueryGraph::EdgeArrayEntry; @@ -78,9 +79,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto graph_edges_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::CH_GRAPH_EDGE_LIST); - util::ShM::vector node_list( + util::ShM::vector node_list( graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_NODE_LIST]); - util::ShM::vector edge_list( + util::ShM::vector edge_list( graph_edges_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_EDGE_LIST]); m_query_graph.reset(new QueryGraph(node_list, edge_list)); } @@ -154,7 +155,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::AlgorithmDataFacade { private: - util::ShM::vector m_is_core_node; + util::ShM::vector m_is_core_node; // allocator that keeps the allocation data std::shared_ptr allocator; @@ -163,7 +164,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade { auto core_marker_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::CH_CORE_MARKER); - util::ShM::vector is_core_node( + util::ShM::vector is_core_node( core_marker_ptr, data_layout.num_entries[storage::DataLayout::CH_CORE_MARKER]); m_is_core_node = std::move(is_core_node); } @@ -199,10 +200,10 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { private: using super = BaseDataFacade; - using IndexBlock = util::RangeTable<16, true>::BlockT; + using IndexBlock = util::RangeTable<16, osrm::storage::MemorySetting::SharedMemory>::BlockT; using RTreeLeaf = super::RTreeLeaf; using SharedRTree = - util::StaticRTree::vector, true>; + util::StaticRTree::vector, osrm::storage::MemorySetting::SharedMemory>; using SharedGeospatialQuery = GeospatialQuery; using RTreeNode = SharedRTree::TreeNode; @@ -211,28 +212,28 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade extractor::Datasources *m_datasources; unsigned m_check_sum; - util::ShM::vector m_coordinate_list; - util::PackedVector m_osmnodeid_list; - util::ShM::vector m_via_geometry_list; - util::ShM::vector m_name_ID_list; - util::ShM::vector m_lane_data_id; - util::ShM::vector m_turn_instruction_list; - util::ShM::vector m_travel_mode_list; - util::ShM::vector m_pre_turn_bearing; - util::ShM::vector m_post_turn_bearing; + util::ShM::vector m_coordinate_list; + util::PackedVector m_osmnodeid_list; + util::ShM::vector m_via_geometry_list; + util::ShM::vector m_name_ID_list; + util::ShM::vector m_lane_data_id; + util::ShM::vector m_turn_instruction_list; + util::ShM::vector m_travel_mode_list; + util::ShM::vector m_pre_turn_bearing; + util::ShM::vector m_post_turn_bearing; util::NameTable m_names_table; - util::ShM::vector m_name_begin_indices; - util::ShM::vector m_is_core_node; - util::ShM::vector m_lane_description_offsets; - util::ShM::vector m_lane_description_masks; - util::ShM::vector m_turn_weight_penalties; - util::ShM::vector m_turn_duration_penalties; + util::ShM::vector m_name_begin_indices; + util::ShM::vector m_is_core_node; + util::ShM::vector m_lane_description_offsets; + util::ShM::vector m_lane_description_masks; + util::ShM::vector m_turn_weight_penalties; + util::ShM::vector m_turn_duration_penalties; extractor::SegmentDataView segment_data; - util::ShM::vector m_datasource_name_data; - util::ShM::vector m_datasource_name_offsets; - util::ShM::vector m_datasource_name_lengths; - util::ShM::vector m_lane_tupel_id_pairs; + util::ShM::vector m_datasource_name_data; + util::ShM::vector m_datasource_name_offsets; + util::ShM::vector m_datasource_name_lengths; + util::ShM::vector m_lane_tupel_id_pairs; std::unique_ptr m_static_rtree; std::unique_ptr m_geospatial_query; @@ -240,17 +241,17 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::NameTable m_name_table; // bearing classes by node based node - util::ShM::vector m_bearing_class_id_table; + util::ShM::vector m_bearing_class_id_table; // entry class IDs - util::ShM::vector m_entry_class_id_list; + util::ShM::vector m_entry_class_id_list; // the look-up table for entry classes. An entry class lists the possibility of entry for all // available turns. Such a class id is stored with every edge. - util::ShM::vector m_entry_class_table; + util::ShM::vector m_entry_class_table; // the look-up table for distinct bearing classes. A bearing class lists the available bearings // at an intersection - std::shared_ptr> m_bearing_ranges_table; - util::ShM::vector m_bearing_values_table; + std::shared_ptr> m_bearing_ranges_table; + util::ShM::vector m_bearing_values_table; // allocator that keeps the allocation data std::shared_ptr allocator; @@ -326,52 +327,52 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade const auto travel_mode_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TRAVEL_MODE); - util::ShM::vector travel_mode_list( + util::ShM::vector travel_mode_list( travel_mode_list_ptr, data_layout.num_entries[storage::DataLayout::TRAVEL_MODE]); m_travel_mode_list = std::move(travel_mode_list); const auto lane_data_id_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::LANE_DATA_ID); - util::ShM::vector lane_data_id( + util::ShM::vector lane_data_id( lane_data_id_ptr, data_layout.num_entries[storage::DataLayout::LANE_DATA_ID]); m_lane_data_id = std::move(lane_data_id); const auto lane_tupel_id_pair_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_LANE_DATA); - util::ShM::vector lane_tupel_id_pair( + util::ShM::vector lane_tupel_id_pair( lane_tupel_id_pair_ptr, data_layout.num_entries[storage::DataLayout::TURN_LANE_DATA]); m_lane_tupel_id_pairs = std::move(lane_tupel_id_pair); const auto turn_instruction_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_INSTRUCTION); - util::ShM::vector turn_instruction_list( + util::ShM::vector turn_instruction_list( turn_instruction_list_ptr, data_layout.num_entries[storage::DataLayout::TURN_INSTRUCTION]); m_turn_instruction_list = std::move(turn_instruction_list); const auto name_id_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::NAME_ID_LIST); - util::ShM::vector name_id_list( + util::ShM::vector name_id_list( name_id_list_ptr, data_layout.num_entries[storage::DataLayout::NAME_ID_LIST]); m_name_ID_list = std::move(name_id_list); const auto entry_class_id_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::ENTRY_CLASSID); - typename util::ShM::vector entry_class_id_list( + typename util::ShM::vector entry_class_id_list( entry_class_id_list_ptr, data_layout.num_entries[storage::DataLayout::ENTRY_CLASSID]); m_entry_class_id_list = std::move(entry_class_id_list); const auto pre_turn_bearing_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::PRE_TURN_BEARING); - typename util::ShM::vector pre_turn_bearing( + typename util::ShM::vector pre_turn_bearing( pre_turn_bearing_ptr, data_layout.num_entries[storage::DataLayout::PRE_TURN_BEARING]); m_pre_turn_bearing = std::move(pre_turn_bearing); const auto post_turn_bearing_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::POST_TURN_BEARING); - typename util::ShM::vector post_turn_bearing( + typename util::ShM::vector post_turn_bearing( post_turn_bearing_ptr, data_layout.num_entries[storage::DataLayout::POST_TURN_BEARING]); m_post_turn_bearing = std::move(post_turn_bearing); } @@ -380,7 +381,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto via_geometry_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::VIA_NODE_LIST); - util::ShM::vector via_geometry_list( + util::ShM::vector via_geometry_list( via_geometry_list_ptr, data_layout.num_entries[storage::DataLayout::VIA_NODE_LIST]); m_via_geometry_list = std::move(via_geometry_list); } @@ -398,14 +399,14 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto offsets_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::LANE_DESCRIPTION_OFFSETS); - util::ShM::vector offsets( + util::ShM::vector offsets( offsets_ptr, data_layout.num_entries[storage::DataLayout::LANE_DESCRIPTION_OFFSETS]); m_lane_description_offsets = std::move(offsets); auto masks_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::LANE_DESCRIPTION_MASKS); - util::ShM::vector masks( + util::ShM::vector masks( masks_ptr, data_layout.num_entries[storage::DataLayout::LANE_DESCRIPTION_MASKS]); m_lane_description_masks = std::move(masks); } @@ -414,12 +415,12 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto turn_weight_penalties_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_WEIGHT_PENALTIES); - m_turn_weight_penalties = util::ShM::vector( + m_turn_weight_penalties = util::ShM::vector( turn_weight_penalties_ptr, data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]); auto turn_duration_penalties_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_DURATION_PENALTIES); - m_turn_duration_penalties = util::ShM::vector( + m_turn_duration_penalties = util::ShM::vector( turn_duration_penalties_ptr, data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]); } @@ -428,42 +429,42 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto geometries_index_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::GEOMETRIES_INDEX); - util::ShM::vector geometry_begin_indices( + util::ShM::vector geometry_begin_indices( geometries_index_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]); auto geometries_node_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_NODE_LIST); - util::ShM::vector geometry_node_list( + util::ShM::vector geometry_node_list( geometries_node_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST]); auto geometries_fwd_weight_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST); - util::ShM::vector geometry_fwd_weight_list( + util::ShM::vector geometry_fwd_weight_list( geometries_fwd_weight_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]); auto geometries_rev_weight_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST); - util::ShM::vector geometry_rev_weight_list( + util::ShM::vector geometry_rev_weight_list( geometries_rev_weight_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]); auto geometries_fwd_duration_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST); - util::ShM::vector geometry_fwd_duration_list( + util::ShM::vector geometry_fwd_duration_list( geometries_fwd_duration_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]); auto geometries_rev_duration_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST); - util::ShM::vector geometry_rev_duration_list( + util::ShM::vector geometry_rev_duration_list( geometries_rev_duration_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]); auto datasources_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::DATASOURCES_LIST); - util::ShM::vector datasources_list( + util::ShM::vector datasources_list( datasources_list_ptr, data_layout.num_entries[storage::DataLayout::DATASOURCES_LIST]); segment_data = extractor::SegmentDataView{std::move(geometry_begin_indices), @@ -482,13 +483,13 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto bearing_class_id_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::BEARING_CLASSID); - typename util::ShM::vector bearing_class_id_table( + typename util::ShM::vector bearing_class_id_table( bearing_class_id_ptr, data_layout.num_entries[storage::DataLayout::BEARING_CLASSID]); m_bearing_class_id_table = std::move(bearing_class_id_table); auto bearing_class_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::BEARING_VALUES); - typename util::ShM::vector bearing_class_table( + typename util::ShM::vector bearing_class_table( bearing_class_ptr, data_layout.num_entries[storage::DataLayout::BEARING_VALUES]); m_bearing_values_table = std::move(bearing_class_table); @@ -496,17 +497,17 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_OFFSETS); auto blocks_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_BLOCKS); - util::ShM::vector bearing_offsets( + util::ShM::vector bearing_offsets( offsets_ptr, data_layout.num_entries[storage::DataLayout::BEARING_OFFSETS]); - util::ShM::vector bearing_blocks( + util::ShM::vector bearing_blocks( blocks_ptr, data_layout.num_entries[storage::DataLayout::BEARING_BLOCKS]); - m_bearing_ranges_table = std::make_unique>( + m_bearing_ranges_table = std::make_unique>( bearing_offsets, bearing_blocks, static_cast(m_bearing_values_table.size())); auto entry_class_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::ENTRY_CLASS); - typename util::ShM::vector entry_class_table( + typename util::ShM::vector entry_class_table( entry_class_ptr, data_layout.num_entries[storage::DataLayout::ENTRY_CLASS]); m_entry_class_table = std::move(entry_class_table); } @@ -929,14 +930,14 @@ class ContiguousInternalMemoryAlgorithmDataFacade memory_block, storage::DataLayout::MLD_PARTITION); auto partition_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_PARTITION); - util::ShM::vector partition(mld_partition_ptr, + util::ShM::vector partition(mld_partition_ptr, partition_entries_count); auto mld_chilren_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::MLD_CELL_TO_CHILDREN); auto children_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_TO_CHILDREN); - util::ShM::vector cell_to_children(mld_chilren_ptr, + util::ShM::vector cell_to_children(mld_chilren_ptr, children_entries_count); mld_partition = @@ -969,14 +970,14 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto cell_level_offsets_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS); - util::ShM::vector weights(mld_cell_weights_ptr, weight_entries_count); - util::ShM::vector source_boundary(mld_source_boundary_ptr, + util::ShM::vector weights(mld_cell_weights_ptr, weight_entries_count); + util::ShM::vector source_boundary(mld_source_boundary_ptr, source_boundary_entries_count); - util::ShM::vector destination_boundary( + util::ShM::vector destination_boundary( mld_destination_boundary_ptr, destination_boundary_entries_count); - util::ShM::vector cells( + util::ShM::vector cells( mld_cells_ptr, cells_entries_counts); - util::ShM::vector level_offsets(mld_cell_level_offsets_ptr, + util::ShM::vector level_offsets(mld_cell_level_offsets_ptr, cell_level_offsets_entries_count); mld_cell_storage = partition::CellStorageView{std::move(weights), @@ -997,11 +998,11 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto graph_node_to_offset_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET); - util::ShM::vector node_list( + util::ShM::vector node_list( graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_NODE_LIST]); - util::ShM::vector edge_list( + util::ShM::vector edge_list( graph_edges_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_EDGE_LIST]); - util::ShM::vector node_to_offset( + util::ShM::vector node_to_offset( graph_node_to_offset_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET]); diff --git a/include/extractor/segment_data_container.hpp b/include/extractor/segment_data_container.hpp index 4a10ca855..3dcb5b7d6 100644 --- a/include/extractor/segment_data_container.hpp +++ b/include/extractor/segment_data_container.hpp @@ -4,6 +4,8 @@ #include "util/shared_memory_vector_wrapper.hpp" #include "util/typedefs.hpp" +#include "storage/shared_memory.hpp" + #include #include #include @@ -22,24 +24,24 @@ class CompressedEdgeContainer; namespace detail { -template class SegmentDataContainerImpl; +template class SegmentDataContainerImpl; } namespace io { -template +template inline void read(const boost::filesystem::path &path, - detail::SegmentDataContainerImpl &segment_data); -template + detail::SegmentDataContainerImpl &segment_data); +template inline void write(const boost::filesystem::path &path, - const detail::SegmentDataContainerImpl &segment_data); + const detail::SegmentDataContainerImpl &segment_data); } namespace detail { -template class SegmentDataContainerImpl +template class SegmentDataContainerImpl { - template using Vector = typename util::ShM::vector; + template using Vector = typename util::ShM::vector; friend CompressedEdgeContainer; @@ -189,11 +191,11 @@ template class SegmentDataContainerImpl auto GetNumberOfSegments() const { return fwd_weights.size(); } friend void - io::read(const boost::filesystem::path &path, - detail::SegmentDataContainerImpl &segment_data); + io::read(const boost::filesystem::path &path, + detail::SegmentDataContainerImpl &segment_data); friend void - io::write(const boost::filesystem::path &path, - const detail::SegmentDataContainerImpl &segment_data); + io::write(const boost::filesystem::path &path, + const detail::SegmentDataContainerImpl &segment_data); private: Vector index; @@ -206,8 +208,8 @@ template class SegmentDataContainerImpl }; } -using SegmentDataView = detail::SegmentDataContainerImpl; -using SegmentDataContainer = detail::SegmentDataContainerImpl; +using SegmentDataView = detail::SegmentDataContainerImpl; +using SegmentDataContainer = detail::SegmentDataContainerImpl; } } diff --git a/include/partition/cell_storage.hpp b/include/partition/cell_storage.hpp index 99ccc02a7..b5d2d1bd4 100644 --- a/include/partition/cell_storage.hpp +++ b/include/partition/cell_storage.hpp @@ -10,6 +10,7 @@ #include "util/typedefs.hpp" #include "storage/io.hpp" +#include "storage/shared_memory.hpp" #include #include @@ -26,24 +27,24 @@ namespace partition { namespace detail { -template class CellStorageImpl; +template class CellStorageImpl; } -using CellStorage = detail::CellStorageImpl; -using CellStorageView = detail::CellStorageImpl; +using CellStorage = detail::CellStorageImpl; +using CellStorageView = detail::CellStorageImpl; namespace io { -template +template inline void read(const boost::filesystem::path &path, - detail::CellStorageImpl &storage); -template + detail::CellStorageImpl &storage); +template inline void write(const boost::filesystem::path &path, - const detail::CellStorageImpl &storage); + const detail::CellStorageImpl &storage); } namespace detail { -template class CellStorageImpl +template class CellStorageImpl { public: using WeightOffset = std::uint32_t; @@ -65,7 +66,7 @@ template class CellStorageImpl }; private: - template using Vector = typename util::ShM::vector; + template using Vector = typename util::ShM::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 class CellStorageImpl CellStorageImpl() {} - template > + template > 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 class CellStorageImpl weights.resize(weight_offset + 1, INVALID_EDGE_WEIGHT); } - template > + template > CellStorageImpl(Vector weights_, Vector source_boundary_, Vector destination_boundary_, @@ -339,7 +340,7 @@ template class CellStorageImpl destination_boundary.empty() ? nullptr : destination_boundary.data()}; } - template > Cell GetCell(LevelID level, CellID id) + template > 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 class CellStorageImpl cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()}; } - friend void io::read(const boost::filesystem::path &path, - detail::CellStorageImpl &storage); - friend void io::write(const boost::filesystem::path &path, - const detail::CellStorageImpl &storage); + friend void io::read(const boost::filesystem::path &path, + detail::CellStorageImpl &storage); + friend void io::write(const boost::filesystem::path &path, + const detail::CellStorageImpl &storage); private: Vector weights; diff --git a/include/partition/io.hpp b/include/partition/io.hpp index 00a03835d..081c06140 100644 --- a/include/partition/io.hpp +++ b/include/partition/io.hpp @@ -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 +template inline void read(const boost::filesystem::path &path, - MultiLevelGraph &graph) + MultiLevelGraph &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 +template inline void write(const boost::filesystem::path &path, - const MultiLevelGraph &graph) + const MultiLevelGraph &graph) { const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; storage::io::FileWriter writer{path, fingerprint}; diff --git a/include/partition/multi_level_graph.hpp b/include/partition/multi_level_graph.hpp index 173b78d9a..387255433 100644 --- a/include/partition/multi_level_graph.hpp +++ b/include/partition/multi_level_graph.hpp @@ -3,6 +3,8 @@ #include "partition/multi_level_partition.hpp" +#include "storage/shared_memory.hpp" + #include "util/static_graph.hpp" #include @@ -14,24 +16,24 @@ namespace osrm { namespace partition { -template class MultiLevelGraph; +template class MultiLevelGraph; namespace io { -template -void read(const boost::filesystem::path &path, MultiLevelGraph &graph); +template +void read(const boost::filesystem::path &path, MultiLevelGraph &graph); -template +template void write(const boost::filesystem::path &path, - const MultiLevelGraph &graph); + const MultiLevelGraph &graph); } -template -class MultiLevelGraph : public util::StaticGraph +template +class MultiLevelGraph : public util::StaticGraph { private: - using SuperT = util::StaticGraph; - template using Vector = typename util::ShM::vector; + using SuperT = util::StaticGraph; + template using Vector = typename util::ShM::vector; public: // We limit each node to have 255 edges @@ -190,11 +192,11 @@ class MultiLevelGraph : public util::StaticGraph } friend void - io::read(const boost::filesystem::path &path, - MultiLevelGraph &graph); + io::read(const boost::filesystem::path &path, + MultiLevelGraph &graph); friend void - io::write(const boost::filesystem::path &path, - const MultiLevelGraph &graph); + io::write(const boost::filesystem::path &path, + const MultiLevelGraph &graph); Vector node_to_edge_offset; }; diff --git a/include/partition/multi_level_partition.hpp b/include/partition/multi_level_partition.hpp index 47bb32b4c..0fbdf5264 100644 --- a/include/partition/multi_level_partition.hpp +++ b/include/partition/multi_level_partition.hpp @@ -8,6 +8,7 @@ #include "util/typedefs.hpp" #include "storage/io.hpp" +#include "storage/shared_memory.hpp" #include #include @@ -25,31 +26,31 @@ namespace partition { namespace detail { -template class MultiLevelPartitionImpl; +template class MultiLevelPartitionImpl; } -using MultiLevelPartition = detail::MultiLevelPartitionImpl; -using MultiLevelPartitionView = detail::MultiLevelPartitionImpl; +using MultiLevelPartition = detail::MultiLevelPartitionImpl; +using MultiLevelPartitionView = detail::MultiLevelPartitionImpl; namespace io { -template +template void read(const boost::filesystem::path &file, - detail::MultiLevelPartitionImpl &mlp); -template + detail::MultiLevelPartitionImpl &mlp); +template void write(const boost::filesystem::path &file, - const detail::MultiLevelPartitionImpl &mlp); + const detail::MultiLevelPartitionImpl &mlp); } namespace detail { -template class MultiLevelPartitionImpl final +template 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 using Vector = typename util::ShM::vector; + template using Vector = typename util::ShM::vector; public: // Contains all data necessary to describe the level hierarchy @@ -68,7 +69,7 @@ template 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 > + template > MultiLevelPartitionImpl(const std::vector> &partitions, const std::vector &lidx_to_num_cells) : level_data(MakeLevelData(lidx_to_num_cells)) @@ -76,7 +77,7 @@ template class MultiLevelPartitionImpl final InitializePartitionIDs(partitions); } - template > + template > MultiLevelPartitionImpl(LevelData level_data, Vector partition_, Vector cell_to_children_) @@ -134,9 +135,9 @@ template class MultiLevelPartitionImpl final return cell_to_children[offset + cell + 1]; } - friend void io::read(const boost::filesystem::path &file, + friend void io::read(const boost::filesystem::path &file, MultiLevelPartitionImpl &mlp); - friend void io::write(const boost::filesystem::path &file, + friend void io::write(const boost::filesystem::path &file, const MultiLevelPartitionImpl &mlp); private: diff --git a/include/storage/shared_memory.hpp b/include/storage/shared_memory.hpp index ea5f95470..112767d09 100644 --- a/include/storage/shared_memory.hpp +++ b/include/storage/shared_memory.hpp @@ -30,6 +30,12 @@ namespace osrm namespace storage { +enum class MemorySetting +{ + SharedMemory, + InternalMemory +}; + struct OSRMLockFile { boost::filesystem::path operator()() diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index 343763aa4..f1ef97779 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -4,6 +4,8 @@ #include "util/shared_memory_vector_wrapper.hpp" #include "util/typedefs.hpp" +#include "storage/shared_memory.hpp" + #include #include @@ -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 class PackedVector +template class PackedVector { static const constexpr std::size_t BITSIZE = 33; static const constexpr std::size_t ELEMSIZE = 64; @@ -120,20 +122,20 @@ template class PackedVector std::size_t size() const { return num_elements; } - template + template void reserve(typename std::enable_if::type capacity) { vec.reserve(elements_to_blocks(capacity)); } - template + template void reset(typename std::enable_if::type *ptr, typename std::enable_if::type size) { vec.reset(ptr, size); } - template + template void set_number_of_entries(typename std::enable_if::type count) { num_elements = count; @@ -145,44 +147,44 @@ template class PackedVector } private: - typename util::ShM::vector vec; + typename util::ShM::vector vec; std::size_t num_elements = 0; signed cursor = -1; - template + template void replace_last_elem(typename std::enable_if::type last_elem) { vec[cursor] = last_elem; } - template + template void replace_last_elem(typename std::enable_if::type last_elem) { vec.back() = last_elem; } - template + template void add_last_elem(typename std::enable_if::type last_elem) { vec[cursor + 1] = last_elem; cursor++; } - template + template void add_last_elem(typename std::enable_if::type last_elem) { vec.push_back(last_elem); } - template + template std::uint64_t vec_back(typename std::enable_if::type * = nullptr) { return vec[cursor]; } - template + template std::uint64_t vec_back(typename std::enable_if::type * = nullptr) { return vec.back(); diff --git a/include/util/range_table.hpp b/include/util/range_table.hpp index f24d32e2e..ab88909ec 100644 --- a/include/util/range_table.hpp +++ b/include/util/range_table.hpp @@ -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 @@ -18,13 +19,13 @@ namespace util * and otherwise the compiler gets confused. */ -template class RangeTable; +template class RangeTable; -template -std::ostream &operator<<(std::ostream &out, const RangeTable &table); +template +std::ostream &operator<<(std::ostream &out, const RangeTable &table); -template -std::istream &operator>>(std::istream &in, RangeTable &table); +template +std::istream &operator>>(std::istream &in, RangeTable &table); /** * Stores adjacent ranges in a compressed format. @@ -35,12 +36,12 @@ std::istream &operator>>(std::istream &in, RangeTable class RangeTable +template class RangeTable { public: using BlockT = std::array; - using BlockContainerT = typename ShM::vector; - using OffsetContainerT = typename ShM::vector; + using BlockContainerT = typename ShM::vector; + using OffsetContainerT = typename ShM::vector; using RangeT = range; friend std::ostream &operator<<<>(std::ostream &out, const RangeTable &table); @@ -212,8 +213,8 @@ template class RangeTable unsigned sum_lengths; }; -template -unsigned RangeTable::PrefixSumAtIndex(int index, +template +unsigned RangeTable::PrefixSumAtIndex(int index, const BlockT &block) const { // this loop looks inefficent, but a modern compiler @@ -227,8 +228,8 @@ unsigned RangeTable::PrefixSumAtIndex(int index, return sum; } -template -std::ostream &operator<<(std::ostream &out, const RangeTable &table) +template +std::ostream &operator<<(std::ostream &out, const RangeTable &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 -std::istream &operator>>(std::istream &in, RangeTable &table) +template +std::istream &operator>>(std::istream &in, RangeTable &table) { // read number of block unsigned number_of_blocks; diff --git a/include/util/shared_memory_vector_wrapper.hpp b/include/util/shared_memory_vector_wrapper.hpp index dacc18b2c..642e907db 100644 --- a/include/util/shared_memory_vector_wrapper.hpp +++ b/include/util/shared_memory_vector_wrapper.hpp @@ -3,6 +3,8 @@ #include "util/log.hpp" +#include "storage/shared_memory.hpp" + #include #include #include @@ -130,7 +132,7 @@ template class SharedMemoryWrapper friend void swap(SharedMemoryWrapper &, SharedMemoryWrapper &) noexcept; }; -template <> class SharedMemoryWrapper +template <> class SharedMemoryWrapper { private: unsigned *m_ptr; @@ -173,9 +175,9 @@ void swap(SharedMemoryWrapper &lhs, SharedMemoryWrapper &rhs) noex std::swap(lhs.m_size, rhs.m_size); } -template struct ShM +template struct ShM { - using vector = typename std::conditional, std::vector>::type; }; diff --git a/include/util/static_graph.hpp b/include/util/static_graph.hpp index 24c03c159..1af6afb4a 100644 --- a/include/util/static_graph.hpp +++ b/include/util/static_graph.hpp @@ -7,6 +7,8 @@ #include "util/shared_memory_vector_wrapper.hpp" #include "util/typedefs.hpp" +#include "storage/shared_memory.hpp" + #include #include @@ -97,7 +99,7 @@ EntryT edgeToEntry(const OtherEdge &from, std::false_type) } // namespace static_graph_details -template class StaticGraph +template class StaticGraph { public: using InputEdge = static_graph_details::SortableEdgeWithData; @@ -122,8 +124,8 @@ template class StaticGraph InitializeFromSortedEdgeRange(nodes, edges.begin(), edges.end()); } - StaticGraph(typename ShM::vector node_array_, - typename ShM::vector edge_array_) + StaticGraph(typename ShM::vector node_array_, + typename ShM::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 class StaticGraph NodeIterator number_of_nodes; EdgeIterator number_of_edges; - typename ShM::vector node_array; - typename ShM::vector edge_array; + typename ShM::vector node_array; + typename ShM::vector edge_array; }; } // namespace util diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index ef6754d48..1203f282a 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -15,6 +15,8 @@ #include "osrm/coordinate.hpp" +#include "storage/shared_memory.hpp" + #include #include #include @@ -52,7 +54,7 @@ namespace util // are computed, this means the internal distance metric doesn not represent meters! template , - 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::vector m_search_tree; + typename ShM::vector m_search_tree; const CoordinateListT &m_coordinate_list; boost::iostreams::mapped_file_source m_leaves_region; // read-only view of leaves - typename ShM::vector m_leaves; + typename ShM::vector m_leaves; public: StaticRTree(const StaticRTree &) = delete; diff --git a/src/benchmarks/static_rtree.cpp b/src/benchmarks/static_rtree.cpp index ea0a48965..2da043d61 100644 --- a/src/benchmarks/static_rtree.cpp +++ b/src/benchmarks/static_rtree.cpp @@ -28,7 +28,7 @@ constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; using RTreeLeaf = extractor::EdgeBasedNode; using BenchStaticRTree = - util::StaticRTree::vector, false>; + util::StaticRTree::vector, osrm::storage::MemorySetting::InternalMemory>; std::vector loadCoordinates(const boost::filesystem::path &nodes_file) { diff --git a/src/customize/customizer.cpp b/src/customize/customizer.cpp index f6f5f987f..3415beccc 100644 --- a/src/customize/customizer.cpp +++ b/src/customize/customizer.cpp @@ -8,6 +8,8 @@ #include "partition/io.hpp" #include "partition/multi_level_partition.hpp" +#include "storage/shared_memory.hpp" + #include "updater/updater.hpp" #include "util/log.hpp" @@ -83,7 +85,7 @@ auto LoadAndUpdateEdgeExpandedGraph(const CustomizationConfig &config, auto tidied = partition::prepareEdgesForUsageInGraph(std::move(directed)); auto edge_based_graph = - std::make_unique>( + std::make_unique>( mlp, num_nodes, std::move(tidied)); util::Log() << "Loaded edge based graph for mapping partition ids: " diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 8e9652f46..b0971bd0c 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -56,7 +56,7 @@ namespace storage using RTreeLeaf = engine::datafacade::BaseDataFacade::RTreeLeaf; using RTreeNode = - util::StaticRTree::vector, true>::TreeNode; + util::StaticRTree::vector, osrm::storage::MemorySetting::SharedMemory>::TreeNode; using QueryGraph = util::StaticGraph; using EdgeBasedGraph = util::StaticGraph; @@ -364,12 +364,12 @@ void Storage::PopulateLayout(DataLayout &layout) intersection_file.Skip(1); // sum_lengths layout.SetBlockSize(DataLayout::BEARING_OFFSETS, bearing_blocks); - layout.SetBlockSize::BlockT>(DataLayout::BEARING_BLOCKS, + layout.SetBlockSize::BlockT>(DataLayout::BEARING_BLOCKS, bearing_blocks); // No need to read the data intersection_file.Skip(bearing_blocks); - intersection_file.Skip::BlockT>(bearing_blocks); + intersection_file.Skip::BlockT>(bearing_blocks); const auto num_bearings = intersection_file.ReadElementCount64(); @@ -694,7 +694,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) layout.GetBlockPtr(memory_ptr, DataLayout::COORDINATE_LIST); const auto osmnodeid_ptr = layout.GetBlockPtr(memory_ptr, DataLayout::OSM_NODE_ID_LIST); - util::PackedVector osmnodeid_list; + util::PackedVector osmnodeid_list; osmnodeid_list.reset(osmnodeid_ptr, layout.num_entries[DataLayout::OSM_NODE_ID_LIST]); @@ -803,7 +803,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) intersection_file.Skip(1); // sum_lengths std::vector bearing_offsets_data(bearing_blocks); - std::vector::BlockT> bearing_blocks_data( + std::vector::BlockT> bearing_blocks_data( bearing_blocks); intersection_file.ReadInto(bearing_offsets_data.data(), bearing_blocks); @@ -844,7 +844,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) if (layout.GetBlockSize(DataLayout::BEARING_BLOCKS) > 0) { const auto bearing_blocks_ptr = - layout.GetBlockPtr::BlockT, true>( + layout.GetBlockPtr::BlockT, true>( memory_ptr, DataLayout::BEARING_BLOCKS); BOOST_ASSERT( static_cast(layout.GetBlockSize(DataLayout::BEARING_BLOCKS)) >= diff --git a/unit_tests/customizer/cell_customization.cpp b/unit_tests/customizer/cell_customization.cpp index f874e7c1c..52ac3ec8c 100644 --- a/unit_tests/customizer/cell_customization.cpp +++ b/unit_tests/customizer/cell_customization.cpp @@ -38,7 +38,7 @@ auto makeGraph(const MultiLevelPartition &mlp, const std::vector &mock edges.push_back(Edge{m.target, m.start, m.weight, false, true}); } std::sort(edges.begin(), edges.end()); - return partition::MultiLevelGraph(mlp, max_id + 1, edges); + return partition::MultiLevelGraph(mlp, max_id + 1, edges); } } diff --git a/unit_tests/partition/multi_level_graph.cpp b/unit_tests/partition/multi_level_graph.cpp index 25281ccd0..2841887e7 100644 --- a/unit_tests/partition/multi_level_graph.cpp +++ b/unit_tests/partition/multi_level_graph.cpp @@ -38,7 +38,7 @@ auto makeGraph(const MultiLevelPartition &mlp, const std::vector &mock edges.push_back(Edge{m.target, m.source, false, true}); } std::sort(edges.begin(), edges.end()); - return MultiLevelGraph(mlp, max_id + 1, edges); + return MultiLevelGraph(mlp, max_id + 1, edges); } } diff --git a/unit_tests/util/packed_vector.cpp b/unit_tests/util/packed_vector.cpp index adb58d4f1..5165c5679 100644 --- a/unit_tests/util/packed_vector.cpp +++ b/unit_tests/util/packed_vector.cpp @@ -12,7 +12,7 @@ using namespace osrm::util; // Verify that the packed vector behaves as expected BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test) { - PackedVector packed_ids; + PackedVector packed_ids; std::vector original_ids; const constexpr std::size_t num_test_cases = 399; @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test) BOOST_AUTO_TEST_CASE(packed_vector_capacity_test) { - PackedVector packed_vec; + PackedVector packed_vec; const std::size_t original_size = packed_vec.capacity(); std::vector dummy_vec; diff --git a/unit_tests/util/range_table.cpp b/unit_tests/util/range_table.cpp index b5f439ec1..1d5c5fd8b 100644 --- a/unit_tests/util/range_table.cpp +++ b/unit_tests/util/range_table.cpp @@ -13,7 +13,7 @@ using namespace osrm; using namespace osrm::util; constexpr unsigned BLOCK_SIZE = 16; -typedef RangeTable TestRangeTable; +typedef RangeTable TestRangeTable; void ConstructionTest(stxxl::vector lengths, std::vector offsets) { diff --git a/unit_tests/util/static_graph.cpp b/unit_tests/util/static_graph.cpp index 3e51a3ef2..6a4b90466 100644 --- a/unit_tests/util/static_graph.cpp +++ b/unit_tests/util/static_graph.cpp @@ -70,8 +70,8 @@ template struct RandomArrayEntryFixture std::shuffle(order.begin(), order.end(), g); } - typename ShM::vector nodes; - typename ShM::vector edges; + typename ShM::vector nodes; + typename ShM::vector edges; std::vector lengths; std::vector order; }; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index ec5ae47e4..199697440 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -42,10 +42,10 @@ constexpr uint32_t TEST_LEAF_NODE_SIZE = 64; using TestData = extractor::EdgeBasedNode; using TestStaticRTree = StaticRTree, - false, + osrm::storage::MemorySetting::InternalMemory, TEST_BRANCHING_FACTOR, TEST_LEAF_NODE_SIZE>; -using MiniStaticRTree = StaticRTree, false, 2, 128>; +using MiniStaticRTree = StaticRTree, osrm::storage::MemorySetting::InternalMemory, 2, 128>; // Choosen by a fair W20 dice roll (this value is completely arbitrary) constexpr unsigned RANDOM_SEED = 42; @@ -273,7 +273,7 @@ void construction_test(const std::string &prefix, FixtureT *fixture) BOOST_FIXTURE_TEST_CASE(construct_tiny, TestRandomGraphFixture_10_30) { - using TinyTestTree = StaticRTree, false, 2, 64>; + using TinyTestTree = StaticRTree, osrm::storage::MemorySetting::InternalMemory, 2, 64>; construction_test("test_tiny", this); }