Skip to content

tight floor plan memory leak bugs #2178

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

Merged
merged 33 commits into from
Oct 29, 2022
Merged

tight floor plan memory leak bugs #2178

merged 33 commits into from
Oct 29, 2022

Conversation

zhaisitong
Copy link
Contributor

@zhaisitong zhaisitong commented Oct 19, 2022

Description

  1. Memory leak bugs on tight floor plan.
  2. Global variable "errno" bug when transfering a string to int.
  3. Create small testcase to test tight floor plan with make sanitizer.

Related Issue

This tasks continues from PR #2161.

  1. memory leak comes from function "save_and_reset_lb_route" in file "vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1342". The reason is that when freeing the "clustering_data.intra_lb_routing" in function "free_clustering_data" of file "vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:230", the count of blocks in cluster netlist is 0, but the count of clustering_data.intra_lb_routing is more than 0.
  2. memory leak comes from "cluster_placement.cpp:63" in function "alloc_and_load_cluster_cluster_placement_stats". In each pack iteration, the cluster_placement_stats of helper_ctx will be allocated once, but we only free cluster_placement_stats in the end of the vpr_flow. So move free function to the end of each pack iteration.
  3. memory leak comes from "cluster_util.cpp:580" in function "alloc_and_init_clustering". In each pack iteration, the primitive_list of helper_ctx will be allocated once, but we only free primitive_list in the end of the vpr_flow. So free the primitive_list at the end of each pack iteration.
  4. memory leak from "cluster_util.cpp:2106" in function "start_new_cluster". Mistakenly clear the netlist before freeing relevant memories at the end of each pack iteration.
  5. Create a new test "strong_tight_floorplan" in vtr_reg_strong for sanitizer test. The new test case using benchmark "bigkey.blif" and architecture "k6_N10_40nm.xml" with a vpr placement constraint file "bigkey_tight_floorplan.xml". This testcase can test the tight floor plan relevant codes to make sure no memory leaks on this part in the furture.
    The runtime of this new testcase with make sanitizer on our check server is 336.56s, without sanitizer is 11s.
  6. Problem reason:
    The global variable "errno" from the GNU C Library "errno.h" is set to 22 because: when invoking"out.set_add_atom_name_pattern(attr.value(), context);" at "vpr_constraints_uxsdcxxx.h:480" in function "inline void load_add_atom(const pugi::xml_node& root, T& out, Context& context, const std::function<void(const char*)>* report_error, ptrdiff_t* offset_debug)", the argument "context" is not used. So the global variable "errno" is set to 22 which means "invalid argument" when making with sanitizer on our check server. Thus, when coming into function load_int, the errno is 22 although there is no problem when parsing int value from a string. This might because of the difference on g++ version or other environment values between the check server with our wintermute server.
    Try to solve directly:
    This problem cannot be solved by fixing the problem on the argument of the function set_add_atom_name_pattern. Because the variable "context" has been declared as "void*" which is correct, and the function "set_add_atom_name_pattern" belong to "class VprConstraintsSerializer" in file "vpr_constraints_serializer.h", and this class inherits from a template class "class VprConstraintsBase". In the base class, the function "set_add_atom_name_pattern" has already been defined as a pure virtual function with template "virtual inline void set_add_atom_name_pattern(const char* name_pattern, typename ContextTypes::AddAtomWriteContext& ctx) = 0;" Although the argument "context" is not used in the derived class "VprConstraintsSerializer", we cannot change the function definition and we cannot give it a default value "NULL" because "context" is a reference of void pointer.
    Final solution:
    A better and more reasonable solution is that we set "errno = 0" before using the global variable "errno". That is, we give a statement "errno = 0;" before transfering a string value to an int value. This is also the correct way to use global variable "errno".

Motivation and Context

  1. Debug memory leaks to make tight floor plan codes work.
  2. Give a small test case to avoid the bugs on tight floor plan with making sanitizer.

How Has This Been Tested?

Use task vpr_tight_floorplan in regression_test vtr_reg_nightly_test5.
Use task strong_tight_floorplan in regression_test vtr_reg_strong for faster sanitizer test.

Types of changes

  • Bug fix (change which fixes an issue)

