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] Add elementwise add xpu after phi, test=develop #39787

Merged

Conversation

Liu-xiandong
Copy link
Member

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

PR types

New features

PR changes

OPs

Describe

Added kernel for XPU2 KP system, elementwise_add

This PR involves 4 changes:

  • Improve the XPU2 source code compilation process, modify cmake/operators.cmake and cmake/xpu_kp.cmake to support .kps files.

  • Added the elementwise_add.kps file and added a test for it. This file provides the forward XPU2 source code compilation code of elementwise_add

  • Modified the relevant components of KP, compute_primitives_xpu2.h, etc., and solved some previous bugs

  • In order to support source code compilation of XPU2, some underlying codes such as elementwise and device have been modified, such as elementwise_base.h and cuda_kernel_config.h, etc.

The result is as follows:
image

The KP_flags turns on:
image

@paddle-bot-old
Copy link

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

@Liu-xiandong Liu-xiandong changed the title [KP] Add elementwise add xpu after phi, test=develope add xpu [KP] Add elementwise add xpu after phi, test=develop Feb 22, 2022
Copy link
Contributor

@AnnaTrainingG AnnaTrainingG left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -127,9 +127,11 @@ macro(compile_kernel COMPILE_ARGS)
kernel_build/${kernel_name}.bin.o
COMMAND
${CMAKE_COMMAND} -E make_directory kernel_build
COMMAND
cp ${kernel_path}/${kernel_name}.kps kernel_build/${kernel_name}.xpu
Copy link
Contributor

Choose a reason for hiding this comment

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

GPU环境下是否需要cp 成.cu文件呢

Copy link
Member Author

Choose a reason for hiding this comment

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

是的,目前直接转成.cu文件还有一些工作量,后续提PR完成

REGISTER_OP_KERNEL(elementwise_add, KP, plat::XPUPlace,
ops::ElementwiseAddXPUKPKernel<float>);

REGISTER_OP_KERNEL(elementwise_add_grad, KP, plat::XPUPlace,
Copy link
Contributor

Choose a reason for hiding this comment

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

此处只有XPU 注册,那GPU注册添加到哪里呢

Copy link
Member Author

Choose a reason for hiding this comment

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

后续会增加GPU注册,通过宏定义隔离


#define KPStream XPUStream
#define KPDevice phi::XPUContext
#define _ptr_ _global_ptr_
#define __forceinline__ __inline__
#define __restrict__

#include "paddle/phi/backends/xpu/xpu_context.h"
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
Member Author

Choose a reason for hiding this comment

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

有影响的

@@ -17,7 +17,7 @@ if(NOT WITH_XPU_KP)
endif()

if(NOT XPU_TOOLCHAIN)
set(XPU_TOOLCHAIN /workspace/paddle/xpu-demo/XTDK)
set(XPU_TOOLCHAIN /workspace/output/XTDK-ubuntu_x86_64)
Copy link
Contributor

Choose a reason for hiding this comment

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

后续需要处理非x86情况

Copy link
Member Author

Choose a reason for hiding this comment

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

好的

Copy link
Contributor

@qili93 qili93 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 unittest.skipIf and skip_check_grad_ci on XPU2

Copy link
Contributor

@ZzSean ZzSean 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

@xingfeng01 xingfeng01 merged commit 1a1a2ce into PaddlePaddle:develop Feb 23, 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