-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[KP] Unify .cu and .xpu files with .kps files #39917
Conversation
Thanks for your contribution! |
@@ -13,22 +13,40 @@ See the License for the specific language governing permissions and | |||
limitations under the License. */ | |||
|
|||
#pragma once | |||
|
|||
#ifdef __xpu__ |
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.
如何判定哪些头文件能够在XPU 中,哪些不能呢?
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.
这个后续再优化,目前暂不明确
|
||
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__ |
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.
为啥需要区分�XPU 是下面的代码XPU不支持吗
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.
是的,直接用下面的代码不能在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__ |
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.
是否考虑将这些宏统一放置到某个地方的,如果每个.kps都添加 感觉好像有一点点重复
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.
嗯嗯,是的,后续考虑对其进行统一
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, |
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.
你这里直接删除GPU 环境会有问题吧(缺少add_grad),毕竟KP环境变量是关闭的
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.
不会有问题,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{ |
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.
添加list后 在进行.kps编译的时候还需要设置list环境变量吗?
- 建议在PR描述中 介绍一下各处修改对现有使用的影响
- 建议及时更新.kps适配文档
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.
添加list之后,直接开启export FLAGS_run_kp_kernel=1就可以直接使用。后续根据建议修改
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文件。