Skip to content
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] Tidy pten core headers #39188

Merged

Conversation

chenwhql
Copy link
Contributor

@chenwhql chenwhql commented Jan 24, 2022

PR types

New features

PR changes

Others

Describe

[PTen] Open pten core headers for custom kernel

pten中的头文件,都是面向API的设计,将来会作为api开发给外部用户进行二次开发,相比fluid来讲,需要更加严谨、规范,且需要时常整理。

  1. 整理pten core中的头文件
  • 很基础的、基本只用在pten/core中的数据结构封装,移到core/utils目录下
  • 用于兼容fluid体系的文件,移到core/compat目录下,将来不应该向用户暴露
  • 头文件中,能不再include fluid的均替换为include pten头文件,并且相应的函数调用,命名空间也改为pten

剩余还无法移除依赖的头文件包括

#include "paddle/fluid/framework/data_type.h" // 待tensor和proto::VarType解耦 
#include "paddle/fluid/platform/stream/stream.h" // 待gpu组件移到pten
#include "paddle/fluid/framework/mixed_vector.h" // lod相关依赖解耦
#include "paddle/fluid/memory/memcpy.h" // tensor copy需移到pten
#include "paddle/fluid/memory/malloc.h" // 可能需要用宏隔开
#include "paddle/fluid/platform/device/gpu/gpu_info.h" // 待gpu组件移到pten
  1. 将pten/core的headers暴露出来用于自定义kernel开发

2.3之前很重要的TODO项,对于用户编写自定义kernel用到的类和接口,需要经过再三check,确保设计合理,DenseTensor和DeviceContext的接口是核心

自定义kernel PR:#38848

安装paddle之后,#include "paddle/pten/include/core.h",即可在外部使用pten/core的组件

目前pten和fluid的源码拆分工作还在进行中,如上所述,pten还有一些基础组件依赖fluid,预计会在推全之前拆分完成,但由于需要兼容fluid的原因,也做不到完全隔离,比如#include "paddle/fluid/memory/malloc.h"在较长时间内都会依赖,可能需要自定义Kernel封装对应的宏,以隔离相应头文件,例如

#ifndef PADDLE_WITH_CUSTOM_KERNEL
#include "paddle/fluid/memory/malloc.h"
#endif

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@chenwhql chenwhql changed the title [PTen] Open pten core headers for custom kernel [PTen] Tidy pten core headers Jan 25, 2022
zyfncg
zyfncg previously approved these changes Jan 28, 2022
@@ -126,8 +129,8 @@ paddle::framework::proto::VarType::Type TransToProtoVarType(
}
}

paddle::framework::LoD TransToFluidLoD(const pten::LoD& lod) {
paddle::framework::LoD out;
pten::LoD TransToFluidLoD(const pten::LoD& lod) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransToFluidLoD这个转换函数是不是可以去掉了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

@@ -136,7 +139,7 @@ paddle::framework::LoD TransToFluidLoD(const pten::LoD& lod) {
return out;
}

pten::LoD TransToPtenLoD(const paddle::framework::LoD& lod) {
pten::LoD TransToPtenLoD(const pten::LoD& lod) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/kernel_def.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/type_defs.h"

// See Note [ Why still include the fluid headers? ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行注释可以删除了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

namespace pten {

/// \brief The interface of contiguous storage used for the dense tensor.
/// It should be used in conjunction with the intrusive pointer. We prohibit
/// all default copy operations to ensure the integrity of the package.
class Storage : public intrusive_ref_counter<Storage> {
public:
using Place = paddle::platform::Place;
using Place = pten::Place;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的using是不是可以去掉?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

};

class TensorStorage : public Storage {
public:
using Place = paddle::platform::Place;
using Place = pten::Place;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

using DDim = pten::framework::DDim;
using Place = paddle::platform::Place;
using Place = pten::Place;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for op_benchmark

@chenwhql chenwhql merged commit dd99098 into PaddlePaddle:develop Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants