forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Prim][PIR] Sink Forward Prim (PaddlePaddle#58130)
* decomp sink * polish code * fix flag * fix code * fix code * fix code2 * fix code2 * fix code3
- Loading branch information
1 parent
d1fc667
commit 62150b2
Showing
13 changed files
with
368 additions
and
7 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py
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,22 @@ | ||
# 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. | ||
|
||
# ===================================== | ||
# DecompInterface gen op list | ||
# ===================================== | ||
|
||
|
||
decomp_interface_declare_gen_op_list = ['mean'] | ||
|
||
decomp_interface_implementation_gen_op_list = ["mean"] |
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,52 @@ | ||
// 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/pir/core/op_base.h" | ||
|
||
namespace paddle { | ||
namespace dialect { | ||
class DecompInterface : public pir::OpInterfaceBase<DecompInterface> { | ||
public: | ||
struct Concept { | ||
explicit Concept( | ||
std::vector<std::vector<pir::OpResult>> (*decomp)(pir::Operation* op)) | ||
: decomp_(decomp) {} | ||
std::vector<std::vector<pir::OpResult>> (*decomp_)(pir::Operation* op); | ||
}; | ||
|
||
template <class ConcreteOp> | ||
struct Model : public Concept { | ||
static std::vector<std::vector<pir::OpResult>> Decomp(pir::Operation* op) { | ||
return ConcreteOp::Decomp(op); | ||
} | ||
Model() : Concept(Decomp) {} | ||
}; | ||
|
||
/// Constructor | ||
DecompInterface(pir::Operation* op, Concept* impl) | ||
: pir::OpInterfaceBase<DecompInterface>(op), impl_(impl) {} | ||
|
||
std::vector<std::vector<pir::OpResult>> Decomp(pir::Operation* op) { | ||
return impl_->decomp_(op); | ||
} | ||
|
||
private: | ||
Concept* impl_; | ||
}; | ||
|
||
} // namespace dialect | ||
} // namespace paddle | ||
|
||
IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::DecompInterface) |
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,65 @@ | ||
// 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/pir/dialect/operator/ir/op_attribute.h" | ||
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" | ||
#include "paddle/fluid/pir/dialect/operator/utils/utils.h" | ||
#include "paddle/fluid/primitive/composite/composite.h" | ||
#include "paddle/fluid/primitive/type/lazy_tensor.h" | ||
#include "paddle/phi/api/include/tensor.h" | ||
#include "paddle/phi/common/int_array.h" | ||
#include "paddle/pir/core/builtin_op.h" | ||
#include "paddle/pir/core/op_base.h" | ||
|
||
// TODO(chenzhuo) | ||
// this file will be generated in pd_op_decomp.cc | ||
|
||
namespace paddle { | ||
namespace dialect { | ||
using IntArray = paddle::experimental::IntArray; | ||
|
||
std::vector<std::vector<pir::OpResult>> MeanOp::Decomp(pir::Operation* op) { | ||
MeanOp op_obj = op->dyn_cast<MeanOp>(); | ||
(void)op_obj; | ||
|
||
VLOG(4) << "Decomp Prepare inputs of mean"; | ||
|
||
Tensor x(std::make_shared<primitive::LazyTensor>(op_obj.x())); | ||
|
||
VLOG(4) << "Decomp prepare attributes of mean"; | ||
|
||
IntArray axis = op->attribute("axis") | ||
.dyn_cast<paddle::dialect::IntArrayAttribute>() | ||
.data(); | ||
|
||
bool keepdim = op->attribute("keepdim").dyn_cast<pir::BoolAttribute>().data(); | ||
VLOG(4) << "Decomp mean keep_dim " << keepdim; | ||
|
||
VLOG(4) << "Decomp prepare call mean's decomp interface"; | ||
|
||
Tensor op_res = | ||
paddle::primitive::details::mean_decomp<primitive::LazyTensor>( | ||
x, axis, keepdim); | ||
|
||
auto org_res = op->results(); | ||
std::vector<std::vector<pir::OpResult>> res(org_res.size()); | ||
res[0].push_back( | ||
std::static_pointer_cast<primitive::LazyTensor>(op_res.impl()) | ||
->value() | ||
.dyn_cast<pir::OpResult>()); | ||
return res; | ||
} | ||
|
||
} // namespace dialect | ||
} // namespace paddle |
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
Oops, something went wrong.