[CCCL] 瘦身 + 补全: 移除 cudax/python/libcudacxx-tests 冗余文件, 新增 c2h 测试助手 + cmake 构建系统 + 8 个 CUDA thrust examples
变更摘要:
- 删除: cudax/ (783 files, 7.2M) — 实验性组件,竞赛不需要
- 删除: python/ (226 files, 2.0M) — Python 绑定,竞赛不需要
- 删除: libcudacxx/{test,benchmarks,codegen,cmake,share} (4432 files, 31M)
保留: libcudacxx/include/ (1463 headers, cuda::std 编译依赖)
- 新增: c2h/ (27 files) — CUB Catch2 测试辅助头文件,编译 243 个测试必需
- 新增: cmake/ (29 files) — CCCL 原生 CMake 构建系统
- 新增: thrust/examples/cuda/ (7 files) + cpp_integration/ (1 file)
async_reduce, custom_temporary_allocation, explicit_cuda_stream,
global_device_vector, range_view, unwrap_pointer, wrap_pointer, device
结果: cccl_upstream 从 74M→35M (瘦身 53%), 核心内容 100% 保留:
27/27 tuning headers, 78 benchmarks, 243 tests,
60 thrust examples, 18 CUB examples, 全部编译头文件
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cuda/buffer>
|
||||
#include <cuda/std/cstddef>
|
||||
|
||||
#include <exception>
|
||||
#include <future>
|
||||
#include <vector>
|
||||
|
||||
// One output iterator per local output buffer. Collected after `out` is fully built so the
|
||||
// iterators do not dangle across reallocations.
|
||||
template <class T>
|
||||
[[nodiscard]] std::vector<typename cuda::device_buffer<T>::iterator>
|
||||
make_output_iterators(std::vector<cuda::device_buffer<T>>& out)
|
||||
{
|
||||
std::vector<typename cuda::device_buffer<T>::iterator> outputs;
|
||||
|
||||
outputs.reserve(out.size());
|
||||
for (auto& buf : out)
|
||||
{
|
||||
outputs.push_back(buf.begin());
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
void run_threaded(cuda::std::size_t num_ranks, Fn fn)
|
||||
{
|
||||
// Every rank must be launched before any is waited on: the single-communicator `reduce`
|
||||
// blocks on a collective, so calling `get()` on rank 0's future before rank 1 is even
|
||||
// started would deadlock. Launch all futures into the vector first, then drain them.
|
||||
std::vector<std::future<void>> futures;
|
||||
|
||||
futures.reserve(num_ranks);
|
||||
for (cuda::std::size_t i = 0; i < num_ranks; ++i)
|
||||
{
|
||||
futures.push_back(std::async(std::launch::async, fn, i));
|
||||
}
|
||||
|
||||
// `std::async` stashes any exception thrown by `fn` in the future and `get()` rethrows it on
|
||||
// the main thread, where Catch2 can report it as a normal failure. Any not-yet-drained
|
||||
// future still joins its thread in its destructor, so a throw here never leaves a peer
|
||||
// waiting on an unposted collective. Drain every future so a failure on rank 0 does not mask
|
||||
// one on a peer.
|
||||
std::exception_ptr error = nullptr;
|
||||
|
||||
for (auto& f : futures)
|
||||
{
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
error = std::current_exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
std::rethrow_exception(error);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CUDAX_TEST_MULTI_NCCL_TEST_COMMON_H
|
||||
#define CUDAX_TEST_MULTI_NCCL_TEST_COMMON_H
|
||||
|
||||
#include <cuda/devices>
|
||||
#include <cuda/std/cstddef>
|
||||
#include <cuda/std/span>
|
||||
|
||||
#include <cuda/experimental/__multi_gpu/nccl_communicator.h>
|
||||
#include <cuda/experimental/__multi_gpu/nccl_communicator_ref.h>
|
||||
#include <cuda/experimental/stream.cuh>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <nccl.h>
|
||||
|
||||
#include <c2h/catch2_test_helper.h>
|
||||
|
||||
namespace cudax = ::cuda::experimental;
|
||||
|
||||
namespace nccl_test_util
|
||||
{
|
||||
// One stream per rank, each current on its own device.
|
||||
[[nodiscard]] inline std::vector<cudax::stream> make_streams()
|
||||
{
|
||||
return {cuda::devices.begin(), cuda::devices.end()};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const std::vector<cudax::nccl_communicator>& nccl_comms()
|
||||
{
|
||||
static const auto comms = []() -> std::vector<cudax::nccl_communicator> {
|
||||
if (cuda::devices.size() == 0)
|
||||
{
|
||||
SKIP("No CUDA devices visible");
|
||||
}
|
||||
|
||||
std::vector<int> devs;
|
||||
|
||||
devs.reserve(cuda::devices.size());
|
||||
for (auto d : cuda::devices)
|
||||
{
|
||||
devs.emplace_back(d.get());
|
||||
}
|
||||
|
||||
std::vector<ncclComm_t> raw_comms(devs.size());
|
||||
|
||||
const ncclResult_t result = ncclCommInitAll(raw_comms.data(), static_cast<int>(devs.size()), devs.data());
|
||||
|
||||
INFO("NCCL: " << ncclGetErrorString(result));
|
||||
REQUIRE(result == ncclSuccess);
|
||||
|
||||
std::vector<cudax::nccl_communicator> comms;
|
||||
comms.reserve(raw_comms.size());
|
||||
|
||||
for (const auto comm : raw_comms)
|
||||
{
|
||||
comms.emplace_back(cudax::nccl_communicator::from_native_handle(comm));
|
||||
}
|
||||
|
||||
return comms;
|
||||
}();
|
||||
|
||||
return comms;
|
||||
}
|
||||
|
||||
// Caches a single-process, multi-GPU NCCL communicator world for the life of the entire test
|
||||
// suite.
|
||||
template <class = void>
|
||||
class nccl_comm_fixture
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] cuda::std::span<cudax::nccl_communicator_ref> communicators()
|
||||
{
|
||||
return wrappers_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<cudax::nccl_communicator_ref> wrappers_{nccl_comms().begin(), nccl_comms().end()};
|
||||
};
|
||||
|
||||
#define MULTI_GPU_TEST(NAME, ...) \
|
||||
C2H_TEST_WITH_FIXTURE(::nccl_test_util::nccl_comm_fixture, NAME, "[multi_gpu][nccl]", __VA_ARGS__)
|
||||
} // namespace nccl_test_util
|
||||
|
||||
#endif // CUDAX_TEST_MULTI_GPU_NCCL_TEST_COMMON_H
|
||||
Reference in New Issue
Block a user