Checklist:

  • I have added tests to cover my changes
  • All new and existing tests passed

@github-actions github-actions bot added infra Project Infrastructure libarchfpga Library for handling FPGA Architecture descriptions labels Oct 19, 2022
@zhaisitong
Copy link
Contributor Author

Move from PR #2161 , continue to fix the memory leak bugs.

@zhaisitong
Copy link
Contributor Author

memory leak bugs list:

Incr Criticality updates 0 in 0 sec
Full Criticality updates 1 in 0.228651 sec
Flow timing analysis took 1067.8 seconds (922.923 STA, 144.876 slack) (211 full updates: 182 setup, 0 hold, 29 combined).
VPR succeeded
The entire flow of VPR took 8805.97 seconds (max_rss 7193.4 MiB)
Incr Slack updates 28 in 3.21793 sec
Full Max Req/Worst Slack updates 6 in 0.616913 sec
Incr Max Req/Worst Slack updates 22 in 5.03899 sec
Incr Criticality updates 19 in 3.88498 sec
Full Criticality updates 9 in 2.03026 sec

=================================================================
==117225==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 88200 byte(s) in 3675 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300d0669a9 in save_and_reset_lb_route /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1342
#2 0x56300d0669a9 in try_intra_lb_route(t_lb_router_data*, int, t_mode_selection_status*) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:517

Direct leak of 336 byte(s) in 1 object(s) allocated from:
#0 0x56300fdf3f07 in operator new[](unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683f07)
#1 0x56300f4aafa7 in alloc_and_load_cluster_placement_stats() /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:63
#2 0x56300f4aafa7 in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:566

Direct leak of 160 byte(s) in 1 object(s) allocated from:
#0 0x56300fdf3f07 in operator new[](unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683f07)
#1 0x56300f4ac72d in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:580

Indirect leak of 56604448 byte(s) in 1497270 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300d064d07 in __gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >::allocate(unsigned long, void const*) /usr/include/c++/11/ext/new_allocator.h:127
#2 0x56300d064d07 in std::allocator_traits<std::allocator<t_lb_trace> >::allocate(std::allocator<t_lb_trace>&, unsigned long) /usr/include/c++/11/bits/alloc_traits.h:464
#3 0x56300d064d07 in std::_Vector_base<t_lb_trace, std::allocator<t_lb_trace> >::_M_allocate(unsigned long) /usr/include/c++/11/bits/stl_vector.h:346
#4 0x56300d064d07 in void std::vector<t_lb_trace, std::allocator<t_lb_trace> >::_M_realloc_insert<t_lb_trace const&>(__gnu_cxx::__normal_iterator<t_lb_trace*, std::vector<t_lb_trace, std::allocator<t_lb_trace> > >, t_lb_trace const&) /usr/include/c++/11/bits/vector.tcc:440
#5 0x56300d064d07 in std::vector<t_lb_trace, std::allocator<t_lb_trace> >::push_back(t_lb_trace const&) /usr/include/c++/11/bits/stl_vector.h:1198
#6 0x56300d064d07 in add_to_rt /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1233
#7 0x56300d064d07 in try_intra_lb_route(t_lb_router_data*, int, t_mode_selection_status*) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:466

Indirect leak of 39085147 byte(s) in 206479 object(s) allocated from:
#0 0x56300fdf2607 in __interceptor_calloc (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9682607)
#1 0x56300f21f243 in vtr::calloc(unsigned long, unsigned long) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/libs/libvtrutil/src/vtr_memory.cpp:44

Indirect leak of 32636176 byte(s) in 150562 object(s) allocated from:
#0 0x56300fdf3f07 in operator new[](unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683f07)
#1 0x56300fd16c0d in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1225

