-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate unstack stack range unique op into Phi #40851
Migrate unstack stack range unique op into Phi #40851
Conversation
2e8109f
to
d60bd3d
Compare
#define _PhiForEachDataTypeTiny_(callback) \ | ||
_PhiForEachDataTypeHelper_(callback, int, DataType::INT32); \ | ||
_PhiForEachDataTypeHelper_(callback, int64_t, DataType::INT64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果只是遍历int类型的话,tiny的命名有些不太准确,建议使用如PhiForEachIntegerDataType之类的命名
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和之前 paddle/fluid/framework/data_type.h 里面定义的tiny是保持一致的
} while (0) | ||
|
||
_PhiForEachDataTypeTiny_(PhiVisitDataTypeCallbackTiny); | ||
#undef PhiVisitDataTypeCallbackTiny |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已加入
"The first dim of the shape of Input(Step) should " | ||
"be 1, but got %d", | ||
step_dims[0])); | ||
out->set_dims({-1}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtype在这里可以设置吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
out->set_dims(out_dims); | ||
if (return_inverse) { | ||
index->set_dims(phi::make_ddim({x.dims()[axis_value]})); | ||
} | ||
} | ||
if (return_index) { | ||
indices->set_dims(phi::make_ddim({-1})); | ||
} | ||
if (return_counts) { | ||
counts->set_dims(phi::make_ddim({-1})); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些dtype可以设置下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些dtype会等到kernel执行的时候,执行VisitDataType函数进行确定,否则需要把那一套逻辑搬进来。
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/copy_kernel.h" | ||
#include "paddle/phi/kernels/funcs/range_function.h" | ||
#include "paddle/phi/kernels/range_kernel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range_kernel.h放在开头
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
#include "paddle/phi/backends/gpu/gpu_context.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/impl/unstack_grad_kernel_impl.h" | ||
#include "paddle/phi/kernels/unstack_grad_kernel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unstack_grad_kernel.h放在开头
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
#include "paddle/phi/backends/gpu/gpu_context.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/impl/unstack_kernel_impl.h" | ||
#include "paddle/phi/kernels/unstack_kernel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unstack_kernel.h放在开头
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
paddle/phi/ops/compat/stack_sig.cc
Outdated
KernelSignature StackOpArgumentMapping(const ArgumentMappingContext& ctx) { | ||
return KernelSignature("stack", {"X"}, {"axis"}, {"Y"}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个前向的ArgumentMapping比较常规,感觉使用默认的也能work,可以去掉试试
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除
paddle/phi/ops/compat/unstack_sig.cc
Outdated
KernelSignature UnStackOpArgumentMapping(const ArgumentMappingContext& ctx) { | ||
return KernelSignature("unstack", {"X"}, {"axis", "num"}, {"Y"}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除
paddle/phi/ops/compat/unique_sig.cc
Outdated
namespace phi { | ||
|
||
KernelSignature UniqueOpArgumentMapping(const ArgumentMappingContext& ctx) { | ||
return KernelSignature("unique_raw", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果unique的单测覆盖率没通过的话,可以使用下面的方式选择下kernel
bool is_sorted = paddle::any_cast<bool>(ctx.Attr("is_sorted"));
if (is_sorted) {
reutrn "unique"
} else {
return "unique_raw"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几个算子有添加benchmark脚本吗
@@ -15,6 +15,7 @@ limitations under the License. */ | |||
#ifdef PADDLE_WITH_XPU | |||
#include "paddle/fluid/operators/range_op.h" | |||
#include "paddle/fluid/framework/op_registry.h" | |||
#include "paddle/phi/kernels/funcs/math_function.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个头文件有用到吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除
"The first dim of the shape of Input(Step) should " | ||
"be 1, but got %d", | ||
step_dims[0])); | ||
out->set_dims({-1}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个out是否需要设置一下dtype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已设置
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/copy_kernel.h" | ||
#include "paddle/phi/kernels/funcs/range_function.h" | ||
#include "paddle/phi/kernels/range_kernel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个头文件可以放到最上边
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
x.dims().size())); | ||
auto out_dims = x.dims(); | ||
out_dims[axis_value] = -1; | ||
out->set_dims(out_dims); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要set_dtype一下吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些dtype会等到kernel执行的时候,执行VisitDataType函数进行确定,否则需要把那一套逻辑搬进来。
#pragma once | ||
#include "paddle/phi/core/enforce.h" | ||
|
||
namespace phi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要加funcs的namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加
|
||
#include "paddle/phi/kernels/funcs/for_range.h" | ||
|
||
namespace phi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/copy_kernel.h" | ||
#include "paddle/phi/kernels/funcs/range_function.h" | ||
#include "paddle/phi/kernels/range_kernel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kernel头文件在前,空行隔开
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
有添加 |
e046cf1
to
9f02a9c
Compare
9f02a9c
to
6706557
Compare
6706557
to
0cbf5ad
Compare
0cbf5ad
to
faf37cb
Compare
faf37cb
to
e311a91
Compare
4ddcf0a
to
76a9da2
Compare
76a9da2
to
9914950
Compare
9914950
to
3d70ba2
Compare
ab64ec6
to
3510cb8
Compare
1582a16
to
7ccdb10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Function optimization
PR changes
OPs
Describe
[Phi] Migrate unstack stack range unique op into Phi