Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
fa7bafe
Integrate warpspeed scan
bernhardmgruber Nov 26, 2025
911b1a2
Drop license header to MIT lisence
miscco Nov 27, 2025
fa84d4a
Inline some methods in SmemAllocator
miscco Nov 27, 2025
adae228
Use proper includes
miscco Nov 27, 2025
fd59bd9
Add missing include
miscco Nov 27, 2025
b200e77
cleanup values
miscco Nov 27, 2025
e431418
cleanup synchandler
miscco Nov 27, 2025
28f0da6
Only included needed ptx header in SpecialRegisters
miscco Nov 27, 2025
3e7c20f
Add nodiscard
miscco Nov 27, 2025
e58b529
Drop unnecessary include
miscco Nov 27, 2025
4c8fa48
Some nodiscard
miscco Nov 27, 2025
461a895
cleanup squads
miscco Nov 27, 2025
58b9685
Minor cleanup
miscco Nov 27, 2025
6255fc1
Cleanup resource
miscco Nov 27, 2025
91c0928
Put everything into CUB namespace
miscco Nov 27, 2025
a25dff4
Fix anemspace issue
miscco Nov 27, 2025
ba48326
Fix includes
miscco Nov 27, 2025
2623a76
Avoid single character names
miscco Nov 27, 2025
4062ce1
Build fixes
miscco Nov 27, 2025
34d7c8a
Fix SM90
miscco Nov 27, 2025
20e82b0
More fixes
miscco Nov 27, 2025
9c465ed
Fixes from Allard
miscco Nov 27, 2025
abc09cb
ahendriksen: Build fixes
ahendriksen Nov 27, 2025
4c3b0d2
Build fixed
bernhardmgruber Nov 27, 2025
fbbc5b7
Try to fix linking
miscco Nov 27, 2025
f0cb49b
Hack benchmark to use inclusive scan
bernhardmgruber Nov 27, 2025
1842de0
FIx benchmark problem sizes
bernhardmgruber Nov 27, 2025
e671ef4
Tune
bernhardmgruber Nov 27, 2025
43ca945
ahendriksen: Use linear layout for resSmemInOut
ahendriksen Nov 27, 2025
7706421
Properly estimate temporary storage
bernhardmgruber Nov 27, 2025
0ee6b75
uses cub cooperative primitives
elstehle Nov 27, 2025
78dd8fb
fixes overflow and adds large
elstehle Nov 27, 2025
a99203c
fix test size
bernhardmgruber Nov 27, 2025
de02615
ceil_div
bernhardmgruber Nov 27, 2025
8815cb4
Increase and fix problem size
bernhardmgruber Nov 27, 2025
c7f3265
Prepare different Input, Output and Accumulator Types
miscco Nov 27, 2025
fa9f20f
Properly forward the binary operator
miscco Nov 27, 2025
13ab486
Fix
bernhardmgruber Nov 27, 2025
c99b28b
fixes benchmarks and oob state init
elstehle Nov 27, 2025
3fad68c
Cleanup launch code
bernhardmgruber Nov 27, 2025
7aab0a4
Fix input output types
miscco Nov 28, 2025
890efcc
Enable exclusive scan and init value
Nov 28, 2025
0a1cc36
Avoid launching the kernel below SM90
miscco Nov 28, 2025
c482bed
Add support for unaligned input
ahendriksen Nov 28, 2025
e0e0ee4
Calculate number of stages in dependence of max available smem
davebayer Nov 28, 2025
0a4ccd4
Enable PDL
Nov 28, 2025
a485d13
Use the different types and initial values for the benchmark
miscco Nov 28, 2025
74a67f4
enable more tests
miscco Nov 28, 2025
f1fd762
Fix SmemResouce
bernhardmgruber Nov 28, 2025
6ce8959
Avoid SmemResource converting into each other for different T
bernhardmgruber Nov 28, 2025
b5aed38
fix for non-contiguous iterators
elstehle Nov 28, 2025
3f94333
Reset presets
bernhardmgruber Nov 28, 2025
1c242f9
FOrmat
bernhardmgruber Nov 28, 2025
26b05c9
Guard against old PTX ISAs
bernhardmgruber Nov 28, 2025
0790765
Make makeWarpUniform compile on older SMs
bernhardmgruber Nov 28, 2025
1fdc5d6
Cleanup
miscco Nov 28, 2025
0375a7c
Move some hard coded parameters into tuning policies
bernhardmgruber Nov 28, 2025
169d9ab
Ensure we compile on older architectures
miscco Dec 1, 2025
fabd246
Fix conversion of InitValue
bernhardmgruber Dec 1, 2025
4bce11b
Wrap warpspeed headers in detail namespace
miscco Dec 1, 2025
5750e0d
Manual tuning of tile size
bernhardmgruber Dec 1, 2025
2b8f25b
Add support for unaligned output and any problem size
ahendriksen Dec 1, 2025
12b4fbe
Avoid assertion
bernhardmgruber Dec 2, 2025
4e3d11d
Use `MaxPotentialDynamicSmemBytes`
davebayer Dec 2, 2025
732ed8c
Simplify warpspeed values
davebayer Dec 2, 2025
e850de7
Prepare a tuning policy for warpspeed and plumb it through
miscco Dec 2, 2025
ef4944c
Fix: Prepare a tuning policy for warpspeed and plumb it through
miscco Dec 2, 2025
09c4975
Move squads definition into the warpspeed policy
miscco Dec 2, 2025
949a7ff
Check single stage SMEM consumption at compile-time
bernhardmgruber Dec 4, 2025
8d88d07
Use the input tile SMEM for staging the output
bernhardmgruber Dec 5, 2025
5d6a9d8
Do not store lookback tile with all threads
miscco Dec 8, 2025
ddaa14d
Do not use 64bit load / stores when using larger types
miscco Dec 8, 2025
158d1fc
Avoid reading garbage in first tile
miscco Dec 8, 2025
485dc6e
Support atomic loading of >16B types
bernhardmgruber Dec 9, 2025
b6fe368
Fixes forgotton to add to MR !63
bernhardmgruber Dec 9, 2025
ed056b4
Properly handle initial value
bernhardmgruber Dec 9, 2025
b3466ef
Fix support for partial tiles
bernhardmgruber Dec 9, 2025
b0f3f53
Drop unused function
miscco Dec 12, 2025
24744dd
Actually test multiple tiles
miscco Dec 12, 2025
41d6124
Add missing includes for atomic load/store
miscco Dec 14, 2025
7df7c7a
Simplify final scan
miscco Dec 14, 2025
e1333ad
Improve lookahead safe
bernhardmgruber Dec 15, 2025
2e1df2e
Cleanup loadLookbackTile
miscco Dec 14, 2025
8581029
Improve lookahead
miscco Dec 16, 2025
718bb61
Fix a bug in lookback
bernhardmgruber Dec 16, 2025
5f64ad7
Fix wrong end index
bernhardmgruber Dec 16, 2025
fdbf4e3
Use a single kernel for both scan implementations
bernhardmgruber Dec 16, 2025
f6fa140
Revert benchmarks and tests to their former problem sizes
bernhardmgruber Dec 16, 2025
b789dca
Fallback to old scan when SMEM is insufficient
bernhardmgruber Dec 16, 2025
08ed34c
Fix tile state alignment
bernhardmgruber Dec 16, 2025
8be951d
Fix handling of non-contigous iterators
bernhardmgruber Dec 16, 2025
e281b10
Drop cudaTypedefs
miscco Dec 17, 2025
81a5fe6
Use ceil_div to avoid zero elem_per_thread
miscco Dec 17, 2025
25ccf5a
Ensure `elemPerThread` is never 0
miscco Dec 17, 2025
5e20e9c
Memset tilestate to zero
bernhardmgruber Dec 17, 2025
343f14c
Fix scan for minimum
ahendriksen Dec 17, 2025
71bbb07
Support CCCL.C
bernhardmgruber Dec 17, 2025
7eba0bf
Ensure items_per_threads is at least one
bernhardmgruber Dec 17, 2025
894f1dc
Fix tile_state_t for older compilers
bernhardmgruber Dec 17, 2025
92306f1
Guard __cccl_ptx_isa >= 860
bernhardmgruber Dec 17, 2025
274d643
Fix NVHPC warning
bernhardmgruber Dec 17, 2025
88e6eaf
Fuse off CCCL.C
bernhardmgruber Dec 17, 2025
aa7c974
Undo line change
bernhardmgruber Dec 18, 2025
75a67f1
Fix typo
bernhardmgruber Dec 18, 2025
b374162
Fix ptxas error
bernhardmgruber Dec 19, 2025
db74281
Fallback for __nv_atomic_store/load
bernhardmgruber Dec 19, 2025
1067030
Limit stages for small problems
bernhardmgruber Dec 19, 2025
2e2b8a7
Increase stages for small problems a bit more
bernhardmgruber Dec 19, 2025
322cf01
Guarantee alignment for output type
bernhardmgruber Dec 19, 2025
3f21b69
Fix constexpr issue with `elem_per_chunk`
miscco Jan 7, 2026
97b6a95
Move warpspeed folder to `cub/detail`
miscco Jan 7, 2026
75244fc
Rename files to match cub naming conventions
miscco Jan 7, 2026
c2d2b7a
Fix compiler warning about sizeof(array)
miscco Jan 7, 2026
f04f8b5
Move warpspeed features out of `detail::scan` into `detail`
miscco Jan 7, 2026
a3219bb
Move squad based load and stores to their own file
miscco Jan 7, 2026
30124b7
Drop threadReduce function
miscco Jan 7, 2026
5834de8
Drop unused function
miscco Jan 7, 2026
8b8f65a
Cleanup include of `<cuda/ptx>`
miscco Jan 7, 2026
99f544a
Pass squad by value
miscco Jan 7, 2026
1bef8a8
Use warpspeed namespace for the warpspeed library
miscco Jan 12, 2026
9c69a87
Fix formatting
bernhardmgruber Jan 13, 2026
0b2d594
Renaming and const
bernhardmgruber Jan 26, 2026
8bf54ed
Consistently switch between old/new kernel
bernhardmgruber Jan 28, 2026
4bfb525
Make CCCL.C work again
bernhardmgruber Jan 28, 2026
02bf755
Works
bernhardmgruber Jan 26, 2026
a39d83f
Works
bernhardmgruber Jan 26, 2026
e08daa6
Works
bernhardmgruber Jan 28, 2026
db8f0b4
1
bernhardmgruber Jan 28, 2026
9027e3a
More char*
bernhardmgruber Jan 26, 2026
8a297b9
Refactor scan tile SMEM allocation
bernhardmgruber Jan 26, 2026
4921f06
Address reviewer feedback
bernhardmgruber Jan 28, 2026
cf2fb5c
Workaround compilers not supporting multiple alignas attributes
bernhardmgruber Jan 28, 2026
82338d7
_CCCL_GRID_CONSTANT
bernhardmgruber Jan 28, 2026
8c4660b
Fix wrong check for include
bernhardmgruber Jan 28, 2026
3b1fec5
.h -> .cuh
bernhardmgruber Jan 28, 2026
a20ad2c
Missing include
bernhardmgruber Jan 28, 2026
a238489
Replace CTK version check by __CUDACC_DEVICE_ATOMIC_BUILTINS__
bernhardmgruber Jan 28, 2026
2e8b6b8
Require is_constant_evaluated and PTX ISA 86
bernhardmgruber Jan 28, 2026
b900464
MSVC workaround
bernhardmgruber Jan 28, 2026
85695cc
MSVC
bernhardmgruber Jan 28, 2026
47a3e52
Fallback to ThreadStore/Load for non-trivially copyable accumulators
bernhardmgruber Jan 29, 2026
bd4ed36
More fallback conditions
bernhardmgruber Jan 29, 2026
18e7f16
Fix MSVC warning
bernhardmgruber Jan 29, 2026
b179d44
Force inline the lambda
bernhardmgruber Jan 29, 2026
cfd405e
Disable SMEM 48KiB reporting
bernhardmgruber Jan 29, 2026
bfda186
Add _CCCL_FORCEINLINE_LAMBDA
bernhardmgruber Jan 29, 2026
6623671
Make _CCCL_FORCEINLINE_LAMBDA empty on MSVC
bernhardmgruber Jan 29, 2026
ce100e4
Fix sign mismatch warnings
bernhardmgruber Jan 29, 2026
04ad78c
Uglify and internalize warpspeed macros
bernhardmgruber Jan 29, 2026
53d1d95
TODO comment
bernhardmgruber Jan 29, 2026
68ad875
Fix warnings
bernhardmgruber Jan 29, 2026
781e488
Check kernel launches
bernhardmgruber Jan 29, 2026
1152bae
Revisit TODOs
bernhardmgruber Jan 29, 2026
f0e885a
Refactor PDL with old kernel
bernhardmgruber Jan 29, 2026
24ac8b0
Reduce test problem sizes
bernhardmgruber Jan 29, 2026
99dc2cf
Assert tile_state is a power of two for built-in atomics
bernhardmgruber Jan 30, 2026
a8acef8
Fix CCCL.C
bernhardmgruber Jan 30, 2026
6c203f4
Workaround: Use atomic_ref for MSVC
bernhardmgruber Jan 30, 2026
a85bd05
Fix MSVC warnings
bernhardmgruber Jan 30, 2026
be22c77
Add a TODO
bernhardmgruber Jan 30, 2026
1efe870
Refactor
bernhardmgruber Feb 2, 2026
aae1436
Workaround for ptxas bug
bernhardmgruber Feb 2, 2026
9a7bf03
Workaround workaround
bernhardmgruber Feb 2, 2026
93b988c
Disable for MSVC + nvcc < 13.1
bernhardmgruber Feb 2, 2026
d807c57
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
15fe49a
Update copyright year
bernhardmgruber Feb 3, 2026
a146677
Qualify integers
bernhardmgruber Feb 3, 2026
d9e6d50
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
daaf795
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
ca19ca0
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
97f5730
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
fc3bb6b
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
c19c8c9
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
a407389
Apply reviewer feedback
bernhardmgruber Feb 3, 2026
1f7e914
Missing include
bernhardmgruber Feb 3, 2026
d4f8adc
Fix namespace
bernhardmgruber Feb 3, 2026
aed948a
Fix CCCL.C
bernhardmgruber Feb 3, 2026
3e06335
Do not try to compile warpspeed for CUDACC prior to 12.8
miscco Feb 5, 2026
fd8d9e0
Revert changes to `dispatch_scan` because ptx_isa might be different …
miscco Feb 5, 2026
7db74ef
Fix NVRTC
miscco Feb 5, 2026
a856424
Guard _CCCL_GRID_CONSTANT
bernhardmgruber Feb 6, 2026
563f712
Remove dead code
bernhardmgruber Feb 6, 2026
d20a272
Fix identity
bernhardmgruber Feb 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions c/parallel/src/scan.cu
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,27 @@ std::string get_output_iterator_name()
return iterator_t;
}

