Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PIR】Support visulization with GraphViz for pir Program #55599

Closed
Aurelius84 opened this issue Jul 21, 2023 · 2 comments
Closed

【PIR】Support visulization with GraphViz for pir Program #55599

Aurelius84 opened this issue Jul 21, 2023 · 2 comments
Assignees
Labels
good first issue PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/feature-request 新需求申请

Comments

@Aurelius84
Copy link
Contributor

Aurelius84 commented Jul 21, 2023

一、任务背景

飞桨近期在重构底层的中间表示(下称:IR),替换原来的 ProgramDesc 为新的 MLIR。具体技术设计详见:IR Dialect

二、任务描述(难度:中)

此项目处于高效迭代期,为了加速开发者们对模型、子图级别下新 IR 表示的熟悉,降低功能开发中的调试成本,希望能够给 IR Dialect 添加「可视化」功能,接口形态如下:

// 详见 test/cpp/ir/core/ir_program_test.cc

#include "paddle/ir/core/program.h"

TEST(program_test, program) {
ir::IrContext *ctx = ir::IrContext::Instance();
ir::Program program(ctx);

// ... (省略了 Program 生成过程)

program.Visualize();  // <----- 核心接口
}

三、思路引导

Visualize() 接口能够输出一个 string 供终端打印调试,其内容可以遵循 GraphViz 的 Dot Language 协议,可以借鉴 CINN 中 dot_lang.cc 中的实现。

其输出范式为(CINN中的一个简单样例):

digraph G {
   subgraph cluster_125 {
      label="group_125(size=3)"
      color="grey"
      style="filled"
      fillcolor="#FFFFF0"
      node_715[label="eager_in_tmp_8\n[128x1x1x128]\nfloat16" color="#FFDC85" style="filled"]
      node_718[label="var_1559\n[128x12x128x128]\nfloat16" color="#FFDC85" style="filled"]
      node_719[label="var_1561\n[128x12x128x128]\nfloat16" color="#FFDC85" style="filled"]
      node_716[label="var_4003\n[128x12x128x128]\nfloat16" color="#FFDC85" style="filled"]
      node_717[label="elementwise_add_515" shape="Mrecord" color="#8EABFF" style="filled"]
      node_720[label="cast_516" shape="Mrecord" color="#8EABFF" style="filled"]
      node_721[label="var_1563\n[128x12x128x128]\nfloat32" color="#FFDC85" style="filled"]
      node_714[label="broadcast_to_514" shape="Mrecord" color="#8EABFF" style="filled"]
   }
   node_722[label="cublas_matmul_513" shape="Mrecord" color="#ff7f00" style="filled"]
   node_724[label="reduce_max_517" shape="Mrecord" color="#ff7f00" style="filled"]
   node_723[label="subtract_518" shape="Mrecord" color="#ff7f00" style="filled"]
   node_715->node_714
   node_714->node_716
   node_718->node_717
   node_716->node_717
   node_717->node_719
   node_719->node_720
   node_720->node_721
   node_722->node_718
   node_721->node_723
   node_721->node_724
} // end G

借助 VScode 的 DOT Preview 插件可以进行便捷化的可视化,即下图:

image

四、一些Tips

4.1 图语义

CINN 中的 Visualize 接口是基于 Graph 来做的。飞桨的新一代 IR 里的 ir::Program 本身借助了 OpOprand 和 OpResult 连接关系表达了 Graph 的语义,所以可以直接借助 ir::Program来实现(详见 OpOperandImpl实现)

下图表示算子A的第一个输出被算子C和算子B用作第一个输入。

image

4.2 子图可视化

此功能支持可以分为两期。第一期可以不考虑控制流、多Region的场景,聚焦单Block即可。控制流和多Region属于「子图可视化」。

@Aurelius84 Aurelius84 added status/new-issue 新建 type/feature-request 新需求申请 good first issue PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc labels Jul 21, 2023
@Aurelius84 Aurelius84 self-assigned this Jul 21, 2023
@GreatV
Copy link
Contributor

GreatV commented Jul 21, 2023

这个我可以报名吗,感觉比较有意思。

@Ligoml Ligoml removed the status/new-issue 新建 label Jul 21, 2023
@Aurelius84
Copy link
Contributor Author

这个我可以报名吗,感觉比较有意思。

@GreatV 感谢关注,明天会有任务宣传,可以重点关注下。

@Aurelius84 Aurelius84 changed the title 【NewIR】Support visulization with GraphViz for new ir Program 【PIR】Support visulization with GraphViz for pir Program Sep 19, 2023
@paddle-bot paddle-bot bot added the status/close 已关闭 label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/feature-request 新需求申请
Projects
None yet
Development

No branches or pull requests

3 participants