Repository navigation
[API] fix paddle.diag with big tensor #72638
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,13 +28,13 @@ namespace phi { | |
| template <typename T> | ||
| __global__ void ExtractDiagonalKernel(T* out, | ||
| const T* x, | ||
| std::ptrdiff_t start, | ||
| std::ptrdiff_t size, | ||
| const std::ptrdiff_t sumStride, | ||
| const std::ptrdiff_t outStride) { | ||
| for (std::ptrdiff_t idx = blockIdx.x * blockDim.x + threadIdx.x; idx < size; | ||
| int64_t start, | ||
| int64_t size, | ||
| const int64_t sumStride, | ||
| const int64_t outStride) { | ||
| for (int64_t idx = blockIdx.x * blockDim.x + threadIdx.x; idx < size; | ||
| idx += gridDim.x * blockDim.x) { | ||
| const std::ptrdiff_t xOffset = start + sumStride * idx; | ||
| const int64_t xOffset = start + sumStride * idx; | ||
| out[outStride * idx] = x[xOffset]; | ||
| } | ||
| } | ||
|
|
@@ -43,14 +43,13 @@ __global__ void ExtractDiagonalKernel(T* out, | |
| template <typename T> | ||
| __global__ void PasteDiagonalKernel(T* out, | ||
| const T* x, | ||
| std::ptrdiff_t start, | ||
| std::ptrdiff_t x_length, | ||
| const std::ptrdiff_t sumStride, | ||
| const std::ptrdiff_t xStride) { | ||
| for (std::ptrdiff_t idx = blockIdx.x * blockDim.x + threadIdx.x; | ||
| idx < x_length; | ||
| int64_t start, | ||
| int64_t x_length, | ||
| const int64_t sumStride, | ||
| const int64_t xStride) { | ||
| for (int64_t idx = blockIdx.x * blockDim.x + threadIdx.x; idx < x_length; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blockIdx.x * blockDim.x,取值范围不超过uint32, 但是idx < x_length在大Tensor场景下,所以需要采用int64_t的取值范围。 |
||
| idx += gridDim.x * blockDim.x) { | ||
| const std::ptrdiff_t outOffset = start + sumStride * idx; | ||
| const int64_t outOffset = start + sumStride * idx; | ||
| out[outOffset] = x[xStride * idx]; | ||
| } | ||
| } | ||
|
|
@@ -81,13 +80,13 @@ void DiagKernel(const Context& dev_ctx, | |
| phi::funcs::SetConstant<Context, T> set_padding_value; | ||
| set_padding_value(dev_ctx, out, static_cast<T>(padding_value)); | ||
|
|
||
| auto x_length = (x_dims.size() == 1UL ? x_dims[0] : int64_t(1)); | ||
| auto size = (offset > 0) ? x_length + offset : x_length - offset; | ||
| const int& x_stride = 1; | ||
| int64_t x_length = (x_dims.size() == 1ULL ? x_dims[0] : int64_t(1)); | ||
| int64_t size = (offset > 0) ? x_length + offset : x_length - offset; | ||
| const int64_t x_stride = 1; | ||
| if (size > 0) { | ||
| const auto& out_stride_0 = phi::funcs::ComputeStride(0, out_dims); | ||
| const auto& out_stride_1 = phi::funcs::ComputeStride(1, out_dims); | ||
| auto start = | ||
| const int64_t out_stride_0 = phi::funcs::ComputeStride(0, out_dims); | ||
| const int64_t out_stride_1 = phi::funcs::ComputeStride(1, out_dims); | ||
| int64_t start = | ||
| (offset >= 0 ? offset * out_stride_1 : -offset * out_stride_0); | ||
|
|
||
| std::tuple<int64_t, int64_t> block_grid_size = GetBlockGridSize(size); | ||
|
|
@@ -103,8 +102,8 @@ void DiagKernel(const Context& dev_ctx, | |
| x_stride); | ||
| } | ||
| } else { | ||
| const int& x_stride_0 = phi::funcs::ComputeStride(0, x_dims); | ||
| const int& x_stride_1 = phi::funcs::ComputeStride(1, x_dims); | ||
| const int64_t x_stride_0 = phi::funcs::ComputeStride(0, x_dims); | ||
| const int64_t x_stride_1 = phi::funcs::ComputeStride(1, x_dims); | ||
|
|
||
| int64_t size; | ||
| if (offset > 0) { | ||
|
|
@@ -114,11 +113,11 @@ void DiagKernel(const Context& dev_ctx, | |
| } | ||
|
|
||
| if (size > 0) { | ||
| auto start = (offset >= 0 ? offset * x_stride_1 : -offset * x_stride_0); | ||
| const auto& out_stride_0 = phi::funcs::ComputeStride(0, out_dims); | ||
| int64_t start = | ||
| (offset >= 0 ? offset * x_stride_1 : -offset * x_stride_0); | ||
| const int64_t out_stride_0 = phi::funcs::ComputeStride(0, out_dims); | ||
|
|
||
| std::tuple<int64_t, int64_t> block_grid_size = GetBlockGridSize(size); | ||
|
|
||
| ExtractDiagonalKernel<T><<<std::get<1>(block_grid_size), | ||
| std::get<0>(block_grid_size), | ||
| 0, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里写
1ULL和直接写1有什么区别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.
这个没有什么区别,只是修改支持unsigned long long int的取值。