std::string
get_init_kernel_name(cccl_iterator_t input_it, cccl_iterator_t /*output_it*/, cccl_op_t op, cccl_type_info init)
std::string get_init_kernel_name(cccl_iterator_t input_it, cccl_iterator_t output_it, cccl_op_t op, cccl_type_info init)
{
std::string chained_policy_t;
check(cccl_type_name_from_nvrtc<device_scan_policy>(&chained_policy_t));

const cccl_type_info accum_t = scan::get_accumulator_type(op, input_it, init);
const std::string accum_cpp_t = cccl_type_enum_to_name(accum_t.type);
return std::format("cub::detail::scan::DeviceScanInitKernel<cub::ScanTileState<{0}>>", accum_cpp_t);
const std::string input_iterator_t =
(input_it.type == cccl_iterator_kind_t::CCCL_POINTER //
? cccl_type_enum_to_name(input_it.value_type.type, true) //
: scan::get_input_iterator_name());
const std::string output_iterator_t =
output_it.type == cccl_iterator_kind_t::CCCL_POINTER //
? cccl_type_enum_to_name(output_it.value_type.type, true) //
: scan::get_output_iterator_name();
return std::format(
"cub::detail::scan::DeviceScanInitKernel<{0}, {1}, {2}, cub::ScanTileState<{3}>, {3}>",
chained_policy_t,
input_iterator_t,
output_iterator_t,
accum_cpp_t);
}

