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
89 lines
2.6 KiB
Plaintext
89 lines
2.6 KiB
Plaintext
// SPDX-FileCopyrightText: Copyright (c) 2011-2026, NVIDIA CORPORATION. All rights reserved.
|
|
// SPDX-License-Identifier: BSD-3
|
|
|
|
#pragma once
|
|
|
|
#include <cub/device/device_scan.cuh>
|
|
|
|
#include <cuda/std/__functional/invoke.h>
|
|
|
|
#include <nvbench_helper.cuh>
|
|
|
|
#include "../policy_selector.h"
|
|
|
|
template <typename T, typename OffsetT>
|
|
static void basic(nvbench::state& state, nvbench::type_list<T, OffsetT>)
|
|
try
|
|
{
|
|
using init_value_t = T;
|
|
using accum_t [[maybe_unused]] = ::cuda::std::__accumulator_t<op_t, init_value_t, T>;
|
|
using offset_t = cub::detail::choose_offset_t<OffsetT>;
|
|
#if USES_LOOKAHEAD()
|
|
static_assert(sizeof(offset_t) == sizeof(size_t)); // lookahead scan uses size_t internally
|
|
#endif // USES_LOOKAHEAD()
|
|
|
|
const auto elements = static_cast<std::size_t>(state.get_int64("Elements{io}"));
|
|
if (sizeof(offset_t) == 4 && elements > std::numeric_limits<offset_t>::max())
|
|
{
|
|
state.skip("Skipping: input size exceeds 32-bit offset type capacity.");
|
|
return;
|
|
}
|
|
|
|
thrust::device_vector<T> input = generate(elements);
|
|
thrust::device_vector<T> output(elements);
|
|
|
|
const T* d_input = thrust::raw_pointer_cast(input.data());
|
|
T* d_output = thrust::raw_pointer_cast(output.data());
|
|
|
|
state.add_element_count(elements);
|
|
state.add_global_memory_reads<T>(elements, "Size");
|
|
state.add_global_memory_writes<T>(elements);
|
|
|
|
caching_allocator_t alloc;
|
|
state.exec(nvbench::exec_tag::gpu | nvbench::exec_tag::no_batch, [&](nvbench::launch& launch) {
|
|
auto env = cub_bench_env(
|
|
alloc,
|
|
launch
|
|
#if !TUNE_BASE
|
|
,
|
|
cuda::execution::tune(policy_selector<accum_t>{})
|
|
#endif // !TUNE_BASE
|
|
);
|
|
_CCCL_TRY_CUDA_API(
|
|
cub::DeviceScan::ExclusiveScan,
|
|
"ExclusiveScan failed",
|
|
d_input,
|
|
d_output,
|
|
op_t{},
|
|
init_value_t{},
|
|
static_cast<offset_t>(input.size()),
|
|
env);
|
|
});
|
|
}
|
|
catch (const std::bad_alloc&)
|
|
{
|
|
state.skip("Skipping: out of memory.");
|
|
}
|
|
|
|
// __half and __nv_bfloat16 are added for full (non-tuning) runs; CUB has fast paths for them (see #9587).
|
|
#ifdef TUNE_T
|
|
using value_types = nvbench::type_list<TUNE_T>;
|
|
#else
|
|
using value_types =
|
|
push_back_t<all_types
|
|
# if _CCCL_HAS_NVFP16() && _CCCL_CTK_AT_LEAST(12, 2)
|
|
,
|
|
__half
|
|
# endif
|
|
# if _CCCL_HAS_NVBF16() && _CCCL_CTK_AT_LEAST(12, 2)
|
|
,
|
|
__nv_bfloat16
|
|
# endif
|
|
>;
|
|
#endif
|
|
|
|
NVBENCH_BENCH_TYPES(basic, NVBENCH_TYPE_AXES(value_types, scan_offset_types))
|
|
.set_name("base")
|
|
.set_type_axes_names({"T{ct}", "OffsetT{ct}"})
|
|
.add_int64_power_of_two_axis("Elements{io}", nvbench::range(16, 32, 4));
|