Migrate to modern TBB version (#6300)

This commit is contained in:
Siarhei Fedartsou
2022-08-24 18:13:49 +02:00
committed by GitHub
parent a98074a051
commit 91895604c9
18 changed files with 586 additions and 718 deletions
+10 -9
View File
@@ -32,7 +32,7 @@
#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>
#include <tbb/pipeline.h>
#include <tbb/parallel_pipeline.h>
namespace std
{
@@ -489,8 +489,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// Sets of intersection IDs are batched in groups of GRAINSIZE (100) `generator_stage`, then
// those groups are processed in parallel `processor_stage`. Finally, results are appended to
// the various buffer vectors by the `output_stage` in the same order that the `generator_stage`
// created them in (tbb::filter::serial_in_order creates this guarantee). The order needs to be
// maintained because we depend on it later in the processing pipeline.
// created them in (tbb::filter_mode::serial_in_order creates this guarantee). The order needs
// to be maintained because we depend on it later in the processing pipeline.
{
const NodeID node_count = m_node_based_graph.GetNumberOfNodes();
@@ -540,8 +540,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const constexpr unsigned GRAINSIZE = 100;
// First part of the pipeline generates iterator ranges of IDs in sets of GRAINSIZE
tbb::filter_t<void, tbb::blocked_range<NodeID>> generator_stage(
tbb::filter::serial_in_order, [&](tbb::flow_control &fc) {
tbb::filter<void, tbb::blocked_range<NodeID>> generator_stage(
tbb::filter_mode::serial_in_order, [&](tbb::flow_control &fc) {
if (current_node < node_count)
{
auto next_node = std::min(current_node + GRAINSIZE, node_count);
@@ -675,8 +675,9 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
//
// Edge-based-graph stage
//
tbb::filter_t<tbb::blocked_range<NodeID>, EdgesPipelineBufferPtr> processor_stage(
tbb::filter::parallel, [&](const tbb::blocked_range<NodeID> &intersection_node_range) {
tbb::filter<tbb::blocked_range<NodeID>, EdgesPipelineBufferPtr> processor_stage(
tbb::filter_mode::parallel,
[&](const tbb::blocked_range<NodeID> &intersection_node_range) {
auto buffer = std::make_shared<EdgesPipelineBuffer>();
buffer->nodes_processed = intersection_node_range.size();
@@ -1085,8 +1086,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
util::UnbufferedLog log;
util::Percent routing_progress(log, node_count);
std::vector<EdgeWithData> delayed_data;
tbb::filter_t<EdgesPipelineBufferPtr, void> output_stage(
tbb::filter::serial_in_order, [&](auto buffer) {
tbb::filter<EdgesPipelineBufferPtr, void> output_stage(
tbb::filter_mode::serial_in_order, [&](auto buffer) {
routing_progress.PrintAddition(buffer->nodes_processed);
m_connectivity_checksum = buffer->checksum.update_checksum(m_connectivity_checksum);
+13 -23
View File
@@ -43,13 +43,8 @@
#include <osmium/io/any_input.hpp>
#include <osmium/thread/pool.hpp>
#include <osmium/visitor.hpp>
#if TBB_VERSION_MAJOR == 2020
#include <tbb/global_control.h>
#else
#include <tbb/task_scheduler_init.h>
#endif
#include <tbb/pipeline.h>
#include <tbb/parallel_pipeline.h>
#include <algorithm>
#include <atomic>
@@ -206,13 +201,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
const unsigned recommended_num_threads = std::thread::hardware_concurrency();
const auto number_of_threads = std::min(recommended_num_threads, config.requested_num_threads);
#if TBB_VERSION_MAJOR == 2020
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
#else
tbb::task_scheduler_init init(config.requested_num_threads);
BOOST_ASSERT(init.is_active());
#endif
LaneDescriptionMap turn_lane_map;
std::vector<TurnRestriction> turn_restrictions;
@@ -456,8 +446,8 @@ std::
ExtractionRelationContainer relations;
const auto buffer_reader = [](osmium::io::Reader &reader) {
return tbb::filter_t<void, SharedBuffer>(
tbb::filter::serial_in_order, [&reader](tbb::flow_control &fc) {
return tbb::filter<void, SharedBuffer>(
tbb::filter_mode::serial_in_order, [&reader](tbb::flow_control &fc) {
if (auto buffer = reader.read())
{
return std::make_shared<osmium::memory::Buffer>(std::move(buffer));
@@ -478,15 +468,15 @@ std::
osmium_index_type location_cache;
osmium_location_handler_type location_handler(location_cache);
tbb::filter_t<SharedBuffer, SharedBuffer> location_cacher(
tbb::filter::serial_in_order, [&location_handler](SharedBuffer buffer) {
tbb::filter<SharedBuffer, SharedBuffer> location_cacher(
tbb::filter_mode::serial_in_order, [&location_handler](SharedBuffer buffer) {
osmium::apply(buffer->begin(), buffer->end(), location_handler);
return buffer;
});
// OSM elements Lua parser
tbb::filter_t<SharedBuffer, ParsedBuffer> buffer_transformer(
tbb::filter::parallel,
tbb::filter<SharedBuffer, ParsedBuffer> buffer_transformer(
tbb::filter_mode::parallel,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
[&](const SharedBuffer buffer) {
ParsedBuffer parsed_buffer;
@@ -507,8 +497,8 @@ std::
unsigned number_of_ways = 0;
unsigned number_of_restrictions = 0;
unsigned number_of_maneuver_overrides = 0;
tbb::filter_t<ParsedBuffer, void> buffer_storage(
tbb::filter::serial_in_order, [&](const ParsedBuffer &parsed_buffer) {
tbb::filter<ParsedBuffer, void> buffer_storage(
tbb::filter_mode::serial_in_order, [&](const ParsedBuffer &parsed_buffer) {
number_of_nodes += parsed_buffer.resulting_nodes.size();
// put parsed objects thru extractor callbacks
for (const auto &result : parsed_buffer.resulting_nodes)
@@ -534,8 +524,8 @@ std::
}
});
tbb::filter_t<SharedBuffer, std::shared_ptr<ExtractionRelationContainer>> buffer_relation_cache(
tbb::filter::parallel,
tbb::filter<SharedBuffer, std::shared_ptr<ExtractionRelationContainer>> buffer_relation_cache(
tbb::filter_mode::parallel,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
[&](const SharedBuffer buffer) {
if (!buffer)
@@ -572,8 +562,8 @@ std::
});
unsigned number_of_relations = 0;
tbb::filter_t<std::shared_ptr<ExtractionRelationContainer>, void> buffer_storage_relation(
tbb::filter::serial_in_order,
tbb::filter<std::shared_ptr<ExtractionRelationContainer>, void> buffer_storage_relation(
tbb::filter_mode::serial_in_order,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
[&](const std::shared_ptr<ExtractionRelationContainer> parsed_relations) {
number_of_relations += parsed_relations->GetRelationsNum();