Indirect leak of 19700200 byte(s) in 3675 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300d066bfc in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::__detail::_NFA<std::__cxx11::regex_traits >, std::allocator<std::__detail::_NFA<std::__cxx11::regex_traits > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /usr/include/c++/11/ext/new_allocator.h:127
#2 0x56300d066bfc in std::allocator_traits<std::allocator<t_intra_lb_net> >::allocate(std::allocator<t_intra_lb_net>&, unsigned long) /usr/include/c++/11/bits/alloc_traits.h:464
#3 0x56300d066bfc in std::_Vector_base<t_intra_lb_net, std::allocator<t_intra_lb_net> >::_M_allocate(unsigned long) /usr/include/c++/11/bits/stl_vector.h:346
#4 0x56300d066bfc in std::_Vector_base<t_intra_lb_net, std::allocator<t_intra_lb_net> >::_M_create_storage(unsigned long) /usr/include/c++/11/bits/stl_vector.h:361
#5 0x56300d066bfc in std::_Vector_base<t_intra_lb_net, std::allocator<t_intra_lb_net> >::_Vector_base(unsigned long, std::allocator<t_intra_lb_net> const&) /usr/include/c++/11/bits/stl_vector.h:305
#6 0x56300d066bfc in std::vector<t_intra_lb_net, std::allocator<t_intra_lb_net> >::vector(unsigned long, std::allocator<t_intra_lb_net> const&) /usr/include/c++/11/bits/stl_vector.h:511
#7 0x56300d066bfc in save_and_reset_lb_route /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1342
#8 0x56300d066bfc in try_intra_lb_route(t_lb_router_data*, int, t_mode_selection_status*) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:517

Indirect leak of 6061600 byte(s) in 189425 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300d05dd90 in add_source_to_rt /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1060
#2 0x56300d05dd90 in try_intra_lb_route(t_lb_router_data*, int, t_mode_selection_status*) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:447

Indirect leak of 2342136 byte(s) in 189425 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300cf3d7ae in __gnu_cxx::new_allocator<vtr::StrongId<cluster_block_id_tag, int, -1> >::allocate(unsigned long, void const*) /usr/include/c++/11/ext/new_allocator.h:127
#2 0x56300cf3d7ae in std::allocator_traits<std::allocator >::allocate(std::allocator&, unsigned long) /usr/include/c++/11/bits/alloc_traits.h:464
#3 0x56300cf3d7ae in std::_Vector_base<int, std::allocator >::_M_allocate(unsigned long) /usr/include/c++/11/bits/stl_vector.h:346
#4 0x56300cf3d7ae in std::vector<int, std::allocator >::_M_default_append(unsigned long) /usr/include/c++/11/bits/vector.tcc:635

Indirect leak of 1204496 byte(s) in 119604 object(s) allocated from:
#0 0x56300fdf3f07 in operator new[](unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683f07)
#1 0x56300fd16a73 in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1222

Indirect leak of 470400 byte(s) in 3675 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300fb9e5ce in start_new_cluster(t_cluster_placement_stats*, t_pb_graph_node**, vtr::StrongId<cluster_block_id_tag, int, -1>, t_pack_molecule*, std::map<t_logical_block_type const*, unsigned long, std::less<t_logical_block_type const*>, std::allocator<std::pair<t_logical_block_type const* const, unsigned long> > >&, float, int, int, t_arch const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_lb_router_data**, int, ClusteredNetlist, std::map<t_model const*, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> >, std::less<t_model const*>, std::allocator<std::pair<t_model const* const, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> > > > > const&, int, bool, bool, int, PartitionRegion&) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:2106
#2 0x56300fbad2b4 in do_clustering(t_packer_opts const&, t_analysis_opts const&, t_arch const*, t_pack_molecule*, int, std::unordered_set<vtr::StrongId<atom_net_id_tag, int, -1>, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<vtr::StrongId<atom_net_id_tag, int, -1> > > const&, std::unordered_map<vtr::StrongId<atom_block_id_tag, int, -1>, t_pb_graph_node*, std::hash<vtr::StrongId<atom_block_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_block_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_block_id_tag, int, -1> const, t_pb_graph_node*> > > const&, bool, bool, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_ext_pin_util_targets const&, t_pack_high_fanout_thresholds const&, AttractionInfo&, bool&, t_clustering_data&) [clone .constprop.0] [clone .isra.0] /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster.cpp:250
#3 0x56300d33f5fb in try_pack(t_packer_opts
, t_analysis_opts const*, t_arch const*, t_model const*, t_model const*, float, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >*) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/pack.cpp:143
#4 0x56300cb49210 in vpr_pack(t_vpr_setup&, t_arch const&) /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/base/vpr_api.cpp:653