std::string get_scan_kernel_name(
Expand Down Expand Up @@ -208,6 +223,33 @@ struct scan_kernel_source
{
return {build.description_bytes_per_tile, build.payload_bytes_per_tile};
}

std::size_t look_ahead_tile_state_size() const
{
return look_ahead_tile_state_alignment();
}

std::size_t look_ahead_tile_state_alignment() const
{
constexpr int state_size = alignof(cub::detail::warpspeed::scan_state);
return ::cuda::next_power_of_two(
::cuda::round_up(state_size, build.accumulator_type.alignment) + build.accumulator_type.size);
}

static auto make_tile_state_kernel_arg(scan_tile_state ts)
{
cub::detail::scan::tile_state_kernel_arg_t<scan_tile_state, char> arg;
::cuda::std::__construct_at(&arg.lookback, ::cuda::std::move(ts));

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.

NIT:

Suggested change
::cuda::std::__construct_at(&arg.lookback, ::cuda::std::move(ts));
cuda::std::__construct_at(&arg.lookback, cuda::std::move(ts));

same for other occurrences

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.

I believe we should always fully qualify in production code

return arg;
}

static auto look_ahead_make_tile_state_kernel_arg(void* ts)
{
// we can ignore passing a wrong AccumT, since we only store a pointer, and the kernel will have the right type
cub::detail::scan::tile_state_kernel_arg_t<scan_tile_state, char> arg;
::cuda::std::__construct_at(&arg.lookahead, static_cast<cub::detail::warpspeed::tile_state_t<char>*>(ts));
return arg;
}
};
} // namespace scan

