From 1151101fb94b5927d755f3b6d2695b8174c4c6e6 Mon Sep 17 00:00:00 2001 From: kilinchange <44265800+kilinchange@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:42:23 +0800 Subject: [PATCH] add naive allocator for debugging (#140) * add naive allocator only for debugging * merge redundant api --------- Co-authored-by: whjthu --- include/core/graph.h | 2 +- src/core/graph.cc | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/core/graph.h b/include/core/graph.h index 8415b15a..a8fc6485 100644 --- a/include/core/graph.h +++ b/include/core/graph.h @@ -64,7 +64,7 @@ class GraphObj : public Object { void optimize(); - void dataMalloc(); + void dataMalloc(bool useNaiveAllocator = false); /** * @brief Add an operator and create its outputs. Output tensor arguments diff --git a/src/core/graph.cc b/src/core/graph.cc index f662cf32..7e902247 100644 --- a/src/core/graph.cc +++ b/src/core/graph.cc @@ -123,9 +123,19 @@ void GraphObj::optimize() { } } -void GraphObj::dataMalloc() { +void GraphObj::dataMalloc(bool useNaiveAllocator) { // topological sorting first IT_ASSERT(topo_sort() == true); + if (useNaiveAllocator) { + // used for debugging memory out-of-bounds access, tensors will not be + // released correctly + // note: behavior may not match running in non-naive mode, and it may + // not reproduce the bug + for (auto &tensor : tensors) { + tensor->dataMalloc(); + } + return; + } // count the number of times all tensors are used std::unordered_map tensorToRefCount; // record the memory address offsets of all tensors to be allocated