Indirect leak of 307168 byte(s) in 9599 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300e74a8d0 in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:264

Indirect leak of 76864 byte(s) in 6 object(s) allocated from:
#0 0x56300fdf3f07 in operator new[](unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683f07)
#1 0x56300f4abb9d in alloc_and_load_cluster_placement_stats() /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:68
#2 0x56300f4abb9d in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:566

Indirect leak of 10112 byte(s) in 316 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300e74b14b in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:277

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300e74a8d0 in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:264
#2 0x9969063dc3523bff ()

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x56300fdf3d97 in operator new(unsigned long) (/home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/build/vpr/vpr+0x9683d97)
#1 0x56300e74a8d0 in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/vtr_master/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:264
#2 0xfffef393437 ()

SUMMARY: AddressSanitizer: 158587539 byte(s) leaked in 2373716 allocation(s).

@zhaisitong
Copy link
Contributor Author

  1. memory leak comes from function "save_and_reset_lb_route" in file "vtr-verilog-to-routing/vpr/src/pack/cluster_router.cpp:1342". The reason is that when freeing the "clustering_data.intra_lb_routing" in function "free_clustering_data" of file "vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:230", the count of blocks in cluster netlist is 0, but the count of clustering_data.intra_lb_routing is more than 0.

@zhaisitong
Copy link
Contributor Author

update the memory leaks' log:

=================================================================
==6588==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 336 byte(s) in 1 object(s) allocated from:
#0 0x555f748ecca7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686ca7)
#1 0x555f73fa4637 in alloc_and_load_cluster_placement_stats() /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:63
#2 0x555f73fa4637 in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:566

Direct leak of 160 byte(s) in 1 object(s) allocated from:
#0 0x555f748ecca7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686ca7)
#1 0x555f73fa5dbd in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:580

Indirect leak of 39085147 byte(s) in 206479 object(s) allocated from:
#0 0x555f748eb3a7 in __interceptor_calloc (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x96853a7)
#1 0x555f73d18c83 in vtr::calloc(unsigned long, unsigned long) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/libs/libvtrutil/src/vtr_memory.cpp:44

Indirect leak of 32636176 byte(s) in 150562 object(s) allocated from:
#0 0x555f748ecca7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686ca7)
#1 0x555f7480f9ad in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1225

Indirect leak of 1204496 byte(s) in 119604 object(s) allocated from:
#0 0x555f748ecca7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686ca7)
#1 0x555f7480f813 in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1222

Indirect leak of 470400 byte(s) in 3675 object(s) allocated from:
#0 0x555f748ecb37 in operator new(unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686b37)
#1 0x555f7469736e in start_new_cluster(t_cluster_placement_stats*, t_pb_graph_node**, vtr::StrongId<cluster_block_id_tag, int, -1>, t_pack_molecule*, std::map<t_logical_block_type const*, unsigned long, std::less<t_logical_block_type const*>, std::allocator<std::pair<t_logical_block_type const* const, unsigned long> > >&, float, int, int, t_arch const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_lb_router_data**, int, ClusteredNetlist, std::map<t_model const*, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> >, std::less<t_model const*>, std::allocator<std::pair<t_model const* const, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> > > > > const&, int, bool, bool, int, PartitionRegion&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:2106
#2 0x555f746a6054 in do_clustering(t_packer_opts const&, t_analysis_opts const&, t_arch const*, t_pack_molecule*, int, std::unordered_set<vtr::StrongId<atom_net_id_tag, int, -1>, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<vtr::StrongId<atom_net_id_tag, int, -1> > > const&, std::unordered_map<vtr::StrongId<atom_block_id_tag, int, -1>, t_pb_graph_node*, std::hash<vtr::StrongId<atom_block_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_block_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_block_id_tag, int, -1> const, t_pb_graph_node*> > > const&, bool, bool, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_ext_pin_util_targets const&, t_pack_high_fanout_thresholds const&, AttractionInfo&, bool&, t_clustering_data&) [clone .constprop.0] [clone .isra.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster.cpp:250
#3 0x555f71e38cbb in try_pack(t_packer_opts
, t_analysis_opts const*, t_arch const*, t_model const*, t_model const*, float, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >*) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/pack.cpp:143
#4 0x555f716432c0 in vpr_pack(t_vpr_setup&, t_arch const&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/base/vpr_api.cpp:650

