[{"data":1,"prerenderedAt":487},["ShallowReactive",2],{"content-query-L7V0s1gFy4":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":481,"_id":482,"_source":483,"_file":484,"_stem":485,"_extension":486},"/technology-blogs/zh/894","zh",false,"","安利！如何提优质的ISSUE？学霸是这样写的！","对CheckCircle进行优化","2021-12-28","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/80a3c775de034224b43a43996e58ef21.png","technology-blogs","开发者分享",{"type":15,"children":16,"toc":469},"root",[17,25,34,43,48,63,70,75,90,114,119,124,131,136,143,150,158,163,176,181,189,197,202,209,214,222,227,234,239,244,251,256,263,268,281,286,294,299,306,311,318,323,328,335,340,347,354,362,380,407,414,421,428,432,442,451,460],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"安利如何提优质的issue学霸是这样写的",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":33},"img",{"alt":7,"src":32},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/5bf26940760143f1a534548533c86002.gif",[],{"type":18,"tag":26,"props":35,"children":36},{},[37],{"type":18,"tag":38,"props":39,"children":40},"strong",{},[41],{"type":24,"value":42},"作者：liujunzhu，来源：gitee",{"type":18,"tag":26,"props":44,"children":45},{},[46],{"type":24,"value":47},"此篇推文为昇思MindSpore社区的优质ISSUE，安利给各位小伙伴参考学习，更多ISSUE详情请查看链接：",{"type":18,"tag":26,"props":49,"children":50},{},[51],{"type":18,"tag":52,"props":53,"children":54},"em",{},[55],{"type":18,"tag":56,"props":57,"children":61},"a",{"href":58,"rel":59},"https://gitee.com/mindspore/mindspore/issues",[60],"nofollow",[62],{"type":24,"value":58},{"type":18,"tag":26,"props":64,"children":65},{},[66],{"type":18,"tag":30,"props":67,"children":69},{"alt":7,"src":68},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/d5e08f5666334a51ae76cffe079f1ccc.png",[],{"type":18,"tag":26,"props":71,"children":72},{},[73],{"type":24,"value":74},"UB融合的处理流程如下：",{"type":18,"tag":76,"props":77,"children":78},"ol",{},[79,85],{"type":18,"tag":80,"props":81,"children":82},"li",{},[83],{"type":24,"value":84},"通过Pass匹配待融合的算子，将fusion id设置到node的属性",{"type":18,"tag":80,"props":86,"children":87},{},[88],{"type":24,"value":89},"将匹配到的小算子融合为FusionOp",{"type":18,"tag":91,"props":92,"children":93},"ul",{},[94,99,104,109],{"type":18,"tag":80,"props":95,"children":96},{},[97],{"type":24,"value":98},"初始化融合信息，包括确定fusion scope包含的结点、确定输入输出的结点等",{"type":18,"tag":80,"props":100,"children":101},{},[102],{"type":24,"value":103},"检查各个fusion scope是否会成环（调用CheckCircle函数）",{"type":18,"tag":80,"props":105,"children":106},{},[107],{"type":24,"value":108},"编译融合算子，编译失败的fusion scope不做UB融合",{"type":18,"tag":80,"props":110,"children":111},{},[112],{"type":24,"value":113},"对每个fusion scope，先检查是否成环（调用CheckCircle函数），如果不成环则创建融合算子并在原图上进行替换",{"type":18,"tag":26,"props":115,"children":116},{},[117],{"type":24,"value":118},"通过实测来看，CheckCircle函数在UB融合的耗时占比为86%，所以需要对CheckCircle进行优化。",{"type":18,"tag":26,"props":120,"children":121},{},[122],{"type":24,"value":123},"UB融合之前图上是没有环的，但融合之后可能会形成环。如下图所示：",{"type":18,"tag":26,"props":125,"children":126},{},[127],{"type":18,"tag":30,"props":128,"children":130},{"alt":7,"src":129},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/0a1ed8f24134441c8b06932b8fea7780.jpg",[],{"type":18,"tag":26,"props":132,"children":133},{},[134],{"type":24,"value":135},"把A、B和C结点融合为E后，E和D形成了环。",{"type":18,"tag":26,"props":137,"children":138},{},[139],{"type":18,"tag":30,"props":140,"children":142},{"alt":7,"src":141},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/e71e371b59464f93a4233bb8c53420fd.jpg",[],{"type":18,"tag":26,"props":144,"children":145},{},[146],{"type":18,"tag":30,"props":147,"children":149},{"alt":7,"src":148},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/4d94414d20d44f5bb94dc4a46648a897.png",[],{"type":18,"tag":26,"props":151,"children":152},{},[153],{"type":18,"tag":38,"props":154,"children":155},{},[156],{"type":24,"value":157},"优化点1",{"type":18,"tag":26,"props":159,"children":160},{},[161],{"type":24,"value":162},"从上面的处理流程来看，有二次成环检查：",{"type":18,"tag":91,"props":164,"children":165},{},[166,171],{"type":18,"tag":80,"props":167,"children":168},{},[169],{"type":24,"value":170},"第一次在算子编译前检查，目的是防止编译耗时太长，通过成环检查提前排除不必要的算子编译，提升性能。从测试数据来看，这个时机的CheckCircle()函数被调用1719次，其中51次成环，成环比例仅为3%，所以这次检查可以删除。",{"type":18,"tag":80,"props":172,"children":173},{},[174],{"type":24,"value":175},"第二次是在每个FusionOp替换之前，这个时机的检查不能删除。",{"type":18,"tag":26,"props":177,"children":178},{},[179],{"type":24,"value":180},"优化方法：删除第一次成环检查。",{"type":18,"tag":182,"props":183,"children":184},"h2",{"id":7},[185],{"type":18,"tag":30,"props":186,"children":188},{"alt":7,"src":187},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/f98d5348aa0e43259142da9481cdf5ee.jpg",[],{"type":18,"tag":182,"props":190,"children":192},{"id":191},"优化点2",[193],{"type":18,"tag":38,"props":194,"children":195},{},[196],{"type":24,"value":191},{"type":18,"tag":26,"props":198,"children":199},{},[200],{"type":24,"value":201},"当前的成环检查，从fusion scope的输入结点（下图中的C和D）开始遍历其前驱结点（下图C和D的前驱都为B）。 如下图所示，先从输入C开始遍历C->B-A，再从输入D开始遍历D->B->A，这样会导致B和A被重复访问。",{"type":18,"tag":26,"props":203,"children":204},{},[205],{"type":18,"tag":30,"props":206,"children":208},{"alt":7,"src":207},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/4ef99e73aba54d928b9e3dc0152288fe.jpg",[],{"type":18,"tag":26,"props":210,"children":211},{},[212],{"type":24,"value":213},"所以在检查fusion scope时，可以记录访问过的结点，避免重复访问。",{"type":18,"tag":182,"props":215,"children":217},{"id":216},"优化点3",[218],{"type":18,"tag":38,"props":219,"children":220},{},[221],{"type":24,"value":216},{"type":18,"tag":26,"props":223,"children":224},{},[225],{"type":24,"value":226},"当前UB融合的pattern基本都是单输入单输出结构：",{"type":18,"tag":26,"props":228,"children":229},{},[230],{"type":18,"tag":30,"props":231,"children":233},{"alt":7,"src":232},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/36a05a0e82fb453796fd1a64ce98a81e.jpg",[],{"type":18,"tag":26,"props":235,"children":236},{},[237],{"type":24,"value":238},"根据这个特点可以做一些优化，避免不必要的检查。",{"type":18,"tag":26,"props":240,"children":241},{},[242],{"type":24,"value":243},"如果所有输入都传给fusion scope内的第一个入口结点（下图2个场景中的C结点），则融合后不会形成环，可跳过成环检查。",{"type":18,"tag":26,"props":245,"children":246},{},[247],{"type":18,"tag":30,"props":248,"children":250},{"alt":7,"src":249},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/c0de318241b24359ae114b5653ff25de.jpg",[],{"type":18,"tag":26,"props":252,"children":253},{},[254],{"type":24,"value":255},"如果输入传给了不同的入口结点（左图中的C和D）或非首个入口结点（fusion scope内部的结点已排拓扑序，从拓扑序上判断右图的C不是第一个入口结点）则可能成环。",{"type":18,"tag":26,"props":257,"children":258},{},[259],{"type":18,"tag":30,"props":260,"children":262},{"alt":7,"src":261},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/1811ac0670a344f4a8a06bd8bcf75c10.jpg",[],{"type":18,"tag":26,"props":264,"children":265},{},[266],{"type":24,"value":267},"考虑到UB融合pattern的特点和实现复杂度，进行如下判断：如果所有输入都传给fusion scope内的第一个结点，则跳过成环检查。",{"type":18,"tag":91,"props":269,"children":270},{},[271,276],{"type":18,"tag":80,"props":272,"children":273},{},[274],{"type":24,"value":275},"因为已经做过拓扑排序，所以第一个结点肯定是入口结点。",{"type":18,"tag":80,"props":277,"children":278},{},[279],{"type":24,"value":280},"这个条件太严苛，其他一些场景也可不必检查，考虑到其他场景在UB融合的占比很小，暂不支持。",{"type":18,"tag":26,"props":282,"children":283},{},[284],{"type":24,"value":285},"实测发现满足该条件的fusion scope占比为：1616/1719 = 94%。",{"type":18,"tag":182,"props":287,"children":289},{"id":288},"优化点4",[290],{"type":18,"tag":38,"props":291,"children":292},{},[293],{"type":24,"value":288},{"type":18,"tag":26,"props":295,"children":296},{},[297],{"type":24,"value":298},"如果所有输出都由fusion scope内的最后一个出口结点（下图左侧的B和右侧的C结点）产生，则融合后不会形成环，可跳过成环检查。",{"type":18,"tag":26,"props":300,"children":301},{},[302],{"type":18,"tag":30,"props":303,"children":305},{"alt":7,"src":304},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/633935b7b4e14796a9758f4b0177ac4a.jpg",[],{"type":18,"tag":26,"props":307,"children":308},{},[309],{"type":24,"value":310},"如果所有输出由不同出口结点（左图中的B和D）产生或由中间结点（右图中的B）产生则可能成环。",{"type":18,"tag":26,"props":312,"children":313},{},[314],{"type":18,"tag":30,"props":315,"children":317},{"alt":7,"src":316},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/e1c58ce74f164aea93147b5ae9b6cd51.jpg",[],{"type":18,"tag":26,"props":319,"children":320},{},[321],{"type":24,"value":322},"考虑到UB融合pattern的特点和实现复杂度，进行如下判断：如果所有输出都由fusion scope内的最后一个出口结点产生，则跳过成环检查。",{"type":18,"tag":26,"props":324,"children":325},{},[326],{"type":24,"value":327},"实测发现满足该条件的fusion scope占比为：1617/1719 = 94%，与优化点3的占比相同。",{"type":18,"tag":26,"props":329,"children":330},{},[331],{"type":18,"tag":30,"props":332,"children":334},{"alt":7,"src":333},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/16a46ec0065245629197a38b64c263f9.png",[],{"type":18,"tag":26,"props":336,"children":337},{},[338],{"type":24,"value":339},"下表的时间单位：秒。",{"type":18,"tag":26,"props":341,"children":342},{},[343],{"type":18,"tag":30,"props":344,"children":346},{"alt":7,"src":345},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/5fb925ed99b54c26adb879fc920787c0.jpg",[],{"type":18,"tag":26,"props":348,"children":349},{},[350],{"type":18,"tag":30,"props":351,"children":353},{"alt":7,"src":352},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/ee4e5bc1a1fe48b9afdefb8fee03ba85.jpg",[],{"type":18,"tag":26,"props":355,"children":356},{},[357],{"type":18,"tag":38,"props":358,"children":359},{},[360],{"type":24,"value":361},"欢迎投稿",{"type":18,"tag":26,"props":363,"children":364},{},[365],{"type":18,"tag":38,"props":366,"children":367},{},[368,370,378],{"type":24,"value":369},"欢迎大家踊跃投稿，有想投稿技术干货、项目经验等分享的同学，可以添加MindSpore官方小助手：小猫子（",{"type":18,"tag":38,"props":371,"children":372},{},[373],{"type":18,"tag":38,"props":374,"children":375},{},[376],{"type":24,"value":377},"mindspore0328",{"type":24,"value":379},"）的微信，告诉猫哥哦！",{"type":18,"tag":26,"props":381,"children":382},{},[383,388,390,395,397,405],{"type":18,"tag":38,"props":384,"children":385},{},[386],{"type":24,"value":387},"昇思MindSpore官方交流QQ群 :",{"type":24,"value":389}," ",{"type":18,"tag":38,"props":391,"children":392},{},[393],{"type":24,"value":394},"486831414",{"type":24,"value":396},"**（",{"type":18,"tag":38,"props":398,"children":399},{},[400],{"type":18,"tag":38,"props":401,"children":402},{},[403],{"type":24,"value":404},"群里有很多技术大咖助力答疑！",{"type":24,"value":406},"）**",{"type":18,"tag":26,"props":408,"children":409},{},[410],{"type":18,"tag":30,"props":411,"children":413},{"alt":7,"src":412},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/28/053dba9bd67546ca990ab406ade2a60f.jpg",[],{"type":18,"tag":415,"props":416,"children":418},"h3",{"id":417},"扫描下方二维码加入mindspore项目",[419],{"type":24,"value":420},"扫描下方二维码加入MindSpore项目",{"type":18,"tag":26,"props":422,"children":423},{},[424],{"type":18,"tag":30,"props":425,"children":427},{"alt":7,"src":426},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/12/13/98daf7ecda28454ba59efd7a354babaf.jpg",[],{"type":18,"tag":415,"props":429,"children":431},{"id":430},"_1",[],{"type":18,"tag":26,"props":433,"children":434},{},[435],{"type":18,"tag":56,"props":436,"children":439},{"href":437,"rel":438},"http://mp.weixin.qq.com/s?__biz=MzAxMDA1MDM0NQ==&mid=2247541446&idx=1&sn=f397c4aadf6313efe8c16d15cec8db3d&chksm=9b542c80ac23a596935839754dc4690c6c0a20319c1bb23c67bc3bd7b527c8cf6d3c1efcc9a9&scene=21#wechat_redirect",[60],[440],{"type":24,"value":441},"MindSpore官方资料",{"type":18,"tag":26,"props":443,"children":444},{},[445],{"type":18,"tag":56,"props":446,"children":448},{"href":437,"rel":447},[60],[449],{"type":24,"value":450},"GitHub : https://github.com/mindspore-ai/mindspore",{"type":18,"tag":26,"props":452,"children":453},{},[454],{"type":18,"tag":56,"props":455,"children":457},{"href":437,"rel":456},[60],[458],{"type":24,"value":459},"Gitee : https : //gitee.com/mindspore/mindspore",{"type":18,"tag":26,"props":461,"children":462},{},[463],{"type":18,"tag":56,"props":464,"children":466},{"href":437,"rel":465},[60],[467],{"type":24,"value":468},"官方QQ群 : 486831414",{"title":7,"searchDepth":470,"depth":470,"links":471},4,[472,474,475,476],{"id":7,"depth":473,"text":7},2,{"id":191,"depth":473,"text":191},{"id":216,"depth":473,"text":216},{"id":288,"depth":473,"text":288,"children":477},[478,480],{"id":417,"depth":479,"text":420},3,{"id":430,"depth":479,"text":7},"markdown","content:technology-blogs:zh:894.md","content","technology-blogs/zh/894.md","technology-blogs/zh/894","md",1776506142031]