Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compare_map_filter): deadlock bug fix #10222

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

badai-nguyen
Copy link
Contributor

@badai-nguyen badai-nguyen commented Mar 4, 2025

Description

  • To add missing mutex for current_voxel_grid_dict_ and current_voxel_grid_array_ in dynamic_map_loader mode such as
    if (current_voxel_grid_dict_.size() == 0) {
    return false;
    }
    // Compare point with map grid that point belong to
    int map_grid_index = static_cast<int>(
    std::floor((point.x - origin_x_) / map_grid_size_x_) +
    map_grids_x_ * std::floor((point.y - origin_y_) / map_grid_size_y_));
    if (static_cast<size_t>(map_grid_index) >= current_voxel_grid_array_.size()) {
    return false;
    }
    if (
    current_voxel_grid_array_.at(map_grid_index) != nullptr &&
    is_close_to_neighbor_voxels(
    point, distance_threshold, current_voxel_grid_array_.at(map_grid_index)->map_cell_pc_ptr,
    current_voxel_grid_array_.at(map_grid_index)->map_cell_voxel_grid)) {
    return true;
    }

Related links

- TIER IV internal link

Parent Issue:

  • Link

How was this PR tested?

  • Testing on Evaluator (wip)
  • Confirm by logging_simulator, and the processing_time is similar with before update
Before After
Screenshot from 2025-03-04 21-40-01_before Screenshot from 2025-03-04 21-36-24_after

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

@github-actions github-actions bot added the component:perception Advanced sensor data processing and environment understanding. (auto-assigned) label Mar 4, 2025
Copy link

github-actions bot commented Mar 4, 2025

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
@badai-nguyen badai-nguyen force-pushed the fix/compare_map_mutex branch from a31564d to 9d844df Compare March 4, 2025 12:26
@badai-nguyen badai-nguyen requested a review from veqcc March 4, 2025 12:49
@badai-nguyen badai-nguyen self-assigned this Mar 4, 2025
@veqcc
Copy link
Contributor

veqcc commented Mar 5, 2025

@badai-nguyen
Thank you for your quick work!!

Requests from me:

  • could you clarify where is the critical section and which is the shared resource?
  • could you avoid writing naive lock() and unlock() ? Instead, use scoped lock as much as possible.

Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
@badai-nguyen
Copy link
Contributor Author

@veqcc

@badai-nguyen Thank you for your quick work!!

Requests from me:

  • could you clarify where is the critical section and which is the shared resource?
  • could you avoid writing naive lock() and unlock() ? Instead, use scoped lock as much as possible.

Thanks for your comment, I fixed here 52c5459

@badai-nguyen badai-nguyen added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Mar 6, 2025
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 74 lines in your changes missing coverage. Please review.

Project coverage is 26.32%. Comparing base (92da629) to head (dc5f72d).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...rc/voxel_grid_map_loader/voxel_grid_map_loader.cpp 0.00% 29 Missing ⚠️
...ion/src/distance_based_compare_map_filter/node.cpp 0.00% 10 Missing ⚠️
...oxel_based_approximate_compare_map_filter/node.cpp 0.00% 10 Missing ⚠️
...rc/voxel_grid_map_loader/voxel_grid_map_loader.hpp 0.00% 9 Missing and 1 partial ⚠️
...c/voxel_distance_based_compare_map_filter/node.cpp 0.00% 9 Missing ⚠️
...ion/src/distance_based_compare_map_filter/node.hpp 0.00% 3 Missing ⚠️
...c/voxel_distance_based_compare_map_filter/node.hpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10222      +/-   ##
==========================================
+ Coverage   26.25%   26.32%   +0.06%     
==========================================
  Files        1381     1384       +3     
  Lines      107503   107525      +22     
  Branches    41411    41385      -26     
==========================================
+ Hits        28229    28305      +76     
+ Misses      76459    76397      -62     
- Partials     2815     2823       +8     
Flag Coverage Δ *Carryforward flag
differential 6.99% <0.00%> (?)
differential-cuda 6.99% <0.00%> (?)
total 26.34% <ø> (+0.08%) ⬆️ Carriedforward from 1065feb

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@veqcc
Copy link
Contributor

veqcc commented Mar 6, 2025

@badai-nguyen

Thank you.
Then please pass required CI checks

Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
@badai-nguyen badai-nguyen added run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) and removed run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) labels Mar 6, 2025
@badai-nguyen badai-nguyen marked this pull request as ready for review March 6, 2025 20:54
@veqcc
Copy link
Contributor