Indirect leak of 307264 byte(s) in 9602 object(s) allocated from:
#0 0x555f748ecb37 in operator new(unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686b37)
#1 0x555f732443f9 in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:264

Indirect leak of 76864 byte(s) in 6 object(s) allocated from:
#0 0x555f748ecca7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686ca7)
#1 0x555f73fa522d in alloc_and_load_cluster_placement_stats() /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:68
#2 0x555f73fa522d in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:566

Indirect leak of 10112 byte(s) in 316 object(s) allocated from:
#0 0x555f748ecb37 in operator new(unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9686b37)
#1 0x555f73244c19 in load_cluster_placement_stats_for_pb_graph_node /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_placement.cpp:277

SUMMARY: AddressSanitizer: 73790955 byte(s) leaked in 490246 allocation(s).

@github-actions github-actions bot added the VPR VPR FPGA Placement & Routing Tool label Oct 21, 2022
@github-actions github-actions bot removed the infra Project Infrastructure label Oct 22, 2022
@zhaisitong
Copy link
Contributor Author

  1. memory leak comes from "cluster_placement.cpp:63" in function "alloc_and_load_cluster_cluster_placement_stats". In each pack iteration, the cluster_placement_stats of helper_ctx will be allocated once, but we only free cluster_placement_stats in the end of the vpr_flow. So move free function to the end of each pack iteration.

@zhaisitong
Copy link
Contributor Author

update the memory leaks' logs:

=================================================================
==194397==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 160 byte(s) in 1 object(s) allocated from:
#0 0x559065b85f87 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9689f87)
#1 0x55906523d74d in alloc_and_init_clustering(t_molecule_stats const&, t_cluster_placement_stats**, t_pb_graph_node***, t_pack_molecule*, t_clustering_data&, std::unordered_map<vtr::StrongId<atom_net_id_tag, int, -1>, int, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_net_id_tag, int, -1> const, int> > >&, int&, int) [clone .constprop.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:580

Indirect leak of 39085147 byte(s) in 206479 object(s) allocated from:
#0 0x559065b84687 in __interceptor_calloc (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9688687)
#1 0x559064fb02a3 in vtr::calloc(unsigned long, unsigned long) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/libs/libvtrutil/src/vtr_memory.cpp:44

Indirect leak of 32636176 byte(s) in 150562 object(s) allocated from:
#0 0x559065b85f87 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9689f87)
#1 0x559065aa8c8d in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1225

Indirect leak of 1204496 byte(s) in 119604 object(s) allocated from:
#0 0x559065b85f87 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9689f87)
#1 0x559065aa8af3 in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1222

Indirect leak of 470400 byte(s) in 3675 object(s) allocated from:
#0 0x559065b85e17 in operator new(unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9689e17)
#1 0x55906593064e in start_new_cluster(t_cluster_placement_stats*, t_pb_graph_node**, vtr::StrongId<cluster_block_id_tag, int, -1>, t_pack_molecule*, std::map<t_logical_block_type const*, unsigned long, std::less<t_logical_block_type const*>, std::allocator<std::pair<t_logical_block_type const* const, unsigned long> > >&, float, int, int, t_arch const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_lb_router_data**, int, ClusteredNetlist, std::map<t_model const*, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> >, std::less<t_model const*>, std::allocator<std::pair<t_model const* const, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> > > > > const&, int, bool, bool, int, PartitionRegion&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:2106
#2 0x55906593f334 in do_clustering(t_packer_opts const&, t_analysis_opts const&, t_arch const*, t_pack_molecule*, int, std::unordered_set<vtr::StrongId<atom_net_id_tag, int, -1>, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<vtr::StrongId<atom_net_id_tag, int, -1> > > const&, std::unordered_map<vtr::StrongId<atom_block_id_tag, int, -1>, t_pb_graph_node*, std::hash<vtr::StrongId<atom_block_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_block_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_block_id_tag, int, -1> const, t_pb_graph_node*> > > const&, bool, bool, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_ext_pin_util_targets const&, t_pack_high_fanout_thresholds const&, AttractionInfo&, bool&, t_clustering_data&) [clone .constprop.0] [clone .isra.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster.cpp:250
#3 0x5590630c7674 in try_pack(t_packer_opts
, t_analysis_opts const*, t_arch const*, t_model const*, t_model const*, float, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >*) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/pack.cpp:143
#4 0x5590628dd830 in vpr_pack(t_vpr_setup&, t_arch const&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/base/vpr_api.cpp:650

