-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CINN] Make Resize Buffer Safer (#59014)
Make Resize Buffer Safer, the old buffer resize didn't consider load, current we add support for it This PR also contain some code of safer UpdateBufferAxis of #59209 We will also clean it in the 59209 PR
- Loading branch information
1 parent
833f556
commit 5c70f3e
Showing
16 changed files
with
805 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023 CINN Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/cinn/optim/replace_mod_to_max.h" | ||
|
||
#include <unordered_map> | ||
|
||
#include "paddle/cinn/ir/ir.h" | ||
#include "paddle/cinn/ir/ir_mutator.h" | ||
#include "paddle/cinn/ir/ir_printer.h" | ||
|
||
namespace cinn { | ||
namespace optim { | ||
|
||
class ReplaceModToMaxMutator : public ir::IRMutator<> { | ||
public: | ||
void operator()(ir::Expr* expr) { ir::IRMutator<>::Visit(expr, expr); } | ||
|
||
void Visit(const ir::Mod* op, ir::Expr* expr) override { | ||
ir::Mod* node = expr->As<ir::Mod>(); | ||
Expr base = node->operand(1); | ||
*expr = ir::Sub::Make(base, Expr(1)); | ||
} | ||
}; | ||
|
||
void ReplaceModToMax(ir::Expr* expr) { | ||
ReplaceModToMaxMutator mutator; | ||
mutator(expr); | ||
} | ||
|
||
} // namespace optim | ||
} // namespace cinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2023 CINN Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
#include <string> | ||
|
||
#include "paddle/cinn/ir/ir.h" | ||
|
||
namespace cinn { | ||
namespace optim { | ||
|
||
/** | ||
* Given Expr AST, analyze the range of N % M will return M - 1. | ||
* This function is used to replace the mod operation with max. | ||
* | ||
* Note: the replacement will change the semantics of the AST. | ||
* It is only used for analyze, not computing. | ||
*/ | ||
void ReplaceModToMax(ir::Expr* expr); | ||
|
||
} // namespace optim | ||
} // namespace cinn |
Oops, something went wrong.