-
Notifications
You must be signed in to change notification settings - Fork 86
The debug binary now show how much memory it will try to allocate on the heap #595
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ class SYM_PUBLIC Network | |
Network(); | ||
~Network(); | ||
|
||
int memory(); | ||
bool init(); | ||
|
||
int get_input_rank(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,32 @@ Network::~Network() | |
#endif | ||
} | ||
|
||
int Network::memory() { | ||
int total_mem_bytes = 0; | ||
{% for node in graph.non_variables -%} | ||
{% if node.available_buffer == '' -%} | ||
{% for out_k in node.output_ops.keys() -%} | ||
{% if node.output_ops.keys()|length > 1 -%} | ||
total_mem_bytes += sizeof({{ node.dtype.cpptype() }}) * ({{ node.view.size_in_words_as_cpp }}); // {{ node.name + '_' + out_k }}_raw | ||
{% else -%} | ||
total_mem_bytes += sizeof({{ node.dtype.cpptype() }}) * ({{ node.view.size_in_words_as_cpp }}); // {{ node.name }}_raw | ||
{%- endif %} | ||
{%- endfor %} | ||
{% elif node.available_buffer != '' and node.output_ops.keys()|length > 1 -%} | ||
{% for out_k in node.output_ops.keys() -%} | ||
{% if out_k != node.output_ops.keys()|list|first -%} | ||
total_mem_bytes += sizeof({{ node.dtype.cpptype() }}) * ({{ node.view.size_in_words_as_cpp }}); // {{ node.name + '_' + out_k }}_raw | ||
{%- endif %} | ||
{%- endfor %} | ||
{%- endif %} | ||
{%- endfor %} | ||
#if !defined RUN_ON_FPGA | ||
total_mem_bytes += sizeof(QUANTIZED_PACKED) * max_device_input_elems; | ||
total_mem_bytes += sizeof(BIN_CONV_OUTPUT) * max_device_output_elems; | ||
#endif | ||
return total_mem_bytes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are several temporary buffer allocated by some operators (ex. kn2row_buf in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah thank you! Didn't know about these buffers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can wait until they are allocated from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These buffers are allocated by I found such buffers in following files:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, seems that for changing layout we need these temporaries... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When #473 is fixed, buffers may be unified into single buffer, total buffer size is obvious. |
||
} | ||
|
||
bool Network::init() | ||
{ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep consistency of API, it looks better to use verb for the method name. Considering that the responsibility of this function should output debug information, how about renaming to
get_debug_info
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I propose to change this API to return string, (or char*), so that we can see the buffer size layer by layer. (Is it possible to change the behavior of this API?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's true. The name can be better and we should return more detailed information.