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

slice large tensor for cudnn_softmax #43681

Merged
merged 2 commits into from
Jun 21, 2022
Merged

Conversation

zhangting2020
Copy link
Contributor

@zhangting2020 zhangting2020 commented Jun 20, 2022

PR types

Bug fixes

PR changes

OPs

Describe

slice large tensor for cudnn_softmax

背景

cuDNN在tensor元素超过2G时,会出现CUDNN_STATUS_NOT_SUPPORT的错误。本PR在输入size超过2G时,将输入切片,调用多次kernel分别处理切片数据。

  • 测试案例
import paddle
import paddle.nn.functional as F
import numpy as np

np.random.seed(1234)
x_np = np.random.random((2, 16, 8481, 8481)).astype('float32')
x = paddle.to_tensor(x_np)
out = F.softmax(x)

性能

  • paddle

image

  • torch

image

@paddle-bot-old
Copy link

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

dim,
dim,
dim_log2);
int64_t remaining = N;
Copy link
Contributor

Choose a reason for hiding this comment

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

如果只是支持了cudnn实现,那这些逻辑是不是直接实现在SoftmaxForward/BackwardCudnnKernel函数里面更好?避免一个函数太长了吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在最外层的softmax接口里去掉了这段,切片的逻辑封装了一下。

dim_log2);
int64_t remaining = N;
auto* x_data = x.data<T>();
int64_t batch_size = INT_MAX / dim;
Copy link
Contributor

Choose a reason for hiding this comment

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

INT_MAX -> std::numeric_limits<int32_t>::max()

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

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

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

LGTM

@Xreki Xreki merged commit bd5e97d into PaddlePaddle:develop Jun 21, 2022
zhangting2020 added a commit to zhangting2020/Paddle that referenced this pull request Jun 21, 2022
lanxianghit pushed a commit that referenced this pull request Jun 22, 2022
…rge tensor for cudnn_softmax (#43719)

 [cherry pick] Support optional residual add in fused ops and slice large tensor for cudnn_softmax

cherry-pick #43635 #43681 #43474
sneaxiy pushed a commit to sneaxiy/Paddle that referenced this pull request Jun 27, 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.

2 participants