forked from jiuyuan/InfiniTensor
add naive allocator for debugging (#140)
* add naive allocator only for debugging * merge redundant api --------- Co-authored-by: whjthu <haojie0429@gmail.com>
This commit is contained in:
parent
90b9a80f72
commit
1151101fb9
|
@ -64,7 +64,7 @@ class GraphObj : public Object {
|
||||||
|
|
||||||
void optimize();
|
void optimize();
|
||||||
|
|
||||||
void dataMalloc();
|
void dataMalloc(bool useNaiveAllocator = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add an operator and create its outputs. Output tensor arguments
|
* @brief Add an operator and create its outputs. Output tensor arguments
|
||||||
|
|
|
@ -123,9 +123,19 @@ void GraphObj::optimize() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphObj::dataMalloc() {
|
void GraphObj::dataMalloc(bool useNaiveAllocator) {
|
||||||
// topological sorting first
|
// topological sorting first
|
||||||
IT_ASSERT(topo_sort() == true);
|
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
|
// count the number of times all tensors are used
|
||||||
std::unordered_map<TensorObj *, size_t> tensorToRefCount;
|
std::unordered_map<TensorObj *, size_t> tensorToRefCount;
|
||||||
// record the memory address offsets of all tensors to be allocated
|
// record the memory address offsets of all tensors to be allocated
|
||||||
|
|
Loading…
Reference in New Issue