Merge branch 'master' of github.com:InfiniTensor/InfiniTensor into xpu_allreduce

This commit is contained in:
zhangyue 2023-10-10 16:59:15 +08:00
commit 53bba11333
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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<TensorObj *, size_t> tensorToRefCount;
// record the memory address offsets of all tensors to be allocated