[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,15 @@
libcudacxx_add_pretty_printer_test(
NAME buffer
SOURCES source.cu
CASES
# gersemi: off
--case inspect_normal 1 buffer.normal normal_values
--case inspect_alias 1 buffer.alias aliased_values
--case inspect_vector 1 buffer.vector.0 "buffer_vector[0]"
--case inspect_vector 1 buffer.vector.1 "buffer_vector[1]"
--case inspect_host_device 1 buffer.host_device host_device_values
--case inspect_empty 1 buffer.empty empty_values
--case inspect_before_update 1 buffer.update.before updated_values
--case inspect_after_update 1 buffer.update.after updated_values
# gersemi: on
)

View File

@@ -0,0 +1,63 @@
=============== buffer.normal begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=10, align=4, data=<address> (device) = {
[0] = -56,
[1] = 22,
[2] = 94,
[3] = -13,
[4] = 7,
[5] = 41,
[6] = -82,
[7] = 0,
[8] = 63,
[9] = -5
}
=============== buffer.normal end ===============
=============== buffer.alias begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) = {
[0] = 17,
[1] = -31,
[2] = 8,
[3] = 55
}
=============== buffer.alias end ===============
=============== buffer.vector.0 begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=3, align=4, data=<address> (device) = {
[0] = -2,
[1] = 4,
[2] = 6
}
=============== buffer.vector.0 end ===============
=============== buffer.vector.1 begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=3, align=4, data=<address> (device) = {
[0] = 11,
[1] = -9,
[2] = 27
}
=============== buffer.vector.1 end ===============
=============== buffer.host_device begin ===============
cuda::buffer<int, cuda::mr::device_accessible, cuda::mr::host_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible, cuda::mr::host_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (host/device) = {
[0] = 3,
[1] = 14,
[2] = -15,
[3] = 92
}
=============== buffer.host_device end ===============
=============== buffer.empty begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=0, align=4, data=0x0 (device)
=============== buffer.empty end ===============
=============== buffer.update.before begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) = {
[0] = 1,
[1] = 2,
[2] = 3,
[3] = 4
}
=============== buffer.update.before end ===============
=============== buffer.update.after begin ===============
cuda::buffer<int, cuda::mr::device_accessible> mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) = {
[0] = -8,
[1] = 13,
[2] = 21,
[3] = -34
}
=============== buffer.update.after end ===============

View File

@@ -0,0 +1,63 @@
=============== buffer.normal begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=10, align=4, data=<address> (device) {
[0] = -56
[1] = 22
[2] = 94
[3] = -13
[4] = 7
[5] = 41
[6] = -82
[7] = 0
[8] = 63
[9] = -5
}
=============== buffer.normal end ===============
=============== buffer.alias begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) {
[0] = 17
[1] = -31
[2] = 8
[3] = 55
}
=============== buffer.alias end ===============
=============== buffer.vector.0 begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=3, align=4, data=<address> (device) {
[0] = -2
[1] = 4
[2] = 6
}
=============== buffer.vector.0 end ===============
=============== buffer.vector.1 begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=3, align=4, data=<address> (device) {
[0] = 11
[1] = -9
[2] = 27
}
=============== buffer.vector.1 end ===============
=============== buffer.host_device begin ===============
(cuda::buffer<int, cuda::mr::device_accessible, cuda::mr::host_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible, cuda::mr::host_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (host/device) {
[0] = 3
[1] = 14
[2] = -15
[3] = 92
}
=============== buffer.host_device end ===============
=============== buffer.empty begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=0, align=4, data=0x0 (device)
=============== buffer.empty end ===============
=============== buffer.update.before begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) {
[0] = 1
[1] = 2
[2] = 3
[3] = 4
}
=============== buffer.update.before end ===============
=============== buffer.update.after begin ===============
(cuda::buffer<int, cuda::mr::device_accessible>) mr=cuda::mr::any_resource<cuda::mr::device_accessible> @ <address>, stream=<address>, size=4, align=4, data=<address> (device) {
[0] = -8
[1] = 13
[2] = 21
[3] = -34
}
=============== buffer.update.after end ===============

View File

@@ -0,0 +1,102 @@
// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <cuda/buffer>
#include <cuda/memory_resource>
#include <cuda/std/array>
#include <cuda/stream>
#include <vector>
#include <cuda_runtime_api.h>
template <class T>
[[gnu::noinline]] void keep_for_debugger(const T& value)
{
asm volatile("" : : "g"(&value) : "memory");
}
[[gnu::noinline]] void inspect_normal(const cuda::device_buffer<int>& values)
{
keep_for_debugger(values);
}
using device_buffer_alias = cuda::buffer<int, cuda::mr::device_accessible>;
[[gnu::noinline]] void inspect_alias(const device_buffer_alias& values)
{
keep_for_debugger(values);
}
[[gnu::noinline]] void inspect_vector(const std::vector<cuda::device_buffer<int>>& values)
{
keep_for_debugger(values[0]);
keep_for_debugger(values[1]);
}
template <class Buffer>
[[gnu::noinline]] void inspect_host_device(const Buffer& values)
{
keep_for_debugger(values);
}
[[gnu::noinline]] void inspect_empty(const cuda::device_buffer<int>& values)
{
keep_for_debugger(values);
}
[[gnu::noinline]] void inspect_before_update(const cuda::device_buffer<int>& values)
{
keep_for_debugger(values);
}
[[gnu::noinline]] void inspect_after_update(const cuda::device_buffer<int>& values)
{
keep_for_debugger(values);
}
int main()
{
constexpr cuda::device_ref device{0};
cuda::stream stream{device};
const cuda::std::array normal_host_values{-56, 22, 94, -13, 7, 41, -82, 0, 63, -5};
const auto normal_values = cuda::make_device_buffer<int>(stream, device, normal_host_values);
const cuda::std::array alias_host_values{17, -31, 8, 55};
const device_buffer_alias aliased_values = cuda::make_device_buffer<int>(stream, device, alias_host_values);
std::vector<cuda::device_buffer<int>> buffer_vector;
buffer_vector.emplace_back(cuda::make_device_buffer<int>(stream, device, cuda::std::array{-2, 4, 6}));
buffer_vector.emplace_back(cuda::make_device_buffer<int>(stream, device, cuda::std::array{11, -9, 27}));
cuda::mr::legacy_managed_memory_resource managed_resource;
const cuda::std::array host_device_host_values{3, 14, -15, 92};
const auto host_device_values = cuda::make_buffer<int>(stream, managed_resource, host_device_host_values);
const auto empty_values = cuda::make_device_buffer<int>(stream, device);
const cuda::std::array initial_updated_host_values{1, 2, 3, 4};
auto updated_values = cuda::make_device_buffer<int>(stream, device, initial_updated_host_values);
stream.sync();
inspect_normal(normal_values);
inspect_alias(aliased_values);
inspect_vector(buffer_vector);
inspect_host_device(host_device_values);
inspect_empty(empty_values);
inspect_before_update(updated_values);
const cuda::std::array replacement_host_values{-8, 13, 21, -34};
if (cudaMemcpyAsync(updated_values.data(),
replacement_host_values.data(),
replacement_host_values.size() * sizeof(*updated_values.data()),
cudaMemcpyDefault,
stream.get())
!= cudaSuccess)
{
return 1;
}
stream.sync();
inspect_after_update(updated_values);
}