-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[PHI]Add new Tensor type and migrate save_combine kernel #47856
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 15 commits into
PaddlePaddle:develop
from
YuanRisheng:perfect_registry
Dec 12, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
60f8c2a
add new tensor
YuanRisheng 60e3717
fix windows compile bugs
YuanRisheng ebbee9a
Merge branch 'develop' of github.com:YuanRisheng/Paddle into perfect_…
YuanRisheng a87999d
fix ci bugs
YuanRisheng 9929a28
fix ci bugs
YuanRisheng c4a66e6
fix ci bugs
YuanRisheng ee11ac6
deal with conflict
YuanRisheng 01e976c
perfect according comment
YuanRisheng bec4990
deal with conflict
YuanRisheng 4010a6f
fix ci compile bugs
YuanRisheng 4ec7569
add raw tensor
YuanRisheng c4cca54
fix ci bugs
YuanRisheng 9bbd512
modify code by comment
YuanRisheng e552774
delete String
YuanRisheng 059e85f
Merge branch 'develop' of github.com:YuanRisheng/Paddle into perfect_…
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* 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. */ | ||
|
||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#include "paddle/phi/core/extended_tensor.h" | ||
#include "paddle/utils/any.h" | ||
|
||
namespace paddle { | ||
namespace framework { | ||
|
||
/// \brief Fluid Kernel and PHI Kernel will be unified in the future. | ||
/// So, we need a class in PHI that can represent the RAW type in Fluid. | ||
/// The RawTensor is for PHI Kernel that has RAW type arguments. | ||
class RawTensor : public phi::ExtendedTensor, | ||
public phi::TypeInfoTraits<phi::TensorBase, RawTensor> { | ||
public: | ||
RawTensor() = default; | ||
|
||
RawTensor(RawTensor&& other) = default; | ||
|
||
RawTensor(const RawTensor& other) = default; | ||
|
||
RawTensor& operator=(RawTensor&& other) = default; | ||
|
||
/// \brief Destroy the RawTensor and release exclusive resources. | ||
virtual ~RawTensor() = default; | ||
|
||
public: | ||
/// \brief Returns the name of the class for type traits. | ||
/// \return The name of the class. | ||
static const char* name() { return "RawTensor"; } | ||
|
||
template <typename T> | ||
T* GetMutable() { | ||
if (!data_.empty()) { | ||
try { | ||
return paddle::any_cast<T*>(data_); | ||
} catch (paddle::bad_any_cast&) { | ||
PADDLE_THROW(phi::errors::InvalidArgument( | ||
"Invalid data type error, expected %s, actual %s.", | ||
typeid(T).name(), | ||
data_type_.name())); | ||
} | ||
} | ||
T* created_data = new T(); | ||
data_ = created_data; | ||
data_deleter_ = [created_data]() { delete created_data; }; | ||
data_type_ = std::type_index(typeid(T)); | ||
return created_data; | ||
} | ||
|
||
template <typename T> | ||
bool IsType() const { | ||
return std::type_index(typeid(T)) == data_type_; | ||
} | ||
|
||
private: | ||
paddle::any data_; | ||
std::function<void(void)> data_deleter_; | ||
std::type_index data_type_ = std::type_index(typeid(void)); | ||
}; | ||
|
||
} // namespace framework | ||
} // 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
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
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
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.
fluid 下的
RawType
是一个数据类型,然而在 phi 下变成了 "Tensor",这个概念是有差异的:enum DataType
做扩展?(phi 下如何表示 RawTensor 的数据类型?)RawType
如何对应到 phi 下的数据类型?(是否会扩展TransToProtoVarType
函数?)RawType
in the fluid isdatatype
. However, it corresponds to "Tensor" in phi. The concepts betweenRawType
andRawTensor
have differences:enum DataType
in the future? (How to represent the datatype ofRawTensor
? )RawType
matches the datatype under 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.
这里RawTensor命名后边可以更改为Raw,可能理解上就更准确一点。
准确意义上来说,RawType在fluid下不是一个具体的数据类型,我的理解把它作为一个标志更为合理一点,类似于DataType里的Undefined。对于RawType的具体类型(可以是任意类型)是在执行Kernel的时候确定,Fluid由于是结构体类型的Kernel,其对于RawType的具体类型处理可以通过传入的参数「ExecutionContext」来展开进行。但是对于PHI Kernel,由于是函数式的,其函数参数类型必须明确,所以这里必须存在一个数据结构能表示不确定的数据类型。所以对于以上提出的俩点:
1,DataType里不需要扩展,从上边可以看出,Raw类型的在PHI下必须是一个类类型,DataType里存放的都是基础数据类型,所以显然是不合适的。
2,PHI下也不需要类型转换,因为RawType在Fluid下就不是一个具体的类型