未验证 提交 8d7c15a7 编写于 作者: J jiangcheng 提交者: GitHub

[CINN] add cinn sub-graph save into graphviz flag (#52766)

上级 d12b1ffa
......@@ -31,6 +31,7 @@
#include "cinn/frontend/syntax.h"
#include "cinn/hlir/framework/graph.h"
#include "cinn/hlir/framework/graph_compiler.h"
#include "cinn/hlir/framework/visualize_helper.h"
#include "gflags/gflags.h"
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/ir/graph.h"
......@@ -49,6 +50,7 @@
DECLARE_bool(enable_pe_launch_cinn);
DECLARE_bool(enable_cinn_auto_tune);
DECLARE_string(cinn_subgraph_graphviz_dir);
namespace paddle {
namespace framework {
namespace paddle2cinn {
......@@ -73,7 +75,6 @@ const CinnCompiledObject &CinnCompiler::Compile(
const std::map<std::string, const phi::DenseTensor *> &input_tensors,
const Target &target,
void *stream) {
VLOG(4) << "-- The graph to be compiled is:\n" << VizGraph(graph);
CinnCacheKeyByAddress cur_key_by_address(
graph, input_tensors, target.arch_str());
CinnCacheKeyByStructure cur_key_by_struct;
......@@ -85,6 +86,26 @@ const CinnCompiledObject &CinnCompiler::Compile(
if (!cache_by_struct_.count(cur_key_by_struct)) {
VLOG(4) << "Not found CinnCompiledObject in cache_by_struct_.";
std::int64_t compiled_num = real_compiled_num_.fetch_add(1);
if (!FLAGS_cinn_subgraph_graphviz_dir.empty()) {
const std::string &viz_path = FLAGS_cinn_subgraph_graphviz_dir +
"/fusion_groups_" +
std::to_string(compiled_num) + "/";
if (!::cinn::hlir::framework::MakeDirectory(
viz_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
LOG_IF(WARNING, compiled_num == 0)
<< "Failed to make directory: \"" << viz_path
<< "\", the CINN subgraph's graphviz dot file will not print.";
} else {
LOG_IF(INFO, compiled_num == 0)
<< "The CINN subgraph's graphviz dot file will writing into "
"path: \""
<< FLAGS_cinn_subgraph_graphviz_dir << "\"";
::cinn::hlir::framework::WriteToFile(viz_path + "cinn_subgraph.dot",
VizGraph(graph));
}
}
auto compiled_res =
CompileGraph(graph, input_tensors, target, compiled_num, stream);
std::unique_lock<std::mutex> guard(lock_);
......
......@@ -1001,6 +1001,20 @@ PADDLE_DEFINE_EXPORTED_bool(enable_cinn_auto_tune,
"It controls whether to use cinn with "
"its auto-tune feature enabled");
/*
* CINN related FLAG
* Name: FLAGS_cinn_subgraph_graphviz_dir
* Since Version: 2.3
* Value Range: string, default=""
* Example: FLAGS_cinn_subgraph_graphviz_dir="./cinn_graph/" will save the
* CINN sub-graph into "./cinn_graph/", and each sub-graph will save into
* "fusion_groups_*"" directory
*/
PADDLE_DEFINE_EXPORTED_string(cinn_subgraph_graphviz_dir,
"",
"Specify the directory path of dot file of "
"graph, which is used for debug.");
#endif
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册