Skip to content

fix(kernels): fix 32-bit signed integer overflow in Dilation GPU kernels - #126937

Merged
copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
adi-IL:fix-dilation-gpu-integer-overflow
Sep 25, 2026
Merged

copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
adi-IL:fix-dilation-gpu-integer-overflow

Conversation

@adi-IL

@adi-IL adi-IL commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

In tensorflow/core/kernels/dilation_ops_gpu.cu.cc, DilationKernel, DilationBackpropInputKernel, and DilationBackpropFilterKernel took const int32_t nthreads and used GPU_1D_KERNEL_LOOP(out_idx, nthreads), which expands to for (int out_idx : GpuGridRangeX(nthreads)).

In addition, the launcher functors calculated the total element count with signed 32-bit arithmetic and passed it to GetGpuLaunchConfig(int, ...). When batch * output_rows * output_cols * depth > INT32_MAX, that overflows, trips CHECK_GE(work_element_count, 0), or launches with a truncated thread count.

Scope

  • In tensorflow/core/kernels/dilation_ops_gpu.cu.cc:
    • Promoted kernel nthreads, tensor dims, and loop indices to int64_t.
    • Replaced GPU_1D_KERNEL_LOOP with for (int64_t out_idx : GpuGridRangeX(nthreads)).
    • Promoted total_count to int64_t.
    • Switched all launch sites (including SetZero init launches) from GetGpuLaunchConfig to GetGpuLaunchConfig64, matching gather_nd_op_gpu.cu.cc.

Blast Radius

GPU Dilations2D forward/backprop only. CPU path untouched.

Verification

  • Launch path uses absl::StatusOr<GpuLaunchConfig64> + CHECK_OK, then config->virtual_thread_count into kernels.
  • SetZero already takes int64_t count on current master.
  • Public CI green/red on this PR is dominated by tensorflow self-hosted runner infra on some jobs; linux-cuda previously passed the int64 kernel change.

@google-ml-butler google-ml-butler Bot added the size:M CL Change Size: Medium label Sep 6, 2026
@keerthanakadiri
keerthanakadiri requested a review from a team September 7, 2026 04:08
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Sep 7, 2026
@keerthanakadiri keerthanakadiri added the comp:core issues related to core part of tensorflow label Sep 7, 2026
@github-project-automation github-project-automation Bot moved this to Assigned Reviewer in PR Queue Sep 7, 2026
@keerthanakadiri

Copy link
Copy Markdown
Contributor

/gemini review

@adi-IL

adi-IL commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Pushed e127988 on fix-dilation-gpu-integer-overflow.

cuda13 root cause: heuristic GetGpuLaunchConfig64(count, device) picks up to maxGpuThreadsPerBlock (often 1024). That over-requests registers for DilationBackpropInputKernel / DilationBackpropFilterKernel (atomics), which fails with too many resources requested for launch at dilation_ops_gpu.cu.cc around the backprop launch. Forward DilationTest cases were fine; failure showed up in morphological_ops_test_gpu gradients. linux-cuda (non-13) was green on the prior tip.

fix: switch forward + both backprop launches to the occupancy-aware overload:
GetGpuLaunchConfig64(count, device, Kernel<T>, 0, 0) so cudaOccupancyMaxPotentialBlockSize sizes the grid. SetZero stays on the lightweight heuristic path.

windows: still unrelated TFLite lld-link undefined FlatBufferFileToMlir@tflite while linking _pywrap_tensorflow_common.dll (infra), not this dilation change.

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Sep 8, 2026
@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Approved by Reviewer in PR Queue Sep 8, 2026
@keerthanakadiri keerthanakadiri removed the awaiting review Pull request awaiting review label Sep 8, 2026
@nithyak0204 nithyak0204 removed the kokoro:force-run Tests on submitted change label Sep 8, 2026
Use 64-bit launch configuration with occupancy-aware GetGpuLaunchConfig64
to prevent integer overflow on large tensors in 2D and 3D dilation kernels,
while staying within device resource limits.
@adi-IL
adi-IL force-pushed the fix-dilation-gpu-integer-overflow branch from e127988 to 3b9e909 Compare September 15, 2026 18:39
@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Sep 15, 2026
@nithyak0204
nithyak0204 requested a review from dmiltr3 September 16, 2026 07:46
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Sep 16, 2026

@dmiltr3 dmiltr3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the fix! The changes to prevent 32-bit signed integer overflows in the 2D and 3D dilation kernels look correct, and everything passes the internal test suite cleanly.

Approving!

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Sep 16, 2026
@nithyak0204 nithyak0204 removed awaiting review Pull request awaiting review kokoro:force-run Tests on submitted change labels Sep 17, 2026
@copybara-service
copybara-service Bot merged commit 294e93d into tensorflow:master Sep 25, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:core issues related to core part of tensorflow ready to pull PR ready for merge process size:M CL Change Size: Medium

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

5 participants