SUMMARY: AddressSanitizer: 73396379 byte(s) leaked in 480321 allocation(s).

@zhaisitong
Copy link
Contributor Author

In regression test task "vpr_ispd" of "vtr_reg_nightly_test5", it seems like the memory usage is 0.6062963593520936 time of golden, which is outside of the range [0.8,1.203]. The reason should be that after fixing the memory leak of cluster_placement_stats, memory usage is greatly reduced. Could I update the golden results? @vaughnbetz

@vaughnbetz
Copy link
Contributor

Yes, that's a great improvement so fine to update the golden result.

@zhaisitong
Copy link
Contributor Author

zhaisitong commented Oct 24, 2022

  1. memory leak comes from "cluster_util.cpp:580" in function "alloc_and_init_clustering". In each pack iteration, the primitive_list of helper_ctx will be allocated once, but we only free primitive_list in the end of the vpr_flow. So free the primitive_list at the end of each pack iteration.

@zhaisitong
Copy link
Contributor Author

update memory leaks' log:

=================================================================
==292334==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 39085147 byte(s) in 206479 object(s) allocated from:
#0 0x56243412aed7 in calloc (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9683ed7)
#1 0x562433557263 in vtr::calloc(unsigned long, unsigned long) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/libs/libvtrutil/src/vtr_memory.cpp:44

Indirect leak of 32636176 byte(s) in 150562 object(s) allocated from:
#0 0x56243412c7d7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x96857d7)
#1 0x56243404f4dd in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1225

Indirect leak of 1204496 byte(s) in 119604 object(s) allocated from:
#0 0x56243412c7d7 in operator new[](unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x96857d7)
#1 0x56243404f343 in try_place_atom_block_rec(t_pb_graph_node const*, vtr::StrongId<atom_block_id_tag, int, -1>, t_pb*, t_pb**, int, int, vtr::StrongId<cluster_block_id_tag, int, -1>, t_cluster_placement_stats const*, t_pack_molecule const*, t_lb_router_data*, int, int) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:1222

Indirect leak of 470400 byte(s) in 3675 object(s) allocated from:
#0 0x56243412c667 in operator new(unsigned long) (/home/zhaisitong/worksapce/work/vtr-verilog-to-routing/build/vpr/vpr+0x9685667)
#1 0x562433ed6e9e in start_new_cluster(t_cluster_placement_stats*, t_pb_graph_node**, vtr::StrongId<cluster_block_id_tag, int, -1>, t_pack_molecule*, std::map<t_logical_block_type const*, unsigned long, std::less<t_logical_block_type const*>, std::allocator<std::pair<t_logical_block_type const* const, unsigned long> > >&, float, int, int, t_arch const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_lb_router_data**, int, ClusteredNetlist, std::map<t_model const*, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> >, std::less<t_model const*>, std::allocator<std::pair<t_model const* const, std::vector<t_logical_block_type const*, std::allocator<t_logical_block_type const*> > > > > const&, int, bool, bool, int, PartitionRegion&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster_util.cpp:2106
#2 0x562433ee5b84 in do_clustering(t_packer_opts const&, t_analysis_opts const&, t_arch const*, t_pack_molecule*, int, std::unordered_set<vtr::StrongId<atom_net_id_tag, int, -1>, std::hash<vtr::StrongId<atom_net_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_net_id_tag, int, -1> >, std::allocator<vtr::StrongId<atom_net_id_tag, int, -1> > > const&, std::unordered_map<vtr::StrongId<atom_block_id_tag, int, -1>, t_pb_graph_node*, std::hash<vtr::StrongId<atom_block_id_tag, int, -1> >, std::equal_to<vtr::StrongId<atom_block_id_tag, int, -1> >, std::allocator<std::pair<vtr::StrongId<atom_block_id_tag, int, -1> const, t_pb_graph_node*> > > const&, bool, bool, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >, t_ext_pin_util_targets const&, t_pack_high_fanout_thresholds const&, AttractionInfo&, bool&, t_clustering_data&) [clone .constprop.0] [clone .isra.0] /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/cluster.cpp:250
#3 0x56243167d514 in try_pack(t_packer_opts
, t_analysis_opts const*, t_arch const*, t_model const*, t_model const*, float, std::vector<t_lb_type_rr_node, std::allocator<t_lb_type_rr_node> >*) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/pack/pack.cpp:143
#4 0x562430e83d90 in vpr_pack(t_vpr_setup&, t_arch const&) /home/zhaisitong/worksapce/work/vtr-verilog-to-routing/vpr/src/base/vpr_api.cpp:650

