已合并
perf(layer_norm): check fusion pass platform before pattern construction #11299
rk创建于 9月28日
perf(layer_norm): check fusion pass platform before pattern construction #11299
已合并
共 6 个文件变更+18-18
| @@ -309,6 +309,9 @@ PatternUniqPtr MakePattern(size_t config, bool form_b) | |||
| 309 | 309 | ||
| 310 | std::vector<PatternUniqPtr> LayerNormFusionPass::Patterns() | 310 | std::vector<PatternUniqPtr> LayerNormFusionPass::Patterns() |
| 311 | { | 311 | { |
| 312 | + if (!IsSupportedPlatform()) { | ||
| 313 | + return {}; | ||
| 314 | + } | ||
| 312 | std::vector<PatternUniqPtr> patterns; | 315 | std::vector<PatternUniqPtr> patterns; |
| 313 | patterns.reserve(kCommConfigNum * 2U); | 316 | patterns.reserve(kCommConfigNum * 2U); |
| 314 | for (size_t config = 0U; config < kCommConfigNum; ++config) { | 317 | for (size_t config = 0U; config < kCommConfigNum; ++config) { |
| @@ -326,9 +329,6 @@ std::vector<PatternUniqPtr> LayerNormFusionPass::Patterns() | |||
| 326 | bool LayerNormFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) | 329 | bool LayerNormFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) |
| 327 | { | 330 | { |
| 328 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); | 331 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); |
| 329 | - if (!IsSupportedPlatform()) { | ||
| 330 | - return false; | ||
| 331 | - } | ||
| 332 | Matched matched; | 332 | Matched matched; |
| 333 | if (!CollectMatched(match_result, matched)) { | 333 | if (!CollectMatched(match_result, matched)) { |
| 334 | return false; | 334 | return false; |
| @@ -635,6 +635,9 @@ bool CreateAffineConst(es::EsGraphBuilder& builder, const Matched& m, es::EsTens | |||
| 635 | std::vector<PatternUniqPtr> LayerNormONNXFusionPass::Patterns() | 635 | std::vector<PatternUniqPtr> LayerNormONNXFusionPass::Patterns() |
| 636 | { | 636 | { |
| 637 | OPS_LOG_D(kPassName.c_str(), "Enter Patterns for LayerNormONNXFusionPass."); | 637 | OPS_LOG_D(kPassName.c_str(), "Enter Patterns for LayerNormONNXFusionPass."); |
| 638 | + if (!IsSupportedPlatform()) { | ||
| 639 | + return {}; | ||
| 640 | + } | ||
| 638 | std::vector<PatternUniqPtr> patterns; | 641 | std::vector<PatternUniqPtr> patterns; |
| 639 | patterns.reserve(kExpectedPatternNum); | 642 | patterns.reserve(kExpectedPatternNum); |
| 640 | for (const auto& shape : kShapes) { | 643 | for (const auto& shape : kShapes) { |
| @@ -651,9 +654,6 @@ std::vector<PatternUniqPtr> LayerNormONNXFusionPass::Patterns() | |||
| 651 | bool LayerNormONNXFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) | 654 | bool LayerNormONNXFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) |
| 652 | { | 655 | { |
| 653 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); | 656 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); |
| 654 | - if (!IsSupportedPlatform()) { | ||
| 655 | - return false; | ||
| 656 | - } | ||
| 657 | Matched m; | 657 | Matched m; |
| 658 | if (!CollectMatched(match_result, m)) { | 658 | if (!CollectMatched(match_result, m)) { |
| 659 | return false; | 659 | return false; |
| @@ -532,6 +532,9 @@ bool CreateAffineConst(es::EsGraphBuilder& builder, const Matched& m, es::EsTens | |||
| 532 | std::vector<PatternUniqPtr> LayerNormONNXMULFusionPass::Patterns() | 532 | std::vector<PatternUniqPtr> LayerNormONNXMULFusionPass::Patterns() |
| 533 | { | 533 | { |
| 534 | OPS_LOG_D(kPassName.c_str(), "Enter Patterns for LayerNormONNXMULFusionPass."); | 534 | OPS_LOG_D(kPassName.c_str(), "Enter Patterns for LayerNormONNXMULFusionPass."); |
| 535 | + if (!IsSupportedPlatform()) { | ||
| 536 | + return {}; | ||
| 537 | + } | ||
| 535 | std::vector<PatternUniqPtr> patterns; | 538 | std::vector<PatternUniqPtr> patterns; |
| 536 | patterns.reserve(kExpectedPatternNum); | 539 | patterns.reserve(kExpectedPatternNum); |
| 537 | for (const bool with_affine : {true, false}) { | 540 | for (const bool with_affine : {true, false}) { |
| @@ -548,9 +551,6 @@ std::vector<PatternUniqPtr> LayerNormONNXMULFusionPass::Patterns() | |||
| 548 | bool LayerNormONNXMULFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) | 551 | bool LayerNormONNXMULFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) |
| 549 | { | 552 | { |
| 550 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); | 553 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); |
| 551 | - if (!IsSupportedPlatform()) { | ||
| 552 | - return false; | ||
| 553 | - } | ||
| 554 | Matched m; | 554 | Matched m; |
| 555 | if (!CollectMatched(match_result, m)) { | 555 | if (!CollectMatched(match_result, m)) { |
| 556 | return false; | 556 | return false; |
| @@ -214,6 +214,10 @@ std::vector<es::EsTensorHolder> CreateReplacementInputs(es::EsGraphBuilder& grap | |||
| 214 | 214 | ||
| 215 | std::vector<PatternUniqPtr> LayerNormRemoveBroadcastFusionPass::Patterns() | 215 | std::vector<PatternUniqPtr> LayerNormRemoveBroadcastFusionPass::Patterns() |
| 216 | { | 216 | { |
| 217 | + if (!IsSupportedPlatform()) { | ||
| 218 | + OPS_LOG_D(kPassName.c_str(), "Platform is not support."); | ||
| 219 | + return {}; | ||
| 220 | + } | ||
| 217 | std::vector<PatternUniqPtr> patterns; | 221 | std::vector<PatternUniqPtr> patterns; |
| 218 | patterns.emplace_back(MakePattern()); | 222 | patterns.emplace_back(MakePattern()); |
| 219 | return patterns; | 223 | return patterns; |
| @@ -222,10 +226,6 @@ std::vector<PatternUniqPtr> LayerNormRemoveBroadcastFusionPass::Patterns() | |||
| 222 | bool LayerNormRemoveBroadcastFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) | 226 | bool LayerNormRemoveBroadcastFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) |
| 223 | { | 227 | { |
| 224 | OPS_LOG_D(kPassName.c_str(), "Enter LayerNormRemoveBroadcastFusionPass MeetRequirements."); | 228 | OPS_LOG_D(kPassName.c_str(), "Enter LayerNormRemoveBroadcastFusionPass MeetRequirements."); |
| 225 | - if (!IsSupportedPlatform()) { | ||
| 226 | - OPS_LOG_D(kPassName.c_str(), "Platform is not support."); | ||
| 227 | - return false; | ||
| 228 | - } | ||
| 229 | 229 | ||
| 230 | GNode ln_node; | 230 | GNode ln_node; |
| 231 | if (!GetCapturedNode(match_result, kLNCaptureIdx, ln_node)) { | 231 | if (!GetCapturedNode(match_result, kLNCaptureIdx, ln_node)) { |
| @@ -262,6 +262,9 @@ PatternUniqPtr MakePattern(size_t config) | |||
| 262 | 262 | ||
| 263 | std::vector<PatternUniqPtr> LayerNormInferenceFusionPass::Patterns() | 263 | std::vector<PatternUniqPtr> LayerNormInferenceFusionPass::Patterns() |
| 264 | { | 264 | { |
| 265 | + if (!IsSupportedPlatform()) { | ||
| 266 | + return {}; | ||
| 267 | + } | ||
| 265 | std::vector<PatternUniqPtr> patterns; | 268 | std::vector<PatternUniqPtr> patterns; |
| 266 | patterns.reserve(kCommConfigNum); | 269 | patterns.reserve(kCommConfigNum); |
| 267 | for (size_t config = 0U; config < kCommConfigNum; ++config) { | 270 | for (size_t config = 0U; config < kCommConfigNum; ++config) { |
| @@ -277,9 +280,6 @@ std::vector<PatternUniqPtr> LayerNormInferenceFusionPass::Patterns() | |||
| 277 | bool LayerNormInferenceFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) | 280 | bool LayerNormInferenceFusionPass::MeetRequirements(const std::unique_ptr<MatchResult>& match_result) |
| 278 | { | 281 | { |
| 279 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); | 282 | OPS_LOG_D(kPassName.c_str(), "guard_begin."); |
| 280 | - if (!IsSupportedPlatform()) { | ||
| 281 | - return false; | ||
| 282 | - } | ||
| 283 | Matched matched; | 283 | Matched matched; |
| 284 | if (!CollectMatched(match_result, matched)) { | 284 | if (!CollectMatched(match_result, matched)) { |
| 285 | return false; | 285 | return false; |
| @@ -159,7 +159,7 @@ aclnnStatus aclnnFastLayerNorm( | |||
| 159 | <td>meanOutOptional(aclTensor*)</td> | 159 | <td>meanOutOptional(aclTensor*)</td> |
| 160 | <td>输出</td> | 160 | <td>输出</td> |
| 161 | <td>可选输出,表示进行归一化后的均值。对应公式中的`meanOutOptional`。</td> | 161 | <td>可选输出,表示进行归一化后的均值。对应公式中的`meanOutOptional`。</td> |
| 162 | - <td><ul><li>支持空Tensor。</li><li>数据类型与`input`的数据类型保持一致。</li><li>shape为[A1,...,Ai,1,...,1],Ai后共有j个1,与需要norm的轴长度保持相同。当`rstdOutOptional`存在时,shape与`rstdOutOptional`相同。</li></ul></td> | 162 | + <td><ul><li>支持空Tensor。</li><li>shape为[A1,...,Ai,1,...,1],Ai后共有j个1,与需要norm的轴长度保持相同。当`rstdOutOptional`存在时,shape与`rstdOutOptional`相同。</li></ul></td> |
| 163 | <td>FLOAT32、FLOAT16、BFLOAT16</td> | 163 | <td>FLOAT32、FLOAT16、BFLOAT16</td> |
| 164 | <td>ND</td> | 164 | <td>ND</td> |
| 165 | <td>1-8</td> | 165 | <td>1-8</td> |
| @@ -169,7 +169,7 @@ aclnnStatus aclnnFastLayerNorm( | |||
| 169 | <td>rstdOutOptional(aclTensor*)</td> | 169 | <td>rstdOutOptional(aclTensor*)</td> |
| 170 | <td>输出</td> | 170 | <td>输出</td> |
| 171 | <td>可选输出,表示进行归一化后的标准差倒数。对应公式中的`rstdOutOptional`。</td> | 171 | <td>可选输出,表示进行归一化后的标准差倒数。对应公式中的`rstdOutOptional`。</td> |
| 172 | - <td><ul><li>支持空Tensor。</li><li>数据类型与`input`的数据类型保持一致。</li><li>shape为[A1,...,Ai,1,...,1],Ai后共有j个1,与需要norm的轴长度保持相同。当`meanOutOptional`存在时,shape与`meanOutOptional`相同。</li></ul></td> | 172 | + <td><ul><li>支持空Tensor。</li><li>shape为[A1,...,Ai,1,...,1],Ai后共有j个1,与需要norm的轴长度保持相同。当`meanOutOptional`存在时,shape与`meanOutOptional`相同。</li></ul></td> |
| 173 | <td>FLOAT32、FLOAT16、BFLOAT16</td> | 173 | <td>FLOAT32、FLOAT16、BFLOAT16</td> |
| 174 | <td>ND</td> | 174 | <td>ND</td> |
| 175 | <td>1-8</td> | 175 | <td>1-8</td> |