pull/1248/head
wangxiaotian22 4 years ago
parent c211d1bd36
commit e8dd99af4e

@ -85,8 +85,9 @@ static Status CheckEngineTypeSupport(const NodePtr &node, OpEngineType engine_ty
} else { } else {
ErrorManager::GetInstance().ATCReportErrMessage("E14001", {"opname", "optype", "value", "reason"}, ErrorManager::GetInstance().ATCReportErrMessage("E14001", {"opname", "optype", "value", "reason"},
{op_desc->GetName(), op_desc->GetType(), "engine type", {op_desc->GetName(), op_desc->GetType(), "engine type",
"it only support kEngineNameDefault/kAIcoreEngine/kVectorEngine"}); "it only support default/AIcoreEngine/VectorEngine"});
GELOGE(FAILED, "CheckEngineType: engine type: %d not support.", static_cast<int>(engine_type)); GELOGE(FAILED, "[Check][EngineType]value:%d not support, "
"only support default/AIcoreEngine/VectorEngine now", static_cast<int>(engine_type));
return FAILED; return FAILED;
} }
@ -190,17 +191,20 @@ static Status AddInputs(const ComputeGraphPtr &graph, const NodePtr &node, const
(void)AttrUtils::SetBool(data_op, "_is_single_op", true); (void)AttrUtils::SetBool(data_op, "_is_single_op", true);
GE_CHK_BOOL_EXEC(data_op->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add input desc fail"); GE_CHK_BOOL_EXEC(data_op->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
GE_CHK_BOOL_EXEC(data_op->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add output desc fail"); "[Add][InputDesc]fail for node:%s", data_op->GetName().c_str());
GE_CHK_BOOL_EXEC(data_op->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][OutputDesc]fail for node:%s", data_op->GetName().c_str());
if (attr) { if (attr) {
GE_CHK_BOOL_EXEC(AttrUtils::SetInt(data_op, ATTR_NAME_INDEX, index), return FAILED, "Set index fail"); GE_CHK_BOOL_EXEC(AttrUtils::SetInt(data_op, ATTR_NAME_INDEX, index), return FAILED,
"[Set][Attr:%s]fail for node:%s", ATTR_NAME_INDEX.c_str(), data_op->GetName().c_str());
} }
ge::NodePtr arg_node = graph->AddNode(data_op); ge::NodePtr arg_node = graph->AddNode(data_op);
GE_CHK_BOOL_EXEC(arg_node != nullptr, return FAILED, "Insert Data node fail"); GE_CHK_BOOL_EXEC(arg_node != nullptr, return FAILED, "Insert Data node fail");
GE_CHK_STATUS(GraphUtils::AddEdge(arg_node->GetOutDataAnchor(0), node->GetInDataAnchor(index)), GE_CHK_STATUS(GraphUtils::AddEdge(arg_node->GetOutDataAnchor(0), node->GetInDataAnchor(index)),
"Add edge[%s->%s] fail", data_op->GetName().c_str(), node->GetName().c_str()); "[Add][Edge]fail from node:%s to node:%s", data_op->GetName().c_str(), node->GetName().c_str());
return SUCCESS; return SUCCESS;
} }
@ -215,20 +219,23 @@ static Status AddOutputs(const ComputeGraphPtr &graph, const NodePtr &node, cons
for (const auto &out_desc : outputs) { for (const auto &out_desc : outputs) {
GeTensorDesc tensor = out_desc.GetTensorDesc(); GeTensorDesc tensor = out_desc.GetTensorDesc();
TensorUtils::SetInputTensor(tensor, true); TensorUtils::SetInputTensor(tensor, true);
GE_CHK_BOOL_EXEC(op_desc->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add input desc fail."); GE_CHK_BOOL_EXEC(op_desc->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][InputDesc]fail for node:%s", op_desc->GetName().c_str());
TensorUtils::SetInputTensor(tensor, false); TensorUtils::SetInputTensor(tensor, false);
TensorUtils::SetOutputTensor(tensor, true); TensorUtils::SetOutputTensor(tensor, true);
GE_CHK_BOOL_EXEC(op_desc->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add output desc fail."); GE_CHK_BOOL_EXEC(op_desc->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][OutputDesc]fail for node:%s", op_desc->GetName().c_str());
count++; count++;
} }
GE_CHECK_NOTNULL_EXEC(graph, return PARAM_INVALID); GE_CHECK_NOTNULL_EXEC(graph, return PARAM_INVALID);
ge::NodePtr out_node = graph->AddNode(op_desc); ge::NodePtr out_node = graph->AddNode(op_desc);
GE_CHK_BOOL_EXEC(out_node != nullptr, return FAILED, "Insert Output node fail"); GE_CHK_BOOL_EXEC(out_node != nullptr, return FAILED,
"[Add][Node:%s]fail in graph:%u", op_desc->GetName().c_str(), graph->GetGraphID());
GE_CHECK_NOTNULL_EXEC(node, return PARAM_INVALID); GE_CHECK_NOTNULL_EXEC(node, return PARAM_INVALID);
for (int32_t i = 0; i < count; ++i) { for (int32_t i = 0; i < count; ++i) {
GE_CHK_STATUS(GraphUtils::AddEdge(node->GetOutDataAnchor(i), out_node->GetInDataAnchor(i)), GE_CHK_STATUS(GraphUtils::AddEdge(node->GetOutDataAnchor(i), out_node->GetInDataAnchor(i)),
"Add edge[%s->%s] fail", node->GetName().c_str(), out_node->GetName().c_str()); "[Add][Edge]fail from node:%s to node:%s", node->GetName().c_str(), out_node->GetName().c_str());
} }
return SUCCESS; return SUCCESS;
@ -248,7 +255,7 @@ static void GetOpsProtoPath(string &opsproto_path) {
return; return;
} }
string path_base = PluginManager::GetPath(); string path_base = PluginManager::GetPath();
GELOGI("path_base is %s.", path_base.c_str()); GELOGI("path_base is %s", path_base.c_str());
path_base = path_base.substr(0, path_base.rfind('/')); path_base = path_base.substr(0, path_base.rfind('/'));
path_base = path_base.substr(0, path_base.rfind('/') + 1); path_base = path_base.substr(0, path_base.rfind('/') + 1);
opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/"); opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/");
@ -333,7 +340,7 @@ Status GeGenerator::Initialize(const map<string, string> &options, OmgContext &o
ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOpsProtoInit); ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOpsProtoInit);
string opsproto_path; string opsproto_path;
GetOpsProtoPath(opsproto_path); GetOpsProtoPath(opsproto_path);
GELOGI("Get opsproto path is %s.", opsproto_path.c_str()); GELOGI("Get opsproto path is %s", opsproto_path.c_str());
OpsProtoManager *manager = OpsProtoManager::Instance(); OpsProtoManager *manager = OpsProtoManager::Instance();
map<string, string> option_tmp; map<string, string> option_tmp;
option_tmp.emplace(std::pair<string, string>(string("ge.opsProtoLibPath"), opsproto_path)); option_tmp.emplace(std::pair<string, string>(string("ge.opsProtoLibPath"), opsproto_path));
@ -712,7 +719,7 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in
auto node = comp_graph->FindNode(op_desc->GetName()); auto node = comp_graph->FindNode(op_desc->GetName());
Status ret = CheckEngineTypeSupport(node, engine_type); Status ret = CheckEngineTypeSupport(node, engine_type);
if (ret != SUCCESS) { if (ret != SUCCESS) {
GELOGE(ret, "check engine type failed"); GELOGE(ret, "[Check][EngineType]value:%d for node:%s not support", engine_type, node->GetName().c_str());
return ret; return ret;
} }
} }
@ -786,9 +793,9 @@ Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor
const vector<GeTensor> &outputs, OpEngineType engine_type, const vector<GeTensor> &outputs, OpEngineType engine_type,
ModelBufferData &model_buff) { ModelBufferData &model_buff) {
ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther);
GELOGI("Start to build single op online, input size: %zu, output size: %zu.", inputs.size(), outputs.size()); GELOGI("Start to build single op online, input size: %zu, output size: %zu", inputs.size(), outputs.size());
Status status = BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false); Status status = BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false);
GELOGI("Finish build single online model, status: %u.", status); GELOGI("Finish build single online model, status: %u", status);
return status; return status;
} }

