@ -1,5 +1,5 @@
/**
/**
* Copyright 20 20 Huawei Technologies Co . , Ltd
* Copyright 20 19- 20 20 Huawei Technologies Co . , Ltd
*
*
* Licensed under the Apache License , Version 2.0 ( the " License " ) ;
* Licensed under the Apache License , Version 2.0 ( the " License " ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -40,34 +40,32 @@ const std::string kFilePath = "./";
const std : : string kAnalyzeFile = " ge_check_op.json " ;
const std : : string kAnalyzeFile = " ge_check_op.json " ;
const std : : string kUnknownShape = " unknownshape " ;
const std : : string kUnknownShape = " unknownshape " ;
const std : : string kUnsupport = " unsupport " ;
const std : : string kUnsupport = " unsupport " ;
const std : : string kSessionId = " session_id " ;
const std : : string kSessionId = " session_id " ;
const std : : string kGraphId = " graph_id " ;
const std : : string kGraphId = " graph_id " ;
const std : : string kOpInfo = " op_info " ;
const std : : string kOpInfo = " op_info " ;
const std : : string kErrorType = " error_type " ;
const std : : string kErrorType = " error_type " ;
const std : : string kOpName = " name " ;
const std : : string kOpName = " name " ;
const std : : string kOpType = " type " ;
const std : : string kOpType = " type " ;
const std : : string kReason = " reason " ;
const std : : string kReason = " reason " ;
const std : : string kInput = " input " ;
const std : : string kInput = " input " ;
const std : : string kOutput = " output " ;
const std : : string kOutput = " output " ;
const std : : string kShape = " shape " ;
const std : : string kShape = " shape " ;
const std : : string kDataType = " data_type " ;
const std : : string kDataType = " data_type " ;
const std : : string kLayout = " layout " ;
const std : : string kLayout = " layout " ;
const std : : string kResult = " result " ;
const std : : string kResult = " result " ;
const std : : string kOp = " op " ;
const std : : string kOp = " op " ;
std : : map < analyzer : : AnalyzeType , std : : string > errors_map {
std : : map < analyzer : : AnalyzeType , std : : string > errors_map { { PARSER , " paser_error " } ,
{ PARSER , " paser_error " } ,
{ INFER_SHAPE , " infer_shape_error " } ,
{ INFER_SHAPE , " infer_shape_error " } ,
{ CHECKSUPPORT , " check_support_error " } ,
{ CHECKSUPPORT , " check_support_error " } ,
{ GRAPH_OPTIMIZE , " graph_optimize_error " } ,
{ GRAPH_OPTIMIZE , " graph_optimize_error " } ,
{ GRAPH_PARTION , " graph_partion_error " } ,
{ GRAPH_PARTION , " graph_partion_error " } ,
{ GRAPH_BUILDER , " graph_builder_error " } } ;
{ GRAPH_BUILDER , " graph_builder_error " }
} // namespace
} ;
}
Analyzer * Analyzer : : GetInstance ( ) {
Analyzer * Analyzer : : GetInstance ( ) {
static Analyzer instance ;
static Analyzer instance ;
return & instance ;
return & instance ;
}
}
@ -77,8 +75,9 @@ Status Analyzer::BuildJsonObject(uint64_t session_id, uint64_t graph_id) {
std : : lock_guard < std : : recursive_mutex > lg ( mutex_ ) ;
std : : lock_guard < std : : recursive_mutex > lg ( mutex_ ) ;
auto iter = graph_infos_ . find ( session_id ) ;
auto iter = graph_infos_ . find ( session_id ) ;
if ( iter = = graph_infos_ . end ( ) ) {
if ( iter = = graph_infos_ . end ( ) ) {
std : : shared_ptr < GraphInfo > graph_info ( new ( std : : nothrow ) GraphInfo ( ) ) ;
auto p = new ( std : : nothrow ) GraphInfo ( ) ;
GE_CHECK_NOTNULL ( graph_info ) ;
GE_CHECK_NOTNULL ( p ) ;
std : : shared_ptr < GraphInfo > graph_info ( p ) ;
std : : map < uint64_t , std : : shared_ptr < GraphInfo > > graph_map ;
std : : map < uint64_t , std : : shared_ptr < GraphInfo > > graph_map ;
graph_map [ graph_id ] = graph_info ;
graph_map [ graph_id ] = graph_info ;
graph_info - > session_id = session_id ;
graph_info - > session_id = session_id ;
@ -87,8 +86,9 @@ Status Analyzer::BuildJsonObject(uint64_t session_id, uint64_t graph_id) {
} else {
} else {
auto iter1 = ( iter - > second ) . find ( graph_id ) ;
auto iter1 = ( iter - > second ) . find ( graph_id ) ;
if ( iter1 = = ( iter - > second ) . end ( ) ) {
if ( iter1 = = ( iter - > second ) . end ( ) ) {
std : : shared_ptr < GraphInfo > graph_info ( new ( std : : nothrow ) GraphInfo ( ) ) ;
auto p = new ( std : : nothrow ) GraphInfo ( ) ;
GE_CHECK_NOTNULL ( graph_info ) ;
GE_CHECK_NOTNULL ( p ) ;
std : : shared_ptr < GraphInfo > graph_info ( p ) ;
graph_info - > session_id = session_id ;
graph_info - > session_id = session_id ;
graph_info - > graph_id = graph_id ;
graph_info - > graph_id = graph_id ;
( iter - > second ) . insert ( { graph_id , graph_info } ) ;
( iter - > second ) . insert ( { graph_id , graph_info } ) ;
@ -100,14 +100,7 @@ Status Analyzer::BuildJsonObject(uint64_t session_id, uint64_t graph_id) {
}
}
ge : : Status Analyzer : : Initialize ( ) {
ge : : Status Analyzer : : Initialize ( ) {
// Initialize file
ClearHistoryFile ( ) ;
string real_path = RealPath ( kFilePath . c_str ( ) ) ;
if ( real_path . empty ( ) ) {
GELOGE ( FAILED , " File path is invalid. " ) ;
return FAILED ;
}
json_file_name_ = real_path + " / " + kAnalyzeFile ;
return SUCCESS ;
return SUCCESS ;
}
}
@ -145,7 +138,6 @@ void Analyzer::DestroyGraphJsonObject(uint64_t session_id, uint64_t graph_id) {
if ( iter1 = = ( iter - > second ) . end ( ) ) {
if ( iter1 = = ( iter - > second ) . end ( ) ) {
GELOGW ( " Can not find the graph json object by session_id[%lu] and graph_id[%lu]. Do nothing. " , session_id ,
GELOGW ( " Can not find the graph json object by session_id[%lu] and graph_id[%lu]. Do nothing. " , session_id ,
graph_id ) ;
graph_id ) ;
return ;
}
}
( iter - > second ) . erase ( iter1 ) ;
( iter - > second ) . erase ( iter1 ) ;
}
}
@ -182,8 +174,15 @@ ge::Status Analyzer::CreateAnalyzerFile() {
return SUCCESS ;
return SUCCESS ;
}
}
GELOGD ( " start to create analyzer file! " ) ;
GELOGD ( " start to create analyzer file! " ) ;
// Check whether the manifest exists, if not, create it.
string real_path = RealPath ( kFilePath . c_str ( ) ) ;
if ( real_path . empty ( ) ) {
GELOGE ( FAILED , " File path is invalid. " ) ;
return FAILED ;
}
std : : lock_guard < std : : mutex > lg ( file_mutex_ ) ;
std : : lock_guard < std : : mutex > lg ( file_mutex_ ) ;
json_file_name_ = real_path + " / " + kAnalyzeFile ;
GELOGD ( " Created analyzer file:[%s] " , json_file_name_ . c_str ( ) ) ;
int fd = open ( json_file_name_ . c_str ( ) , O_WRONLY | O_CREAT | O_TRUNC , kFileAuthority ) ;
int fd = open ( json_file_name_ . c_str ( ) , O_WRONLY | O_CREAT | O_TRUNC , kFileAuthority ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
GELOGE ( INTERNAL_ERROR , " Fail to open the file: %s. " , json_file_name_ . c_str ( ) ) ;
GELOGE ( INTERNAL_ERROR , " Fail to open the file: %s. " , json_file_name_ . c_str ( ) ) ;
@ -199,27 +198,25 @@ ge::Status Analyzer::CreateAnalyzerFile() {
return SUCCESS ;
return SUCCESS ;
}
}
ge : : Status Analyzer : : SaveAnalyzerDataToFile ( uint64_t session_id , uint64_t graph_id ) {
ge : : Status Analyzer : : SaveAnalyzerDataToFile ( ) {
GELOGD ( " start to save analyze file! " ) ;
GELOGD ( " start to save analyze file! " ) ;
auto graph_info = GetJsonObject ( session_id , graph_id ) ;
GE_CHECK_NOTNULL ( graph_info ) ;
if ( graph_info - > op_info . size ( ) = = 0 ) {
GELOGD ( " session_id:%lu graph_id:%lu does not owner op info, break it! " , session_id , graph_id ) ;
return SUCCESS ;
}
std : : lock_guard < std : : mutex > lg ( file_mutex_ ) ;
std : : lock_guard < std : : mutex > lg ( file_mutex_ ) ;
json_file_ . open ( json_file_name_ , std : : ios : : app ) ;
json_file_ . open ( json_file_name_ , std : : ios : : out ) ;
if ( ! json_file_ . is_open ( ) ) {
if ( ! json_file_ . is_open ( ) ) {
GELOGE ( FAILED , " analyzer file does not exist[%s] " , json_file_name_ . c_str ( ) ) ;
GELOGE ( FAILED , " analyzer file does not exist[%s] " , json_file_name_ . c_str ( ) ) ;
return PARAM_INVALID ;
return PARAM_INVALID ;
}
}
json jsn ;
std : : lock_guard < std : : recursive_mutex > lk ( mutex_ ) ;
GraphInfoToJson ( jsn , * graph_info ) ;
for ( auto & ele : graph_infos_ ) {
json_file_ < < jsn . dump ( kJsonDumpLevel ) < < std : : endl ;
for ( auto & ele2 : ele . second ) {
json_file_ . close ( ) ;
json jsn ;
GraphInfoToJson ( jsn , * ( ele2 . second ) ) ;
json_file_ < < jsn . dump ( kJsonDumpLevel ) < < std : : endl ;
}
}
json_file_ . close ( ) ;
return SUCCESS ;
return SUCCESS ;
}
}
@ -240,7 +237,13 @@ ge::Status Analyzer::DoAnalyze(DataInfo &data_info) {
return FAILED ;
return FAILED ;
}
}
// create json file
// create json file
return CreateAnalyzerFile ( ) ;
status = CreateAnalyzerFile ( ) ;
if ( status ! = SUCCESS ) {
GELOGE ( status , " create analyzer file failed! " ) ;
return status ;
}
// save data to file
return SaveAnalyzerDataToFile ( ) ;
}
}
ge : : Status Analyzer : : SaveOpInfo ( ge : : OpDescPtr desc , DataInfo & data_info ,
ge : : Status Analyzer : : SaveOpInfo ( ge : : OpDescPtr desc , DataInfo & data_info ,
@ -253,18 +256,18 @@ ge::Status Analyzer::SaveOpInfo(ge::OpDescPtr desc, DataInfo &data_info,
op_info . error_type = iter - > second ;
op_info . error_type = iter - > second ;
op_info . op_name = desc - > GetName ( ) ;
op_info . op_name = desc - > GetName ( ) ;
op_info . op_type = desc - > GetType ( ) ;
op_info . op_type = desc - > GetType ( ) ;
op_info . reason = data_info . reason ;
op_info . reason = data_info . reason ;
for ( const auto & ptr : desc - > GetAllInputsDescPtr ( ) ) {
for ( const auto & ptr : desc - > GetAllInputsDescPtr ( ) ) {
TensorInfo tensor_info ;
TensorInfo tensor_info ;
tensor_info . shape = ptr - > GetShape ( ) . GetDims ( ) ;
tensor_info . shape = ptr - > GetShape ( ) . GetDims ( ) ;
tensor_info . d_type = ge : : TypeUtils : : DataTypeToSerialString ( ptr - > GetDataType ( ) ) ;
tensor_info . d_type = ge : : TypeUtils : : DataTypeToSerialString ( ptr - > GetDataType ( ) ) ;
tensor_info . layout = ge : : TypeUtils : : FormatToSerialString ( ptr - > GetFormat ( ) ) ;
tensor_info . layout = ge : : TypeUtils : : FormatToSerialString ( ptr - > GetFormat ( ) ) ;
op_info . input_info . emplace_back ( tensor_info ) ;
op_info . input_info . emplace_back ( tensor_info ) ;
}
}
for ( const auto & ptr : desc - > GetAllOutputsDescPtr ( ) ) {
for ( const auto & ptr : desc - > GetAllOutputsDescPtr ( ) ) {
TensorInfo tensor_info ;
TensorInfo tensor_info ;
tensor_info . shape = ptr - > GetShape ( ) . GetDims ( ) ;
tensor_info . shape = ptr - > GetShape ( ) . GetDims ( ) ;
tensor_info . d_type = ge : : TypeUtils : : DataTypeToSerialString ( ptr - > GetDataType ( ) ) ;
tensor_info . d_type = ge : : TypeUtils : : DataTypeToSerialString ( ptr - > GetDataType ( ) ) ;
tensor_info . layout = ge : : TypeUtils : : FormatToSerialString ( ptr - > GetFormat ( ) ) ;
tensor_info . layout = ge : : TypeUtils : : FormatToSerialString ( ptr - > GetFormat ( ) ) ;
op_info . output_info . emplace_back ( tensor_info ) ;
op_info . output_info . emplace_back ( tensor_info ) ;
@ -274,13 +277,13 @@ ge::Status Analyzer::SaveOpInfo(ge::OpDescPtr desc, DataInfo &data_info,
return SUCCESS ;
return SUCCESS ;
}
}
void Analyzer : : TensorInfoToJson ( json & j , const TensorInfo & tensor_info ) {
void Analyzer : : TensorInfoToJson ( json & j , const TensorInfo & tensor_info ) {
j [ kShape ] = tensor_info . shape ;
j [ kShape ] = tensor_info . shape ;
j [ kDataType ] = tensor_info . d_type ;
j [ kDataType ] = tensor_info . d_type ;
j [ kLayout ] = tensor_info . layout ;
j [ kLayout ] = tensor_info . layout ;
}
}
void Analyzer : : OpInfoToJson ( json & j , const OpInfo & op_info ) {
void Analyzer : : OpInfoToJson ( json & j , const OpInfo & op_info ) {
j [ kErrorType ] = op_info . error_type ;
j [ kErrorType ] = op_info . error_type ;
j [ kOpName ] = op_info . op_name ;
j [ kOpName ] = op_info . op_name ;
j [ kOpType ] = op_info . op_type ;
j [ kOpType ] = op_info . op_type ;
@ -297,7 +300,7 @@ void Analyzer::OpInfoToJson(json& j, const OpInfo &op_info) {
}
}
}
}
void Analyzer : : GraphInfoToJson ( json & j , const GraphInfo & graph_info ) {
void Analyzer : : GraphInfoToJson ( json & j , const GraphInfo & graph_info ) {
GELOGD ( " start to buff graph info! " ) ;
GELOGD ( " start to buff graph info! " ) ;
j [ kSessionId ] = graph_info . session_id ;
j [ kSessionId ] = graph_info . session_id ;
j [ kGraphId ] = graph_info . graph_id ;
j [ kGraphId ] = graph_info . graph_id ;
@ -309,4 +312,4 @@ void Analyzer::GraphInfoToJson(json& j, const GraphInfo &graph_info) {
}
}
j [ kOp ] = json_op_infos ;
j [ kOp ] = json_op_infos ;
}
}
} // namespace ge
} // namespace ge