Expand Down
23 changes: 23 additions & 0 deletions cub/cub/detail/launcher/cuda_runtime.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ struct TripleChevronFactory

return cudaDeviceGetAttribute(&max_shared_memory, cudaDevAttrMaxSharedMemoryPerBlock, device);
}

template <typename Kernel>
_CCCL_HIDE_FROM_ABI CUB_RUNTIME_FUNCTION ::cudaError_t
max_dynamic_smem_size_for(int& max_dynamic_smem_size, [[maybe_unused]] Kernel kernel_ptr)
{
NV_IF_ELSE_TARGET(NV_IS_HOST, //
({ return MaxPotentialDynamicSmemBytes(max_dynamic_smem_size, kernel_ptr); }),

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.

Suggested change
({ return MaxPotentialDynamicSmemBytes(max_dynamic_smem_size, kernel_ptr); }),
({ return ::MaxPotentialDynamicSmemBytes(max_dynamic_smem_size, kernel_ptr); }),

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.

MaxPotentialDynamicSmemBytes is just an ordinary CUB API living in namespace cub.

({
::cudaFuncAttributes func_attrs{};
if (const auto error = CubDebug(::cudaFuncGetAttributes(&func_attrs, kernel_ptr)))
{
return error;
}
max_dynamic_smem_size = func_attrs.maxDynamicSharedSizeBytes;
return cudaSuccess;
}))
}