File diff suppressed because it is too large Load Diff

@ -40,7 +40,7 @@ static bool BlockComparator(const Block *left, const Block *right) {
} }
bool CanMerge(Block *block) { bool CanMerge(Block *block) {
if (block == nullptr || block->allocated || !block->IsSplit()) { if ((block == nullptr) || block->allocated || !block->IsSplit()) {
return false; return false;
} }
return true; return true;
@ -52,7 +52,7 @@ size_t GetBinIndex(size_t size) {
if (size <= range) { if (size <= range) {
break; break;
} }
++index; index++;
} }
if (index > kNumBins - 1) { if (index > kNumBins - 1) {
index = kNumBins - 1; index = kNumBins - 1;
@ -95,17 +95,17 @@ void IncreaseCount(std::map<size_t, size_t> &count, size_t size) {
} }
CachingAllocator::CachingAllocator(rtMemType_t memory_type) : memory_type_(memory_type), memory_allocator_(nullptr) { CachingAllocator::CachingAllocator(rtMemType_t memory_type) : memory_type_(memory_type), memory_allocator_(nullptr) {
for (uint32_t i = 0; i < kNumBins; ++i) { for (uint32_t i = 0; i < kNumBins; i++) {
free_block_bins_[i] = nullptr; free_block_bins_[i] = nullptr;
} }
} }
Status CachingAllocator::Initialize(uint32_t device_id) { Status CachingAllocator::Initialize(uint32_t device_id) {
GELOGI("Device id %u.", device_id); GELOGI("Device id %u", device_id);
// when redo Initialize free old memory // when redo Initialize free old memory
FreeBlocks(); FreeBlocks();
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
for (uint32_t i = 0; i < kNumBins; ++i) { for (uint32_t i = 0; i < kNumBins; i++) {
if (free_block_bins_[i] != nullptr) { if (free_block_bins_[i] != nullptr) {
continue; continue;
} }
@ -124,14 +124,14 @@ Status CachingAllocator::Initialize(uint32_t device_id) {
} }
void CachingAllocator::Finalize(uint32_t device_id) { void CachingAllocator::Finalize(uint32_t device_id) {
GELOGI("Device id %u.", device_id); GELOGI("Device id %u", device_id);
PrintStatics(); PrintStatics();
FreeBlocks(); FreeBlocks();
FreeBlockBins(); FreeBlockBins();
} }
uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device_id) { uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device_id) {
GELOGI("Start malloc pool memory, size = %zu, device id = %u.", size, device_id); GELOGI("Start malloc pool memory, size = %zu, device id = %u", size, device_id);
uint8_t *ptr = nullptr; uint8_t *ptr = nullptr;
size = GetBlockSize(size); size = GetBlockSize(size);
Block *block = FindFreeBlock(size, org_ptr, device_id); Block *block = FindFreeBlock(size, org_ptr, device_id);
@ -152,7 +152,7 @@ uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device
} }
Status CachingAllocator::Free(uint8_t *ptr, uint32_t device_id) { Status CachingAllocator::Free(uint8_t *ptr, uint32_t device_id) {
GELOGI("Free device id = %u.", device_id); GELOGI("Free device id = %u", device_id);
if (ptr == nullptr) { if (ptr == nullptr) {
GELOGE(PARAM_INVALID, "Invalid memory pointer"); GELOGE(PARAM_INVALID, "Invalid memory pointer");
return ge::PARAM_INVALID; return ge::PARAM_INVALID;
@ -171,10 +171,10 @@ Status CachingAllocator::Free(uint8_t *ptr, uint32_t device_id) {
} }
void CachingAllocator::FreeBlock(Block *block) { void CachingAllocator::FreeBlock(Block *block) {
if (block == nullptr || !block->allocated) { if ((block == nullptr) || !block->allocated) {
return; return;
} }
GELOGI("Free block size = %zu.", block->size); GELOGI("Free block size = %zu", block->size);
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
block->allocated = false; block->allocated = false;
@ -227,7 +227,7 @@ Block *CachingAllocator::FindFreeBlock(size_t size, uint8_t *org_ptr, uint32_t d
Block *block = *it; Block *block = *it;
bin->erase(it); bin->erase(it);
if (block != nullptr) { if (block != nullptr) {
GELOGI("Find block size = %zu.", block->size); GELOGI("Find block size = %zu", block->size);
if (ShouldSplit(block, size)) { if (ShouldSplit(block, size)) {
block = SplitBlock(block, size, *bin, device_id); block = SplitBlock(block, size, *bin, device_id);
} }
@ -235,7 +235,7 @@ Block *CachingAllocator::FindFreeBlock(size_t size, uint8_t *org_ptr, uint32_t d
if (block->ptr != nullptr) { if (block->ptr != nullptr) {
block->allocated = true; block->allocated = true;
allocated_blocks_[block->ptr] = block; allocated_blocks_[block->ptr] = block;
GELOGI("Malloc device id = %u, size= %zu.", device_id, size); GELOGI("Malloc device id = %u, size= %zu", device_id, size);
} }
} }
@ -265,7 +265,7 @@ Block *CachingAllocator::SplitBlock(Block *block, size_t size, BlockBin &bin, ui
} }
Status CachingAllocator::TryExtendCache(size_t size, uint32_t device_id) { Status CachingAllocator::TryExtendCache(size_t size, uint32_t device_id) {
GELOGI("Try to extend cache. size = %zu, device id = %u.", size, device_id); GELOGI("Try to extend cache. size = %zu, device id = %u", size, device_id);
auto memory_size = GetAllocationSize(size); auto memory_size = GetAllocationSize(size);
const std::string purpose = "Memory for caching."; const std::string purpose = "Memory for caching.";
auto memory_addr = memory_allocator_->MallocMemory(purpose, memory_size, device_id); auto memory_addr = memory_allocator_->MallocMemory(purpose, memory_size, device_id);
@ -302,7 +302,7 @@ Status CachingAllocator::AddToBlockBin(uint8_t *ptr, size_t size, uint32_t devic
return ge::FAILED; return ge::FAILED;
} }
GELOGI("Block size = %zu.", size); GELOGI("Block size = %zu", size);
block->ptr = ptr; block->ptr = ptr;
block->size = size; block->size = size;
@ -313,10 +313,10 @@ Status CachingAllocator::AddToBlockBin(uint8_t *ptr, size_t size, uint32_t devic
} }
size_t CachingAllocator::FreeCachedBlocks() { size_t CachingAllocator::FreeCachedBlocks() {
GELOGI("Free cached blocks."); GELOGI("Free cached blocks");
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
size_t free_cached_memory_size = 0; size_t free_cached_memory_size = 0;
for (uint32_t i = 0; i < kNumBins; ++i) { for (uint32_t i = 0; i < kNumBins; i++) {
auto pool = free_block_bins_[i]; auto pool = free_block_bins_[i];
if (pool == nullptr) { if (pool == nullptr) {
continue; continue;
@ -324,7 +324,8 @@ size_t CachingAllocator::FreeCachedBlocks() {
for (auto it = pool->begin(); it != pool->end();) { for (auto it = pool->begin(); it != pool->end();) {
Block *block = *it; Block *block = *it;
// free block memory that has not been split // free block memory that has not been split
if ((block != nullptr) && (block->ptr != nullptr) && (block->prev == nullptr) && (block->next == nullptr) && if ((block != nullptr) && (block->ptr != nullptr) &&
(block->prev == nullptr) && (block->next == nullptr) &&
(memory_allocator_->FreeMemory(block->ptr) == ge::SUCCESS)) { (memory_allocator_->FreeMemory(block->ptr) == ge::SUCCESS)) {
auto itcount = malloced_memory_.find(block->size); auto itcount = malloced_memory_.find(block->size);
free_cached_memory_size += block->size; free_cached_memory_size += block->size;
@ -345,7 +346,7 @@ size_t CachingAllocator::FreeCachedBlocks() {
} }
void CachingAllocator::FreeBlocks() { void CachingAllocator::FreeBlocks() {
GELOGI("Free blocks"); GELOGI("Free blocks.");
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
// free allocated blocks and put to cache // free allocated blocks and put to cache
for (auto &it : allocated_blocks_) { for (auto &it : allocated_blocks_) {
@ -356,9 +357,9 @@ void CachingAllocator::FreeBlocks() {
} }
void CachingAllocator::FreeBlockBins() { void CachingAllocator::FreeBlockBins() {
GELOGI("Free block bins"); GELOGI("Free block bins.");
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
for (uint32_t i = 0; i < kNumBins; ++i) { for (uint32_t i = 0; i < kNumBins; i++) {
if (free_block_bins_[i] != nullptr) { if (free_block_bins_[i] != nullptr) {
delete free_block_bins_[i]; delete free_block_bins_[i];
free_block_bins_[i] = nullptr; free_block_bins_[i] = nullptr;
@ -367,9 +368,9 @@ void CachingAllocator::FreeBlockBins() {
} }
void PrintCount(std::map<size_t, size_t> &count, const std::string &name, size_t total_size, size_t total_count) { void PrintCount(std::map<size_t, size_t> &count, const std::string &name, size_t total_size, size_t total_count) {
GELOGI("%6s total[size:%10zu count:%10zu]", name.c_str(), total_size, total_count); GELOGI("%6s total[size:%10zu count:%10zu].", name.c_str(), total_size, total_count);
for (auto &it : count) { for (auto &it : count) {
GELOGI(" |- block[size:%10zu count:%10zu]", it.first, it.second); GELOGI(" |- block[size:%10zu count:%10zu].", it.first, it.second);
} }
} }
@ -383,20 +384,20 @@ void CachingAllocator::PrintStatics() {
size_t total_free_count = 0; size_t total_free_count = 0;
size_t total_malloc_size = 0; size_t total_malloc_size = 0;
size_t total_malloc_count = 0; size_t total_malloc_count = 0;
std::map<size_t, size_t> using_block; std::map<size_t, size_t> using_block_stat;
std::map<size_t, size_t> free_block; std::map<size_t, size_t> free_block_stat;
std::map<size_t, size_t> malloc_block; std::map<size_t, size_t> malloc_block_stat;
do { do {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
for (uint32_t i = 0; i < kNumBins; ++i) { for (uint32_t i = 0; i < kNumBins; i++) {
auto pool = free_block_bins_[i]; auto pool = free_block_bins_[i];
if (pool == nullptr) { if (pool == nullptr) {
continue; continue;
} }
for (auto it = pool->begin(); it != pool->end(); ++it) { for (auto it = pool->begin(); it != pool->end(); it++) {
if ((*it) != nullptr) { if ((*it) != nullptr) {
total_free_size += (*it)->size; total_free_size += (*it)->size;
IncreaseCount(free_block, (*it)->size); IncreaseCount(free_block_stat, (*it)->size);
total_free_count++; total_free_count++;
} }
} }
@ -405,7 +406,7 @@ void CachingAllocator::PrintStatics() {
for (auto &it : allocated_blocks_) { for (auto &it : allocated_blocks_) {
if (it.second != nullptr) { if (it.second != nullptr) {
total_using_size += it.second->size; total_using_size += it.second->size;
IncreaseCount(using_block, it.second->size); IncreaseCount(using_block_stat, it.second->size);
total_using_count++; total_using_count++;
} }
} }
@ -413,12 +414,12 @@ void CachingAllocator::PrintStatics() {
for (auto &it : malloced_memory_) { for (auto &it : malloced_memory_) {
total_malloc_size += it.first * it.second; total_malloc_size += it.first * it.second;
total_malloc_count += it.second; total_malloc_count += it.second;
malloc_block[it.first] = it.second; malloc_block_stat[it.first] = it.second;
} }
} while (0); } while (0);
PrintCount(malloc_block, "Malloc", total_malloc_size, total_malloc_count); PrintCount(malloc_block_stat, "Malloc", total_malloc_size, total_malloc_count);
PrintCount(using_block, "Using", total_using_size, total_using_count); PrintCount(using_block_stat, "Using", total_using_size, total_using_count);
PrintCount(free_block, "Free", total_free_size, total_free_count); PrintCount(free_block_stat, "Free", total_free_size, total_free_count);
} }
} // namespace ge } // namespace ge

Loading…
Cancel
Save