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
79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// %RANGE% TUNE_BIF_BIAS bif -16:16:4
|
|
// %RANGE% TUNE_ALGORITHM alg 0:4:1
|
|
// %RANGE% TUNE_THREADS tpb 128:1024:128
|
|
|
|
// for TUNE_ALGORITHM == 1 (vectorized), this is the number of vectors per thread, which is similar in spirit
|
|
// %RANGE% TUNE_UNROLL_FACTOR unrl 1:4:1
|
|
|
|
// those parameters only apply if TUNE_ALGORITHM == 0 (prefetch)
|
|
// %RANGE% TUNE_PREFETCH_MULT pref 1:3:1
|
|
|
|
// those parameters only apply if TUNE_ALGORITHM == 1 (vectorized)
|
|
// %RANGE% TUNE_VEC_SIZE_POW2 vsp2 1:6:1
|
|
|
|
#if !TUNE_BASE && TUNE_ALGORITHM != 0 && (TUNE_PREFETCH_MULT != 1)
|
|
# error "Non-prefetch algorithms require prefetch multiple to be 1 since they ignore the parameters"
|
|
#endif // !TUNE_BASE && TUNE_ALGORITHM != 0 && (TUNE_PREFETCH_MULT != 1)
|
|
|
|
#if !TUNE_BASE && TUNE_ALGORITHM != 1 && (TUNE_VEC_SIZE_POW2 != 1)
|
|
# error "Non-vectorized algorithms require vector size to be 1 since they ignore the parameters"
|
|
#endif // !TUNE_BASE && TUNE_ALGORITHM != 1 && (TUNE_VEC_SIZE_POW2 != 1)
|
|
|
|
#include "common.h"
|
|
|
|
// This benchmark is compute intensive with diverging threads
|
|
|
|
template <class IndexT, class OutputT>
|
|
struct fib_t
|
|
{
|
|
__device__ OutputT operator()(IndexT n)
|
|
{
|
|
OutputT t1 = 0;
|
|
OutputT t2 = 1;
|
|
|
|
if (n < 1)
|
|
{
|
|
return t1;
|
|
}
|
|
if (n == 1)
|
|
{
|
|
return t1;
|
|
}
|
|
if (n == 2)
|
|
{
|
|
return t2;
|
|
}
|
|
for (IndexT i = 3; i <= n; ++i)
|
|
{
|
|
const auto next = t1 + t2;
|
|
t1 = t2;
|
|
t2 = next;
|
|
}
|
|
return t2;
|
|
}
|
|
};
|
|
static void fibonacci(nvbench::state& state)
|
|
try
|
|
{
|
|
using index_t = int64_t;
|
|
using output_t = uint32_t;
|
|
const auto n = state.get_int64("Elements{io}");
|
|
thrust::device_vector<index_t> in = generate(n, bit_entropy::_1_000, index_t{0}, index_t{42});
|
|
thrust::device_vector<output_t> out(n);
|
|
|
|
state.add_element_count(n);
|
|
state.add_global_memory_reads<index_t>(n);
|
|
state.add_global_memory_writes<output_t>(n);
|
|
|
|
bench_transform(state, cuda::std::tuple{in.begin()}, out.begin(), n, fib_t<index_t, output_t>{});
|
|
}
|
|
catch (const std::bad_alloc&)
|
|
{
|
|
state.skip("Skipping: out of memory.");
|
|
}
|
|
|
|
NVBENCH_BENCH(fibonacci).set_name("fibonacci").add_int64_power_of_two_axis("Elements{io}", nvbench::range(16, 32, 4));
|