template <typename Kernel>
_CCCL_HIDE_FROM_ABI CUB_RUNTIME_FUNCTION ::cudaError_t set_max_dynamic_smem_size_for(Kernel kernel_ptr, int smem_size)
{
return CubDebug(::cudaFuncSetAttribute(kernel_ptr, cudaFuncAttributeMaxDynamicSharedMemorySize, smem_size));
}
};
} // namespace detail

Expand Down
83 changes: 83 additions & 0 deletions cub/cub/detail/warpspeed/allocators/smem_allocator.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES.
#pragma once

#include <cub/config.cuh>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#include <cub/detail/warpspeed/optimize_smem_ptr.cuh>

#include <cuda/std/__type_traits/is_constant_evaluated.h>
#include <cuda/std/cstdint>

#include <nv/target>

CUB_NAMESPACE_BEGIN

namespace detail::warpspeed
{
struct SmemAllocator
{
::cuda::std::uint32_t mPtrSmem32 = 0;
int mAllocatedSize = 0;

_CCCL_API constexpr SmemAllocator() noexcept
{
// we only need the real pointer at runtime in device code
if (!::cuda::std::is_constant_evaluated())
{
NV_IF_TARGET(NV_IS_DEVICE, mPtrSmem32 = dynamic_smem_base();)
}
}

[[nodiscard]] _CCCL_DEVICE_API static ::cuda::std::uint32_t dynamic_smem_base() noexcept
{
extern __shared__ char warpSpeedDynamicSmemBase[];

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.

I start to get confused by the code convention for variable names. Should not be snake_style?

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.

Yes. The whole part of this PR that does not touch CUB has been written in the style that @ahendriksen chose. I am still not sure whether we want to change it, since warpspeed is also intended to be used outside CCCL. Not sure.

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.

I just adapt to the library that I am contributing to. Warpspeed uses a convention from a different library. It wasn't originally developed for scan. So if it has to adapt for CUB, then we should adapt.

I would advise to make those changes in a separate PR in one go though. Making changes to all files in this PR just creates churn for no good reason.

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.

Agreed, let's file the style fix as a separate PR.

return __cvta_generic_to_shared(warpSpeedDynamicSmemBase);
}

// SmemAllocator is a non-copyable, non-movable type. It must be passed by
// (mutable) reference to be useful.
SmemAllocator(const SmemAllocator&) = delete; // Delete copy constructor
SmemAllocator(SmemAllocator&&) = delete; // Delete move constructor
SmemAllocator& operator=(const SmemAllocator&) = delete; // Delete copy assignment
SmemAllocator& operator=(SmemAllocator&&) = delete; // Delete move assignment

[[nodiscard]] _CCCL_API constexpr void* alloc(::cuda::std::uint32_t size, ::cuda::std::uint32_t align = 0)
{
// Align mPtrSmem32 to requested alignment (round-up)
::cuda::std::uint32_t ptrAllocation32 = (mPtrSmem32 + (align - 1)) & ~(align - 1);

// Move base pointer and update allocated size
mAllocatedSize += size + ptrAllocation32 - mPtrSmem32;
mPtrSmem32 = ptrAllocation32 + size;

// we only need the pointer at runtime in device code
if (!::cuda::std::is_constant_evaluated())
{
NV_IF_TARGET(
NV_IS_DEVICE,
(
// Convert allocated smem address to generic pointer
void* mPtrAllocation = __cvta_shared_to_generic(ptrAllocation32);
// Ensure alignment calculation does not move down into rest of kernel code.
return optimizeSmemPtr(mPtrAllocation);))

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.

Suggested change
return optimizeSmemPtr(mPtrAllocation);))
return cub::detail::warpspeed::optimizeSmemPtr(mPtrAllocation);))

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.

