[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,161 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDAX__STREAM_STREAM_CUH
|
||||
#define _CUDAX__STREAM_STREAM_CUH
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#include <cuda_runtime_api.h>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/__device/device_ref.h>
|
||||
#include <cuda/__runtime/api_wrapper.h>
|
||||
#include <cuda/__stream/invalid_stream.h>
|
||||
|
||||
#include <cuda/experimental/__device/logical_device.cuh>
|
||||
#include <cuda/experimental/__stream/stream_ref.cuh> // IWYU pragma: export
|
||||
#include <cuda/experimental/__utility/ensure_current_device.cuh>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
//! @brief An owning wrapper for cudaStream_t.
|
||||
struct stream : stream_ref
|
||||
{
|
||||
// 0 is documented as default priority
|
||||
static constexpr int default_priority = 0;
|
||||
|
||||
//! @brief Constructs a stream on a specified device and with specified priority
|
||||
//!
|
||||
//! Priority is defaulted to stream::default_priority
|
||||
//!
|
||||
//! @throws cuda_error if stream creation fails
|
||||
explicit stream(device_ref __dev, int __priority = default_priority)
|
||||
: stream_ref(::cuda::__invalid_stream())
|
||||
{
|
||||
[[maybe_unused]] __ensure_current_device __dev_setter(__dev);
|
||||
_CCCL_TRY_CUDA_API(
|
||||
::cudaStreamCreateWithPriority, "Failed to create a stream", &__stream, cudaStreamNonBlocking, __priority);
|
||||
}
|
||||
|
||||
//! @brief Constructs a stream on a specified logical device and with specified priority
|
||||
//!
|
||||
//! Priority is defaulted to stream::default_priority
|
||||
//!
|
||||
//! @throws cuda_error if stream creation fails
|
||||
explicit stream(::cuda::experimental::logical_device __dev, int __priority = default_priority)
|
||||
: stream_ref(::cuda::__invalid_stream())
|
||||
{
|
||||
[[maybe_unused]] __ensure_current_device __dev_setter(__dev);
|
||||
_CCCL_TRY_CUDA_API(
|
||||
::cudaStreamCreateWithPriority, "Failed to create a stream", &__stream, cudaStreamNonBlocking, __priority);
|
||||
}
|
||||
|
||||
//! @brief Construct a new `stream` object into the moved-from state.
|
||||
//!
|
||||
//! @post `stream()` returns an invalid stream handle
|
||||
// Can't be constexpr because __invalid_stream isn't
|
||||
explicit stream(no_init_t) noexcept
|
||||
: stream_ref(::cuda::__invalid_stream())
|
||||
{}
|
||||
|
||||
//! @brief Move-construct a new `stream` object
|
||||
//!
|
||||
//! @param __other
|
||||
//!
|
||||
//! @post `__other` is in moved-from state.
|
||||
stream(stream&& __other) noexcept
|
||||
: stream(::cuda::std::exchange(__other.__stream, ::cuda::__invalid_stream()))
|
||||
{}
|
||||
|
||||
stream(const stream&) = delete;
|
||||
|
||||
//! Destroy the `stream` object
|
||||
//!
|
||||
//! @note If the stream fails to be destroyed, the error is silently ignored.
|
||||
~stream()
|
||||
{
|
||||
if (__stream != ::cuda::__invalid_stream())
|
||||
{
|
||||
// Needs to call driver API in case current device is not set, runtime version would set dev 0 current
|
||||
// Alternative would be to store the device and push/pop here
|
||||
[[maybe_unused]] auto status = ::cuda::__driver::__streamDestroyNoThrow(__stream);
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Move-assign a `stream` object
|
||||
//!
|
||||
//! @param __other
|
||||
//!
|
||||
//! @post `__other` is in a moved-from state.
|
||||
stream& operator=(stream&& __other) noexcept
|
||||
{
|
||||
stream __tmp(::cuda::std::move(__other));
|
||||
::cuda::std::swap(__stream, __tmp.__stream);
|
||||
return *this;
|
||||
}
|
||||
|
||||
stream& operator=(const stream&) = delete;
|
||||
|
||||
//! @brief Construct an `stream` object from a native `cudaStream_t` handle.
|
||||
//!
|
||||
//! @param __handle The native handle
|
||||
//!
|
||||
//! @return stream The constructed `stream` object
|
||||
//!
|
||||
//! @note The constructed `stream` object takes ownership of the native handle.
|
||||
[[nodiscard]] static stream from_native_handle(::cudaStream_t __handle)
|
||||
{
|
||||
return stream(__handle);
|
||||
}
|
||||
|
||||
// Disallow construction from an `int`, e.g., `0`.
|
||||
static stream from_native_handle(int) = delete;
|
||||
|
||||
// Disallow construction from `nullptr`.
|
||||
static stream from_native_handle(::cuda::std::nullptr_t) = delete;
|
||||
|
||||
//! @brief Retrieve the native `cudaStream_t` handle and give up ownership.
|
||||
//!
|
||||
//! @return cudaStream_t The native handle being held by the `stream` object.
|
||||
//!
|
||||
//! @post The stream object is in a moved-from state.
|
||||
[[nodiscard]] ::cudaStream_t release()
|
||||
{
|
||||
return ::cuda::std::exchange(__stream, ::cuda::__invalid_stream());
|
||||
}
|
||||
|
||||
//! @brief Returns a \c execution::scheduler that enqueues work on this stream.
|
||||
auto get_scheduler() const noexcept -> stream_ref
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
// Use `stream::from_native_handle(s)` to construct an owning `stream`
|
||||
// object from a `cudaStream_t` handle.
|
||||
explicit stream(::cudaStream_t __handle)
|
||||
: stream_ref(__handle)
|
||||
{}
|
||||
};
|
||||
} // namespace cuda::experimental
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDAX__STREAM_STREAM_CUH
|
||||
@@ -1,137 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDAX__STREAM_STREAM_REF_CUH
|
||||
#define _CUDAX__STREAM_STREAM_REF_CUH
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/__device/all_devices.h>
|
||||
#include <cuda/__event/timed_event.h>
|
||||
#include <cuda/__runtime/api_wrapper.h>
|
||||
#include <cuda/__stream/stream_ref.h>
|
||||
|
||||
#include <cuda/experimental/__device/logical_device.cuh>
|
||||
#include <cuda/experimental/__execution/completion_behavior.cuh>
|
||||
#include <cuda/experimental/__execution/fwd.cuh>
|
||||
#include <cuda/experimental/__utility/ensure_current_device.cuh>
|
||||
|
||||
#include <cuda_runtime_api.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
//! @brief A non-owning wrapper for cudaStream_t.
|
||||
//!
|
||||
//! @note It is undefined behavior to use a `stream_ref` object beyond the lifetime of the stream it was created from,
|
||||
//! except for the `get()` member function.
|
||||
struct stream_ref : ::cuda::stream_ref
|
||||
{
|
||||
using scheduler_concept = execution::scheduler_t;
|
||||
|
||||
stream_ref() = delete;
|
||||
|
||||
//! @brief Converting constructor from ``cuda::stream_ref``
|
||||
//!
|
||||
//! @post `*this == __other`
|
||||
_CCCL_HOST_DEVICE_API constexpr stream_ref(const ::cuda::stream_ref& __other) noexcept
|
||||
: ::cuda::stream_ref(__other)
|
||||
{}
|
||||
|
||||
using ::cuda::stream_ref::stream_ref;
|
||||
|
||||
//! @brief Deprecated. Use is_done() instead.
|
||||
[[deprecated("Use is_done() instead.")]] [[nodiscard]] bool ready() const
|
||||
{
|
||||
return is_done();
|
||||
}
|
||||
|
||||
//! @brief Returns a \c execution::sender that completes on this stream.
|
||||
//!
|
||||
//! @note Equivalent to `execution::schedule(execution::stream_scheduler{*this})`.
|
||||
_CCCL_HOST_DEVICE_API auto schedule() const noexcept;
|
||||
|
||||
//! @brief Get the logical device under which this stream was created.
|
||||
//!
|
||||
//! Compared to `device()` member function the returned \c logical_device will
|
||||
//! hold a green context for streams created under one.
|
||||
_CCCL_HOST_API logical_device logical_device() const
|
||||
{
|
||||
CUcontext __stream_ctx;
|
||||
::cuda::experimental::logical_device::kinds __ctx_kind = ::cuda::experimental::logical_device::kinds::device;
|
||||
#if _CCCL_CTK_AT_LEAST(12, 5)
|
||||
if (::cuda::__driver::__version_at_least(12, 5))
|
||||
{
|
||||
auto __ctx = ::cuda::__driver::__streamGetCtx_v2(__stream);
|
||||
if (__ctx.__ctx_kind_ == ::cuda::__driver::__ctx_from_stream::__kind::__green)
|
||||
{
|
||||
__stream_ctx = ::cuda::__driver::__ctxFromGreenCtx(__ctx.__ctx_green_);
|
||||
__ctx_kind = ::cuda::experimental::logical_device::kinds::green_context;
|
||||
}
|
||||
else
|
||||
{
|
||||
__stream_ctx = __ctx.__ctx_device_;
|
||||
__ctx_kind = ::cuda::experimental::logical_device::kinds::device;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif // _CCCL_CTK_AT_LEAST(12, 5)
|
||||
{
|
||||
__stream_ctx = ::cuda::__driver::__streamGetCtx(__stream);
|
||||
__ctx_kind = ::cuda::experimental::logical_device::kinds::device;
|
||||
}
|
||||
// Because the stream can come from_native_handle, we can't just loop over devices comparing contexts,
|
||||
// lower to CUDART for this instead
|
||||
__ensure_current_device __setter(__stream_ctx);
|
||||
int __id;
|
||||
_CCCL_TRY_CUDA_API(cudaGetDevice, "Could not get device from a stream", &__id);
|
||||
return __logical_device_access::make_logical_device(__id, __stream_ctx, __ctx_kind);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto
|
||||
query(const execution::get_forward_progress_guarantee_t&) const noexcept -> execution::forward_progress_guarantee
|
||||
{
|
||||
return execution::forward_progress_guarantee::weakly_parallel;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto query(const execution::get_completion_behavior_t&) const noexcept
|
||||
{
|
||||
return execution::completion_behavior::asynchronous;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto
|
||||
query(const execution::get_completion_scheduler_t<execution::set_value_t>&) const noexcept -> stream_ref;
|
||||
|
||||
template <class _Env>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto
|
||||
query(const execution::get_completion_scheduler_t<execution::set_error_t>&, const _Env& __env) const noexcept
|
||||
-> execution::__scheduler_of_t<const _Env&>;
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto
|
||||
query(const execution::get_completion_domain_t<execution::set_value_t>&) const noexcept -> execution::stream_domain;
|
||||
|
||||
template <class _Env>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr auto
|
||||
query(const execution::get_completion_domain_t<execution::set_error_t>&, const _Env& __env) const noexcept
|
||||
-> __call_result_t<execution::get_domain_t, const _Env&>;
|
||||
};
|
||||
} // namespace cuda::experimental
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDAX__STREAM_STREAM_REF_CUH
|
||||
Reference in New Issue
Block a user