-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Pten] Add selected_rows kernel for Full #39465
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ce14288
Add selected_rows kernel for full
zyfncg c06a12f
remove fill_constant register in fluid
zyfncg 8cac0cb
fix bug without GPU
zyfncg 5fd6318
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 3dc11df
add jit_kernel_helper dependency for fc
zyfncg 9a414ff
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 04b8d1b
do some refactor
zyfncg 32cc4c8
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg d791cee
add unittest for ops signatures
zyfncg 0e85f47
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg d8404d6
add coverage unittest
zyfncg 282e504
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 50ae8dc
fix merge conflict
zyfncg 84dd376
fix full selectew_rows bug
zyfncg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
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,70 @@ | ||
/* Copyright (c) 2022 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/pten/kernels/full_kernel.h" | ||
|
||
#include "paddle/pten/backends/cpu/cpu_context.h" | ||
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) | ||
#include "paddle/pten/backends/gpu/gpu_context.h" | ||
#endif | ||
#include "paddle/pten/core/kernel_registry.h" | ||
|
||
#include "paddle/pten/common/bfloat16.h" | ||
#include "paddle/pten/common/complex.h" | ||
|
||
namespace pten { | ||
|
||
template <typename T, typename Context> | ||
void FullSR(const Context& dev_ctx, | ||
const ScalarArray& shape, | ||
const Scalar& val, | ||
DataType dtype, | ||
SelectedRows* out) { | ||
pten::FullKernel<T>(dev_ctx, shape, val, dtype, out->mutable_value()); | ||
} | ||
|
||
} // namespace pten | ||
|
||
PT_REGISTER_KERNEL(full_sr, | ||
CPU, | ||
ALL_LAYOUT, | ||
pten::FullSR, | ||
float, | ||
double, | ||
uint8_t, | ||
int16_t, | ||
int, | ||
int64_t, | ||
bool, | ||
pten::dtype::float16, | ||
pten::dtype::bfloat16, | ||
pten::dtype::complex<float>, | ||
pten::dtype::complex<double>) {} | ||
|
||
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) | ||
PT_REGISTER_KERNEL(full_sr, | ||
GPU, | ||
ALL_LAYOUT, | ||
pten::FullSR, | ||
float, | ||
double, | ||
uint8_t, | ||
int16_t, | ||
int, | ||
int64_t, | ||
bool, | ||
pten::dtype::float16, | ||
pten::dtype::complex<float>, | ||
pten::dtype::complex<double>) {} | ||
#endif |
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 |
---|---|---|
|
@@ -66,6 +66,57 @@ KernelSignature FillConstantOpArgumentMapping( | |
} | ||
} | ||
} | ||
} else if (ctx.IsSelectedRowsOutput("Out")) { | ||
if (ctx.HasInput("ShapeTensor")) { | ||
if (ctx.HasInput("ValueTensor")) { | ||
return KernelSignature( | ||
"full_sr", {}, {"ShapeTensor", "ValueTensor", "dtype"}, {"Out"}); | ||
} else { | ||
const auto& str_value = | ||
paddle::any_cast<std::string>(ctx.Attr("str_value")); | ||
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 有用到,case比较特殊 |
||
if (str_value.empty()) { | ||
return KernelSignature( | ||
"full_sr", {}, {"ShapeTensor", "value", "dtype"}, {"Out"}); | ||
} else { | ||
return KernelSignature( | ||
"full_sr", {}, {"ShapeTensor", "str_value", "dtype"}, {"Out"}); | ||
} | ||
} | ||
} else if (ctx.InputSize("ShapeTensorList") > 0) { | ||
if (ctx.HasInput("ValueTensor")) { | ||
return KernelSignature("full_sr", | ||
{}, | ||
{"ShapeTensorList", "ValueTensor", "dtype"}, | ||
{"Out"}); | ||
} else { | ||
const auto& str_value = | ||
paddle::any_cast<std::string>(ctx.Attr("str_value")); | ||
if (str_value.empty()) { | ||
return KernelSignature( | ||
"full_sr", {}, {"ShapeTensorList", "value", "dtype"}, {"Out"}); | ||
} else { | ||
return KernelSignature("full_sr", | ||
{}, | ||
{"ShapeTensorList", "str_value", "dtype"}, | ||
{"Out"}); | ||
} | ||
} | ||
} else { | ||
if (ctx.HasInput("ValueTensor")) { | ||
return KernelSignature( | ||
"full_sr", {}, {"shape", "ValueTensor", "dtype"}, {"Out"}); | ||
} else { | ||
const auto& str_value = | ||
paddle::any_cast<std::string>(ctx.Attr("str_value")); | ||
if (str_value.empty()) { | ||
return KernelSignature( | ||
"full_sr", {}, {"shape", "value", "dtype"}, {"Out"}); | ||
} else { | ||
return KernelSignature( | ||
"full_sr", {}, {"shape", "str_value", "dtype"}, {"Out"}); | ||
} | ||
} | ||
} | ||
} | ||
return KernelSignature("unregistered", {}, {}, {}); | ||
} | ||
|
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 @@ | ||
cc_test(test_op_signature SRCS test_op_signature.cc DEPS op_utils) |
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,118 @@ | ||
/* Copyright (c) 2022 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/pten/tests/ops_signature/test_op_signature.h" | ||
|
||
#include <gtest/gtest.h> | ||
#include <memory> | ||
#include <unordered_set> | ||
|
||
#include "paddle/pten/core/compat/op_utils.h" | ||
#include "paddle/pten/ops/compat/signatures.h" | ||
|
||
namespace pten { | ||
namespace tests { | ||
|
||
// The unittests in this file are just order to pass the CI-Coverage, | ||
// so it isn't necessary to check the all cases. | ||
|
||
TEST(ARG_MAP, fill_constant) { | ||
TestArgumentMappingContext arg_case1( | ||
{"ShapeTensor", "ValueTensor"}, {}, {}, {}, {"Out"}); | ||
auto signature1 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case1); | ||
ASSERT_EQ(signature1.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case2( | ||
{"ShapeTensor"}, | ||
{}, | ||
{{"str_value", paddle::any{std::string{"10"}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature2 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case2); | ||
ASSERT_EQ(signature2.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case3( | ||
{"ShapeTensor"}, | ||
{}, | ||
{{"value", paddle::any{0}}, {"str_value", paddle::any{std::string{""}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature3 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case3); | ||
ASSERT_EQ(signature3.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case4( | ||
{"ShapeTensorList", "ValueTensor"}, {}, {}, {}, {"Out"}); | ||
auto signature4 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case4); | ||
ASSERT_EQ(signature4.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case5( | ||
{"ShapeTensorList"}, | ||
{}, | ||
{{"str_value", paddle::any{std::string{"10"}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature5 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case5); | ||
ASSERT_EQ(signature5.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case6( | ||
{"ShapeTensorList"}, | ||
{}, | ||
{{"value", paddle::any{0}}, {"str_value", paddle::any{std::string{""}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature6 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case6); | ||
ASSERT_EQ(signature6.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case7( | ||
{"ValueTensor"}, | ||
{}, | ||
{{"shape", paddle::any{std::vector<int64_t>{2, 3}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature7 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case7); | ||
ASSERT_EQ(signature7.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case8( | ||
{}, | ||
{}, | ||
{{"shape", paddle::any{std::vector<int64_t>{2, 3}}}, | ||
{"value", paddle::any{0}}, | ||
{"str_value", paddle::any{std::string{""}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature8 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case8); | ||
ASSERT_EQ(signature8.name, "full_sr"); | ||
|
||
TestArgumentMappingContext arg_case9( | ||
{}, | ||
{}, | ||
{{"shape", paddle::any{std::vector<int64_t>{2, 3}}}, | ||
{"str_value", paddle::any{std::string{"10"}}}}, | ||
{}, | ||
{"Out"}); | ||
auto signature9 = | ||
OpUtilsMap::Instance().GetArgumentMappingFn("fill_constant")(arg_case9); | ||
ASSERT_EQ(signature9.name, "full_sr"); | ||
} | ||
|
||
} // namespace tests | ||
} // namespace pten |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里引用gpu_context.h 头文件,是否需要加 #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) 宏判断?
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.
这里可以不加宏应该也没有影响,严谨一些这里先加上宏判断,后面再看情况是否保留