//===----------------------------------------------------------------------===// // // Part of libcu++, the C++ Standard Library for your entire system, // under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// #include #include #include #include #include #include #include #include "nvbench_helper.cuh" // Input with runs of equal elements: 0,0,1,1,2,2,... (segment size 2) template static void make_unique_input(thrust::device_vector& in, std::size_t elements) { in.resize(elements); thrust::transform( thrust::counting_iterator(0), thrust::counting_iterator(elements), in.begin(), [] __device__(std::size_t i) { // This seems like a clang-tidy bug. Yes we end up converting to double, but the division // is done entirely in integer land... return static_cast(i / 2ULL); // NOLINT(bugprone-integer-division) }); } template static void basic(nvbench::state& state, nvbench::type_list) { const auto elements = static_cast(state.get_int64("Elements")); thrust::device_vector in; make_unique_input(in, elements); state.add_element_count(elements); state.add_global_memory_reads(elements); // unique writes at most elements state.add_global_memory_writes(elements / 2); caching_allocator_t alloc{}; state.exec(nvbench::exec_tag::gpu | nvbench::exec_tag::no_batch | nvbench::exec_tag::sync, [&](nvbench::launch& launch) { do_not_optimize(cuda::std::unique(cuda_policy(alloc, launch), in.begin(), in.end())); }); } NVBENCH_BENCH_TYPES(basic, NVBENCH_TYPE_AXES(fundamental_types)) .set_name("base") .set_type_axes_names({"T{ct}"}) .add_int64_power_of_two_axis("Elements", nvbench::range(16, 28, 4)); template static void with_comp(nvbench::state& state, nvbench::type_list) { const auto elements = static_cast(state.get_int64("Elements")); thrust::device_vector in; make_unique_input(in, elements); state.add_element_count(elements); state.add_global_memory_reads(elements); // unique writes at most elements state.add_global_memory_writes(elements / 2); caching_allocator_t alloc{}; state.exec( nvbench::exec_tag::gpu | nvbench::exec_tag::no_batch | nvbench::exec_tag::sync, [&](nvbench::launch& launch) { do_not_optimize(cuda::std::unique(cuda_policy(alloc, launch), in.begin(), in.end(), cuda::std::equal_to{})); }); } NVBENCH_BENCH_TYPES(with_comp, NVBENCH_TYPE_AXES(fundamental_types)) .set_name("with_comp") .set_type_axes_names({"T{ct}"}) .add_int64_power_of_two_axis("Elements", nvbench::range(16, 28, 4));