未验证 提交 16a58283 编写于 作者: R RedContritio 提交者: GitHub

support auto generate for static op elementwise_floordiv (#55025)

* configure elementwise_floordiv op_version

* support auto generate for static op elementwise_floordiv

* update unity_build_rule.cmake
上级 402e277f
/* Copyright (c) 2019 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 <string>
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
namespace paddle {
namespace framework {
class OpDesc;
template <typename T>
class EmptyGradOpMaker;
} // namespace framework
namespace imperative {
class OpBase;
} // namespace imperative
} // namespace paddle
namespace paddle {
namespace operators {
class ElementwiseFloorDivOpMaker : public ElementwiseOpMaker {
protected:
std::string GetName() const override { return "FloorDiv"; }
std::string GetEquation() const override { return "Out = X // Y"; }
void AddInputX() override {
AddInput(
"X",
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype "
"should be int32, int64.");
}
void AddInputY() override {
AddInput(
"Y",
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype "
"should be int32, int64.");
}
std::string GetOpFunctionality() const override {
return "Floor divide two tensors element-wise";
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP_WITHOUT_GRADIENT(elementwise_floordiv,
ops::ElementwiseOp,
ops::ElementwiseFloorDivOpMaker);
REGISTER_OP_VERSION(elementwise_floordiv)
.AddCheckpoint(
R"ROC(Register elementwise_floordiv for adding the attribute of Scale_y)ROC",
paddle::framework::compatible::OpVersionDesc().NewAttr(
"Scale_y",
"In order to support the function of scaling the input Y when "
"using the operator of elementwise_floordiv.",
1.0f));
......@@ -8,7 +8,6 @@ register_unity_group(
cc
elementwise_add_op.cc
elementwise_div_op.cc
elementwise_floordiv_op.cc
elementwise_min_op.cc
elementwise_mod_op.cc
elementwise_mul_op.cc
......
......@@ -1066,9 +1066,15 @@
attrs : [bool use_mkldnn = false, bool use_cudnn = false]
- op : floor_divide (elementwise_floordiv)
inputs :
{x : X, y : Y}
outputs :
{out : Out}
extra :
attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]
complex_promote : [X, Y]
manual_signature : [floor_divide]
- op : fmax (elementwise_fmax)
backward : fmax_grad (elementwise_fmax_grad)
......
......@@ -165,6 +165,14 @@
comment : In order to add additional size to one side of each dimension in the output.
default : "std::vector<int>{}"
- op : elementwise_floordiv
version :
- checkpoint : Register elementwise_floordiv for adding the attribute of Scale_y
action :
- add_attr : Scale_y
comment : In order to support the function of scaling the input Y when using the operator of elementwise_floordiv.
default : 1.0
- op : elementwise_max
version :
- checkpoint : Register elementwise_max for adding the attribute of Scale_y.
......
......@@ -225,6 +225,14 @@
param : [num_rows, num_columns, dtype]
data_type : dtype
- op : floor_divide
args : (Tensor x, Tensor y, int axis = -1)
output : Tensor(out)
infer_meta :
func : ElementwiseRawInferMeta
kernel :
func : floor_divide
- op : frobenius_norm
args : (Tensor x, IntArray axis={0}, bool keepdim=false, bool reduce_all=false, int in_dtype=-1, int out_dtype=-1)
output : Tensor(out)
......
......@@ -96,6 +96,9 @@ KernelSignature ElementwiseModOpArgumentMapping(
KernelSignature ElementwiseFloorDivOpArgumentMapping(
const ArgumentMappingContext& ctx) {
if (ctx.IsForInferShape()) {
return KernelSignature("floor_divide_raw", {"X", "Y"}, {"axis"}, {"Out"});
}
int axis = paddle::any_cast<int>(ctx.Attr("axis"));
if (axis == -1) {
return KernelSignature("floor_divide", {"X", "Y"}, {}, {"Out"});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册