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

[KP] Unify .cu and .xpu files with .kps files #39917

Merged
merged 5 commits into from
Feb 28, 2022

Conversation

Liu-xiandong
Copy link
Member

@Liu-xiandong Liu-xiandong commented Feb 25, 2022

PR types

New features

PR changes

OPs

Describe

Unify .cu and .xpu files with .kps files

There are two main changes in this PR

  • For cmake changes, rename .kps file to .cu file in GPU

  • Using the .kps file to unify the .cu and .xpu files, the original elementwise_add_op.cu file is deleted, and the relevant code is merged into the .kps file

PR对现有框架的影响:
1.对编译层的影响,在cmake的GPU环境中增加对.kps文件的支持。需要将.kps文件重命名后的.cu文件放置在build文件下,.xpu文件同理。
2.对OP的影响,将原有的elementwise_add_op.cu文件变成了elementwise_add_op.kps文件。

@paddle-bot-old
Copy link

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

@@ -13,22 +13,40 @@ See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#ifdef __xpu__
Copy link
Contributor

Choose a reason for hiding this comment

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

如何判定哪些头文件能够在XPU 中,哪些不能呢?

Copy link
Member Author

Choose a reason for hiding this comment

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

这个后续再优化,目前暂不明确


namespace paddle {
namespace operators {

template <typename DeviceContext, typename T>
class ElementwiseAddKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
void Compute(const framework::ExecutionContext& ctx) const override {
#ifdef __xpu__
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥需要区分�XPU 是下面的代码XPU不支持吗

Copy link
Member Author

Choose a reason for hiding this comment

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

是的,直接用下面的代码不能在XPU上跑

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. */

#ifdef PADDLE_WITH_XPU_KP

// Please do not modify the following code
#if defined(__CUDA_ARCH__)
#undef __CUDA_ARCH__
Copy link
Contributor

Choose a reason for hiding this comment

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

是否考虑将这些宏统一放置到某个地方的,如果每个.kps都添加 感觉好像有一点点重复

Copy link
Member Author

Choose a reason for hiding this comment

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

嗯嗯,是的,后续考虑对其进行统一

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

你这里直接删除GPU 环境会有问题吧(缺少add_grad),毕竟KP环境变量是关闭的

Copy link
Member Author

Choose a reason for hiding this comment

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

不会有问题,elementwise_add_op.kps文件在GPU中会被重命名为elementwise_add_op.cu,然后进行正常的编译

@@ -27,7 +27,10 @@ using XPUKernelSet =
using XPUOpMap = std::unordered_map<std::string, XPUKernelSet>;

XPUOpMap& get_kp_ops() {
static XPUOpMap s_xpu_kp_kernels{};
static XPUOpMap s_xpu_kp_kernels{
Copy link
Contributor

Choose a reason for hiding this comment

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

添加list后 在进行.kps编译的时候还需要设置list环境变量吗?

  1. 建议在PR描述中 介绍一下各处修改对现有使用的影响
  2. 建议及时更新.kps适配文档

Copy link
Member Author

Choose a reason for hiding this comment

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

添加list之后,直接开启export FLAGS_run_kp_kernel=1就可以直接使用。后续根据建议修改

@xingfeng01 xingfeng01 merged commit 0ff72e5 into PaddlePaddle:develop Feb 28, 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.

3 participants