[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,141 @@
//===----------------------------------------------------------------------===//
//
// Part of CUDA Experimental in 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/devices>
#include <cuda/hierarchy>
#include <cuda/launch>
#include <cuda/stream>
#include <cuda/type_traits>
#include <cuda/experimental/coop.cuh>
#include <cuda/experimental/group.cuh>
#include "testing.cuh"
template <class T>
__device__ T make_instance_for(unsigned rank)
{
if constexpr (cuda::is_vector_type_v<T>)
{
using U = cuda::scalar_type_t<T>;
return T{static_cast<U>(rank), static_cast<U>(rank), static_cast<U>(rank)};
}
else
{
return static_cast<T>(rank);
}
}
template <class T, class Group>
__device__ void test_group(const Group& group)
{
// Exit all threads that are not part of the group.
if (!cuda::gpu_thread.is_part_of(group))
{
return;
}
const auto my_rank = cuda::gpu_thread.rank_as<unsigned>(group);
const auto my_value = make_instance_for<T>(my_rank);
// Test identity.
REQUIRE(cudax::coop::shuffle(group, my_value, my_rank) == my_value);
// Test broadcast from root rank.
REQUIRE(cudax::coop::shuffle(group, my_value, 0) == make_instance_for<T>(0));
// Test broadcast from last rank.
{
const auto other_rank = cuda::gpu_thread.count_as<unsigned>(group) - 1;
REQUIRE(cudax::coop::shuffle(group, my_value, other_rank) == make_instance_for<T>(other_rank));
}
// Test my_rank + 1.
{
const auto other_rank = (my_rank + 1) % cuda::gpu_thread.count_as<unsigned>(group);
REQUIRE(cudax::coop::shuffle(group, my_value, other_rank) == make_instance_for<T>(other_rank));
}
// Test my_rank + 6.
{
const auto other_rank = (my_rank + 6) % cuda::gpu_thread.count_as<unsigned>(group);
REQUIRE(cudax::coop::shuffle(group, my_value, other_rank) == make_instance_for<T>(other_rank));
}
// Test my_rank +- 1 based on whether my_rank is even or not.
{
const auto other_rank =
((my_rank % 2 == 0) ? my_rank + 1 : my_rank - 1) % cuda::gpu_thread.count_as<unsigned>(group);
REQUIRE(cudax::coop::shuffle(group, my_value, other_rank) == make_instance_for<T>(other_rank));
}
// Test my_rank +- 3 based on whether my_rank is even or not.
{
const auto other_rank =
((my_rank % 2 == 0) ? my_rank + 3 : my_rank - 3) % cuda::gpu_thread.count_as<unsigned>(group);
REQUIRE(cudax::coop::shuffle(group, my_value, other_rank) == make_instance_for<T>(other_rank));
}
}
struct CustomBinaryPartition
{
template <class MappingResult>
__device__ bool operator()(MappingResult mapping_result)
{
switch (mapping_result.unit_rank())
{
case 1:
case 5:
case 14:
case 15:
case 31:
return true;
default:
return false;
}
}
};
template <class T, class Config>
__device__ void test_type(const Config& config)
{
const cudax::this_warp warp{config};
test_group<T>(cudax::group{cuda::gpu_thread, warp, cudax::identity_mapping{}, cudax::lane_synchronizer{}});
test_group<T>(cudax::group{cuda::gpu_thread, warp, cudax::group_by<4>{}, cudax::lane_synchronizer{}});
test_group<T>(cudax::group{cuda::gpu_thread, warp, cudax::group_by{1}, cudax::lane_synchronizer{}});
test_group<T>(
cudax::group{cuda::gpu_thread, warp, cudax::group_by{3, cudax::non_exhaustive}, cudax::lane_synchronizer{}});
test_group<T>(
cudax::group{cuda::gpu_thread, warp, cudax::binary_partition{CustomBinaryPartition{}}, cudax::lane_synchronizer{}});
}
struct TestKernel
{
template <class Config>
__device__ void operator()(const Config& config)
{
test_type<signed char>(config);
test_type<unsigned>(config);
test_type<unsigned long long>(config);
test_type<longlong3>(config);
}
};
C2H_TEST("shuffle/threads_within_warp", "[shuffle][threads_within_warp]")
{
const auto device = cuda::devices[0];
const cuda::stream stream{device};
const auto config = cuda::make_config(cuda::grid_dims<1>(), cuda::block_dims<32>());
cuda::launch(stream, config, TestKernel{});
stream.sync();
}