We haven't established the convention (yet) that CUB should also (fully) qualify function calls. Here, we call a function from the same namespace and do not rely on ADL.

}
return nullptr;
}

[[nodiscard]] _CCCL_API constexpr ::cuda::std::uint32_t sizeBytes() const
{
return mAllocatedSize;
}
};
} // namespace detail::warpspeed

CUB_NAMESPACE_END
52 changes: 52 additions & 0 deletions cub/cub/detail/warpspeed/constant_assert.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES.
#pragma once

#include <cub/config.cuh>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#include <cuda/std/cassert>

/*
* _WS_CONSTANT_ASSERT: an assertion that is intended to be verified at compile time.
*
* A _WS_CONSTANT_ASSERT asserts something that the compiler (optimizer) can verify
* at compile time. Therefore, it does not result in an actual call to assert in
* the compiled binary. This allows checking various properties that cannot be
* verified using static_assert.
*
* To ensure that all _WS_CONSTANT_ASSERTs are in fact eliminated, compile with
* -D_WARPSPEED_FORCE_ASSERT_AT_COMPILE_TIME. With this macro defined, any
* _WS_CONSTANT_ASSERT failure will output illegal PTX containing the error message.
* As a result, compilation will fail.
*
* Compiling with -D_WARPSPEED_FORCE_ASSERT_AT_COMPILE_TIME has the additional
* advantage that violating any of the assertions can be detected at compile
* time and before even running the code.
*
*/

#if defined(_WARPSPEED_FORCE_ASSERT_AT_COMPILE_TIME) && defined(__CUDA_ARCH__)
// When _WARPSPEED_FORCE_ASSERT_AT_COMPILE_TIME is defined and compiling for device, output illegal PTX.
// This causes the compilation to fail.
# define _WS_CONSTANT_ASSERT(expr, msg) \
do \
{ \
if (!(expr)) \
{ \
asm volatile(".pragma \"\n" __FILE__ "(" _CCCL_TO_STRING( \
__LINE__) "): %0" \
": error: constant assertion failed with '" msg "'\n\";" ::"C"(__func__)); \
} \
} while (0)
#else
// Host or !_WARPSPEED_FORCE_ASSERT_AT_COMPILE_TIME
# define _WS_CONSTANT_ASSERT(expr, msg) (assert((expr) && (msg)))
#endif
Loading