[INFRA] Import NVIDIA/CCCL upstream as optimization reference library

CCCL (CUDA C++ Core Libraries) provides:
- CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk)
- Thrust: high-level parallel algorithms (transform_reduce, sort, scan)
- libcudacxx: CUDA C++ standard library (atomics, barriers, memory)
- cudax: experimental features (memory resources, allocators)
- Tuning policies: per-SM hardware-specific algorithm parameters

Competition optimization vectors mapped to CCCL:
- Output TPS (83% weight): warp_reduce, block_reduce, device_topk
- Input TPS (14% weight): device_scan, block_load, prefetch
- Cache TPS (3% weight): prefix caching strategy patterns
- Memory (0.9 util): pooled/cached/buddy allocators

Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only)
License: Apache-2.0
This commit is contained in:
EngineX CI
2026-07-30 09:35:51 +00:00
parent b4d01f481e
commit 56fd68e7dd
8871 changed files with 1454674 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
Python benchmark for reduce custom operation using cuda.compute.reduce_into.
C++ equivalent: cub/benchmarks/bench/reduce/custom.cu
Notes:
- Uses a custom max operator (not OpKind) to exercise generic path
- int128 and complex32 are not supported by cupy
- Migration: Python limits to basic numeric types; C++ includes int128/complex.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
import cupy as cp
import numpy as np
from utils import SIGNED_TYPES as TYPE_MAP
from utils import as_cupy_stream, generate_data_with_entropy
import cuda.bench as bench
from cuda.compute import make_reduce_into
def max_op(a, b):
return a if a > b else b
def bench_reduce_custom(state: bench.State):
type_str = state.get_string("T{ct}")
dtype = TYPE_MAP[type_str]
num_items = int(state.get_int64("Elements{io}"))
alloc_stream = as_cupy_stream(state.get_stream())
with alloc_stream:
d_in = generate_data_with_entropy(num_items, dtype, "1.000", alloc_stream)
d_out = cp.empty(1, dtype=dtype)
h_init = np.zeros(1, dtype=dtype)
reducer = make_reduce_into(d_in=d_in, d_out=d_out, op=max_op, h_init=h_init)
temp_storage_bytes = reducer(
temp_storage=None,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=max_op,
h_init=h_init,
)
with alloc_stream:
temp_storage = cp.empty(temp_storage_bytes, dtype=np.uint8)
state.add_element_count(num_items)
state.add_global_memory_reads(num_items * d_in.dtype.itemsize, "Size")
state.add_global_memory_writes(d_out.dtype.itemsize)
def launcher(launch: bench.Launch):
reducer(
temp_storage=temp_storage,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=max_op,
h_init=h_init,
stream=launch.get_stream(),
)
state.exec(launcher, batched=False)
if __name__ == "__main__":
b = bench.register(bench_reduce_custom)
b.set_name("base")
b.add_string_axis("T{ct}", list(TYPE_MAP.keys()))
b.add_int64_power_of_two_axis("Elements{io}", range(16, 29, 4))
bench.run_all_benchmarks(sys.argv)

View File

@@ -0,0 +1,85 @@
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
Python benchmark for reduce min operation using cuda.compute.reduce_into.
C++ equivalent: cub/benchmarks/bench/reduce/min.cu
Notes:
- Uses OpKind.MINIMUM for minimum reduction
- C++ uses cuda::minimum<> which CUB recognizes for optimized code paths (DPX on Hopper+)
- int128 and complex32 are not supported by cupy
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
import cupy as cp
import numpy as np
from utils import FUNDAMENTAL_TYPES as TYPE_MAP
from utils import as_cupy_stream, generate_data_with_entropy
import cuda.bench as bench
from cuda.compute import OpKind, make_reduce_into
def bench_reduce_min(state: bench.State):
type_str = state.get_string("T{ct}")
dtype = TYPE_MAP[type_str]
num_items = int(state.get_int64("Elements{io}"))
alloc_stream = as_cupy_stream(state.get_stream())
with alloc_stream:
d_in = generate_data_with_entropy(num_items, dtype, "1.000", alloc_stream)
d_out = cp.empty(1, dtype=dtype)
# Initial value for min reduction (max value of type)
if np.issubdtype(dtype, np.integer):
init_val = np.iinfo(dtype).max
else:
init_val = np.finfo(dtype).max
h_init = np.array([init_val], dtype=dtype)
reducer = make_reduce_into(d_in=d_in, d_out=d_out, op=OpKind.MINIMUM, h_init=h_init)
temp_storage_bytes = reducer(
temp_storage=None,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.MINIMUM,
h_init=h_init,
)
with alloc_stream:
temp_storage = cp.empty(temp_storage_bytes, dtype=np.uint8)
state.add_element_count(num_items)
state.add_global_memory_reads(num_items * d_in.dtype.itemsize, "Size")
state.add_global_memory_writes(d_out.dtype.itemsize)
def launcher(launch: bench.Launch):
reducer(
temp_storage=temp_storage,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.MINIMUM,
h_init=h_init,
stream=launch.get_stream(),
)
state.exec(launcher, batched=False)
if __name__ == "__main__":
b = bench.register(bench_reduce_min)
b.set_name("base")
b.add_string_axis("T{ct}", list(TYPE_MAP.keys()))
b.add_int64_power_of_two_axis("Elements{io}", range(16, 29, 4))
bench.run_all_benchmarks(sys.argv)