SUMMARY: AddressSanitizer: 73396219 byte(s) leaked in 480320 allocation(s).

@zhaisitong
Copy link
Contributor Author

  1. memory leak from "cluster_util.cpp:2106" in function "start_new_cluster". Mistakenly clear the netlist before freeing relevant memories at the end of each pack iteration.

@zhaisitong
Copy link
Contributor Author

All memory leaks are clear now!

Copy link
Contributor

@vaughnbetz vaughnbetz left a comment

Choose a reason for hiding this comment

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

Looks good to me; just suggest deleting the commented out code.

@zhaisitong
Copy link
Contributor Author

Failed reason: when reading vpr constraint xml file, and loading int, encounter errno=22, which means invalid argument.

@github-actions github-actions bot added the infra Project Infrastructure label Oct 28, 2022
@github-actions github-actions bot removed the infra Project Infrastructure label Oct 28, 2022
@zhaisitong
Copy link
Contributor Author

Problem reason:
The global variable "errno" from the GNU C Library "errno.h" is set to 22 because: when invoking"out.set_add_atom_name_pattern(attr.value(), context);" at "vpr_constraints_uxsdcxxx.h:480" in function "inline void load_add_atom(const pugi::xml_node& root, T& out, Context& context, const std::function<void(const char*)>* report_error, ptrdiff_t* offset_debug)", the argument "context" is not used. So the global variable "errno" is set to 22 which means "invalid argument" when making with sanitizer on our check server. Thus, when coming into function load_int, the errno is 22 although there is no problem when parsing int value from a string. This might because of the difference on g++ version or other environment values between the check server with our wintermute server.

Try to solve directly:
This problem cannot be solved by fixing the problem on the argument of the function set_add_atom_name_pattern. Because the variable "context" has been declared as "void*" which is correct, and the function "set_add_atom_name_pattern" belong to "class VprConstraintsSerializer" in file "vpr_constraints_serializer.h", and this class inherits from a template class "class VprConstraintsBase". In the base class, the function "set_add_atom_name_pattern" has already been defined as a pure virtual function with template "virtual inline void set_add_atom_name_pattern(const char* name_pattern, typename ContextTypes::AddAtomWriteContext& ctx) = 0;" Although the argument "context" is not used in the derived class "VprConstraintsSerializer", we cannot change the function definition and we cannot give it a default value "NULL" because "context" is a reference of void pointer.

Final solution:
A better and more reasonable solution is that we set "errno = 0" before using the global variable "errno". That is, we give a statement "errno = 0;" before transfering a string value to an int value. This is also the correct way to use global variable "errno".

@zhaisitong
Copy link
Contributor Author

Now all the checks passed.

@zhaisitong
Copy link
Contributor Author

zhaisitong commented Oct 29, 2022

Create a new test "strong_tight_floorplan" in vtr_reg_strong for sanitizer test. The new test case using benchmark "bigkey.blif" and architecture "k6_N10_40nm.xml" with a vpr placement constraint file "bigkey_tight_floorplan.xml". This testcase can test the tight floor plan relevant codes to make sure no memory leaks on this part in the furture.
The runtime of this new testcase with make sanitizer on our check server is 336.56s, without sanitizer is 11s.

@zhaisitong zhaisitong merged commit b25f941 into master Oct 29, 2022
@zhaisitong zhaisitong deleted the tight_floor_plan_bugs branch October 29, 2022 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libarchfpga Library for handling FPGA Architecture descriptions VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants