Skip to content

Remaining malloc to new #2100

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 55 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7d2e180
vpr_utils
jmah76 Jul 7, 2022
e9ae316
misc. mallocs to new
jmah76 Jul 7, 2022
6d13214
power
jmah76 Jul 7, 2022
6797d8d
some in vpr power
jmah76 Jul 8, 2022
4ee9a81
more power
jmah76 Jul 8, 2022
bcc3bcf
fixed log messages in power_util
jmah76 Jul 8, 2022
1070e65
power_ctx arch
jmah76 Jul 8, 2022
2c0373e
more power_cmos_tech swaps
jmah76 Jul 8, 2022
9c3b9f9
Fixed typo in cmos tech
jmah76 Jul 8, 2022
a78ec80
SetUpVPR
jmah76 Jul 9, 2022
e3d56c3
power
jmah76 Jul 9, 2022
e3a4a0d
power_cmos_tech
jmah76 Jul 9, 2022
bb63fb7
hash in vpr/utils
jmah76 Jul 9, 2022
60e1553
Removing rpt files
jmah76 Jul 9, 2022
83f1a3c
draw.cpp
jmah76 Jul 9, 2022
46cc019
BinaryHeap heap
jmah76 Jul 11, 2022
754aedc
Removed .rpt files & old code
jmah76 Jul 11, 2022
357640d
bucket.cpp heap
jmah76 Jul 11, 2022
1707790
formatting anf removing .rpt files
jmah76 Jul 11, 2022
0480d2c
Fixed warning messages
jmah76 Jul 12, 2022
10b1c9c
chunk malloc
jmah76 Jul 18, 2022
282b1b5
removed .rpt files
jmah76 Jul 18, 2022
52a6a78
fixed alloc dealloc mismatch for chunk malloc
jmah76 Jul 19, 2022
4f6ac3a
Fixed problem w/ new+free in ODIN II
jmah76 Jul 20, 2022
65a82ba
remove rpt files
jmah76 Jul 20, 2022
59fe896
Merge branch 'master' into rem_malloc_to_new
jmah76 Jul 21, 2022
8bc977f
Removed redundant for loops
jmah76 Jul 25, 2022
bb3540a
bucket.cpp
jmah76 Jul 26, 2022
a966dd7
Merge branch 'rem_malloc_to_new' of https://github.com/verilog-to-rou…
jmah76 Jul 26, 2022
46c2321
binary_heap
jmah76 Jul 26, 2022
0b1cbe8
FIx compilation warnings
jmah76 Jul 26, 2022
1b2aefb
binary_heap to vector
jmah76 Jul 26, 2022
954e48d
format
jmah76 Jul 26, 2022
3e605ed
removing rpt files
jmah76 Jul 26, 2022
2da2652
bucket.cpp
jmah76 Jul 27, 2022
02bd2db
Formatting changes
jmah76 Jul 28, 2022
5cd437c
Removed qor files
jmah76 Jul 28, 2022
67ea56d
Revert "bucket.cpp"
jmah76 Jul 28, 2022
b4f35bd
Revert "Revert "bucket.cpp"" wrong commit
jmah76 Jul 28, 2022
6035137
Revert "Formatting changes"
jmah76 Jul 28, 2022
263dfa2
formatting changes
jmah76 Jul 28, 2022
5d7ea7f
formatting
jmah76 Jul 28, 2022
d68436a
format fixes missing vpr_utils
jmah76 Jul 28, 2022
e5a1a9c
rm .rpt
jmah76 Jul 28, 2022
abf58ea
Merge branch 'master' into rem_malloc_to_new
jmah76 Jul 28, 2022
959bd4b
undoing vectorization of bucket
jmah76 Jul 28, 2022
19bcf19
Merge branch 'rem_malloc_to_new' of https://github.com/verilog-to-rou…
jmah76 Jul 28, 2022
b1b82a7
Another bucket change
jmah76 Aug 2, 2022
aace716
Reverting to last time bucket worked
jmah76 Aug 3, 2022
ec774b6
formatting
jmah76 Aug 4, 2022
88e16dc
Merge branch 'rem_malloc_to_new' of https://github.com/verilog-to-rou…
jmah76 Aug 4, 2022
4c4f815
Updating golden results
jmah76 Aug 5, 2022
e7380ff
Merge branch 'rem_malloc_to_new' of https://github.com/verilog-to-rou…
jmah76 Aug 5, 2022
321a85b
Update max mem usage
jmah76 Aug 8, 2022
4397396
Removing rpt files
jmah76 Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ODIN_II/SRC/adders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ void remove_list_node(t_linked_vptr* pre, t_linked_vptr* next) {
pre->next = next->next;
else
pre->next = NULL;
vtr::free(next);
delete next;
}

/*---------------------------------------------------------------------------
Expand Down Expand Up @@ -1434,4 +1434,4 @@ nnode_t* check_missing_ports(nnode_t* node, uintptr_t traverse_mark_number, netl
}

return new_node;
}
}
14 changes: 3 additions & 11 deletions libs/libvtrutil/src/vtr_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@ t_linked_vptr* insert_in_vptr_list(t_linked_vptr* head, void* vptr_to_add) {
/* Inserts a new element at the head of a linked list of void pointers. *
* Returns the new head of the list. */

t_linked_vptr* linked_vptr;

linked_vptr = (t_linked_vptr*)vtr::malloc(sizeof(t_linked_vptr));

linked_vptr->data_vptr = vptr_to_add;
linked_vptr->next = head;
return (linked_vptr); /* New head of the list */
return new t_linked_vptr{vptr_to_add, head}; /* New head of the list */
}

/* Deletes the element at the head of a linked list of void pointers. *
* Returns the new head of the list. */
t_linked_vptr* delete_in_vptr_list(t_linked_vptr* head) {
t_linked_vptr* linked_vptr;

if (head == nullptr)
return nullptr;
linked_vptr = head->next;
free(head);
t_linked_vptr* const linked_vptr = head->next;
delete head;
return linked_vptr; /* New head of the list */
}

Expand Down
29 changes: 18 additions & 11 deletions libs/libvtrutil/src/vtr_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstddef>
#include <cstdlib>
#include <math.h>

#include "vtr_assert.h"
#include "vtr_list.h"
Expand Down Expand Up @@ -43,7 +44,7 @@ void* calloc(size_t nelem, size_t size) {
if ((ret = std::calloc(nelem, size)) == nullptr) {
throw VtrError("Unable to calloc memory.", __FILE__, __LINE__);
}
return (ret);
return ret;
}

void* malloc(size_t size) {
Expand All @@ -55,7 +56,7 @@ void* malloc(size_t size) {
if ((ret = std::malloc(size)) == nullptr && size != 0) {
throw VtrError("Unable to malloc memory.", __FILE__, __LINE__);
}
return (ret);
return ret;
}

void* realloc(void* ptr, size_t size) {
Expand All @@ -66,7 +67,7 @@ void* realloc(void* ptr, size_t size) {
throw VtrError(string_fmt("Unable to realloc memory (ptr=%p, size=%d).", ptr, size),
__FILE__, __LINE__);
}
return (ret);
return ret;
}

void* chunk_malloc(size_t size, t_chunk* chunk_info) {
Expand Down Expand Up @@ -102,7 +103,9 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) {

if ((size_t)(chunk_info->mem_avail) < size) { /* Need to malloc more memory. */
if (size > CHUNK_SIZE) { /* Too big, use standard routine. */
tmp_ptr = (char*)vtr::malloc(size);
/* Want to allocate a block of memory the size of size.
* i.e. malloc(size) */
tmp_ptr = new char[size];

/* When debugging, uncomment the code below to see if memory allocation size */
/* makes sense */
Expand All @@ -113,11 +116,11 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) {

VTR_ASSERT(chunk_info != nullptr);
chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, tmp_ptr);
return (tmp_ptr);
return tmp_ptr;
}

if (chunk_info->mem_avail < FRAGMENT_THRESHOLD) { /* Only a small scrap left. */
chunk_info->next_mem_loc_ptr = (char*)vtr::malloc(CHUNK_SIZE);
chunk_info->next_mem_loc_ptr = new char[CHUNK_SIZE];
chunk_info->mem_avail = CHUNK_SIZE;
VTR_ASSERT(chunk_info != nullptr);
chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, chunk_info->next_mem_loc_ptr);
Expand All @@ -128,10 +131,11 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) {
* to allocate normally. */

else {
tmp_ptr = (char*)vtr::malloc(size);
tmp_ptr = new char[size];
VTR_ASSERT(chunk_info != nullptr);
chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, tmp_ptr);
return (tmp_ptr);

return tmp_ptr;
}
}

Expand All @@ -147,7 +151,7 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) {
tmp_ptr = chunk_info->next_mem_loc_ptr;
chunk_info->next_mem_loc_ptr += aligned_size;
chunk_info->mem_avail -= aligned_size;
return (tmp_ptr);
return tmp_ptr;
}

void free_chunk_memory(t_chunk* chunk_info) {
Expand All @@ -158,11 +162,14 @@ void free_chunk_memory(t_chunk* chunk_info) {
curr_ptr = chunk_info->chunk_ptr_head;

while (curr_ptr != nullptr) {
free(curr_ptr->data_vptr); /* Free memory "chunk". */
/* Must cast pointers to type char*, since the're of type void*, which delete can't
* be called on.*/
delete[]((char*)curr_ptr->data_vptr); /* Free memory "chunk". */
prev_ptr = curr_ptr;
curr_ptr = curr_ptr->next;
free(prev_ptr); /* Free memory used to track "chunk". */
delete (t_linked_vptr*)prev_ptr; /* Free memory used to track "chunk". */
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the typecast ?

}

chunk_info->chunk_ptr_head = nullptr;
chunk_info->mem_avail = 0;
chunk_info->next_mem_loc_ptr = nullptr;
Expand Down
6 changes: 4 additions & 2 deletions vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,11 @@ static void SetupPowerOpts(const t_options& Options, t_power_opts* power_opts, t

if (power_opts->do_power) {
if (!Arch->power)
Arch->power = (t_power_arch*)vtr::malloc(sizeof(t_power_arch));
Arch->power = new t_power_arch();

if (!Arch->clocks)
Arch->clocks = (t_clock_arch*)vtr::malloc(sizeof(t_clock_arch));
Arch->clocks = new t_clock_arch();

device_ctx.clock_arch = Arch->clocks;
} else {
Arch->power = nullptr;
Expand Down
12 changes: 2 additions & 10 deletions vpr/src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ void alloc_draw_structs(const t_arch* arch) {

/* Space is allocated for draw_rr_node but not initialized because we do *
* not yet know information about the routing resources. */
draw_state->draw_rr_node = (t_draw_rr_node*)vtr::malloc(
device_ctx.rr_graph.num_nodes() * sizeof(t_draw_rr_node));
draw_state->draw_rr_node.resize(device_ctx.rr_graph.num_nodes());

draw_state->arch_info = arch;

Expand All @@ -534,7 +533,6 @@ void free_draw_structs() {
*
* For safety, set all the array pointers to NULL in case any data
* structure gets freed twice. */
t_draw_state* draw_state = get_draw_state_vars();
t_draw_coords* draw_coords = get_draw_coords_vars();

if (draw_coords != nullptr) {
Expand All @@ -544,10 +542,6 @@ void free_draw_structs() {
draw_coords->tile_y = nullptr;
}

if (draw_state != nullptr) {
free(draw_state->draw_rr_node);
draw_state->draw_rr_node = nullptr;
}
#else
;
#endif /* NO_GRAPHICS */
Expand All @@ -569,9 +563,7 @@ void init_draw_coords(float width_val) {
/* Each time routing is on screen, need to reallocate the color of each *
* rr_node, as the number of rr_nodes may change. */
if (rr_graph.num_nodes() != 0) {
draw_state->draw_rr_node = (t_draw_rr_node*)vtr::realloc(
draw_state->draw_rr_node,
(rr_graph.num_nodes()) * sizeof(t_draw_rr_node));
draw_state->draw_rr_node.resize(rr_graph.num_nodes());
/*FIXME: the type cast should be eliminated by making draw_rr_node adapt RRNodeId */
for (const RRNodeId& rr_id : rr_graph.nodes()) {
draw_state->draw_rr_node[(size_t)rr_id].color = DEFAULT_RR_NODE_COLOR;
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/draw/draw_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct t_draw_state {
e_route_type draw_route_type = GLOBAL;
char default_message[vtr::bufsize];
vtr::vector<ClusterNetId, ezgl::color> net_color;
t_draw_rr_node* draw_rr_node = nullptr;
std::vector<t_draw_rr_node> draw_rr_node;
std::shared_ptr<const SetupTimingInfo> setup_timing_info;
const t_arch* arch_info = nullptr;
std::shared_ptr<const vtr::ColorMap> color_map = nullptr;
Expand Down
1 change: 1 addition & 0 deletions vpr/src/pack/cluster_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_size) {
pb->pb_stats->lookahead_output_pins_used = std::vector<std::vector<AtomNetId>>(pb->pb_graph_node->num_output_pin_class);
pb->pb_stats->num_feasible_blocks = NOT_VALID;
pb->pb_stats->feasible_blocks = new t_pack_molecule*[feasible_block_array_size];

for (int i = 0; i < feasible_block_array_size; i++)
pb->pb_stats->feasible_blocks[i] = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions vpr/src/place/place_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,17 @@ void free_placement_macros_structs() {
unsigned int itype;
if (f_idirect_from_blk_pin != nullptr) {
for (itype = 1; itype < device_ctx.physical_tile_types.size(); itype++) {
free(f_idirect_from_blk_pin[itype]);
delete[](f_idirect_from_blk_pin[itype]);
}
free(f_idirect_from_blk_pin);
delete[](f_idirect_from_blk_pin);
f_idirect_from_blk_pin = nullptr;
}

if (f_direct_type_from_blk_pin != nullptr) {
for (itype = 1; itype < device_ctx.physical_tile_types.size(); itype++) {
free(f_direct_type_from_blk_pin[itype]);
delete[](f_direct_type_from_blk_pin[itype]);
}
free(f_direct_type_from_blk_pin);
delete[](f_direct_type_from_blk_pin);
f_direct_type_from_blk_pin = nullptr;
}
}
Expand Down
Loading