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