Log node placement info in verbose logging mode + turn on verbose mode in onnx_test_runner -vv switch. (#2221)

This commit is contained in:
Pranav Sharma 2019-10-22 07:22:18 -07:00 committed by Changming Sun
parent 384c686f40
commit 04b8a4bb34
2 changed files with 35 additions and 4 deletions

View file

@ -46,7 +46,7 @@
#include "core/optimizer/transformer_memcpy.h"
#include "core/providers/cpu/controlflow/utils.h"
#include "core/providers/cpu/cpu_execution_provider.h"
#ifdef USE_DML // TODO: This is necessary for the workaround in TransformGraph
#ifdef USE_DML // TODO: This is necessary for the workaround in TransformGraph
#include "core/providers/dml/DmlExecutionProvider/src/GraphTransformer.h"
#endif
#include "core/session/IOBinding.h"
@ -382,7 +382,7 @@ common::Status InferenceSession::TransformGraph(onnxruntime::Graph& graph,
// transformer applies DML-specific fusions that go beyond what ORT offers by default. Ideally the DML EP should
// apply these transforms during partitioning, but the full mutable Graph object isn't exposed to
// IExecutionProvider::GetCapability, which is necessary for the DML EP's transforms.
//
//
// To prevent this from interfering with other EPs, we only apply this transform if the DML EP is the only one that's
// registered (aside from the CPU EP, which is always registered by default.)
if (execution_providers_.Get(kDmlExecutionProvider) && execution_providers_.NumProviders() <= 2) {
@ -409,8 +409,11 @@ common::Status InferenceSession::TransformGraph(onnxruntime::Graph& graph,
ORT_RETURN_IF_ERROR_SESSIONID_(insert_cast_transformer.Apply(graph, modified));
// Now every node should be already assigned to an execution provider
std::unordered_map<std::string, std::vector<std::string>> node_placements;
bool is_verbose_mode = session_logger_->GetSeverity() == logging::Severity::kVERBOSE;
for (auto& node : graph.Nodes()) {
if (node.GetExecutionProviderType().empty()) {
const auto& node_provider = node.GetExecutionProviderType();
if (node_provider.empty()) {
std::ostringstream oss;
oss << "Could not find an implementation for the node ";
if (!node.Name().empty()) oss << node.Name() << ":";
@ -419,6 +422,25 @@ common::Status InferenceSession::TransformGraph(onnxruntime::Graph& graph,
oss << "(" << node.Op()->since_version() << ")";
}
return Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED, oss.str());
} else {
if (is_verbose_mode) { // TODO: should we disable this if the number of nodes are above a certain threshold?
std::string node_str = node.OpType();
node_str += " (";
node_str += node.Name();
node_str += ")";
node_placements[node_provider].push_back(node_str);
}
}
}
// print placement info
if (is_verbose_mode) {
LOGS(*session_logger_, VERBOSE) << "Node placements";
for (const auto& pr : node_placements) {
std::ostringstream all_nodes_str;
std::copy(pr.second.begin(), pr.second.end(), std::ostream_iterator<std::string>(all_nodes_str, ", "));
LOGS(*session_logger_, VERBOSE) << " Provider: [" << pr.first << "]"
<< ": [" << all_nodes_str.str() << "]";
}
}

View file

@ -106,6 +106,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) {
int device_id = 0;
GraphOptimizationLevel graph_optimization_level = ORT_DISABLE_ALL;
bool user_graph_optimization_level_set = false;
int verbosity_option_count = 0;
OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING;
{
@ -116,7 +117,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) {
enable_cpu_mem_arena = false;
break;
case 'v':
logging_level = ORT_LOGGING_LEVEL_INFO;
verbosity_option_count += 1;
break;
case 'c':
concurrent_session_runs = static_cast<int>(OrtStrtol<PATH_CHAR_TYPE>(optarg, nullptr));
@ -217,6 +218,14 @@ int real_main(int argc, char* argv[], Ort::Env& env) {
}
}
}
// set log level based on number of verbosity options
if (verbosity_option_count == 1) {
logging_level = ORT_LOGGING_LEVEL_INFO;
} else if (verbosity_option_count > 1) {
logging_level = ORT_LOGGING_LEVEL_VERBOSE;
}
if (concurrent_session_runs > 1 && repeat_count > 1) {
fprintf(stderr, "when you use '-r [repeat]', please set '-c' to 1\n");
usage();