feat(cccl): integrate missing CCCL directories — python/, ci/, .agent/, docs/, test/

Sparse-checkout from NVIDIA/cccl main branch to complete cccl_upstream:

Added:
- python/cuda_cccl/ (226 files) — Python bindings for device-level algorithms
  Critical for muh toolchain: cuda.compute.reduce_into, scan, radix_sort, etc.
  Includes 204 .py files with full test coverage for all 27 algorithms
- ci/ (163 files) — Build/test infrastructure
  build_cub.sh, test_cub.sh, build_and_test_targets.sh, matrix.yaml
  Directly maps to our [INFRA-CI] and [INFRA-BUILD] items
- .agent/skills/ (7 files) — NVIDIA's own agent skills for CCCL
  cccl-style/SKILL.md, cccl-test/SKILL.md, sass-diff/SKILL.md
- docs/ (491 files) — Official CCCL documentation
  CI references, CMake guides, Python compute docs, libcudacxx PTX docs
- test/ (12 files) — Top-level integration tests (cuda_smoke, stdpar)
- Root configs: .clang-format, .clang-tidy, CONTRIBUTING.md, pyproject.toml
- CLAUDE.md symlink → AGENTS.md (NVIDIA's standard)

cccl_upstream now mirrors full NVIDIA/cccl structure:
  Before: 42M (cub + thrust + libcudacxx + cudax + c + examples + benchmarks)
  After:  53M (+python +ci +docs +.agent +test +configs)

This completes the CCCL base needed for:
- [muh-bench] items: ci/util/build_and_test_targets.sh for targeted builds
- [CCCL-verify] items: python/cuda_cccl/tests/ as reference implementations
- [CCCL-test] items: ci/test_cub.sh, ci/test_thrust.sh
- Agent workflow: .agent/skills/ for consistent style and test patterns
This commit is contained in:
muh-bot
2026-08-07 02:34:33 +00:00
parent 3f97dca7ad
commit 2a7ca101d7
908 changed files with 121615 additions and 0 deletions

View File

@@ -0,0 +1 @@
add_subdirectory(cmake)

View File

@@ -0,0 +1,78 @@
set(
cmake_opts
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
)
# Temporary installation prefix for tests against installed project:
set(tmp_install_prefix "${CMAKE_CURRENT_BINARY_DIR}/test_install")
foreach (root_type IN ITEMS SOURCE INSTALL)
if (root_type STREQUAL "INSTALL")
set(cccl_root "${tmp_install_prefix}")
else()
set(cccl_root "${CCCL_SOURCE_DIR}")
endif()
set(comps DEFAULT Thrust CUB libcudacxx)
if (CCCL_ENABLE_UNSTABLE)
list(APPEND comps cudax)
endif()
foreach (components IN LISTS comps)
set(package_types CCCL)
if (NOT components STREQUAL "DEFAULT")
list(APPEND package_types NATIVE)
endif()
if (root_type STREQUAL "SOURCE")
list(APPEND package_types SUBDIR)
endif()
foreach (package_type IN LISTS package_types)
string(TOLOWER "${root_type}.${package_type}.${components}" suffix)
cccl_add_compile_test(
test_name
cccl.test.cmake
test_export
"${suffix}"
${cmake_opts}
"-DCCCL_ROOT=${cccl_root}"
"-DCOMPONENTS=${components}"
"-DPACKAGE_TYPE=${package_type}"
"-DCCCL_ENABLE_UNSTABLE=${CCCL_ENABLE_UNSTABLE}"
)
if (root_type STREQUAL "INSTALL")
set_tests_properties(
${test_name}
PROPERTIES FIXTURES_REQUIRED install_tree
)
endif()
endforeach() # package_type
endforeach() # components
endforeach() # root_type
################################################################################
# Install tree fixtures
add_test(
NAME cccl.test.cmake.install_tree.install
# gersemi: off
COMMAND
"${CMAKE_COMMAND}"
--install "${CCCL_BINARY_DIR}"
--prefix "${tmp_install_prefix}"
# gersemi: on
)
set_tests_properties(
cccl.test.cmake.install_tree.install
PROPERTIES FIXTURES_SETUP install_tree
)
add_test(
NAME cccl.test.cmake.install_tree.cleanup
COMMAND "${CMAKE_COMMAND}" -E rm -rf "${tmp_install_prefix}"
)
set_tests_properties(
cccl.test.cmake.install_tree.cleanup
PROPERTIES FIXTURES_CLEANUP install_tree
)

View File

@@ -0,0 +1,166 @@
# Test the CMake packages for CCCL and all subprojects.
#
# Parameters:
# - CCCL_ROOT [Path] Root of the CCCL repo, or an installation root.
# - COMPONENTS [StringList] {Thrust CUB libcudacxx} Which CCCL subprojects
# should be found.
# - PACKAGE_TYPE [String] {CCCL | NATIVE | SUBDIR}:
# - CCCL -> `find_package(CCCL COMPONENTS <subproject>)`
# - NATIVE -> `find_package(<subproject>)`
# - SUBDIR -> `set(CCCL_REQUIRED_COMPONENTS <subproject>)`
# `add_subdirectory(${cccl_root})`
cmake_minimum_required(VERSION 3.21)
project(CCCLTestExport LANGUAGES CXX)
include(CTest)
enable_testing()
set(CCCL_ROOT "" CACHE PATH "Root of the CCCL repo, or an installation root.")
set(
COMPONENTS
""
CACHE STRING
"DEFAULT for no components, or semi-colon delimited list of Thrust, CUB, and/or libcudacxx."
)
set(
PACKAGE_TYPE
""
CACHE STRING
"CCCL: Find CCCL with subpackages as components; NATIVE: Find subpackages directly; SUBDIR: add_subdirectory(${CCCL_ROOT}"
)
set_property(CACHE PACKAGE_TYPE PROPERTY STRINGS CCCL NATIVE SUBDIR)
message(STATUS "CCCL_ROOT=${CCCL_ROOT}")
message(STATUS "COMPONENTS=${COMPONENTS}")
message(STATUS "PACKAGE_TYPE=${PACKAGE_TYPE}")
function(do_find_package pkg_name pkg_prefix)
list(
APPEND arg_list
REQUIRED
${ARGN}
NO_DEFAULT_PATH
HINTS
"${pkg_prefix}"
)
list(JOIN arg_list " " arg_str)
message(STATUS "Executing: find_package(${pkg_name} ${arg_str})")
find_package(${pkg_name} ${arg_list})
if (NOT ${pkg_name}_FOUND)
message(FATAL_ERROR "Failed: find_package(${pkg_name} ${arg_str})")
endif()
# Re-execute find_package to ensure that repeated calls don't break:
find_package(${pkg_name} ${arg_list})
endfunction()
# Run find package with the requested configuration:
if (PACKAGE_TYPE STREQUAL "CCCL")
if (COMPONENTS STREQUAL "DEFAULT")
do_find_package(CCCL "${CCCL_ROOT}")
else()
do_find_package(CCCL "${CCCL_ROOT}" COMPONENTS ${COMPONENTS})
endif()
elseif (PACKAGE_TYPE STREQUAL "NATIVE")
if (COMPONENTS STREQUAL "DEFAULT")
message(
FATAL_ERROR
"COMPONENTS=DEFAULT incompatible with PACKAGE_TYPE=NATIVE"
)
endif()
foreach (component IN LISTS COMPONENTS)
do_find_package(${component} "${CCCL_ROOT}")
endforeach()
elseif (PACKAGE_TYPE STREQUAL "SUBDIR")
if (COMPONENTS STREQUAL "DEFAULT")
set(CCCL_REQUIRED_COMPONENTS)
else()
set(CCCL_REQUIRED_COMPONENTS ${COMPONENTS})
endif()
add_subdirectory("${CCCL_ROOT}" "${CMAKE_CURRENT_BINARY_DIR}/subdir")
else()
message(FATAL_ERROR "Invalid PACKAGE_TYPE: ${PACKAGE_TYPE}")
endif()
if (COMPONENTS STREQUAL "DEFAULT")
set(COMPONENTS libcudacxx CUB Thrust)
if (CCCL_ENABLE_UNSTABLE)
list(APPEND COMPONENTS cudax)
endif()
endif()
foreach (component IN LISTS COMPONENTS)
set(test_target version_check.${component})
set(component_target "${component}::${component}")
add_executable(${test_target} version_check.cxx)
target_compile_features(${test_target} PUBLIC cxx_std_17)
target_link_libraries(${test_target} PRIVATE ${component_target})
add_test(NAME ${test_target} COMMAND ${test_target})
if (component STREQUAL "libcudacxx")
math(
EXPR
component_cmake_version
"(${LIBCUDACXX_VERSION_MAJOR} * 1000000) +
${LIBCUDACXX_VERSION_MINOR} * 1000 +
${LIBCUDACXX_VERSION_PATCH}"
)
target_compile_definitions(
${test_target}
PRIVATE
"VERSION_HEADER=cuda/std/version"
"VERSION_MACRO=_LIBCUDACXX_CUDA_API_VERSION"
"EXPECTED_VERSION=${component_cmake_version}"
)
elseif (component STREQUAL "CUB")
math(
EXPR
component_cmake_version
"(${CUB_VERSION_MAJOR} * 100000) +
${CUB_VERSION_MINOR} * 100 +
${CUB_VERSION_PATCH}"
)
target_compile_definitions(
${test_target}
PRIVATE
"VERSION_HEADER=cub/version.cuh"
"VERSION_MACRO=CUB_VERSION"
"EXPECTED_VERSION=${component_cmake_version}"
)
elseif (component STREQUAL "Thrust")
math(
EXPR
component_cmake_version
"(${THRUST_VERSION_MAJOR} * 100000) +
${THRUST_VERSION_MINOR} * 100 +
${THRUST_VERSION_PATCH}"
)
target_compile_definitions(
${test_target}
PRIVATE
"VERSION_HEADER=thrust/version.h"
"VERSION_MACRO=THRUST_VERSION"
"EXPECTED_VERSION=${component_cmake_version}"
)
elseif (component STREQUAL "cudax")
math(
EXPR
component_cmake_version
"(${CUDAX_VERSION_MAJOR} * 1000000) +
${CUDAX_VERSION_MINOR} * 1000 +
${CUDAX_VERSION_PATCH}"
)
target_compile_definitions(
${test_target}
PRIVATE
"VERSION_HEADER=cuda/experimental/version.cuh"
"VERSION_MACRO=CUDAX_VERSION"
"EXPECTED_VERSION=${component_cmake_version}"
)
else()
message(
FATAL_ERROR
"Valid COMPONENTS are (case-sensitive): Thrust;CUB;libcudacxx;cudax"
)
endif()
endforeach()

View File

@@ -0,0 +1,20 @@
// Compile with:
// -DVERSION_HEADER=include/path/for/version.h
// -DEXPECTED_VERSION=XXYYZZ
// -DVERSION_MACRO=PROJECT_VERSION
#define HEADER <VERSION_HEADER>
#include HEADER
#include <cstdio>
#define DETECTED_VERSION VERSION_MACRO
int main()
{
printf("Expected version: %d\n"
"Detected version: %d\n",
EXPECTED_VERSION,
VERSION_MACRO);
return EXPECTED_VERSION == DETECTED_VERSION ? 0 : 1;
}

View File

@@ -0,0 +1,14 @@
# Simple smoke test verifying the CUDA runtime is functional (device visible,
# kernel launch + managed-memory round-trip work). Invoked explicitly from CI
# via ci/build_common.sh before GPU test presets run. Not registered in CTest
# (GPU-only; CPU test presets such as thrust-cpu would pick it up otherwise).
#
# Declare CUDA inside this subproject only so the root project() can stay
# CXX-only (external consumers via add_subdirectory(cccl) see no change).
project(CCCL_CUDA_SMOKE LANGUAGES CUDA)
cccl_get_catch2()
cccl_add_executable(${CCCL_CUDA_SMOKE_TARGET} SOURCES cuda_runtime_smoke.cu)
target_link_libraries(${CCCL_CUDA_SMOKE_TARGET} PRIVATE Catch2::Catch2WithMain)

View File

@@ -0,0 +1,184 @@
//===----------------------------------------------------------------------===//
//
// Part of CUDA C++ Core Libraries, 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 <cuda_runtime.h>
#include <catch2/catch_test_macros.hpp>
#define CUDART_REQUIRE(call) REQUIRE((call) == cudaSuccess)
__global__ void increment_kernel(int* p, int n)
{
int idx = static_cast<int>(blockIdx.x * blockDim.x + threadIdx.x);
if (idx < n)
{
p[idx] += 1;
}
}
TEST_CASE("CUDA device is available", "[cuda_smoke]")
{
int device_count = 0;
CUDART_REQUIRE(cudaGetDeviceCount(&device_count));
REQUIRE(device_count > 0);
CUDART_REQUIRE(cudaSetDevice(0));
cudaDeviceProp props{};
CUDART_REQUIRE(cudaGetDeviceProperties(&props, 0));
REQUIRE(props.name[0] != '\0');
REQUIRE(cudaGetLastError() == cudaSuccess);
}
TEST_CASE("cudaMallocManaged round-trip works", "[cuda_smoke][managed_memory]")
{
(void) cudaGetLastError(); // clear any pre-existing error state
int managed_supported = 0;
CUDART_REQUIRE(cudaDeviceGetAttribute(&managed_supported, cudaDevAttrManagedMemory, 0));
if (!managed_supported)
{
SKIP("Device does not support managed memory (cudaDevAttrManagedMemory == 0).");
}
constexpr int n = 256;
int* p = nullptr;
CUDART_REQUIRE(cudaMallocManaged(&p, n * sizeof(int)));
for (int i = 0; i < n; ++i) // host write
{
p[i] = i;
}
CUDART_REQUIRE(cudaDeviceSynchronize());
increment_kernel<<<4, 64>>>(p, n); // device transform
CUDART_REQUIRE(cudaGetLastError());
CUDART_REQUIRE(cudaDeviceSynchronize());
for (int i = 0; i < n; ++i) // host read-back
{
REQUIRE(p[i] == i + 1);
}
CUDART_REQUIRE(cudaFree(p));
REQUIRE(cudaGetLastError() == cudaSuccess);
}
// smoke test for GPU memory allocation/deallocation
TEST_CASE("cudaMalloc/cudaFree round-trip works", "[cuda_smoke][device_memory]")
{
(void) cudaGetLastError();
constexpr int n = 256;
int* d_ptr = nullptr;
CUDART_REQUIRE(cudaMalloc(&d_ptr, n * sizeof(int)));
REQUIRE(d_ptr != nullptr);
int h_ins[n];
for (int i = 0; i < n; ++i)
{
h_ins[i] = i;
}
CUDART_REQUIRE(cudaMemcpy(d_ptr, h_ins, n * sizeof(int), cudaMemcpyHostToDevice));
increment_kernel<<<4, 64>>>(d_ptr, n);
CUDART_REQUIRE(cudaGetLastError());
CUDART_REQUIRE(cudaDeviceSynchronize());
int h_outs[n];
CUDART_REQUIRE(cudaMemcpy(h_outs, d_ptr, n * sizeof(int), cudaMemcpyDeviceToHost));
for (int i = 0; i < n; ++i)
{
REQUIRE(h_outs[i] == i + 1);
}
CUDART_REQUIRE(cudaFree(d_ptr));
REQUIRE(cudaGetLastError() == cudaSuccess);
}
// smoke test for pinned host memory
TEST_CASE("cudaMallocHost round-trip works", "[cuda_smoke][pinned_memory]")
{
(void) cudaGetLastError();
constexpr int n = 256;
int* h_pinned = nullptr;
CUDART_REQUIRE(cudaMallocHost(&h_pinned, n * sizeof(int)));
REQUIRE(h_pinned != nullptr);
int* d_ptr = nullptr;
CUDART_REQUIRE(cudaMalloc(&d_ptr, n * sizeof(int)));
REQUIRE(d_ptr != nullptr);
for (int i = 0; i < n; ++i)
{
h_pinned[i] = i;
}
CUDART_REQUIRE(cudaMemcpy(d_ptr, h_pinned, n * sizeof(int), cudaMemcpyHostToDevice));
increment_kernel<<<4, 64>>>(d_ptr, n);
CUDART_REQUIRE(cudaGetLastError());
CUDART_REQUIRE(cudaDeviceSynchronize());
CUDART_REQUIRE(cudaMemcpy(h_pinned, d_ptr, n * sizeof(int), cudaMemcpyDeviceToHost));
for (int i = 0; i < n; ++i)
{
REQUIRE(h_pinned[i] == i + 1);
}
CUDART_REQUIRE(cudaFree(d_ptr));
CUDART_REQUIRE(cudaFreeHost(h_pinned));
REQUIRE(cudaGetLastError() == cudaSuccess);
}
// smoke test for mapped pinned host memory
TEST_CASE("cudaHostAlloc mapped (zero-copy) works", "[cuda_smoke][pinned_memory][mapped]")
{
(void) cudaGetLastError();
int can_map = 0;
CUDART_REQUIRE(cudaDeviceGetAttribute(&can_map, cudaDevAttrCanMapHostMemory, 0));
if (!can_map)
{
SKIP("Device cannot map host memory (cudaDevAttrCanMapHostMemory == 0).");
}
constexpr int n = 256;
int* h_mapped = nullptr;
CUDART_REQUIRE(cudaHostAlloc(&h_mapped, n * sizeof(int), cudaHostAllocMapped));
REQUIRE(h_mapped != nullptr);
for (int i = 0; i < n; ++i)
{
h_mapped[i] = i;
}
int* d_view = nullptr;
CUDART_REQUIRE(cudaHostGetDevicePointer(&d_view, h_mapped, 0));
REQUIRE(d_view != nullptr);
increment_kernel<<<4, 64>>>(d_view, n);
CUDART_REQUIRE(cudaGetLastError());
CUDART_REQUIRE(cudaDeviceSynchronize());
for (int i = 0; i < n; ++i)
{
REQUIRE(h_mapped[i] == i + 1);
}
CUDART_REQUIRE(cudaFreeHost(h_mapped));
REQUIRE(cudaGetLastError() == cudaSuccess);
}

View File

@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.21)
# NOTE: this is build outside of the libcu++ test harness
project(CCCL_STDPAR_TESTS LANGUAGES CXX)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL NVHPC)
message(FATAL_ERROR "The stdpar tests require nvc++ for CMAKE_CXX_COMPILER.")
endif()
# Enable testing for the project
enable_testing()
find_package(
CCCL
CONFIG
REQUIRED
NO_DEFAULT_PATH # Only check the explicit HINTS below:
HINTS "${CMAKE_CURRENT_LIST_DIR}/../../lib/cmake/cccl/"
)
file(
GLOB test_files
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_LIST_DIR}"
CONFIGURE_DEPENDS
"tests/*.cpp"
)
function(cccl_add_stdpar_test test_file)
get_filename_component(test_name ${test_file} NAME_WE)
add_executable(stdpar_test_${test_name} ${test_file})
target_link_libraries(stdpar_test_${test_name} PUBLIC CCCL::CCCL)
# Ensure that we are testing with GPU support
target_compile_options(stdpar_test_${test_name} PUBLIC -stdpar=gpu)
target_link_options(stdpar_test_${test_name} PUBLIC -stdpar=gpu)
# Ensure that we are indeed testing the same CCCL version
target_compile_definitions(
stdpar_test_${test_name}
PUBLIC
CMAKE_CCCL_VERSION_MAJOR=${CCCL_VERSION_MAJOR}
CMAKE_CCCL_VERSION_MINOR=${CCCL_VERSION_MINOR}
CMAKE_CCCL_VERSION_PATCH=${CCCL_VERSION_PATCH}
)
# Register with ctest
add_test(NAME stdpar_test_${test_name} COMMAND stdpar_test_${test_name})
endfunction()
foreach (test IN LISTS test_files)
cccl_add_stdpar_test(${test})
endforeach()

View File

@@ -0,0 +1,52 @@
#include <algorithm>
#include <cstddef>
#include <execution>
#include <numeric>
#include <vector>
int main()
{
constexpr std::size_t N = 1 << 16;
auto all_one = [](const int val) {
return val == 1;
};
std::vector<int> in(N);
std::vector<int> out(N);
std::iota(in.begin(), in.end(), 0);
// Default op (difference)
std::adjacent_difference(std::execution::par, in.begin(), in.end(), out.begin());
if (out[0] != in[0])
{
return 1;
}
if (!std::all_of(out.begin() + 1, out.end(), all_one))
{
return 1;
}
// Custom binary op: sum of neighbors: out[0] = in[0]
std::fill(out.begin(), out.end(), 0);
std::adjacent_difference(std::execution::par, in.begin(), in.end(), out.begin(), [](int x, int y) {
return x + y;
});
if (out[0] != in[0])
{
return 1;
}
for (std::size_t i = 1; i < N; ++i)
{
const int expected = in[i] + in[i - 1];
if (out[i] != expected)
{
return 1;
}
}
return 0;
}

View File

@@ -0,0 +1,38 @@
#include <algorithm>
#include <cstddef>
#include <execution>
#include <vector>
// Ensure that we are indeed using the correct CCCL version
static_assert(CCCL_MAJOR_VERSION == CMAKE_CCCL_VERSION_MAJOR);
static_assert(CCCL_MINOR_VERSION == CMAKE_CCCL_VERSION_MINOR);
static_assert(CCCL_PATCH_VERSION == CMAKE_CCCL_VERSION_PATCH);
int main()
{
constexpr std::size_t N = 1 << 16;
std::vector<int> v(N, 1);
// All elements are 1, so this should be true
const bool all_ones = std::all_of(std::execution::par, v.begin(), v.end(), [](int x) {
return x == 1;
});
if (!all_ones)
{
return 1;
}
// Flip a single element in the middle, now all elements are not 1
v[N / 2] = 2;
const bool still_all_ones = std::all_of(std::execution::par, v.begin(), v.end(), [](int x) {
return x == 1;
});
if (still_all_ones)
{
return 1;
}
return 0;
}

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// Part of CUDA C++ Core Libraries, 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 <cuda/version>
#include <algorithm>
#include <cstddef>
#include <execution>
#include <vector>
// Ensure that we are indeed using the correct CCCL version
static_assert(CCCL_MAJOR_VERSION == CMAKE_CCCL_VERSION_MAJOR);
static_assert(CCCL_MINOR_VERSION == CMAKE_CCCL_VERSION_MINOR);
static_assert(CCCL_PATCH_VERSION == CMAKE_CCCL_VERSION_PATCH);
int main()
{
constexpr std::size_t num_items = 1 << 16;
std::vector<int> values(num_items, 0);
constexpr auto is_one = [](const int value) {
return value == 1;
};
const bool initially_contains_one = std::any_of(std::execution::par, values.begin(), values.end(), is_one);
if (initially_contains_one)
{
return 1;
}
values[num_items / 2] = 1;
const bool contains_one = std::any_of(std::execution::par, values.begin(), values.end(), is_one);
const bool empty_has_a_one = std::any_of(std::execution::par, values.begin(), values.begin(), is_one);
if (!contains_one || empty_has_a_one)
{
return 1;
}
return 0;
}

View File

@@ -0,0 +1,26 @@
#include <algorithm>
#include <cassert>
#include <execution>
#include <numeric>
#include <vector>
// Ensure that we are indeed using the correct CCCL version
static_assert(CCCL_MAJOR_VERSION == CMAKE_CCCL_VERSION_MAJOR);
static_assert(CCCL_MINOR_VERSION == CMAKE_CCCL_VERSION_MINOR);
static_assert(CCCL_PATCH_VERSION == CMAKE_CCCL_VERSION_PATCH);
constexpr int N = 1000;
int main()
{
std::vector<int> v(N);
std::fill(std::execution::par_unseq, v.begin(), v.end(), 42);
int sum = std::reduce(std::execution::par_unseq, v.begin(), v.end(), 100, [](int a, int b) {
return a + b;
});
assert(sum == (42 * N) + 100);
sum = std::reduce(std::execution::par_unseq, v.begin(), v.end(), 100);
assert(sum == (42 * N) + 100);
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// Part of CUDA C++ Core Libraries, 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 <cuda/version>
#include <algorithm>
#include <cstddef>
#include <execution>
#include <numeric>
#include <vector>
// Ensure that we are indeed using the correct CCCL version
static_assert(CCCL_MAJOR_VERSION == CMAKE_CCCL_VERSION_MAJOR);
static_assert(CCCL_MINOR_VERSION == CMAKE_CCCL_VERSION_MINOR);
static_assert(CCCL_PATCH_VERSION == CMAKE_CCCL_VERSION_PATCH);
int main()
{
constexpr std::size_t num_items = 1 << 16;
std::vector<int> values(num_items);
const std::vector<int> offsets(num_items, 5);
std::vector<int> output(num_items, 0);
std::iota(values.begin(), values.end(), 0);
constexpr auto double_value = [](const int value) {
return value * 2;
};
constexpr auto add_values = [](const int lhs, const int rhs) {
return lhs + rhs;
};
const auto unary_end =
std::transform(std::execution::par, values.begin(), values.end(), output.begin(), double_value);
if (unary_end != output.end())
{
return 1;
}
for (std::size_t i = 0; i < num_items; ++i)
{
if (output[i] != values[i] * 2)
{
return 1;
}
}
const auto binary_end =
std::transform(std::execution::par, values.begin(), values.end(), offsets.begin(), output.begin(), add_values);
if (binary_end != output.end())
{
return 1;
}
for (std::size_t i = 0; i < num_items; ++i)
{
if (output[i] != values[i] + offsets[i])
{
return 1;
}
}
const auto empty_end =
std::transform(std::execution::par, values.begin(), values.begin(), output.begin(), double_value);
if (empty_end != output.begin())
{
return 1;
}
return 0;
}