Skip to content

Hardcode DeviceTransform OffsetT to int64 - #9127

Merged
bernhardmgruber merged 7 commits into
NVIDIA:mainfrom
bernhardmgruber:transform_hardcode_64
May 27, 2026
Merged

bernhardmgruber merged 7 commits into
NVIDIA:mainfrom
bernhardmgruber:transform_hardcode_64

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

This change is going to cause a tiny regression (benchmarks in #8805, important ones repeated below). However, it:

  • halfs compilation time for thrust::transform (and any other Thrust call using DeviceTransform, because we got rid of the index type dispatch
  • halfs compilation time of all DeviceTransform tests
  • halfs benchmark time for DeviceTransform
  • doubles tuning throughput for DeviceTransform

I am gladly eating a small regression for these benefits. Here are the regressions:

A100 (1/200 workloads regressed):

# triad

## [0] NVIDIA A100-SXM4-80GB

|  T{ct}  |  OffsetT{ct}  |  Elements{io}  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |     Diff |   %Diff |  Status  |
|---------|---------------|----------------|------------|-------------|------------|-------------|----------|---------|----------|
|   F64   |      I64      |      2^24      | 243.144 us |       1.02% | 245.588 us |       0.38% | 2.444 us |   1.01% |  🔴 SLOW  |

H200 (1/200 workloads regressed):

# nstream

## [0] NVIDIA H200 NVL

|  T{ct}  |  OffsetT{ct}  |  Elements{io}  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |      Diff |   %Diff |  Status  |
|---------|---------------|----------------|------------|-------------|------------|-------------|-----------|---------|----------|
|   F32   |      I64      |      2^20      |   9.963 us |       1.47% |  10.443 us |       6.24% |  0.480 us |   4.82% |  🔴 SLOW  |

B200 (4/200 workloads regressed):

# mul

## [0] NVIDIA B200

|  T{ct}  |  OffsetT{ct}  |  Elements{io}  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |      Diff |   %Diff |  Status  |
|---------|---------------|----------------|------------|-------------|------------|-------------|-----------|---------|----------|
|   I8    |      I32      |      2^28      | 116.430 us |       0.54% | 117.871 us |       0.70% |  1.442 us |   1.24% |  🔴 SLOW  |

# triad

## [0] NVIDIA B200

|  T{ct}  |  OffsetT{ct}  |  Elements{io}  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |     Diff |   %Diff |  Status  |
|---------|---------------|----------------|------------|-------------|------------|-------------|----------|---------|----------|
|   I8    |      I32      |      2^28      | 153.406 us |       0.32% | 155.685 us |       0.25% | 2.280 us |   1.49% |  🔴 SLOW  |

# nstream

## [0] NVIDIA B200

|  T{ct}  |  OffsetT{ct}  |  Elements{io}  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |     Diff |   %Diff |  Status  |
|---------|---------------|----------------|------------|-------------|------------|-------------|----------|---------|----------|
|   I8    |      I32      |      2^28      | 208.966 us |       0.18% | 212.496 us |       0.36% | 3.531 us |   1.69% |  🔴 SLOW  |
|   I16   |      I32      |      2^28      | 317.133 us |       0.23% | 322.522 us |       0.29% | 5.389 us |   1.70% |  🔴 SLOW  |

Let me know if we need more benchmarks, like on non-data-center-grade GPUs.

Fixes: #8805

@bernhardmgruber
bernhardmgruber requested review from a team as code owners May 26, 2026 07:26
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 26, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e930db54-dd43-4037-9721-7edf9bc0af0c

📥 Commits

Reviewing files that changed from the base of the PR and between 033e402 and b63852b.

📒 Files selected for processing (2)
  • cub/cub/device/device_transform.cuh
  • thrust/thrust/system/cuda/detail/transform.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • cub/cub/device/device_transform.cuh

📝 Walkthrough

Summary by CodeRabbit

  • Refactor

    • Standardized transform benchmarks and runtime to use a fixed 64-bit offset size, simplifying type axes and benchmark registrations.
    • Simplified internal dispatch and kernel offset handling for more consistent behavior across transform code paths.
  • Tests

    • Updated transform-related tests and benchmark registrations to remove multi-offset variations and use the standardized offset type.

important:

Walkthrough

Standardizes DeviceTransform internals to use a fixed ::cuda::std::int64_t offset and updates benchmarks, tests, dispatch, kernels, and Thrust call-sites to pass element counts as int64_t and use int64_t-based Offset logic.

Changes

DeviceTransform Offset Type Standardization

Layer / File(s) Summary
Internal offset selection and validation
cub/cub/device/device_transform.cuh
Fixes internal offset to ::cuda::std::int64_t and performs an explicit bounds validation before dispatch.
Dispatch & kernel offsets and casts
cub/cub/device/dispatch/dispatch_transform.cuh, cub/cub/device/dispatch/kernels/kernel_transform.cuh
Tightens Offset requirement to int64_t and replaces Offset{...} brace-init with static_cast<Offset>(...) in min/ceil_div/grid/tile computations.
Benchmarks: remove OffsetT parameter
cub/benchmarks/bench/transform/*, cub/benchmarks/bench/transform/common.h
Removes OffsetT from benchmark helpers and NVBench registrations; bench_transform now takes ::cuda::std::int64_t num_items; benchmarks pass n directly and type axes expose only value-type.
Tests: remove offset_types parameterization
cub/test/catch2_test_device_transform.cu, cub/test/catch2_test_device_transform_if.cu
Removes offset_types from C2H_TEST instantiations and hard-codes offset_t to ::cuda::std::int64_t in affected tests.
Thrust integration callsite
thrust/thrust/system/cuda/detail/transform.h
Adds underflow guard on num_items and replaces THRUST_INDEX_TYPE_DISPATCH indirection with direct CUB DeviceTransform calls passing num_items and the policy stream.

Assessment against linked issues

Objective Addressed Explanation
Hardcode 64-bit offset type for DeviceTransform to simplify implementation and prevent 32-bit overflow bugs [#8805] ✅

Suggested labels

backport branch/3.4.x

Suggested reviewers

  • davebayer
  • NaderAlAwar

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/benchmarks/bench/transform/complex_cmp.cu (1)

32-43: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

important: benchmark accounting is inconsistent with the actual transform length. You execute n - 1 items on Line 42, but record n on Line 36 and Line 38. Use the same count for execution and metrics so reported throughput is accurate.

As per coding guidelines, "Use docs/cub/benchmarking.rst for benchmark conventions... keep axes comparable... and preserve useful comparison data."

🧹 Nitpick comments (1)
cub/test/catch2_test_device_transform.cu (1)

108-111: ⚡ Quick win

suggestion: Update comment to remove I32 offset type reference.

The comment mentions "Both deltas fit in I32 and I64 offset types," but the test now only uses ::cuda::std::int64_t since offset types are hardcoded per this PR. Update the comment to clarify this test exercises the >4 GiB byte-offset regime with int64_t offsets only, removing the now-obsolete I32 mention.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 59a54297-0830-4d6c-92df-5b5f88afaa8c

📥 Commits

Reviewing files that changed from the base of the PR and between a6a5665 and 12ed874.

📒 Files selected for processing (14)
  • cub/benchmarks/bench/transform/babelstream.cu
  • cub/benchmarks/bench/transform/common.h
  • cub/benchmarks/bench/transform/complex_cmp.cu
  • cub/benchmarks/bench/transform/fib.cu
  • cub/benchmarks/bench/transform/fill.cu
  • cub/benchmarks/bench/transform/grayscale.cu
  • cub/benchmarks/bench/transform/heavy.cu
  • cub/benchmarks/bench/transform/pytorch.cu
  • cub/cub/device/device_transform.cuh
  • cub/cub/device/dispatch/dispatch_transform.cuh
  • cub/cub/device/dispatch/kernels/kernel_transform.cuh
  • cub/test/catch2_test_device_transform.cu
  • cub/test/catch2_test_device_transform_if.cu
  • thrust/thrust/system/cuda/detail/transform.h

@miscco miscco 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.

Looks good to me, the regressions are small enough IMHO to be ignored.

I would also be curious if we could get rid of them by tuning with just the 64 bit offset

Comment thread cub/benchmarks/bench/transform/common.h Outdated
::cuda::std::tuple<RandomAccessIteratorsIn...> inputs,
RandomAccessIteratorOut output,
OffsetT num_items,
::cuda::std::size_t num_items,

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.

Shouldnt this be int64_t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed the public API again to use a templated NumItemsT parameter, so a user does not suddenly get conversion warnings. I only cast to int64 before calling the dispatch layer now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the occurrence here to int64

Comment on lines 136 to +137
const Offset offset = static_cast<Offset>(blockIdx.x) * tile_size;
const int valid_items = static_cast<int>((::cuda::std::min) (num_items - offset, Offset{tile_size}));
const int valid_items = static_cast<int>((::cuda::std::min) (num_items - offset, static_cast<Offset>(tile_size)));

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.

Why do we still have a template Offset when it should always be int64_t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I left the dispatch and kernel as is for now, since I want to play a bit withuint64_t in the future. It did give a speedup in some runs, so I want to know why and whether we can extract that speedup somehow #8805 by using unsigned types in a few places in the kernel.

};

// Reduces the items_per_thread when necessary to generate enough blocks to reach the maximum occupancy.
template <typename Offset, typename Policy>

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.

Ditto: Why is Offset still needed as a template argument?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason as above

@bernhardmgruber
bernhardmgruber force-pushed the transform_hardcode_64 branch from 12ed874 to 39955ac Compare May 26, 2026 12:37

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3605c976-410b-4902-9735-813b6468e626

📥 Commits

Reviewing files that changed from the base of the PR and between 12ed874 and 965e43e.

📒 Files selected for processing (14)
  • cub/benchmarks/bench/transform/babelstream.cu
  • cub/benchmarks/bench/transform/common.h
  • cub/benchmarks/bench/transform/complex_cmp.cu
  • cub/benchmarks/bench/transform/fib.cu
  • cub/benchmarks/bench/transform/fill.cu
  • cub/benchmarks/bench/transform/grayscale.cu
  • cub/benchmarks/bench/transform/heavy.cu
  • cub/benchmarks/bench/transform/pytorch.cu
  • cub/cub/device/device_transform.cuh
  • cub/cub/device/dispatch/dispatch_transform.cuh
  • cub/cub/device/dispatch/kernels/kernel_transform.cuh
  • cub/test/catch2_test_device_transform.cu
  • cub/test/catch2_test_device_transform_if.cu
  • thrust/thrust/system/cuda/detail/transform.h

Comment thread cub/benchmarks/bench/transform/common.h Resolved

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/benchmarks/bench/transform/common.h (1)

79-84: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

important: Annotate bench_transform with a CCCL function API macro.

bench_transform is declared in a header without _CCCL_HOST_API, _CCCL_DEVICE_API, or _CCCL_API. Please add the appropriate annotation on this function declaration.

As per coding guidelines, "All functions must be marked with _CCCL_HOST_API, _CCCL_DEVICE_API, or _CCCL_API".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 77e6018f-c6ca-411a-984f-388ee8c64293

📥 Commits

Reviewing files that changed from the base of the PR and between 965e43e and 275ca8b.

📒 Files selected for processing (1)
  • cub/benchmarks/bench/transform/common.h

Comment thread cub/cub/device/device_transform.cuh Resolved
@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

@NaderAlAwar thanks for the review and the good findings! I addressed your comments. Please have another look!

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 30m: Pass: 100%/342 | Total: 14d 00h | Max: 2h 29m | Hits: 26%/1408254

See results here.

@bernhardmgruber
bernhardmgruber merged commit d2d87ed into NVIDIA:main May 27, 2026
361 of 362 checks passed
@bernhardmgruber
bernhardmgruber deleted the transform_hardcode_64 branch May 27, 2026 21:34
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 27, 2026
shwina pushed a commit to shwina/cccl that referenced this pull request Jun 1, 2026
shwina pushed a commit to shwina/cccl that referenced this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Consider hardcoding a 64-bit offset type for DeviceTransform

3 participants