View File

@@ -0,0 +1,87 @@
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
Python benchmark for nondeterministic reduce sum using cuda.compute.reduce_into.
C++ equivalent: cub/benchmarks/bench/reduce/nondeterministic.cu
Notes:
- Uses Determinism.NOT_GUARANTEED
- C++ tests int32, int64, float, double
- Migration: Python fixes offsets; C++ exposes an OffsetT axis.
- OffsetT axis is omitted because the Python API does not expose offset type.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
import cupy as cp
import numpy as np
from utils import ALL_TYPES as _ALL_TYPES
from utils import as_cupy_stream, generate_data_with_entropy
import cuda.bench as bench
from cuda.compute import Determinism, OpKind, make_reduce_into
TYPE_MAP = {k: _ALL_TYPES[k] for k in ("I32", "I64", "F32", "F64")}
def bench_reduce_nondeterministic(state: bench.State):
type_str = state.get_string("T{ct}")
dtype = TYPE_MAP[type_str]
num_items = int(state.get_int64("Elements{io}"))
alloc_stream = as_cupy_stream(state.get_stream())
with alloc_stream:
d_in = generate_data_with_entropy(num_items, dtype, "1.000", alloc_stream)
d_out = cp.empty(1, dtype=dtype)
h_init = np.zeros(1, dtype=dtype)
reducer = make_reduce_into(
d_in=d_in,
d_out=d_out,
op=OpKind.PLUS,
h_init=h_init,
determinism=Determinism.NOT_GUARANTEED,
)
temp_storage_bytes = reducer(
temp_storage=None,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.PLUS,
h_init=h_init,
)
with alloc_stream:
temp_storage = cp.empty(temp_storage_bytes, dtype=np.uint8)
state.add_element_count(num_items)
state.add_global_memory_reads(num_items * d_in.dtype.itemsize, "Size")
state.add_global_memory_writes(1 * d_out.dtype.itemsize)
def launcher(launch: bench.Launch):
reducer(
temp_storage=temp_storage,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.PLUS,
h_init=h_init,
stream=launch.get_stream(),
)
state.exec(launcher, batched=False)
if __name__ == "__main__":
b = bench.register(bench_reduce_nondeterministic)
b.set_name("base")
b.add_string_axis("T{ct}", list(TYPE_MAP.keys()))
b.add_int64_power_of_two_axis("Elements{io}", range(16, 29, 4))
bench.run_all_benchmarks(sys.argv)

View File

@@ -0,0 +1,80 @@
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
Python benchmark for reduce sum operation using cuda.compute.reduce_into.
C++ equivalent: cub/benchmarks/bench/reduce/sum.cu
Notes:
- int128 and complex32 are not supported by cupy
- Migration: Python excludes int128/complex; C++ supports more types/tuning.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
import cupy as cp
import numpy as np
from utils import SIGNED_TYPES as TYPE_MAP
from utils import as_cupy_stream, generate_data_with_entropy
import cuda.bench as bench
from cuda.compute import OpKind, make_reduce_into
def bench_reduce_sum(state: bench.State):
type_str = state.get_string("T{ct}")
dtype = TYPE_MAP[type_str]
num_items = int(state.get_int64("Elements{io}"))
alloc_stream = as_cupy_stream(state.get_stream())
with alloc_stream:
d_in = generate_data_with_entropy(num_items, dtype, "1.000", alloc_stream)
d_out = cp.empty(1, dtype=dtype)
# Initial value for reduction
h_init = np.zeros(1, dtype=dtype)
reducer = make_reduce_into(d_in=d_in, d_out=d_out, op=OpKind.PLUS, h_init=h_init)
temp_storage_bytes = reducer(
temp_storage=None,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.PLUS,
h_init=h_init,
)
with alloc_stream:
temp_storage = cp.empty(temp_storage_bytes, dtype=np.uint8)
state.add_element_count(num_items)
state.add_global_memory_reads(num_items * d_in.dtype.itemsize, "Size")
state.add_global_memory_writes(d_out.dtype.itemsize)
def launcher(launch: bench.Launch):
reducer(
temp_storage=temp_storage,
d_in=d_in,
d_out=d_out,
num_items=num_items,
op=OpKind.PLUS,
h_init=h_init,
stream=launch.get_stream(),
)
state.exec(launcher, batched=False)
if __name__ == "__main__":
b = bench.register(bench_reduce_sum)
b.set_name("base")
b.add_string_axis("T{ct}", list(TYPE_MAP.keys()))
b.add_int64_power_of_two_axis("Elements{io}", range(16, 29, 4))
bench.run_all_benchmarks(sys.argv)