提交 c6b18cca 编写于 作者: D Dong Li 提交者: Liangliang Zhang

planning: use original ctpl

上级 89432616
......@@ -40,6 +40,14 @@ new_http_archive(
url = "file:///home/tmp/benchmark-1.1.0.tar.gz",
)
new_http_archive(
name = "ctpl",
build_file = "third_party/ctpl.BUILD",
sha256 = "8c1cec7c570d6d84be1d29283af5039ea27c3e69703bd446d396424bf619816e",
strip_prefix = "CTPL-ctpl_v.0.0.2",
url = "https://github.com/vit-vit/CTPL/archive/ctpl_v.0.0.2.tar.gz",
)
# cpplint from google style guide
new_git_repository(
name = "google_styleguide",
......
......@@ -193,6 +193,7 @@ cc_library(
"//modules/planning/common/trajectory:publishable_trajectory",
"//modules/planning/proto:lattice_structure_proto",
"//modules/planning/reference_line",
"@ctpl",
"@eigen",
],
)
......
......@@ -276,8 +276,8 @@ DEFINE_bool(enable_follow_accel_constraint, true,
DEFINE_bool(enable_sqp_solver, true, "True to enable SQP solver.");
/// thread pool
DEFINE_int32(num_thread_planning_thread_pool, 5,
"num of thread used in planning thread pool.");
DEFINE_uint32(max_planning_thread_pool_size, 5,
"num of thread used in planning thread pool.");
DEFINE_bool(use_multi_thread_to_add_obstacles, false,
"use multiple thread to add obstacles.");
DEFINE_bool(
......
......@@ -142,7 +142,7 @@ DECLARE_bool(enable_follow_accel_constraint);
DECLARE_bool(enable_sqp_solver);
/// thread pool
DECLARE_int32(num_thread_planning_thread_pool);
DECLARE_uint32(max_planning_thread_pool_size);
DECLARE_bool(use_multi_thread_to_add_obstacles);
DECLARE_bool(enable_multi_thread_in_dp_poly_path);
DECLARE_bool(enable_multi_thread_in_dp_st_graph);
......
......@@ -32,7 +32,7 @@ void PlanningThreadPool::Init() {
return;
}
thread_pool_.reset(
new common::util::ThreadPool(FLAGS_num_thread_planning_thread_pool));
new common::util::ThreadPool(FLAGS_max_planning_thread_pool_size));
is_initialized = true;
}
......
......@@ -24,6 +24,8 @@
#include <functional>
#include <utility>
#include "ctpl/ctpl_stl.h"
#include "modules/planning/proto/sl_boundary.pb.h"
#include "modules/common/adapters/adapter_manager.h"
......@@ -267,14 +269,19 @@ PathObstacle* ReferenceLineInfo::AddObstacle(const Obstacle* obstacle) {
bool ReferenceLineInfo::AddObstacles(
const std::vector<const Obstacle*>& obstacles) {
if (obstacles.empty()) {
return true;
}
if (FLAGS_use_multi_thread_to_add_obstacles) {
std::vector<int> ret(obstacles.size(), 0);
ctpl::thread_pool pool(
std::min<int>(FLAGS_max_planning_thread_pool_size, obstacles.size()));
for (size_t i = 0; i < obstacles.size(); ++i) {
const auto* obstacle = obstacles.at(i);
PlanningThreadPool::instance()->Push(std::bind(
&ReferenceLineInfo::AddObstacleHelper, this, obstacle, &(ret[i])));
pool.push(std::bind(&ReferenceLineInfo::AddObstacleHelper, this, obstacle,
&(ret[i])));
}
PlanningThreadPool::instance()->Synchronize();
pool.stop(true);
if (std::find(ret.begin(), ret.end(), 0) != ret.end()) {
return false;
}
......@@ -397,7 +404,7 @@ bool ReferenceLineInfo::IsChangeLanePath() const {
}
bool ReferenceLineInfo::IsNeighborLanePath() const {
return Lanes().IsNeighborSegment();
return Lanes().IsNeighborSegment();
}
std::string ReferenceLineInfo::PathSpeedDebugString() const {
......
......@@ -41,6 +41,9 @@ DEFINE_string(test_previous_planning_file, "",
"The previous planning test file");
void PlanningTestBase::SetUpTestCase() {
FLAGS_use_multi_thread_to_add_obstacles = false;
FLAGS_enable_multi_thread_in_dp_poly_path = false;
FLAGS_enable_multi_thread_in_dp_st_graph = false;
FLAGS_planning_config_file = "modules/planning/conf/planning_config.pb.txt";
FLAGS_planning_adapter_config_filename =
"modules/planning/testdata/conf/adapter.conf";
......
......@@ -132,9 +132,6 @@ Status Planning::Init() {
<< "Failed to load traffic rule config file "
<< FLAGS_traffic_rule_config_filename;
// initialize planning thread pool
PlanningThreadPool::instance()->Init();
// clear planning status
util::GetPlanningStatus()->Clear();
......@@ -489,7 +486,6 @@ void Planning::SetFallbackTrajectory(ADCTrajectory* trajectory_pb) {
void Planning::Stop() {
AERROR << "Planning Stop is called";
// PlanningThreadPool::instance()->Stop();
if (reference_line_provider_) {
reference_line_provider_->Stop();
}
......
......@@ -23,6 +23,8 @@
#include <algorithm>
#include <utility>
#include "ctpl/ctpl_stl.h"
#include "modules/common/proto/error_code.pb.h"
#include "modules/common/proto/pnc_point.pb.h"
#include "modules/planning/proto/planning_internal.pb.h"
......@@ -43,8 +45,8 @@ namespace apollo {
namespace planning {
using apollo::common::ErrorCode;
using apollo::common::Status;
using apollo::common::SLPoint;
using apollo::common::Status;
using apollo::common::math::CartesianFrenetConverter;
using apollo::common::util::MakeSLPoint;
......@@ -150,23 +152,26 @@ bool DPRoadGraph::GenerateMinCostPath(
graph_nodes.emplace_back();
ctpl::thread_pool pool(std::min<std::size_t>(
FLAGS_max_planning_thread_pool_size, level_points.size()));
for (size_t i = 0; i < level_points.size(); ++i) {
const auto &cur_point = level_points[i];
graph_nodes.back().emplace_back(cur_point, nullptr);
auto &cur_node = graph_nodes.back().back();
if (FLAGS_enable_multi_thread_in_dp_poly_path) {
PlanningThreadPool::instance()->Push(std::bind(
&DPRoadGraph::UpdateNode, this, std::ref(prev_dp_nodes), level,
total_level, &trajectory_cost, &(front), &(cur_node)));
pool.push(std::bind(&DPRoadGraph::UpdateNode, this,
std::ref(prev_dp_nodes), level, total_level,
&trajectory_cost, &(front), &(cur_node)));
} else {
UpdateNode(prev_dp_nodes, level, total_level, &trajectory_cost, &front,
&cur_node);
}
}
if (FLAGS_enable_multi_thread_in_dp_poly_path) {
PlanningThreadPool::instance()->Synchronize();
pool.stop(true);
}
}
......
......@@ -57,6 +57,7 @@ cc_library(
"//modules/planning/proto:planning_config_proto",
"//modules/planning/proto:planning_proto",
"//modules/planning/tasks/st_graph:st_graph_data",
"@ctpl",
],
)
......
......@@ -25,6 +25,8 @@
#include <string>
#include <utility>
#include "ctpl/ctpl_stl.h"
#include "modules/common/proto/pnc_point.pb.h"
#include "modules/common/log.h"
......@@ -172,17 +174,21 @@ Status DpStGraph::CalculateTotalCost() {
int highest_row = 0;
int lowest_row = cost_table_.back().size() - 1;
for (uint32_t r = next_lowest_row; r <= next_highest_row; ++r) {
int count = next_highest_row - next_lowest_row + 1;
if (count > 0) {
ctpl::thread_pool pool(
std::min<std::size_t>(FLAGS_max_planning_thread_pool_size, count));
for (uint32_t r = next_lowest_row; r <= next_highest_row; ++r) {
if (FLAGS_enable_multi_thread_in_dp_st_graph) {
pool.push(std::bind(&DpStGraph::CalculateCostAt, this, c, r));
} else {
CalculateCostAt(c, r);
}
}
if (FLAGS_enable_multi_thread_in_dp_st_graph) {
PlanningThreadPool::instance()->Push(
std::bind(&DpStGraph::CalculateCostAt, this, c, r));
} else {
CalculateCostAt(c, r);
pool.stop(true);
}
}
if (FLAGS_enable_multi_thread_in_dp_st_graph) {
PlanningThreadPool::instance()->Synchronize();
}
for (uint32_t r = next_lowest_row; r <= next_highest_row; ++r) {
const auto& cost_cr = cost_table_[c][r];
......
......@@ -36,10 +36,9 @@ namespace planning {
class DpStGraphTest : public ::testing::Test {
public:
virtual void SetUp() {
PlanningThreadPool::instance()->Init();
// dp_config_
PlanningConfig config;
FLAGS_enable_multi_thread_in_dp_st_graph = true;
FLAGS_planning_config_file = "modules/planning/conf/planning_config.pb.txt";
CHECK(apollo::common::util::GetProtoFromFile(FLAGS_planning_config_file,
&config));
......
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
cc_library(
name = "ctpl",
hdrs = [
"ctpl_stl.h",
],
include_prefix = "ctpl",
linkopts = [
"-lpthread",
],
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册