[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,112 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF 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) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/__places/exec/green_context.cuh>
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
// Green contexts are only supported since CUDA 12.4
|
||||
#if _CCCL_CTK_AT_LEAST(12, 4)
|
||||
__global__ void axpy(double a, slice<const double> x, slice<double> y)
|
||||
{
|
||||
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int nthreads = gridDim.x * blockDim.x;
|
||||
|
||||
size_t n = x.extent(0);
|
||||
for (int ind = tid; ind < n; ind += nthreads)
|
||||
{
|
||||
y(ind) += a * x(ind);
|
||||
}
|
||||
}
|
||||
|
||||
void debug_info(cudaStream_t stream, CUgreenCtx g_ctx)
|
||||
{
|
||||
// Get the green context associated to that CUDA stream
|
||||
CUgreenCtx stream_cugc;
|
||||
cuda_safe_call(cuStreamGetGreenCtx(CUstream(stream), &stream_cugc));
|
||||
assert(stream_cugc != nullptr);
|
||||
|
||||
CUcontext stream_green_primary;
|
||||
CUcontext place_green_primary;
|
||||
|
||||
unsigned long long stream_ctxId;
|
||||
unsigned long long place_ctxId;
|
||||
|
||||
// Convert green contexts to primary contexts and get their ID
|
||||
cuda_safe_call(cuCtxFromGreenCtx(&stream_green_primary, stream_cugc));
|
||||
cuda_safe_call(cuCtxGetId(stream_green_primary, &stream_ctxId));
|
||||
|
||||
cuda_safe_call(cuCtxFromGreenCtx(&place_green_primary, g_ctx));
|
||||
cuda_safe_call(cuCtxGetId(place_green_primary, &place_ctxId));
|
||||
|
||||
// Make sure the stream belongs to the same green context as the execution place
|
||||
EXPECT(stream_ctxId == place_ctxId);
|
||||
}
|
||||
#endif // _CCCL_CTK_AT_LEAST(12, 4)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _CCCL_CTK_BELOW(12, 4)
|
||||
fprintf(stderr, "Green contexts are not supported by this version of CUDA: skipping test.\n");
|
||||
return 0;
|
||||
#else // ^^^ _CCCL_CTK_BELOW(12, 4) ^^^ / vvv _CCCL_CTK_AT_LEAST(12, 4) vvv
|
||||
int ndevs;
|
||||
const int num_sms = 8;
|
||||
cuda_safe_call(cudaGetDeviceCount(&ndevs));
|
||||
|
||||
stream_ctx ctx;
|
||||
const double alpha = 2.0;
|
||||
|
||||
int NITER = 30;
|
||||
const int n = 12;
|
||||
|
||||
double X[n], Y[n];
|
||||
|
||||
for (int ind = 0; ind < n; ind++)
|
||||
{
|
||||
X[ind] = 1.0 * ind;
|
||||
Y[ind] = 2.0 * ind - 3.0;
|
||||
}
|
||||
|
||||
auto handle_X = ctx.logical_data(make_slice(&X[0], n));
|
||||
auto handle_Y = ctx.logical_data(make_slice(&Y[0], n));
|
||||
|
||||
// The green_context_helper class automates the creation of green context views
|
||||
std::vector<green_context_helper> gc(ndevs);
|
||||
for (int devid = 0; devid < ndevs; devid++)
|
||||
{
|
||||
gc[devid] = green_context_helper(num_sms, devid);
|
||||
}
|
||||
|
||||
for (int iter = 0; iter < NITER; iter++)
|
||||
{
|
||||
for (int devid = 0; devid < ndevs; devid++)
|
||||
{
|
||||
auto& g_ctx = gc[devid];
|
||||
auto cnt = g_ctx.get_count();
|
||||
ctx.task(exec_place::green_ctx(g_ctx.get_view(iter % cnt)), handle_X.read(), handle_Y.rw())
|
||||
->*[&](cudaStream_t stream, auto dX, auto dY) {
|
||||
debug_info(stream, g_ctx.get_view(iter % cnt).g_ctx);
|
||||
axpy<<<16, 16, 0, stream>>>(alpha, dX, dY);
|
||||
};
|
||||
}
|
||||
}
|
||||
ctx.host_launch(handle_X.read(), handle_Y.read())->*[&](auto hX, auto hY) {
|
||||
for (int ind = 0; ind < n; ind++)
|
||||
{
|
||||
EXPECT(fabs(hX(ind) - 1.0 * ind) < 0.00001);
|
||||
EXPECT(fabs(hY(ind) - (2.0 * ind - 3.0) - NITER * ndevs * alpha * hX(ind)) < 0.00001);
|
||||
}
|
||||
};
|
||||
|
||||
ctx.finalize();
|
||||
#endif // ^^^ _CCCL_CTK_AT_LEAST(12, 4) ^^^
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF 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) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/__places/exec/green_context.cuh>
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
// Green contexts are only supported since CUDA 12.4
|
||||
#if _CCCL_CTK_AT_LEAST(12, 4)
|
||||
__global__ void axpy(double a, slice<const double> x, slice<double> y)
|
||||
{
|
||||
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int nthreads = gridDim.x * blockDim.x;
|
||||
|
||||
size_t n = x.extent(0);
|
||||
for (int ind = tid; ind < n; ind += nthreads)
|
||||
{
|
||||
y(ind) += a * x(ind);
|
||||
}
|
||||
}
|
||||
#endif // _CCCL_CTK_AT_LEAST(12, 4)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _CCCL_CTK_BELOW(12, 4)
|
||||
fprintf(stderr, "Green contexts are not supported by this version of CUDA: skipping test.\n");
|
||||
return 0;
|
||||
#else // ^^^ _CCCL_CTK_BELOW(12, 4) ^^^ / vvv _CCCL_CTK_AT_LEAST(12, 4) vvv
|
||||
int ndevs;
|
||||
const int num_sms = 16;
|
||||
cuda_safe_call(cudaGetDeviceCount(&ndevs));
|
||||
|
||||
graph_ctx ctx;
|
||||
const double alpha = 2.0;
|
||||
|
||||
int NITER = 30;
|
||||
const int n = 12;
|
||||
|
||||
double X[n], Y[n];
|
||||
|
||||
for (int ind = 0; ind < n; ind++)
|
||||
{
|
||||
X[ind] = 1.0 * ind;
|
||||
Y[ind] = 2.0 * ind - 3.0;
|
||||
}
|
||||
|
||||
auto handle_X = ctx.logical_data(make_slice(&X[0], n));
|
||||
auto handle_Y = ctx.logical_data(make_slice(&Y[0], n));
|
||||
|
||||
// The green_context_helper class automates the creation of green context views
|
||||
std::vector<green_context_helper> gc(ndevs);
|
||||
for (int devid = 0; devid < ndevs; devid++)
|
||||
{
|
||||
gc[devid] = green_context_helper(num_sms, devid);
|
||||
}
|
||||
|
||||
for (int iter = 0; iter < NITER; iter++)
|
||||
{
|
||||
for (int devid = 0; devid < ndevs; devid++)
|
||||
{
|
||||
auto& g_ctx = gc[devid];
|
||||
auto cnt = g_ctx.get_count();
|
||||
ctx.task(exec_place::green_ctx(g_ctx.get_view(iter % cnt)), handle_X.read(), handle_Y.rw())
|
||||
->*[&](cudaStream_t stream, auto dX, auto dY) {
|
||||
axpy<<<16, 16, 0, stream>>>(alpha, dX, dY);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ctx.host_launch(handle_X.read(), handle_Y.read())->*[&](auto hX, auto hY) {
|
||||
for (int ind = 0; ind < n; ind++)
|
||||
{
|
||||
EXPECT(fabs(hX(ind) - 1.0 * ind) < 0.00001);
|
||||
EXPECT(fabs(hY(ind) - (2.0 * ind - 3.0) - NITER * ndevs * alpha * hX(ind)) < 0.00001);
|
||||
}
|
||||
};
|
||||
|
||||
ctx.finalize();
|
||||
#endif // ^^^ _CCCL_CTK_AT_LEAST(12, 4) ^^^
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF 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) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/__places/exec/green_context.cuh>
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
// Green contexts are only supported since CUDA 12.4
|
||||
#if _CCCL_CTK_AT_LEAST(12, 4)
|
||||
__global__ void axpy(double a, slice<const double> x, slice<double> y)
|
||||
{
|
||||
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int nthreads = gridDim.x * blockDim.x;
|
||||
|
||||
size_t n = x.extent(0);
|
||||
for (int ind = tid; ind < n; ind += nthreads)
|
||||
{
|
||||
y(ind) += a * x(ind);
|
||||
}
|
||||
}
|
||||
|
||||
void debug_info(cudaStream_t stream, CUgreenCtx g_ctx)
|
||||
{
|
||||
// Get the green context associated to that CUDA stream
|
||||
CUgreenCtx stream_cugc;
|
||||
cuda_safe_call(cuStreamGetGreenCtx(CUstream(stream), &stream_cugc));
|
||||
assert(stream_cugc != nullptr);
|
||||
|
||||
CUcontext stream_green_primary;
|
||||
CUcontext place_green_primary;
|
||||
|
||||
unsigned long long stream_ctxId;
|
||||
unsigned long long place_ctxId;
|
||||
|
||||
// Convert green contexts to primary contexts and get their ID
|
||||
cuda_safe_call(cuCtxFromGreenCtx(&stream_green_primary, stream_cugc));
|
||||
cuda_safe_call(cuCtxGetId(stream_green_primary, &stream_ctxId));
|
||||
|
||||
cuda_safe_call(cuCtxFromGreenCtx(&place_green_primary, g_ctx));
|
||||
cuda_safe_call(cuCtxGetId(place_green_primary, &place_ctxId));
|
||||
|
||||
// Make sure the stream belongs to the same green context as the execution place
|
||||
EXPECT(stream_ctxId == place_ctxId);
|
||||
}
|
||||
#endif // _CCCL_CTK_AT_LEAST(12, 4)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _CCCL_CTK_BELOW(12, 4)
|
||||
fprintf(stderr, "Green contexts are not supported by this version of CUDA: skipping test.\n");
|
||||
return 0;
|
||||
#else // ^^^ _CCCL_CTK_BELOW(12, 4) ^^^ / vvv _CCCL_CTK_AT_LEAST(12, 4) vvv
|
||||
int ndevs;
|
||||
const int num_sms = 8;
|
||||
cuda_safe_call(cudaGetDeviceCount(&ndevs));
|
||||
|
||||
stream_ctx ctx;
|
||||
|
||||
int NITER = 8;
|
||||
const int n = 16 * 1024 * 1024;
|
||||
|
||||
std::vector<double> X(n);
|
||||
std::vector<double> Y(n);
|
||||
|
||||
for (int ind = 0; ind < n; ind++)
|
||||
{
|
||||
X[ind] = 1.0 * ind;
|
||||
Y[ind] = 2.0 * ind - 3.0;
|
||||
}
|
||||
|
||||
auto handle_X = ctx.logical_data(make_slice(&X[0], n));
|
||||
auto handle_Y = ctx.logical_data(make_slice(&Y[0], n));
|
||||
|
||||
std::vector<exec_place> exec_places;
|
||||
|
||||
// The green_context_helper class automates the creation of green context views
|
||||
std::vector<green_context_helper> gc(ndevs);
|
||||
for (int devid = 0; devid < ndevs; devid++)
|
||||
{
|
||||
gc[devid] = green_context_helper(num_sms, devid);
|
||||
|
||||
auto& g_ctx = gc[devid];
|
||||
auto cnt = g_ctx.get_count();
|
||||
for (size_t i = 0; i < cnt; i++)
|
||||
{
|
||||
exec_places.push_back(exec_place::green_ctx(g_ctx.get_view(i)));
|
||||
}
|
||||
}
|
||||
|
||||
auto where = make_grid(exec_places);
|
||||
|
||||
for (int iter = 0; iter < NITER; iter++)
|
||||
{
|
||||
ctx.parallel_for(blocked_partition(), where, handle_X.shape(), handle_X.rw(), handle_Y.read())
|
||||
->*[] __device__(size_t i, auto x, auto y) {
|
||||
x(i) += y(i);
|
||||
};
|
||||
}
|
||||
|
||||
ctx.finalize();
|
||||
#endif // ^^^ _CCCL_CTK_AT_LEAST(12, 4) ^^^
|
||||
}
|
||||
Reference in New Issue
Block a user