[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,311 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#pragma once
|
||||
|
||||
#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/std/__exception/exception_macros.h>
|
||||
#include <cuda/std/__host_stdlib/stdexcept>
|
||||
#include <cuda/std/__utility/exchange.h>
|
||||
#include <cuda/std/string_view>
|
||||
|
||||
#include <cuda/experimental/__cufile/cufile_ref.cuh>
|
||||
#include <cuda/experimental/__cufile/driver.cuh>
|
||||
#include <cuda/experimental/__cufile/exception.cuh>
|
||||
#include <cuda/experimental/__cufile/open_mode.cuh>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cufile.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
//! @brief An owning wrapper of \c CUfileHandle_t and the OS specific native file handle.
|
||||
class cufile : public cufile_ref
|
||||
{
|
||||
public:
|
||||
using native_handle_type = __cufile_os_native_type; //!< The underlying OS native handle type.
|
||||
|
||||
private:
|
||||
using __oflags_type = int;
|
||||
|
||||
static constexpr native_handle_type __invalid_native_handle = -1;
|
||||
|
||||
native_handle_type __native_handle_{__invalid_native_handle}; //< The native handle.
|
||||
|
||||
//! @brief Constructs the object from native handle and cuFile file handle.
|
||||
_CCCL_HIDE_FROM_ABI cufile(cufile_ref __cufile_handle, native_handle_type __native_handle) noexcept
|
||||
: cufile_ref{__cufile_handle}
|
||||
, __native_handle_{__native_handle}
|
||||
{}
|
||||
|
||||
//! @brief Make open flags from the \c cuda::cufile_open_mode.
|
||||
//!
|
||||
//! @param __om The cuFile open mode.
|
||||
//!
|
||||
//! @return The flags mask to be passed to open function.
|
||||
[[nodiscard]] static _CCCL_HOST_API constexpr __oflags_type __make_oflags(cufile_open_mode __om) noexcept
|
||||
{
|
||||
__oflags_type __ret{};
|
||||
if ((__om & (cufile_open_mode::in | cufile_open_mode::out)) == (cufile_open_mode::in | cufile_open_mode::out))
|
||||
{
|
||||
__ret |= O_RDWR | O_CREAT;
|
||||
}
|
||||
else if ((__om & cufile_open_mode::in) == cufile_open_mode::in)
|
||||
{
|
||||
__ret |= O_RDONLY;
|
||||
}
|
||||
else if ((__om & cufile_open_mode::out) == cufile_open_mode::out)
|
||||
{
|
||||
__ret |= O_WRONLY | O_CREAT;
|
||||
}
|
||||
|
||||
__ret |= ((__om & cufile_open_mode::trunc) == cufile_open_mode::trunc) ? O_TRUNC : 0;
|
||||
__ret |= ((__om & cufile_open_mode::noreplace) == cufile_open_mode::noreplace) ? O_EXCL : 0;
|
||||
__ret |= ((__om & cufile_open_mode::direct) == cufile_open_mode::direct) ? O_DIRECT : 0;
|
||||
return __ret;
|
||||
}
|
||||
|
||||
//! @brief Wrapper for opening the native handle.
|
||||
[[nodiscard]] static _CCCL_HOST_API native_handle_type __open_file(const char* __filename, __oflags_type __oflags)
|
||||
{
|
||||
// if O_CREAT flag is specified, use the same mode as if opened by fopend
|
||||
::mode_t __ocreat_mode{};
|
||||
if (__oflags & O_CREAT)
|
||||
{
|
||||
__ocreat_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
}
|
||||
|
||||
int __fd = ::open(__filename, __oflags, __ocreat_mode);
|
||||
|
||||
if (__fd == -1)
|
||||
{
|
||||
errno = 0; // clear errno
|
||||
_CCCL_THROW(::std::runtime_error, "Failed to open file.");
|
||||
}
|
||||
|
||||
return __fd;
|
||||
}
|
||||
|
||||
//! @brief Wrapper for retrieving the open mode.
|
||||
[[nodiscard]] static _CCCL_HOST_API cufile_open_mode __open_mode(native_handle_type __native_handle)
|
||||
{
|
||||
int __oflags = ::fcntl(__native_handle, F_GETFL);
|
||||
|
||||
if (__oflags == -1)
|
||||
{
|
||||
errno = 0; // clear errno
|
||||
_CCCL_THROW(::std::runtime_error, "Failed to retrieve open flags.");
|
||||
}
|
||||
|
||||
cufile_open_mode __om{};
|
||||
if (__oflags & O_RDWR)
|
||||
{
|
||||
__om |= cufile_open_mode::in | cufile_open_mode::out;
|
||||
}
|
||||
else if (__oflags & O_RDONLY)
|
||||
{
|
||||
__om |= cufile_open_mode::in;
|
||||
}
|
||||
else if (__oflags & O_WRONLY)
|
||||
{
|
||||
__om |= cufile_open_mode::out;
|
||||
}
|
||||
__om |= (__oflags & O_TRUNC) ? cufile_open_mode::trunc : cufile_open_mode{};
|
||||
__om |= (__oflags & O_EXCL) ? cufile_open_mode::noreplace : cufile_open_mode{};
|
||||
__om |= (__oflags & O_DIRECT) ? cufile_open_mode::direct : cufile_open_mode{};
|
||||
return __om;
|
||||
}
|
||||
|
||||
//! @brief Wrapper for closing the native handle.
|
||||
[[nodiscard]] static _CCCL_HOST_API bool __close_file_no_throw(native_handle_type __native_handle) noexcept
|
||||
{
|
||||
return ::close(__native_handle) == 0;
|
||||
}
|
||||
|
||||
//! @brief Wrapper for closing the native handle. Throws \c cuda::std::runtime_error if an error occurs.
|
||||
static _CCCL_HOST_API void __close_file(native_handle_type __native_handle)
|
||||
{
|
||||
if (!__close_file_no_throw(__native_handle))
|
||||
{
|
||||
errno = 0; // clear errno
|
||||
_CCCL_THROW(::std::runtime_error, "Failed to close file.");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
//! @brief Make a cufile object from already existing native handle.
|
||||
//!
|
||||
// The ownership of the handle is transferred to the object and the handle is registered by the cuFile driver.
|
||||
//!
|
||||
//! @param __native_handle The native handle.
|
||||
//!
|
||||
//! @return The created cufile object.
|
||||
[[nodiscard]] static _CCCL_HOST_API cufile from_native_handle(native_handle_type __native_handle)
|
||||
{
|
||||
return cufile{cufile_driver.register_native_handle(__native_handle), __native_handle};
|
||||
}
|
||||
|
||||
_CCCL_HIDE_FROM_ABI cufile() noexcept = default;
|
||||
|
||||
//! @brief Constructs the object by opening file @c __filename in mode @c __open_mode.
|
||||
//!
|
||||
//! @param __filename Path to the file. Must be a zero terminated string.
|
||||
//! @param __open_mode Open mode to open the file with.
|
||||
//!
|
||||
//! @throws cuda::std::runtime_error if the file cannot be opened.
|
||||
//! @throws cuda::cuda_error if a CUDA driver error occurs.
|
||||
//! @throws cuda::cufile_error if a cuFile driver error occurs.
|
||||
_CCCL_HOST_API cufile(const char* __filename, cufile_open_mode __open_mode)
|
||||
{
|
||||
__native_handle_ = __open_file(__filename, __make_oflags(__open_mode));
|
||||
try
|
||||
{
|
||||
__cufile_handle_ = cufile_driver.register_native_handle(__native_handle_).get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
__close_file(__native_handle_);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
cufile(const cufile&) = delete;
|
||||
|
||||
//! @brief Move-construct a new @c cufile.
|
||||
//!
|
||||
//! @param __other The other @c cufile.
|
||||
//!
|
||||
//! @post `__other` is in moved-from state.
|
||||
_CCCL_HOST_API cufile(cufile&& __other) noexcept
|
||||
: cufile_ref{::cuda::std::exchange(__other.__cufile_handle_, nullptr)}
|
||||
, __native_handle_{::cuda::std::exchange(__other.__native_handle_, __invalid_native_handle)}
|
||||
{}
|
||||
|
||||
cufile& operator=(const cufile&) = delete;
|
||||
|
||||
//! @brief Move-assign from a @c cufile object.
|
||||
//!
|
||||
//! @param __other The other @c cufile.
|
||||
//!
|
||||
//! @post `__other` is in moved-from state.
|
||||
//!
|
||||
//! @throws cuda::std::runtime_error if the currently opened file fails to close.
|
||||
_CCCL_HOST_API cufile& operator=(cufile&& __other)
|
||||
{
|
||||
if (this != ::cuda::std::addressof(__other))
|
||||
{
|
||||
close();
|
||||
__native_handle_ = ::cuda::std::exchange(__other.__native_handle_, __invalid_native_handle);
|
||||
__cufile_handle_ = ::cuda::std::exchange(__other.__cufile_handle_, nullptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Destructor. Deregisters the cuFile file handle and closes the native handle.
|
||||
_CCCL_HOST_API ~cufile()
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
cufile_driver.deregister_native_handle(__cufile_handle_);
|
||||
[[maybe_unused]] const auto __ignore_close_retval = __close_file_no_throw(__native_handle_);
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Queries whether the file is opened.
|
||||
//!
|
||||
//! @return True, if opened, false otherwise.
|
||||
[[nodiscard]] _CCCL_HOST_API bool is_open() const noexcept
|
||||
{
|
||||
return __native_handle_ != __invalid_native_handle;
|
||||
}
|
||||
|
||||
//! @brief Queries the open mode the object was opened with.
|
||||
//!
|
||||
//! @return The \c cuda::cufile_open_mode value if opened, empty value otherwise.
|
||||
[[nodiscard]] _CCCL_HOST_API cufile_open_mode open_mode() const
|
||||
{
|
||||
return is_open() ? __open_mode(__native_handle_) : cufile_open_mode{};
|
||||
}
|
||||
|
||||
//! @brief Opens file @c __filename in mode @c __open_mode.
|
||||
//!
|
||||
//! @param __filename Path to the file.
|
||||
//! @param __open_mode Open mode to open the file with.
|
||||
//!
|
||||
//! @throws cuda::std::runtime_error if the file cannot be opened or if a file is already opened.
|
||||
//! @throws cuda::cuda_error if a CUDA driver error occurs.
|
||||
//! @throws cuda::cufile_error if a cuFile driver error occurs.
|
||||
_CCCL_HOST_API void open(const char* __filename, cufile_open_mode __open_mode)
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
_CCCL_THROW(::std::runtime_error, "File is already opened.");
|
||||
}
|
||||
|
||||
__native_handle_ = __open_file(__filename, __make_oflags(__open_mode));
|
||||
|
||||
try
|
||||
{
|
||||
__cufile_handle_ = cufile_driver.register_native_handle(__native_handle_).get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
__close_file(::cuda::std::exchange(__native_handle_, __invalid_native_handle));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Closes the currently opened file. If there is no opened file, no action is taken.
|
||||
//!
|
||||
//! @throws cuda::std::runtime_error if the file fails to close.
|
||||
//! @throws cuda::cuda_error if a CUDA driver error occurs.
|
||||
//! @throws cuda::cufile_error if a cuFile driver error occurs.
|
||||
_CCCL_HOST_API void close()
|
||||
{
|
||||
if (!is_open())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cufile_driver.deregister_native_handle(::cuda::std::exchange(__cufile_handle_, nullptr));
|
||||
__close_file(::cuda::std::exchange(__native_handle_, __invalid_native_handle));
|
||||
}
|
||||
|
||||
//! @brief Gets the OS native handle.
|
||||
//!
|
||||
//! @return The native handle.
|
||||
[[nodiscard]] _CCCL_HOST_API native_handle_type native_handle() const noexcept
|
||||
{
|
||||
return __native_handle_;
|
||||
}
|
||||
|
||||
//! @brief Deregisters the cuFile file handle and releases the native handle. The ownership of the native handle is
|
||||
//! transferred to the caller.
|
||||
//!
|
||||
//! @returns The native handle.
|
||||
[[nodiscard]] _CCCL_HOST_API native_handle_type release() noexcept
|
||||
{
|
||||
cufile_driver.deregister_native_handle(::cuda::std::exchange(__cufile_handle_, nullptr));
|
||||
return ::cuda::std::exchange(__native_handle_, __invalid_native_handle);
|
||||
}
|
||||
};
|
||||
} // namespace cuda::experimental
|
||||
@@ -1,61 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#pragma once
|
||||
|
||||
#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/std/__cstddef/types.h>
|
||||
|
||||
#include <cufile.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
using __cufile_os_native_type = int;
|
||||
|
||||
//! @brief A non-owning wrapper of \c CUfileHandle_t.
|
||||
class cufile_ref
|
||||
{
|
||||
protected:
|
||||
::CUfileHandle_t __cufile_handle_{}; //!< The cuFile file handle.
|
||||
|
||||
_CCCL_HIDE_FROM_ABI cufile_ref() noexcept = default;
|
||||
|
||||
public:
|
||||
using off_type = ::off_t;
|
||||
|
||||
//! @brief Constructs the object from a \c CUfileHandle_t handle.
|
||||
_CCCL_HOST_API cufile_ref(::CUfileHandle_t __cufile_handle) noexcept
|
||||
: __cufile_handle_{__cufile_handle}
|
||||
{}
|
||||
|
||||
//! @brief Disallow construction from nullptr.
|
||||
cufile_ref(::cuda::std::nullptr_t) = delete;
|
||||
|
||||
_CCCL_HIDE_FROM_ABI cufile_ref(const cufile_ref&) noexcept = default;
|
||||
|
||||
_CCCL_HIDE_FROM_ABI cufile_ref& operator=(const cufile_ref&) noexcept = default;
|
||||
|
||||
//! @brief Retrieve the \c CUfileHandle_t handle.
|
||||
//!
|
||||
//! @returns The handle being held by the object.
|
||||
[[nodiscard]] _CCCL_HOST_API ::CUfileHandle_t get() const noexcept
|
||||
{
|
||||
return __cufile_handle_;
|
||||
}
|
||||
};
|
||||
} // namespace cuda::experimental
|
||||
@@ -1,314 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#pragma once
|
||||
|
||||
#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/std/__exception/exception_macros.h>
|
||||
#include <cuda/std/__host_stdlib/stdexcept>
|
||||
#include <cuda/std/__type_traits/always_false.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
|
||||
#include <cuda/experimental/__cufile/cufile_ref.cuh>
|
||||
#include <cuda/experimental/__cufile/driver_attributes.cuh>
|
||||
#include <cuda/experimental/__cufile/exception.cuh>
|
||||
|
||||
#include <cufile.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
#if _CCCL_CTK_AT_LEAST(13, 0)
|
||||
//! @brief Structure representing the range of valid values for a cuFile driver attribute.
|
||||
//!
|
||||
//! @tparam _Attr The attribute type. Must be one of the types defined in cufile_driver_attributes that has a queryable
|
||||
//! range.
|
||||
template <class _Attr>
|
||||
struct cufile_driver_attribute_range
|
||||
{
|
||||
static_assert(_Attr::__has_queryable_range, "Attribute does not have a queryable range");
|
||||
|
||||
typename _Attr::type min; //!< Minimum value of the attribute.
|
||||
typename _Attr::type max; //!< Maximum value of the attribute.
|
||||
};
|
||||
#endif // _CCCL_CTK_AT_LEAST(13, 0)
|
||||
|
||||
//! @brief Implementation defined type that implements the cuFILE driver interface.
|
||||
class cufile_driver_t
|
||||
{
|
||||
_CCCL_HIDE_FROM_ABI constexpr cufile_driver_t() noexcept = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static _CCCL_HOST_API constexpr cufile_driver_t __make_instance() noexcept
|
||||
{
|
||||
return cufile_driver_t{};
|
||||
}
|
||||
|
||||
cufile_driver_t(const cufile_driver_t&) = delete;
|
||||
cufile_driver_t& operator=(const cufile_driver_t&) = delete;
|
||||
cufile_driver_t(cufile_driver_t&&) = delete;
|
||||
cufile_driver_t& operator=(cufile_driver_t&&) = delete;
|
||||
|
||||
//! @brief Check if the driver is open.
|
||||
//!
|
||||
//! @return true if the driver is open, false otherwise.
|
||||
[[nodiscard]] _CCCL_HOST_API bool is_open() const noexcept
|
||||
{
|
||||
return ::cuFileUseCount() > 0;
|
||||
}
|
||||
|
||||
//! @brief Open the cuFile driver if it is not already open.
|
||||
//!
|
||||
//! @throws cufile_error if cuFileDriverOpen fails.
|
||||
//! @throws cuda_error if a CUDA driver error occurs.
|
||||
//!
|
||||
//! @note Some driver attributes cannot be modified after the driver is opened.
|
||||
//! Attempting to modify these attributes after the driver is opened will result in a runtime error.
|
||||
_CCCL_HOST_API void open() const
|
||||
{
|
||||
if (!is_open())
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(::cuFileDriverOpen, "Failed to open cuFile driver");
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Close the cuFile driver if it is open.
|
||||
//!
|
||||
//! @throws cufile_error if cuFileDriverClose fails.
|
||||
//! @throws cuda_error if a CUDA driver error occurs.
|
||||
_CCCL_HOST_API void close() const
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(::cuFileDriverClose, "Failed to close cuFile driver");
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Get the value of a cuFile driver attribute.
|
||||
//!
|
||||
//! @tparam _Attr The attribute type to query. Must be one of the types defined in cufile_driver_attributes.
|
||||
//!
|
||||
//! @param __attr The attribute to query.
|
||||
//!
|
||||
//! @return The value of the attribute.
|
||||
//!
|
||||
//! @throws cufile_error if the underlying cuFile API call fails.
|
||||
//! @throws cuda_error if a CUDA driver error occurs.
|
||||
//! @throws std::runtime_error if the driver is not open when querying certain attributes.
|
||||
//!
|
||||
//! @note Some attributes can only be queried when the driver is open. Attempting to query these attributes
|
||||
//! when the driver is not open will result in a runtime error. See attribute documentation for details.
|
||||
template <class _Attr>
|
||||
[[nodiscard]] _CCCL_HOST_API typename _Attr::type attribute([[maybe_unused]] const _Attr& __attr) const
|
||||
{
|
||||
using _AttrEnum = typename _Attr::__enum_type;
|
||||
|
||||
typename _Attr::type __ret{};
|
||||
if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUFileSizeTConfigParameter_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(::cuFileGetParameterSizeT, "Failed to get cuFile parameter", _Attr::__enum_value, &__ret);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUFileBoolConfigParameter_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(::cuFileGetParameterBool, "Failed to get cuFile parameter", _Attr::__enum_value, &__ret);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUfileDriverStatusFlags_t>
|
||||
|| ::cuda::std::is_same_v<_AttrEnum, ::CUfileFeatureFlags_t>)
|
||||
{
|
||||
if (!is_open())
|
||||
{
|
||||
_CCCL_THROW(::std::runtime_error, "cuFile driver must be opened to query this attribute.");
|
||||
}
|
||||
|
||||
::CUfileDrvProps_t __props{};
|
||||
_CCCL_TRY_CUFILE_API(::cuFileDriverGetProperties, "Failed to get cuFile driver properties", &__props);
|
||||
|
||||
if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUfileDriverStatusFlags_t>)
|
||||
{
|
||||
__ret = __props.nvfs.dstatusflags & _Attr::__enum_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
__ret = __props.fflags & _Attr::__enum_value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(::cuda::std::__always_false_v<_AttrEnum>, "Unsupported parameter type");
|
||||
}
|
||||
return __ret;
|
||||
}
|
||||
|
||||
#if _CCCL_CTK_AT_LEAST(13, 0)
|
||||
//! @brief Get the valid range of values for a cuFile driver attribute.
|
||||
//!
|
||||
//! @tparam _Attr The attribute type to query. Must be one of the types defined in cufile_driver_attributes that has
|
||||
//! a queryable range.
|
||||
//!
|
||||
//! @param __attr The attribute to query.
|
||||
//!
|
||||
//! @return The valid range of values for the attribute.
|
||||
//!
|
||||
//! @throws cufile_error if the underlying cuFile API call fails.
|
||||
//! @throws cuda_error if a CUDA driver error occurs.
|
||||
template <class _Attr>
|
||||
[[nodiscard]] _CCCL_HOST_API cufile_driver_attribute_range<_Attr>
|
||||
attribute_range([[maybe_unused]] const _Attr& __attr) const
|
||||
{
|
||||
static_assert(_Attr::__has_queryable_range, "Attribute does not have a queryable range");
|
||||
|
||||
using _AttrEnum = typename _Attr::__enum_type;
|
||||
|
||||
if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::max_device_cache_size_kb_t>
|
||||
|| ::cuda::std::is_same_v<_Attr, cufile_driver_attributes::max_device_pinned_mem_size_kb_t>)
|
||||
{
|
||||
if (!is_open())
|
||||
{
|
||||
_CCCL_THROW(::std::runtime_error,
|
||||
"This cuFile driver attribute range must be queried after the driver is opened.");
|
||||
}
|
||||
}
|
||||
|
||||
cufile_driver_attribute_range<_Attr> __ret{};
|
||||
if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUFileSizeTConfigParameter_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileGetParameterMinMaxValue,
|
||||
"Failed to get cuFile parameter range",
|
||||
_Attr::__enum_value,
|
||||
&__ret.min,
|
||||
&__ret.max);
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(::cuda::std::__always_false_v<_AttrEnum>, "Unsupported parameter type");
|
||||
}
|
||||
return __ret;
|
||||
}
|
||||
#endif // _CCCL_CTK_AT_LEAST(13, 0)
|
||||
|
||||
//! @brief Set the value of a cuFile driver attribute.
|
||||
//!
|
||||
//! @tparam _Attr The attribute type to set. Must be one of the types defined in cufile_driver_attributes that is not
|
||||
//! read-only.
|
||||
//!
|
||||
//! @param __attr The attribute to set.
|
||||
//! @param __value The value to set the attribute to.
|
||||
//!
|
||||
//! @throws cufile_error if the underlying cuFile API call fails.
|
||||
//! @throws cuda_error if a CUDA driver error occurs.
|
||||
//! @throws std::runtime_error if the attribute cannot be modified after the driver is opened.
|
||||
//!
|
||||
//! @note Some attributes cannot be modified after the driver is opened. Attempting to modify these attributes
|
||||
//! after the driver is opened will result in a runtime error. See attribute documentation for details.
|
||||
template <class _Attr>
|
||||
_CCCL_HOST_API void set_attribute([[maybe_unused]] const _Attr& __attr, typename _Attr::type __value) const
|
||||
{
|
||||
static_assert(_Attr::__can_be_set_when_closed || _Attr::__can_be_set_when_opened,
|
||||
"Cannot modify read-only attribute");
|
||||
|
||||
using _AttrEnum = typename _Attr::__enum_type;
|
||||
|
||||
if (is_open())
|
||||
{
|
||||
if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::use_poll_mode_t>)
|
||||
{
|
||||
const auto __pollthreshold_size = attribute(cufile_driver_attributes::pollthreshold_size_kb);
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileDriverSetPollMode, "Failed to set cuFile driver poll mode", __value, __pollthreshold_size);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::pollthreshold_size_kb_t>)
|
||||
{
|
||||
const auto __use_poll_mode = attribute(cufile_driver_attributes::use_poll_mode);
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileDriverSetPollMode, "Failed to set cuFile driver poll mode", __use_poll_mode, __value);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::max_direct_io_size_kb_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileDriverSetMaxDirectIOSize, "Failed to set cuFile driver max direct IO size", __value);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::max_device_cache_size_kb_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(::cuFileDriverSetMaxCacheSize, "Failed to set cuFile driver max cache size", __value);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_Attr, cufile_driver_attributes::max_device_pinned_mem_size_kb_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileDriverSetMaxPinnedMemSize, "Failed to set cuFile driver max pinned mem size", __value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CCCL_THROW(::std::runtime_error,
|
||||
"This cuFile driver attribute cannot be modified after the driver is opened.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUFileSizeTConfigParameter_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileSetParameterSizeT, "Failed to set cuFile parameter size", _Attr::__enum_value, __value);
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_AttrEnum, ::CUFileBoolConfigParameter_t>)
|
||||
{
|
||||
_CCCL_TRY_CUFILE_API(
|
||||
::cuFileSetParameterBool, "Failed to set cuFile parameter bool", _Attr::__enum_value, __value);
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(::cuda::std::__always_false_v<_AttrEnum>, "Unsupported parameter type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Registers an OS native file handle type in the cuFile driver. The registered cuFile handle can be used with
|
||||
//! other cuFile APIs. The handle must be deregistered calling the \c
|
||||
//! cuda::cufile_driver.deregister_native_handle(...) method with the obtained cuFile handle. For each OS
|
||||
//! native file handle can be called once before deregistered.
|
||||
//!
|
||||
//! @param __native_handle The OS native file handle.
|
||||
//!
|
||||
//! @return \c cuda::cufile_ref handle.
|
||||
//!
|
||||
//! @throws cuda::cuda_error if a CUDA driver error occurs.
|
||||
//! @throws cuda::cufile_error if a cuFile driver error occurs.
|
||||
[[nodiscard]] _CCCL_HOST_API cufile_ref register_native_handle(__cufile_os_native_type __native_handle) const
|
||||
{
|
||||
::CUfileDescr_t __desc{};
|
||||
__desc.type = ::CU_FILE_HANDLE_TYPE_OPAQUE_FD;
|
||||
__desc.handle.fd = __native_handle;
|
||||
|
||||
::CUfileHandle_t __handle{};
|
||||
_CCCL_TRY_CUFILE_API(::cuFileHandleRegister, "Failed to register cuFile handle", &__handle, &__desc);
|
||||
return __handle;
|
||||
}
|
||||
|
||||
//! @brief Deregisters the previously registered cuFile handle in the driver.
|
||||
//!
|
||||
//! @param __file The cuFile handle.
|
||||
//!
|
||||
//! @note The \c cuda::cufile implementation relies on this function being \c noexcept.
|
||||
_CCCL_HOST_API void deregister_native_handle(cufile_ref __file) const noexcept
|
||||
{
|
||||
::cuFileHandleDeregister(__file.get());
|
||||
}
|
||||
};
|
||||
|
||||
//! @brief Global instance of the cuFile driver interface.
|
||||
inline constexpr cufile_driver_t cufile_driver = cufile_driver_t::__make_instance();
|
||||
} // namespace cuda::experimental
|
||||
@@ -1,173 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#pragma once
|
||||
|
||||
#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/std/__cstddef/types.h>
|
||||
#include <cuda/std/__type_traits/always_false.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
|
||||
#include <cufile.h>
|
||||
|
||||
namespace cuda::experimental::cufile_driver_attributes
|
||||
{
|
||||
template <class _ParamEnum>
|
||||
[[nodiscard]] _CCCL_CONSTEVAL auto __attr_from_param_type() noexcept
|
||||
{
|
||||
if constexpr (::cuda::std::is_same_v<_ParamEnum, ::CUFileSizeTConfigParameter_t>)
|
||||
{
|
||||
return ::cuda::std::size_t{};
|
||||
}
|
||||
else if constexpr (::cuda::std::is_same_v<_ParamEnum, ::CUFileBoolConfigParameter_t>)
|
||||
{
|
||||
return bool{};
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(::cuda::std::__always_false_v<_ParamEnum>, "Unsupported parameter type");
|
||||
}
|
||||
}
|
||||
|
||||
template <auto _Param, bool _CanBeSetWhenOpened = false>
|
||||
struct __attr_from_param
|
||||
{
|
||||
using __enum_type = decltype(_Param);
|
||||
static constexpr auto __enum_value = _Param;
|
||||
static constexpr auto __can_be_get_when_closed = true;
|
||||
static constexpr auto __can_be_set_when_closed = true;
|
||||
static constexpr auto __can_be_set_when_opened = _CanBeSetWhenOpened;
|
||||
static constexpr auto __has_queryable_range = ::cuda::std::is_same_v<__enum_type, ::CUFileSizeTConfigParameter_t>;
|
||||
|
||||
using type = decltype(__attr_from_param_type<__enum_type>());
|
||||
};
|
||||
|
||||
template <::CUfileDriverStatusFlags_t _Status>
|
||||
struct __attr_from_status
|
||||
{
|
||||
using __enum_type = ::CUfileDriverStatusFlags_t;
|
||||
static constexpr auto __enum_value = _Status;
|
||||
static constexpr auto __can_be_get_when_closed = false;
|
||||
static constexpr auto __can_be_set_when_closed = false;
|
||||
static constexpr auto __can_be_set_when_opened = false;
|
||||
static constexpr auto __has_queryable_range = false;
|
||||
|
||||
using type = bool;
|
||||
};
|
||||
|
||||
template <::CUfileFeatureFlags_t _Feature>
|
||||
struct __attr_from_feature
|
||||
{
|
||||
using __enum_type = ::CUfileFeatureFlags_t;
|
||||
static constexpr auto __enum_value = _Feature;
|
||||
static constexpr auto __can_be_get_when_closed = false;
|
||||
static constexpr auto __can_be_set_when_closed = false;
|
||||
static constexpr auto __can_be_set_when_opened = false;
|
||||
static constexpr auto __has_queryable_range = false;
|
||||
|
||||
using type = bool;
|
||||
};
|
||||
|
||||
using max_io_queue_depth_t = __attr_from_param<::CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH>;
|
||||
using max_io_threads_t = __attr_from_param<::CUFILE_PARAM_EXECUTION_MAX_IO_THREADS>;
|
||||
using min_io_threshold_size_kb_t = __attr_from_param<::CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB>;
|
||||
using max_request_parallelism_t = __attr_from_param<::CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM>;
|
||||
using max_direct_io_size_kb_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB, true>;
|
||||
using max_device_cache_size_kb_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB, true>;
|
||||
using per_buffer_cache_size_kb_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB>;
|
||||
using max_device_pinned_mem_size_kb_t =
|
||||
__attr_from_param<::CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB, true>;
|
||||
using io_batchsize_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE>;
|
||||
using pollthreshold_size_kb_t = __attr_from_param<::CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB, true>;
|
||||
using batch_io_timeout_ms_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS>;
|
||||
using use_poll_mode_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_USE_POLL_MODE, true>;
|
||||
using allow_compat_mode_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE>;
|
||||
using force_compat_mode_t = __attr_from_param<::CUFILE_PARAM_FORCE_COMPAT_MODE>;
|
||||
using fs_misc_api_check_aggressive_t = __attr_from_param<::CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE>;
|
||||
using parallel_io_t = __attr_from_param<::CUFILE_PARAM_EXECUTION_PARALLEL_IO>;
|
||||
using profile_nvtx_t = __attr_from_param<::CUFILE_PARAM_PROFILE_NVTX>;
|
||||
using allow_system_memory_t = __attr_from_param<::CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY>;
|
||||
using use_pcip2pdma_t = __attr_from_param<::CUFILE_PARAM_USE_PCIP2PDMA>;
|
||||
using prefer_io_uring_t = __attr_from_param<::CUFILE_PARAM_PREFER_IO_URING>;
|
||||
using force_odirect_mode_t = __attr_from_param<::CUFILE_PARAM_FORCE_ODIRECT_MODE>;
|
||||
using skip_topology_detection_t = __attr_from_param<::CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION>;
|
||||
using stream_memops_bypass_t = __attr_from_param<::CUFILE_PARAM_STREAM_MEMOPS_BYPASS>;
|
||||
using has_luster_support_t = __attr_from_status<::CU_FILE_LUSTRE_SUPPORTED>;
|
||||
using has_wekafs_support_t = __attr_from_status<::CU_FILE_WEKAFS_SUPPORTED>;
|
||||
using has_nfs_support_t = __attr_from_status<::CU_FILE_NFS_SUPPORTED>;
|
||||
using has_gpfs_support_t = __attr_from_status<::CU_FILE_GPFS_SUPPORTED>;
|
||||
using has_nvme_support_t = __attr_from_status<::CU_FILE_NVME_SUPPORTED>;
|
||||
using has_nvmeof_support_t = __attr_from_status<::CU_FILE_NVMEOF_SUPPORTED>;
|
||||
using has_scsi_support_t = __attr_from_status<::CU_FILE_SCSI_SUPPORTED>;
|
||||
using has_scaleflux_csd_support_t = __attr_from_status<::CU_FILE_SCALEFLUX_CSD_SUPPORTED>;
|
||||
using has_nvmesh_support_t = __attr_from_status<::CU_FILE_NVMESH_SUPPORTED>;
|
||||
using has_beegfs_support_t = __attr_from_status<::CU_FILE_BEEGFS_SUPPORTED>;
|
||||
using has_nvme_p2p_support_t = __attr_from_status<::CU_FILE_NVME_P2P_SUPPORTED>;
|
||||
using has_scatefs_support_t = __attr_from_status<::CU_FILE_SCATEFS_SUPPORTED>;
|
||||
using has_dynamic_routing_support_t = __attr_from_feature<::CU_FILE_DYN_ROUTING_SUPPORTED>;
|
||||
using has_batch_io_support_t = __attr_from_feature<::CU_FILE_BATCH_IO_SUPPORTED>;
|
||||
using has_streams_support_t = __attr_from_feature<::CU_FILE_STREAMS_SUPPORTED>;
|
||||
using has_parallel_io_support_t = __attr_from_feature<::CU_FILE_PARALLEL_IO_SUPPORTED>;
|
||||
|
||||
// todo: add documentation of each attribute
|
||||
// 1. type
|
||||
// 2. whether it is read-only or can be set
|
||||
// 3. if it can be set/read when driver is open/closed
|
||||
// 4. default value, constraints
|
||||
|
||||
inline constexpr max_io_queue_depth_t max_io_queue_depth{};
|
||||
inline constexpr max_io_threads_t max_io_threads{};
|
||||
inline constexpr min_io_threshold_size_kb_t min_io_threshold_size_kb{};
|
||||
inline constexpr max_request_parallelism_t max_request_parallelism{};
|
||||
inline constexpr max_direct_io_size_kb_t max_direct_io_size_kb{};
|
||||
inline constexpr max_device_cache_size_kb_t max_device_cache_size_kb{};
|
||||
inline constexpr per_buffer_cache_size_kb_t per_buffer_cache_size_kb{};
|
||||
inline constexpr max_device_pinned_mem_size_kb_t max_device_pinned_mem_size_kb{};
|
||||
inline constexpr io_batchsize_t io_batchsize{};
|
||||
inline constexpr pollthreshold_size_kb_t pollthreshold_size_kb{};
|
||||
inline constexpr batch_io_timeout_ms_t batch_io_timeout_ms{};
|
||||
inline constexpr use_poll_mode_t use_poll_mode{};
|
||||
inline constexpr allow_compat_mode_t allow_compat_mode{};
|
||||
inline constexpr force_compat_mode_t force_compat_mode{};
|
||||
inline constexpr fs_misc_api_check_aggressive_t fs_misc_api_check_aggressive{};
|
||||
inline constexpr parallel_io_t parallel_io{};
|
||||
inline constexpr profile_nvtx_t profile_nvtx{};
|
||||
inline constexpr allow_system_memory_t allow_system_memory{};
|
||||
inline constexpr use_pcip2pdma_t use_pcip2pdma{};
|
||||
inline constexpr prefer_io_uring_t prefer_io_uring{};
|
||||
inline constexpr force_odirect_mode_t force_odirect_mode{};
|
||||
inline constexpr skip_topology_detection_t skip_topology_detection{};
|
||||
inline constexpr stream_memops_bypass_t stream_memops_bypass{};
|
||||
inline constexpr has_luster_support_t has_luster_support{};
|
||||
inline constexpr has_wekafs_support_t has_wekafs_support{};
|
||||
inline constexpr has_nfs_support_t has_nfs_support{};
|
||||
inline constexpr has_gpfs_support_t has_gpfs_support{};
|
||||
inline constexpr has_nvme_support_t has_nvme_support{};
|
||||
inline constexpr has_nvmeof_support_t has_nvmeof_support{};
|
||||
inline constexpr has_scsi_support_t has_scsi_support{};
|
||||
inline constexpr has_scaleflux_csd_support_t has_scaleflux_csd_support{};
|
||||
inline constexpr has_nvmesh_support_t has_nvmesh_support{};
|
||||
inline constexpr has_beegfs_support_t has_beegfs_support{};
|
||||
inline constexpr has_nvme_p2p_support_t has_nvme_p2p_support{};
|
||||
inline constexpr has_scatefs_support_t has_scatefs_support{};
|
||||
inline constexpr has_dynamic_routing_support_t has_dynamic_routing_support{};
|
||||
inline constexpr has_batch_io_support_t has_batch_io_support{};
|
||||
inline constexpr has_streams_support_t has_streams_support{};
|
||||
inline constexpr has_parallel_io_support_t has_parallel_io_support{};
|
||||
} // namespace cuda::experimental::cufile_driver_attributes
|
||||
@@ -1,107 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#pragma once
|
||||
|
||||
#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/std/__exception/cuda_error.h>
|
||||
#include <cuda/std/__exception/exception_macros.h>
|
||||
#include <cuda/std/__exception/terminate.h>
|
||||
#include <cuda/std/__host_stdlib/stdexcept>
|
||||
#include <cuda/std/source_location>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <cufile.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
#if _CCCL_HAS_CTK()
|
||||
using __cufile_error_t = ::CUfileOpError;
|
||||
#else // ^^^ _CCCL_HAS_CTK() ^^^ // vvv !_CCCL_HAS_CTK() vvv
|
||||
using __cufile_error_t = int;
|
||||
#endif // ^^^ !_CCCL_HAS_CTK() ^^^
|
||||
|
||||
struct __cufile_msg_storage
|
||||
{
|
||||
char __buffer[512]{};
|
||||
};
|
||||
|
||||
static char* __format_cufile_error_message(
|
||||
__cufile_msg_storage& __msg_buffer,
|
||||
const __cufile_error_t __status,
|
||||
const char* __msg,
|
||||
const char* __api = nullptr,
|
||||
::cuda::std::source_location __loc = ::cuda::std::source_location::current()) noexcept
|
||||
{
|
||||
::snprintf(
|
||||
__msg_buffer.__buffer,
|
||||
512,
|
||||
"%s:%d %s%s%s(%d): %s",
|
||||
__loc.file_name(),
|
||||
__loc.line(),
|
||||
__api ? __api : "",
|
||||
__api ? " " : "",
|
||||
#if _CCCL_HAS_CTK()
|
||||
::cufileop_status_error(::CUfileOpError{__status}),
|
||||
#else // ^^^ _CCCL_HAS_CTK() ^^^ / vvv !_CCCL_HAS_CTK() vvv
|
||||
"cuFile error",
|
||||
#endif // ^^^ !_CCCL_HAS_CTK() ^^^
|
||||
__status,
|
||||
__msg);
|
||||
return __msg_buffer.__buffer;
|
||||
}
|
||||
|
||||
//! @brief Exception class for errors from cuFile APIs.
|
||||
class cufile_error : public ::std::runtime_error
|
||||
{
|
||||
__cufile_error_t __status_; //!< The cuFile error code.
|
||||
|
||||
public:
|
||||
_CCCL_HOST_API cufile_error(
|
||||
__cufile_error_t __status,
|
||||
const char* __msg,
|
||||
const char* __api,
|
||||
::cuda::std::source_location loc = ::cuda::std::source_location::current(),
|
||||
__cufile_msg_storage __msg_buffer = {})
|
||||
: ::std::runtime_error{__format_cufile_error_message(__msg_buffer, __status, __msg, __api, loc)}
|
||||
, __status_{__status}
|
||||
{}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_API __cufile_error_t status() const noexcept
|
||||
{
|
||||
return __status_;
|
||||
}
|
||||
};
|
||||
|
||||
//! @brief Macro to call a cuFile API and throw a cufile_error or cuda_error if it fails.
|
||||
#define _CCCL_TRY_CUFILE_API(_NAME, _MSG, ...) \
|
||||
do \
|
||||
{ \
|
||||
const ::CUfileError_t __cufile_error_status = _NAME(__VA_ARGS__); \
|
||||
switch (__cufile_error_status.err) \
|
||||
{ \
|
||||
case ::CU_FILE_SUCCESS: \
|
||||
break; \
|
||||
case ::CU_FILE_CUDA_DRIVER_ERROR: \
|
||||
_CCCL_THROW(::cuda::cuda_error, static_cast<::cudaError_t>(__cufile_error_status.cu_err), _MSG, #_NAME); \
|
||||
default: \
|
||||
_CCCL_THROW(::cuda::experimental::cufile_error, __cufile_error_status.err, _MSG, #_NAME); \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace cuda::experimental
|
||||
@@ -1,73 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#pragma once
|
||||
|
||||
#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/std/__utility/to_underlying.h>
|
||||
|
||||
namespace cuda::experimental
|
||||
{
|
||||
//! @brief Open mode for cufile.
|
||||
enum class cufile_open_mode : unsigned
|
||||
{
|
||||
in = (1u << 0),
|
||||
out = (1u << 1),
|
||||
trunc = (1u << 2),
|
||||
noreplace = (1u << 3),
|
||||
direct = (1u << 4),
|
||||
};
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_API constexpr cufile_open_mode
|
||||
operator|(cufile_open_mode __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return static_cast<cufile_open_mode>(::cuda::std::to_underlying(__lhs) | ::cuda::std::to_underlying(__rhs));
|
||||
}
|
||||
|
||||
_CCCL_HOST_API constexpr cufile_open_mode& operator|=(cufile_open_mode& __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return __lhs = __lhs | __rhs;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_API constexpr cufile_open_mode
|
||||
operator&(cufile_open_mode __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return static_cast<cufile_open_mode>(::cuda::std::to_underlying(__lhs) & ::cuda::std::to_underlying(__rhs));
|
||||
}
|
||||
|
||||
_CCCL_HOST_API constexpr cufile_open_mode& operator&=(cufile_open_mode& __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return __lhs = __lhs & __rhs;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_API constexpr cufile_open_mode
|
||||
operator^(cufile_open_mode __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return static_cast<cufile_open_mode>(::cuda::std::to_underlying(__lhs) ^ ::cuda::std::to_underlying(__rhs));
|
||||
}
|
||||
|
||||
_CCCL_HOST_API constexpr cufile_open_mode& operator^=(cufile_open_mode& __lhs, cufile_open_mode __rhs) noexcept
|
||||
{
|
||||
return __lhs = __lhs ^ __rhs;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_API constexpr cufile_open_mode operator~(cufile_open_mode __b) noexcept
|
||||
{
|
||||
return static_cast<cufile_open_mode>(~::cuda::std::to_underlying(__b));
|
||||
}
|
||||
} // namespace cuda::experimental
|
||||
Reference in New Issue
Block a user