-
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.
[IR&PASS] add conv2d + bn fuse pattern, pass support ir verify
- Loading branch information
1 parent
12a296c
commit 182fd35
Showing
20 changed files
with
340 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
add_subdirectory(interface) | ||
add_subdirectory(dialect) | ||
add_subdirectory(pass) | ||
add_subdirectory(transforms) | ||
add_subdirectory(phi_kernel_adaptor) |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
cc_library( | ||
transform_general_functions | ||
SRCS transform_general_functions.cc | ||
DEPS ir phi pd_dialect) | ||
|
||
cc_library( | ||
pd_op_to_kernel_pass | ||
SRCS pd_op_to_kernel_pass.cc | ||
DEPS ir phi_utils pd_interface) |
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
File renamed without changes.
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,46 @@ | ||
// Copyright (c) 2023 PaddlePaddle 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/fluid/ir/transforms/transform_general_functions.h" | ||
|
||
#include "paddle/fluid/ir/dialect/pd_dialect.h" | ||
#include "paddle/fluid/ir/dialect/pd_type.h" | ||
#include "paddle/ir/core/builtin_op.h" | ||
#include "paddle/ir/core/program.h" | ||
|
||
namespace ir { | ||
|
||
ir::Parameter* GetParameterFromValue(ir::Value value) { | ||
ir::GetParameterOp op = value.GetDefiningOp()->dyn_cast<ir::GetParameterOp>(); | ||
PADDLE_ENFORCE_NOT_NULL( | ||
op, | ||
phi::errors::InvalidArgument( | ||
"Value must be a weight from a GetParameter op.")); | ||
ir::Program* program = op->GetParentProgram(); | ||
std::string name = op->attributes() | ||
.at(op.attributes_name[0]) | ||
.dyn_cast<ir::StrAttribute>() | ||
.data(); | ||
return program->GetParameter(name); | ||
} | ||
|
||
const phi::DDim& GetShapeFromValue(ir::Value value) { | ||
PADDLE_ENFORCE_EQ( | ||
value.type().isa<paddle::dialect::DenseTensorType>(), | ||
true, | ||
phi::errors::InvalidArgument("Value's type must be a DenseTensorType.")); | ||
return value.type().dyn_cast<paddle::dialect::DenseTensorType>().dims(); | ||
} | ||
|
||
} // namespace ir |
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,84 @@ | ||
// Copyright (c) 2023 PaddlePaddle 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 "paddle/ir/core/operation.h" | ||
#include "paddle/ir/core/parameter.h" | ||
#include "paddle/ir/core/value.h" | ||
#include "paddle/phi/core/ddim.h" | ||
#include "paddle/phi/core/enforce.h" | ||
#include "paddle/phi/core/errors.h" | ||
|
||
namespace ir { | ||
|
||
/** | ||
* @brief | ||
* | ||
* @note | ||
* | ||
* @param ir::Value | ||
* | ||
* @return ir::Parameter* | ||
*/ | ||
ir::Parameter* GetParameterFromValue(ir::Value value); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @note | ||
* | ||
* @param ir::Value | ||
* | ||
* @return const phi::DDim& | ||
*/ | ||
const phi::DDim& GetShapeFromValue(ir::Value value); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @note | ||
* | ||
* @param Operation* | ||
* | ||
* @return Operation* | ||
*/ | ||
template <uint32_t Index = 0> | ||
Operation* GetPreviousOperation(Operation* op) { | ||
PADDLE_ENFORCE_EQ( | ||
Index < op->num_operands(), | ||
true, | ||
phi::errors::InvalidArgument("Intput operand's index must be valid.")); | ||
return op->operand(Index).GetDefiningOp(); | ||
} | ||
|
||
/** | ||
* @brief | ||
* | ||
* @note | ||
* | ||
* @param Operation* | ||
* | ||
* @return Operation* | ||
*/ | ||
template <uint32_t Index = 0> | ||
Operation* GetNextFirstUseOperation(Operation* op) { | ||
PADDLE_ENFORCE_EQ( | ||
Index < op->num_results(), | ||
true, | ||
phi::errors::InvalidArgument("Output op result's index must be valid.")); | ||
return op->result(Index).first_use().owner(); | ||
} | ||
|
||
} // namespace ir |
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
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ cc_test_old( | |
DEPS | ||
ir | ||
pd_dialect | ||
transform_general_functions | ||
gtest) |
Oops, something went wrong.