areusch commented on a change in pull request #7785:
URL: https://github.com/apache/tvm/pull/7785#discussion_r619491548
##########
File path: src/runtime/crt/memory/stack_allocator.c
##########
@@ -16,17 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-
// LINT_C_FILE
-
#include <tvm/runtime/crt/stack_allocator.h>
+#ifdef TVM_CRT_DEBUG
+#include <tvm/runtime/crt/logging.h>
+#endif
void* StackMemoryManager_Allocate(tvm_workspace_t* tvm_runtime_workspace,
int32_t nbytes) {
uint32_t offset_bytes = (~nbytes + 1) & (TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES -
1);
uint8_t* current_alloc = tvm_runtime_workspace->next_alloc;
uint8_t* next_alloc = tvm_runtime_workspace->next_alloc + nbytes +
offset_bytes;
uint8_t* workspace_end = tvm_runtime_workspace->workspace +
tvm_runtime_workspace->workspace_size;
-
+#ifdef TVM_CRT_DEBUG
Review comment:
> this example is accessing the next_alloc via some pointer arithmetic
on a nearby data that got linked in in the .data section?
yeah exactly. common cause is passing in a bad pointer to some other data
structure which then causes a library to corrupt the data. on x86, e.g.
dereferencing a nullptr (e.g. trying to access a struct member with struct
ptr==0) causes a segfault; on bare metal, you just read whatever program data
happens to be there (often .text or from the SoC ROM).
one thing with the current impl is that currently `tag` is just placed in
the extra space given by `TVM_CRT_ALIGNMENT_BYTES`, so because that's 16, there
is always an extra word of memory. the overhead here is a few cycles of
compute. I don't see it as particularly large considering we are doing a lot
more compute when e.g. doing a conv2d.
> is there a concern of not being able to unit test because of its not on by
default ?
yeah exactly--but it would be fine to just turn it on for unit tests too. If
you want to do that, perhaps we should create a `crt_config.h` for unit tests
and then change the include path used for unit tests in StandaloneCrt.cmake and
in the python code which builds the AOT makefile.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]