veqcc commented Mar 7, 2025

@badai-nguyen

Are you missing mutex for map_grid_size_x_ and map_grid_size_y_ ?

  inline void addMapCellAndFilter(
    const autoware_map_msgs::msg::PointCloudMapCellWithID & map_cell_to_add) override
  {
    map_grid_size_x_ = map_cell_to_add.metadata.max_x - map_cell_to_add.metadata.min_x;
    map_grid_size_y_ = map_cell_to_add.metadata.max_y - map_cell_to_add.metadata.min_y;

    pcl::PointCloud<pcl::PointXYZ> map_cell_pc_tmp;
    pcl::fromROSMsg(map_cell_to_add.pointcloud, map_cell_pc_tmp);

    auto map_cell_voxel_input_tmp_ptr =
      std::make_shared<pcl::PointCloud<pcl::PointXYZ>>(map_cell_pc_tmp);

    MapGridVoxelInfo current_voxel_grid_list_item;
    current_voxel_grid_list_item.min_b_x = map_cell_to_add.metadata.min_x;
    current_voxel_grid_list_item.min_b_y = map_cell_to_add.metadata.min_y;
    current_voxel_grid_list_item.max_b_x = map_cell_to_add.metadata.max_x;
    current_voxel_grid_list_item.max_b_y = map_cell_to_add.metadata.max_y;

    // add kdtree
    pcl::search::Search<pcl::PointXYZ>::Ptr tree_tmp;
    if (!tree_tmp) {
      if (map_cell_voxel_input_tmp_ptr->isOrganized()) {
        tree_tmp.reset(new pcl::search::OrganizedNeighbor<pcl::PointXYZ>());
      } else {
        tree_tmp.reset(new pcl::search::KdTree<pcl::PointXYZ>(false));
      }
    }
    tree_tmp->setInputCloud(map_cell_voxel_input_tmp_ptr);
    current_voxel_grid_list_item.map_cell_kdtree = tree_tmp;

    // add
    std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
    current_voxel_grid_dict_.insert({map_cell_to_add.cell_id, current_voxel_grid_list_item});
  }

Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
@badai-nguyen
Copy link
Contributor Author

@badai-nguyen

Are you missing mutex for map_grid_size_x_ and map_grid_size_y_ ?

  inline void addMapCellAndFilter(
    const autoware_map_msgs::msg::PointCloudMapCellWithID & map_cell_to_add) override
  {
    map_grid_size_x_ = map_cell_to_add.metadata.max_x - map_cell_to_add.metadata.min_x;
    map_grid_size_y_ = map_cell_to_add.metadata.max_y - map_cell_to_add.metadata.min_y;

    pcl::PointCloud<pcl::PointXYZ> map_cell_pc_tmp;
    pcl::fromROSMsg(map_cell_to_add.pointcloud, map_cell_pc_tmp);

    auto map_cell_voxel_input_tmp_ptr =
      std::make_shared<pcl::PointCloud<pcl::PointXYZ>>(map_cell_pc_tmp);

    MapGridVoxelInfo current_voxel_grid_list_item;
    current_voxel_grid_list_item.min_b_x = map_cell_to_add.metadata.min_x;
    current_voxel_grid_list_item.min_b_y = map_cell_to_add.metadata.min_y;
    current_voxel_grid_list_item.max_b_x = map_cell_to_add.metadata.max_x;
    current_voxel_grid_list_item.max_b_y = map_cell_to_add.metadata.max_y;

    // add kdtree
    pcl::search::Search<pcl::PointXYZ>::Ptr tree_tmp;
    if (!tree_tmp) {
      if (map_cell_voxel_input_tmp_ptr->isOrganized()) {
        tree_tmp.reset(new pcl::search::OrganizedNeighbor<pcl::PointXYZ>());
      } else {
        tree_tmp.reset(new pcl::search::KdTree<pcl::PointXYZ>(false));
      }
    }
    tree_tmp->setInputCloud(map_cell_voxel_input_tmp_ptr);
    current_voxel_grid_list_item.map_cell_kdtree = tree_tmp;

    // add
    std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
    current_voxel_grid_dict_.insert({map_cell_to_add.cell_id, current_voxel_grid_list_item});
  }

@veqcc Thank you for your pointing out.
I fixed by dc5f72d

Copy link
Contributor

@veqcc veqcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM about mutex.
I cannot review the logic of compare_map_filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:perception Advanced sensor data processing and environment understanding. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)
Projects
Status: To Triage
Development

Successfully merging this pull request may close these issues.

2 participants