Browse Source

add stream block reuse related

pull/277/head
wangxiaotian22 4 years ago
parent
commit
508b392792
2 changed files with 22 additions and 11 deletions
  1. +19
    -10
      ge/graph/build/memory/block_mem_assigner.cc
  2. +3
    -1
      ge/graph/build/memory/block_mem_assigner.h

+ 19
- 10
ge/graph/build/memory/block_mem_assigner.cc View File

@@ -318,7 +318,11 @@ void MemoryBlock::AddDependLifeBegin(DependStreamLife &total_node_depend_stream_
AddDependLife(node, node, stream_id_, depend_stream_life_, total_node_depend_stream_life); AddDependLife(node, node, stream_id_, depend_stream_life_, total_node_depend_stream_life);
} }
} }
depend_stream_life_[stream_id_] = GetLifeBegin();

// not same stream can't be reused by life time directly, should be reused by dependence
if (same_stream_) {
depend_stream_life_[stream_id_] = GetLifeBegin();
}
} }


size_t MemoryBlock::GetLifeEnd() { size_t MemoryBlock::GetLifeEnd() {
@@ -1130,15 +1134,21 @@ bool IsKnownSubgraphData(const NodePtr &node) {
return node->GetOpDesc()->HasAttr(ATTR_NAME_PARENT_NODE_INDEX); return node->GetOpDesc()->HasAttr(ATTR_NAME_PARENT_NODE_INDEX);
} }


void BlockMemAssigner::ReleaseMemory(MemoryBlock *to_release, vector<MemoryBlock *> &reusable_memory) {
void BlockMemAssigner::ReleaseMemory(MemoryBlock *to_release, vector<MemoryBlock *> &reusable_memory,
bool same_stream) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(to_release == nullptr, return, "Input parameter to_release is null."); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(to_release == nullptr, return, "Input parameter to_release is null.");
GE_CHK_TRUE_EXEC_INFO(to_release->ref_count_ <= 0, return, "Release memory"); GE_CHK_TRUE_EXEC_INFO(to_release->ref_count_ <= 0, return, "Release memory");
GE_CHK_TRUE_EXEC_INFO(!to_release->reuse_mem_, return, "doesn't reuse memory"); GE_CHK_TRUE_EXEC_INFO(!to_release->reuse_mem_, return, "doesn't reuse memory");
--to_release->ref_count_; --to_release->ref_count_;
if (!same_stream) {
to_release->same_stream_ = false;
}
if (to_release->ref_count_ == 0) { if (to_release->ref_count_ == 0) {
to_release->SetLifeTimeEnd(life_time_); to_release->SetLifeTimeEnd(life_time_);
reusable_memory.emplace_back(to_release);
AddReusableBlockCount(*to_release, reusable_block_counts_);
if (to_release->same_stream_) {
reusable_memory.emplace_back(to_release);
AddReusableBlockCount(*to_release, reusable_block_counts_);
}
} }
} }


@@ -1178,10 +1188,9 @@ void BlockMemAssigner::ReleaseInputNodeOutMemory(const unordered_map<string, vec
node_type_indexs.back().node->GetName().c_str()); node_type_indexs.back().node->GetName().c_str());


if ((node_type_indexs.back().node == in_anchor->GetPeerOutAnchor()->GetOwnerNode()) && if ((node_type_indexs.back().node == in_anchor->GetPeerOutAnchor()->GetOwnerNode()) &&
(node_type_indexs.back().index == static_cast<uint32_t>(in_anchor->GetPeerOutAnchor()->GetIdx())) &&
(node->GetOpDesc()->GetStreamId() == block->stream_id_)) {
ReleaseMemory(block, reusable_memory);
if (block->ref_count_ == 0) {
(node_type_indexs.back().index == static_cast<uint32_t>(in_anchor->GetPeerOutAnchor()->GetIdx()))) {
ReleaseMemory(block, reusable_memory, (node->GetOpDesc()->GetStreamId() == block->stream_id_));
if (block->ref_count_ == 0 && block->same_stream_) {
SetLastUsedInputMemAttr(node, in_anchor->GetIdx()); SetLastUsedInputMemAttr(node, in_anchor->GetIdx());
} }
} }
@@ -1701,10 +1710,10 @@ void SetOffsetSize(const NodeTypeIndex &node_type, const MemoryBlock *block,
op_desc->SetWorkspace(workspace_list); op_desc->SetWorkspace(workspace_list);
} }
GELOGI("[IMAS]Set %s name[%s] %s[%u] offset to [%ld] streamid[%ld] size[%zu] realsize[%zu]" GELOGI("[IMAS]Set %s name[%s] %s[%u] offset to [%ld] streamid[%ld] size[%zu] realsize[%zu]"
" noalignsize[%zu] life time begin[%zu] life time end[%zu] child[%d:%d:%d:%d] isref[%d].", graph_name.c_str(),
" noalignsize[%zu] life time begin[%zu] life time end[%zu] child[%d:%d:%d:%d:%d] isref[%d].", graph_name.c_str(),
op_desc->GetName().c_str(), node_type.GetMemType().c_str(), node_type.index, offset, op_desc->GetStreamId(), op_desc->GetName().c_str(), node_type.GetMemType().c_str(), node_type.index, offset, op_desc->GetStreamId(),
block->Size(), real_size, no_align_size, op_desc->GetId(), end, child_block, block->reuse_mem_, block->Size(), real_size, no_align_size, op_desc->GetId(), end, child_block, block->reuse_mem_,
block->continuous_block_, block->deleted_block_, node_type.ref_input);
block->continuous_block_, block->deleted_block_, block->same_stream_, node_type.ref_input);
} }


void SetBlockOpMemOffset(MemoryBlock *block, bool child_block) { void SetBlockOpMemOffset(MemoryBlock *block, bool child_block) {


+ 3
- 1
ge/graph/build/memory/block_mem_assigner.h View File

@@ -65,6 +65,7 @@ class MemoryBlock {
stream_id_(stream_id), stream_id_(stream_id),
deleted_block_(false), deleted_block_(false),
reuse_mem_(reuse_mem), reuse_mem_(reuse_mem),
same_stream_(true)
input_index_(0), input_index_(0),
continuous_block_(false), continuous_block_(false),
first_continuous_block_(false), first_continuous_block_(false),
@@ -142,6 +143,7 @@ class MemoryBlock {
int64_t stream_id_; int64_t stream_id_;
bool deleted_block_; bool deleted_block_;
bool reuse_mem_; bool reuse_mem_;
bool same_stream_;
uint32_t input_index_; uint32_t input_index_;
bool continuous_block_; bool continuous_block_;
bool first_continuous_block_; bool first_continuous_block_;
@@ -353,7 +355,7 @@ class BlockMemAssigner : public MemAssigner {
/// @return void /// @return void
/// @author /// @author
/// ///
void ReleaseMemory(MemoryBlock *to_release, vector<MemoryBlock *> &reusable_memory);
void ReleaseMemory(MemoryBlock *to_release, vector<MemoryBlock *> &reusable_memory, bool same_stream = true);


/// ///
/// @ingroup GE /// @ingroup GE


Loading…
Cancel
Save