-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Pten]Move kernel_primitives lib to Pten directory #39169
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
Merged
YuanRisheng
merged 6 commits into
PaddlePaddle:develop
from
YuanRisheng:move_primitive2
Jan 26, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5f520da
move kernel_primitives
YuanRisheng f8a4d38
Merge branch 'develop' of github.com:YuanRisheng/Paddle into move_pri…
YuanRisheng dc5738c
merge develop
YuanRisheng 43901b9
deal with conflict
YuanRisheng 8f6c8ce
Merge branch 'develop' of github.com:YuanRisheng/Paddle into move_pri…
YuanRisheng f8baddc
use pten's errors
YuanRisheng 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,241 +13,10 @@ | |
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paddle/fluid/operators/amp/fp16_type_traits.h" | ||
| #include "paddle/fluid/platform/enforce.h" | ||
| #include "paddle/fluid/platform/float16.h" | ||
| #include "paddle/pten/kernels/funcs/eigen/extensions.h" | ||
| #include "paddle/pten/kernels/primitive/functor_primitives.h" | ||
|
|
||
| namespace paddle { | ||
| namespace operators { | ||
| namespace kernel_primitives { | ||
| namespace details { | ||
|
|
||
| static __device__ __forceinline__ platform::float16 Exp(platform::float16 x) { | ||
| return ::Eigen::numext::exp(x); | ||
| } | ||
|
|
||
| static __device__ __forceinline__ float Exp(float x) { return expf(x); } | ||
|
|
||
| static __device__ __forceinline__ double Exp(double x) { return exp(x); } | ||
|
|
||
| static __device__ __forceinline__ platform::float16 Log(platform::float16 x) { | ||
| return ::Eigen::numext::log(x); | ||
| } | ||
|
|
||
| static __device__ __forceinline__ float Log(float x) { return logf(x); } | ||
|
|
||
| static __device__ __forceinline__ double Log(double x) { return log(x); } | ||
|
|
||
| } // namespace details | ||
|
|
||
| /******************************** Unary Functor *******************************/ | ||
|
|
||
| /** | ||
| * @brief Default unary exp functor | ||
| */ | ||
| template <typename Tx, typename Ty = Tx> | ||
| struct ExpFunctor { | ||
| HOSTDEVICE inline ExpFunctor() {} | ||
|
|
||
| HOSTDEVICE explicit inline ExpFunctor(int n) {} | ||
|
|
||
| HOSTDEVICE inline Ty operator()(const Tx x) const { | ||
| return static_cast<Ty>(details::Exp(x)); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default unary identity functor | ||
| */ | ||
| template <typename Tx, typename Ty = Tx> | ||
| struct IdentityFunctor { | ||
| HOSTDEVICE inline IdentityFunctor() {} | ||
|
|
||
| HOSTDEVICE explicit inline IdentityFunctor(int n) {} | ||
|
|
||
| HOSTDEVICE inline Ty operator()(const Tx x) const { | ||
| return static_cast<Ty>(x); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default unary div functor. Divide by a constant | ||
| */ | ||
| template <typename Tx, typename Ty = Tx> | ||
| struct DivideFunctor { | ||
| private: | ||
| using MPType = typename ::paddle::operators::details::MPTypeTrait<Tx>::Type; | ||
|
|
||
| public: | ||
| HOSTDEVICE inline DivideFunctor() { n_inv = static_cast<MPType>(1.0f); } | ||
|
|
||
| HOSTDEVICE explicit inline DivideFunctor(int n) : n_inv((MPType)(1.0 / n)) {} | ||
|
|
||
| HOSTDEVICE inline Ty operator()(const Tx x) const { | ||
| return static_cast<Ty>(static_cast<MPType>(x) * n_inv); | ||
| } | ||
|
|
||
| private: | ||
| MPType n_inv; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default inverse functor | ||
| */ | ||
| template <typename Tx, typename Ty = Tx> | ||
| struct InverseFunctor { | ||
| HOSTDEVICE inline InverseFunctor() {} | ||
|
|
||
| HOSTDEVICE explicit inline InverseFunctor(int n) {} | ||
|
|
||
| HOSTDEVICE inline Ty operator()(const Tx x) const { | ||
| return static_cast<Ty>(-x); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default unary square functor | ||
| */ | ||
| template <typename Tx, typename Ty = Tx> | ||
| struct SquareFunctor { | ||
| HOSTDEVICE inline SquareFunctor() {} | ||
|
|
||
| HOSTDEVICE explicit inline SquareFunctor(int n) {} | ||
|
|
||
| HOSTDEVICE inline Ty operator()(const Tx x) const { | ||
| return static_cast<Ty>(x) * static_cast<Ty>(x); | ||
| } | ||
| }; | ||
|
|
||
| /****************************** Binary Functor ********************************/ | ||
|
|
||
| /** | ||
| * @brief Default binary min functor | ||
| */ | ||
| template <typename T> | ||
| struct MinFunctor { | ||
| inline T initial() { return static_cast<T>(std::numeric_limits<T>::max()); } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return (b < a) ? b : a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary max functor | ||
| */ | ||
| template <typename T> | ||
| struct MaxFunctor { | ||
| inline T initial() { | ||
| return static_cast<T>(std::numeric_limits<T>::lowest()); | ||
| } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return (b > a) ? b : a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary add functor | ||
| */ | ||
| template <typename T> | ||
| struct AddFunctor { | ||
| inline T initial() { return static_cast<T>(0.0f); } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return b + a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary add functor | ||
| */ | ||
| template <typename T> | ||
| struct MulFunctor { | ||
| inline T initial() { return static_cast<T>(1.0f); } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return b * a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary logic or functor | ||
| */ | ||
| template <typename T> | ||
| struct LogicalOrFunctor { | ||
| inline T initial() { return static_cast<T>(false); } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return b || a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary logic and functor | ||
| */ | ||
| template <typename T> | ||
| struct LogicalAndFunctor { | ||
| inline T initial() { return static_cast<T>(true); } | ||
|
|
||
| __device__ __forceinline__ T operator()(const T a, const T b) const { | ||
| return b && a; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary sub functor | ||
| */ | ||
| template <typename T> | ||
| struct SubFunctor { | ||
| inline T initial() { return static_cast<T>(0.0f); } | ||
|
|
||
| inline HOSTDEVICE T operator()(const T a, const T b) const { return a - b; } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary div functor | ||
| */ | ||
| template <typename T, typename Enable = void> | ||
| struct DivFunctor { | ||
| inline T initial() { return static_cast<T>(1.0f); } | ||
|
|
||
| inline HOSTDEVICE T operator()(const T a, const T b) const { return a / b; } | ||
| }; | ||
|
|
||
| template <typename T> | ||
| struct DivFunctor<T, | ||
| typename std::enable_if<std::is_integral<T>::value>::type> { | ||
| inline T initial() { return static_cast<T>(1.0f); } | ||
|
|
||
| inline HOSTDEVICE T operator()(const T a, const T b) const { | ||
| // For int32/int64, need to check whether the divison is zero. | ||
| PADDLE_ENFORCE_NE(b, 0, | ||
| platform::errors::InvalidArgument( | ||
| "Integer division by zero encountered " | ||
| "in (floor) divide. Please check the input value.")); | ||
| return a / b; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Default binary floor divide functor | ||
| */ | ||
| template <typename T> | ||
| struct FloorDivFunctor { | ||
| inline T initial() { return static_cast<T>(1.0f); } | ||
|
|
||
| inline HOSTDEVICE T operator()(const T a, const T b) const { | ||
| PADDLE_ENFORCE_NE(b, 0, | ||
| platform::errors::InvalidArgument( | ||
| "Integer division by zero encountered " | ||
| "in (floor) divide. Please check the input value.")); | ||
| return static_cast<T>(std::trunc(a / b)); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace kernel_primitives | ||
| namespace kernel_primitives = pten::kps; | ||
|
Contributor
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. 希望尽快删除该文件,该文件只在paddle/fluid/operators/kernel_primitives/kernel_primitives.h中使用,可以只修改paddle/fluid/operators/kernel_primitives/kernel_primitives.h中的头文件引用。 |
||
| } // namespace operators | ||
| } // namespace paddle | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
文件是否可以删除 ?
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.
后续进行删除