Repository navigation
Conversation
dmiltr3
left a comment
There was a problem hiding this comment.
Hi @kokol16,
Thank you for contributing! Extending the 1D GPU kernel loops to support generic types is highly valuable for numerical robustness. However, we found a few issues that need to be resolved before this PR is ready to merge:
1. 32-Bit Parameter Truncation in GPU Kernels
Simply changing the loop iteration type to int64_t in the macro is not sufficient because the loop boundaries passed to the kernel signatures are still 32-bit signed integers:
- In
tensorflow/core/kernels/population_count_op_gpu.cu.cc, the kernel signature takesconst int size. - In
tensorflow/core/kernels/roll_op_gpu.cu.cc, the kernel signature takesconst int32_t nthreads.
If a tensor exceeds int64_t (or int64 type alias).
2. 32-Bit Launch Configuration
The host-side launch logic for both operations currently uses GetGpuLaunchConfig(), which only accepts a 32-bit signed integer count and returning a 32-bit GpuLaunchConfig struct (truncating your actual 64-bit totals).
To fully support these large sizes, you'll need to update the launch configurations to use GetGpuLaunchConfig64 and GpuLaunchConfig64 respectively.
3. Missing Unit Tests
Please add test coverage to verify compilation and execution of the three-argument variant (such as with int64_t) in tensorflow/core/util/gpu_kernel_helper_test.cu.cc.
Could you please update the PR to include these updates? Let us know if you have any questions!
|
This PR is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you. |
|
This PR was closed because it has been inactive for 14 days since being marked as stale. Please reopen if you'd like to work on this further. |
|
@dmiltr3 Reopening via a new PR with your requested changes addressed:
New PR: #126698 Thanks for the review feedback. |
GPU_1D_KERNEL_LOOPandCUDA_1D_KERNEL_LOOPcurrently hardcode the loopindex type to
intviaGpuGridRangeX<int>. That can be safe for some kernels, butit becomes fragile for very large launches: when the iteration space is close to
the 32-bit limit, the range helper’s internal stride arithmetic can overflow,
which may yield incorrect indices.
This patch extends both macros with an optional explicit index type:
GPU_1D_KERNEL_LOOP(i, n, T)andCUDA_1D_KERNEL_LOOP(i, n, T). Callers thatoperate on large tensor sizes can now request
int64_t, so the range/stridecomputation is performed in 64-bit arithmetic.
The change is backward compatible. The existing 2-argument form is preserved and
continues to instantiate
GpuGridRangeX<int>, while the new 3-argument form isselected only for call sites that explicitly provide a type. This patch updates
the
population_countandrollGPU kernels to useint64_tindices.fixed issues #109520 #104077
There are ~20 open issues that can be fixed using this new macro, would you like me
to create one pull request that fixes them all or split in chunks?