[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:
muh-bot
2026-08-03 12:39:26 +00:00
parent a2a5dd8f00
commit 24ef6a91b5
5439 changed files with 0 additions and 719516 deletions

View File

@@ -1,34 +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 <cstdio>
#include <cstdlib>
#include <string>
#include <fcntl.h>
#include <unistd.h>
void test_check_fd_is_valid(int fd)
{
REQUIRE(fcntl(fd, F_GETFD) != -1);
}
void test_check_file_exists(const char* filename)
{
REQUIRE(access(filename, F_OK) == 0);
}
void test_remove_file(const char* filename)
{
test_check_file_exists(filename);
REQUIRE(std::remove(filename) == 0);
}

View File

@@ -1,224 +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.
//
//===----------------------------------------------------------------------===//
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/cufile.cuh>
#include <cstdio>
#include <testing.cuh>
#include <unistd.h>
#include "common.h"
#if _CCCL_COMPILER(GCC, >=, 13)
_CCCL_DIAG_SUPPRESS_GCC("-Wself-move")
#endif // _CCCL_COMPILER(GCC, >=, 13)
_CCCL_DIAG_SUPPRESS_CLANG("-Wself-move")
// todo: test error states and resetting errno
C2H_CCCLRT_TEST("cuFile cufile", "[cufile][cufile]")
{
constexpr auto filename = "cufile_test_file";
// 1. Test public cufile types and properties.
STATIC_REQUIRE(cuda::std::is_base_of_v<cudax::cufile_ref, cudax::cufile>);
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile::off_type, ::off_t>);
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile::native_handle_type, int>);
// 2. Test default constructor.
STATIC_REQUIRE(cuda::std::is_nothrow_default_constructible_v<cudax::cufile>);
{
cudax::cufile file;
REQUIRE(file.get() == nullptr);
REQUIRE(file.native_handle() == -1);
}
// 3. Test cufile(const char*, cufile_open_mode) constructor.
STATIC_REQUIRE(cuda::std::is_constructible_v<cudax::cufile, const char*, cudax::cufile_open_mode>);
{
cudax::cufile file{filename, cudax::cufile_open_mode::out};
REQUIRE(file.get() != nullptr);
test_check_fd_is_valid(file.native_handle());
test_check_file_exists(filename);
// todo: test different open flags
}
test_remove_file(filename);
// 4. Test copy constructor.
STATIC_REQUIRE(!cuda::std::is_copy_constructible_v<cudax::cufile>);
// 5. Test move constructor.
STATIC_REQUIRE(cuda::std::is_nothrow_move_constructible_v<cudax::cufile>);
{
cudax::cufile file1{filename, cudax::cufile_open_mode::out};
test_check_file_exists(filename);
cudax::cufile file2{cuda::std::move(file1)};
REQUIRE(file1.get() == nullptr);
REQUIRE(file1.native_handle() == -1);
REQUIRE(file2.get() != nullptr);
test_check_fd_is_valid(file2.native_handle());
}
test_remove_file(filename);
// 6. Test copy assignment.
STATIC_REQUIRE(!cuda::std::is_copy_assignable_v<cudax::cufile>);
// 7. Test move assignment.
STATIC_REQUIRE(cuda::std::is_move_assignable_v<cudax::cufile>);
{
cudax::cufile file2;
{
cudax::cufile file1{filename, cudax::cufile_open_mode::out};
// self move assignment
file1 = cuda::std::move(file1);
REQUIRE(file1.get() != nullptr);
test_check_fd_is_valid(file1.native_handle());
test_check_file_exists(filename);
// move assignment
file2 = cuda::std::move(file1);
REQUIRE(file1.get() == nullptr);
REQUIRE(file1.native_handle() == -1);
REQUIRE(file2.get() != nullptr);
test_check_fd_is_valid(file2.native_handle());
}
test_check_file_exists(filename);
}
test_remove_file(filename);
// 8. Test destructor.
STATIC_REQUIRE(cuda::std::is_nothrow_destructible_v<cudax::cufile>);
// 9. Test is_open().
STATIC_REQUIRE(noexcept(cuda::std::declval<cudax::cufile>().is_open()));
STATIC_REQUIRE(cuda::std::is_same_v<bool, decltype(cuda::std::declval<cudax::cufile>().is_open())>);
{
cudax::cufile file;
REQUIRE(!file.is_open());
file = cudax::cufile{filename, cudax::cufile_open_mode::out};
test_check_file_exists(filename);
REQUIRE(file.is_open());
}
test_remove_file(filename);
// 10. Test open_mode().
STATIC_REQUIRE(!noexcept(cuda::std::declval<cudax::cufile>().open_mode()));
STATIC_REQUIRE(
cuda::std::is_same_v<cudax::cufile_open_mode, decltype(cuda::std::declval<cudax::cufile>().open_mode())>);
{
cudax::cufile file;
REQUIRE(file.open_mode() == cudax::cufile_open_mode{});
file = cudax::cufile{filename, cudax::cufile_open_mode::out};
test_check_file_exists(filename);
REQUIRE(file.open_mode() == cudax::cufile_open_mode::out);
// todo: test other flags
}
test_remove_file(filename);
// 11. Test open().
STATIC_REQUIRE(!noexcept(cuda::std::declval<cudax::cufile>().open(
cuda::std::declval<const char*>(), cuda::std::declval<cudax::cufile_open_mode>())));
STATIC_REQUIRE(
cuda::std::is_same_v<void,
decltype(cuda::std::declval<cudax::cufile>().open(
cuda::std::declval<const char*>(), cuda::std::declval<cudax::cufile_open_mode>()))>);
{
cudax::cufile file;
REQUIRE(!file.is_open());
file.open(filename, cudax::cufile_open_mode::out);
REQUIRE(file.get() != nullptr);
test_check_fd_is_valid(file.native_handle());
test_check_file_exists(filename);
REQUIRE(file.is_open());
CHECK_THROWS_AS(file.open(filename, cudax::cufile_open_mode::out), std::runtime_error);
}
test_remove_file(filename);
// 12. Test close().
STATIC_REQUIRE(!noexcept(cuda::std::declval<cudax::cufile>().close()));
STATIC_REQUIRE(cuda::std::is_same_v<void, decltype(cuda::std::declval<cudax::cufile>().close())>);
{
cudax::cufile file;
file.close();
REQUIRE(file.get() == nullptr);
REQUIRE(file.native_handle() == -1);
file.open(filename, cudax::cufile_open_mode::out);
REQUIRE(file.get() != nullptr);
test_check_fd_is_valid(file.native_handle());
test_check_file_exists(filename);
file.close();
REQUIRE(file.get() == nullptr);
REQUIRE(file.native_handle() == -1);
file.close();
REQUIRE(file.get() == nullptr);
REQUIRE(file.native_handle() == -1);
}
test_remove_file(filename);
// 13. Test native_handle().
STATIC_REQUIRE(noexcept(cuda::std::declval<cudax::cufile>().native_handle()));
STATIC_REQUIRE(cuda::std::is_same_v<int, decltype(cuda::std::declval<cudax::cufile>().native_handle())>);
// 14. Test release().
STATIC_REQUIRE(noexcept(cuda::std::declval<cudax::cufile>().release()));
STATIC_REQUIRE(cuda::std::is_same_v<int, decltype(cuda::std::declval<cudax::cufile>().release())>);
{
cudax::cufile file;
REQUIRE(file.release() == -1);
file.open(filename, cudax::cufile_open_mode::out);
REQUIRE(file.get() != nullptr);
test_check_fd_is_valid(file.native_handle());
int fd = file.release();
REQUIRE(file.get() == nullptr);
REQUIRE(file.native_handle() == -1);
REQUIRE(close(fd) == 0);
}
test_remove_file(filename);
// 15. Test from_native_handle(native_handle).
STATIC_REQUIRE(!noexcept(cudax::cufile::from_native_handle(cuda::std::declval<int>())));
STATIC_REQUIRE(
cuda::std::is_same_v<cudax::cufile, decltype(cudax::cufile::from_native_handle(cuda::std::declval<int>()))>);
{
FILE* cfile = std::fopen(filename, "w");
test_check_file_exists(filename);
int fd = fileno(cfile);
REQUIRE(fd != -1);
cudax::cufile file = cudax::cufile::from_native_handle(fd);
REQUIRE(file.get() != nullptr);
REQUIRE(file.native_handle() == fd);
}
test_remove_file(filename);
}

View File

@@ -1,69 +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.
//
//===----------------------------------------------------------------------===//
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/cufile.cuh>
#include <cufile.h>
#include <testing.cuh>
#include "common.h"
C2H_CCCLRT_TEST("cuFile cufile_ref", "[cufile][cufile]")
{
constexpr auto filename = "cufile_ref_test_file";
// 1. Test public cufile_ref types and properties.
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_ref::off_type, ::off_t>);
// 2. Test default constructor.
STATIC_REQUIRE(!cuda::std::is_default_constructible_v<cudax::cufile_ref>);
// 3. Test cufile_ref(CUfileHandle_t) constructor.
STATIC_REQUIRE(cuda::std::is_nothrow_constructible_v<cudax::cufile_ref, CUfileHandle_t>);
STATIC_REQUIRE(cuda::std::is_convertible_v<CUfileHandle_t, cudax::cufile_ref>);
{
cudax::cufile file{filename, cudax::cufile_open_mode::out};
cudax::cufile_ref file_ref{file.get()};
REQUIRE(file_ref.get() == file.get());
}
test_remove_file(filename);
// 4. Test copy constructor.
STATIC_REQUIRE(cuda::std::is_trivially_copy_constructible_v<cudax::cufile_ref>);
// 5. Test move constructor.
STATIC_REQUIRE(cuda::std::is_trivially_move_constructible_v<cudax::cufile_ref>);
// 6. Test copy assignment.
STATIC_REQUIRE(cuda::std::is_trivially_copy_assignable_v<cudax::cufile_ref>);
// 7. Test move assignment.
STATIC_REQUIRE(cuda::std::is_trivially_move_assignable_v<cudax::cufile_ref>);
// 8. Test destructor.
STATIC_REQUIRE(cuda::std::is_trivially_destructible_v<cudax::cufile_ref>);
// 9. Test get().
STATIC_REQUIRE(noexcept(cuda::std::declval<cudax::cufile_ref>().get()));
STATIC_REQUIRE(cuda::std::is_same_v<CUfileHandle_t, decltype(cuda::std::declval<cudax::cufile_ref>().get())>);
{
const cudax::cufile file;
REQUIRE(cudax::cufile_ref{file}.get() == nullptr);
}
{
cudax::cufile file{filename, cudax::cufile_open_mode::out};
REQUIRE(cudax::cufile_ref{file}.get() != nullptr);
}
test_remove_file(filename);
}

View File

@@ -1,289 +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.
//
//===----------------------------------------------------------------------===//
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/cufile.cuh>
#include <stdexcept>
#include <testing.cuh>
void test_is_open(bool is_open)
{
STATIC_REQUIRE(cuda::std::is_same_v<bool, decltype(cudax::cufile_driver.is_open())>);
STATIC_REQUIRE(noexcept(cudax::cufile_driver.is_open()));
REQUIRE(cudax::cufile_driver.is_open() == is_open);
}
template <class Attr>
void test_attribute_range([[maybe_unused]] const Attr& attr, [[maybe_unused]] const bool is_open)
{
#if _CCCL_CTK_AT_LEAST(13, 0)
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_driver_attribute_range<Attr>,
decltype(cudax::cufile_driver.attribute_range(attr))>);
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.attribute_range(attr)));
const bool expect_success =
is_open
|| !(cuda::std::is_same_v<Attr, cudax::cufile_driver_attributes::max_device_cache_size_kb_t>
|| cuda::std::is_same_v<Attr, cudax::cufile_driver_attributes::max_device_pinned_mem_size_kb_t>);
if (expect_success)
{
CHECK_NOTHROW((void) cudax::cufile_driver.attribute_range(attr));
}
else
{
CHECK_THROWS_AS((void) cudax::cufile_driver.attribute_range(attr), std::runtime_error);
}
#endif // _CCCL_CTK_AT_LEAST(13, 0)
}
void test_attribute_ranges(const bool is_open)
{
using namespace cudax::cufile_driver_attributes;
// CUFileSizeTConfigParameter_t
test_attribute_range(max_io_queue_depth, is_open);
test_attribute_range(max_io_threads, is_open);
test_attribute_range(min_io_threshold_size_kb, is_open);
test_attribute_range(max_request_parallelism, is_open);
test_attribute_range(max_direct_io_size_kb, is_open);
test_attribute_range(max_device_cache_size_kb, is_open);
test_attribute_range(per_buffer_cache_size_kb, is_open);
test_attribute_range(max_device_pinned_mem_size_kb, is_open);
test_attribute_range(io_batchsize, is_open);
test_attribute_range(pollthreshold_size_kb, is_open);
test_attribute_range(batch_io_timeout_ms, is_open);
// CUFileBoolConfigParameter_t are unsupported
// CUfileDriverStatusFlags are unsupported
// CUfileFeatureFlags are unsupported
}
template <class Attr>
void test_get_attribute(const Attr& attr, const bool is_open)
{
using ValueType = typename Attr::type;
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.attribute(attr)));
STATIC_REQUIRE(cuda::std::is_same_v<ValueType, decltype(cudax::cufile_driver.attribute(attr))>);
if (is_open || Attr::__can_be_get_when_closed)
{
CHECK_NOTHROW((void) cudax::cufile_driver.attribute(attr));
}
else
{
CHECK_THROWS_AS((void) cudax::cufile_driver.attribute(attr), std::runtime_error);
}
}
void test_get_attributes(const bool is_open)
{
using namespace cudax::cufile_driver_attributes;
// CUFileSizeTConfigParameter_t
test_get_attribute(max_io_queue_depth, is_open);
test_get_attribute(max_io_threads, is_open);
test_get_attribute(min_io_threshold_size_kb, is_open);
test_get_attribute(max_request_parallelism, is_open);
test_get_attribute(max_direct_io_size_kb, is_open);
test_get_attribute(max_device_cache_size_kb, is_open);
test_get_attribute(per_buffer_cache_size_kb, is_open);
test_get_attribute(max_device_pinned_mem_size_kb, is_open);
test_get_attribute(io_batchsize, is_open);
test_get_attribute(pollthreshold_size_kb, is_open);
test_get_attribute(batch_io_timeout_ms, is_open);
// CUFileBoolConfigParameter_t
test_get_attribute(use_poll_mode, is_open);
test_get_attribute(allow_compat_mode, is_open);
test_get_attribute(force_compat_mode, is_open);
test_get_attribute(fs_misc_api_check_aggressive, is_open);
test_get_attribute(parallel_io, is_open);
// test_get_attribute(profile_nvtx is_open);
test_get_attribute(allow_system_memory, is_open);
test_get_attribute(use_pcip2pdma, is_open);
test_get_attribute(prefer_io_uring, is_open);
test_get_attribute(force_odirect_mode, is_open);
test_get_attribute(skip_topology_detection, is_open);
test_get_attribute(stream_memops_bypass, is_open);
// CUfileDriverStatusFlags
test_get_attribute(has_luster_support, is_open);
test_get_attribute(has_wekafs_support, is_open);
test_get_attribute(has_nfs_support, is_open);
test_get_attribute(has_gpfs_support, is_open);
test_get_attribute(has_nvme_support, is_open);
test_get_attribute(has_nvmeof_support, is_open);
test_get_attribute(has_scsi_support, is_open);
test_get_attribute(has_scaleflux_csd_support, is_open);
test_get_attribute(has_nvmesh_support, is_open);
test_get_attribute(has_beegfs_support, is_open);
test_get_attribute(has_nvme_p2p_support, is_open);
test_get_attribute(has_scatefs_support, is_open);
// CUfileFeatureFlags
test_get_attribute(has_dynamic_routing_support, is_open);
test_get_attribute(has_batch_io_support, is_open);
test_get_attribute(has_streams_support, is_open);
test_get_attribute(has_parallel_io_support, is_open);
}
template <class Attr>
void test_set_attribute(const Attr& attr, const bool is_open)
{
using ValueType = typename Attr::type;
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.set_attribute(attr, cuda::std::declval<ValueType>())));
STATIC_REQUIRE(
cuda::std::is_same_v<void, decltype(cudax::cufile_driver.set_attribute(attr, cuda::std::declval<ValueType>()))>);
const bool expect_success = is_open == Attr::__can_be_set_when_opened || !is_open == Attr::__can_be_set_when_closed;
ValueType value{};
if (expect_success)
{
CHECK_NOTHROW(value = cudax::cufile_driver.attribute(attr));
}
if (expect_success)
{
CHECK_NOTHROW(cudax::cufile_driver.set_attribute(attr, value));
}
else
{
CHECK_THROWS_AS(cudax::cufile_driver.set_attribute(attr, value), std::runtime_error);
}
}
void test_set_attributes(const bool is_open)
{
using namespace cudax::cufile_driver_attributes;
// CUFileSizeTConfigParameter_t
test_get_attribute(max_io_queue_depth, is_open);
test_get_attribute(max_io_threads, is_open);
test_get_attribute(min_io_threshold_size_kb, is_open);
test_get_attribute(max_request_parallelism, is_open);
test_get_attribute(max_direct_io_size_kb, is_open);
test_get_attribute(max_device_cache_size_kb, is_open);
test_get_attribute(per_buffer_cache_size_kb, is_open);
test_get_attribute(max_device_pinned_mem_size_kb, is_open);
test_get_attribute(io_batchsize, is_open);
test_get_attribute(pollthreshold_size_kb, is_open);
test_get_attribute(batch_io_timeout_ms, is_open);
// CUFileBoolConfigParameter_t
test_get_attribute(use_poll_mode, is_open);
test_get_attribute(allow_compat_mode, is_open);
test_get_attribute(force_compat_mode, is_open);
test_get_attribute(fs_misc_api_check_aggressive, is_open);
test_get_attribute(parallel_io, is_open);
// test_get_attribute(profile_nvtx is_open);
test_get_attribute(allow_system_memory, is_open);
test_get_attribute(use_pcip2pdma, is_open);
test_get_attribute(prefer_io_uring, is_open);
test_get_attribute(force_odirect_mode, is_open);
test_get_attribute(skip_topology_detection, is_open);
test_get_attribute(stream_memops_bypass, is_open);
// CUfileDriverStatusFlags are unsupported
// CUfileFeatureFlags are unsupported
}
void test_open()
{
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.open()));
STATIC_REQUIRE(cuda::std::is_same_v<void, decltype(cudax::cufile_driver.open())>);
CHECK_NOTHROW(cudax::cufile_driver.open());
}
void test_close()
{
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.close()));
STATIC_REQUIRE(cuda::std::is_same_v<void, decltype(cudax::cufile_driver.close())>);
CHECK_NOTHROW(cudax::cufile_driver.close());
}
C2H_CCCLRT_TEST("cuFile driver", "[cufile][driver]")
{
// 1. Test that the driver initial state is closed.
test_is_open(false);
// 2. Test that the attribute ranges can be queried when the driver is closed.
test_attribute_ranges(false);
// 3. Test getting attribute values when the driver is closed.
test_get_attributes(false);
// 4. Test setting attribute values when the driver is closed.
test_set_attributes(false);
// 5. Open the driver.
test_open();
// 6. Test that the driver is opened.
test_is_open(true);
// 7. Test that the attribute ranges can be queried when the driver is opened.
test_attribute_ranges(true);
// 8. Test getting attribute values when the driver is opened.
test_get_attributes(true);
// 9. Test setting attribute values when the driver is opened.
test_set_attributes(true);
// 10. Close the driver.
test_close();
// 11. Test that the driver is closed.
test_is_open(false);
// 12. Test that the attribute ranges can be queried when the driver after is closed.
test_attribute_ranges(false);
// 13. Test getting attribute values when the driver after is closed.
test_get_attributes(false);
// 14. Test setting attribute values when the driver after is closed.
test_set_attributes(false);
// 15. Reopen the driver.
test_open();
// 16. Test that the driver is opened.
test_is_open(true);
// 17. Reopen the driver for second time.
test_open();
// 18. Test that the driver is opened.
test_is_open(true);
// 19. Close the driver.
test_close();
// 20. Test that the driver is closed.
test_is_open(false);
// 21. Close the driver again.
test_close();
// 22. Test that the driver is closed.
test_is_open(false);
}

View File

@@ -1,63 +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.
//
//===----------------------------------------------------------------------===//
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/cufile.cuh>
#include <cstdio>
#include <stdexcept>
#include <testing.cuh>
#include "common.h"
void test_register_native_handle()
{
constexpr auto filename = "cufile_driver_register_test_file";
// 1. Check noexcept.
STATIC_REQUIRE(!noexcept(cudax::cufile_driver.register_native_handle(cuda::std::declval<int>())));
STATIC_REQUIRE(noexcept(cudax::cufile_driver.deregister_native_handle(cuda::std::declval<cudax::cufile_ref>())));
// 2. Test return type.
STATIC_REQUIRE(
cuda::std::is_same_v<cudax::cufile_ref,
decltype(cudax::cufile_driver.register_native_handle(cuda::std::declval<int>()))>);
STATIC_REQUIRE(
cuda::std::
is_same_v<void, decltype(cudax::cufile_driver.deregister_native_handle(cuda::std::declval<cudax::cufile_ref>()))>);
FILE* cfile = std::fopen(filename, "w");
test_check_file_exists(filename);
int fd = fileno(cfile);
REQUIRE(fd != -1);
// 3. Register a file handle. Should return a valid cuFile handle.
cudax::cufile_ref file = cudax::cufile_driver.register_native_handle(fd);
REQUIRE(file.get() != nullptr);
// 4. Reregistering the same file handle should result in an cufile_error.
CHECK_THROWS_AS((void) cudax::cufile_driver.register_native_handle(fd), cudax::cufile_error);
// 5. Deregister the cuFile handles. Can be called multiple times.
cudax::cufile_driver.deregister_native_handle(file);
cudax::cufile_driver.deregister_native_handle(file); // should be fine
test_remove_file(filename);
}
C2H_CCCLRT_TEST("cuFile driver register", "[cufile][driver]")
{
// 1. Test registering a native file handle.
test_register_native_handle();
}

View File

@@ -1,98 +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.
//
//===----------------------------------------------------------------------===//
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/cufile.cuh>
#include <testing.cuh>
C2H_CCCLRT_TEST("cuFile open mode", "[cufile][open_mode]")
{
// 1. Test cufile_open_flags properties
STATIC_REQUIRE(cuda::std::is_scoped_enum_v<cudax::cufile_open_mode>);
STATIC_REQUIRE(cuda::std::is_same_v<unsigned, cuda::std::underlying_type_t<cudax::cufile_open_mode>>);
// 2. Test cufile_oepn_flags values
STATIC_REQUIRE(cuda::std::to_underlying(cudax::cufile_open_mode::in) == 0x01u);
STATIC_REQUIRE(cuda::std::to_underlying(cudax::cufile_open_mode::out) == 0x02u);
STATIC_REQUIRE(cuda::std::to_underlying(cudax::cufile_open_mode::trunc) == 0x04u);
STATIC_REQUIRE(cuda::std::to_underlying(cudax::cufile_open_mode::noreplace) == 0x08u);
STATIC_REQUIRE(cuda::std::to_underlying(cudax::cufile_open_mode::direct) == 0x10u);
// 3. Test operator|(cufile_open_flags, cufile_open_flags)
{
constexpr auto lhs = cudax::cufile_open_mode::in;
constexpr auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode, decltype(lhs | rhs)>);
STATIC_REQUIRE(noexcept(lhs | rhs));
STATIC_REQUIRE(cuda::std::to_underlying(lhs | rhs) == 0x3u);
STATIC_REQUIRE(cuda::std::to_underlying(lhs | lhs) == 0x1u);
}
// 3. Test operator=|(cufile_open_flags&, cufile_open_flags)
{
auto lhs = cudax::cufile_open_mode::in;
auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode&, decltype(lhs |= rhs)>);
STATIC_REQUIRE(noexcept(lhs |= rhs));
REQUIRE(cuda::std::to_underlying(lhs |= cudax::cufile_open_mode::in) == 0x1u);
REQUIRE(cuda::std::to_underlying(lhs |= rhs) == 0x3u);
}
// 4. Test operator&(cufile_open_flags, cufile_open_flags)
{
constexpr auto lhs = cudax::cufile_open_mode::in;
constexpr auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode, decltype(lhs & rhs)>);
STATIC_REQUIRE(noexcept(lhs & rhs));
STATIC_REQUIRE(cuda::std::to_underlying(lhs & lhs) == 0x1u);
STATIC_REQUIRE(cuda::std::to_underlying(lhs & rhs) == 0x0u);
}
// 5. Test operator=&(cufile_open_flags&, cufile_open_flags)
{
auto lhs = cudax::cufile_open_mode::in;
auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode&, decltype(lhs &= rhs)>);
STATIC_REQUIRE(noexcept(lhs &= rhs));
REQUIRE(cuda::std::to_underlying(lhs &= cudax::cufile_open_mode::in) == 0x1u);
REQUIRE(cuda::std::to_underlying(lhs &= rhs) == 0x0u);
}
// 5. Test operator^(cufile_open_flags, cufile_open_flags)
{
constexpr auto lhs = cudax::cufile_open_mode::in;
constexpr auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode, decltype(lhs ^ rhs)>);
STATIC_REQUIRE(noexcept(lhs ^ rhs));
STATIC_REQUIRE(cuda::std::to_underlying(lhs ^ lhs) == 0x0u);
STATIC_REQUIRE(cuda::std::to_underlying(lhs ^ rhs) == 0x3u);
}
// 6. Test operator=^(cufile_open_flags&, cufile_open_flags)
{
auto lhs = cudax::cufile_open_mode::in;
auto rhs = cudax::cufile_open_mode::out;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode&, decltype(lhs ^= rhs)>);
STATIC_REQUIRE(noexcept(lhs ^= rhs));
REQUIRE(cuda::std::to_underlying(lhs ^= rhs) == 0x3u);
REQUIRE(cuda::std::to_underlying(lhs ^= cudax::cufile_open_mode::in) == 0x2u);
}
// 5. Test operator~(cufile_open_flags)
{
constexpr auto v = cudax::cufile_open_mode::in;
STATIC_REQUIRE(cuda::std::is_same_v<cudax::cufile_open_mode, decltype(~v)>);
STATIC_REQUIRE(noexcept(~v));
STATIC_REQUIRE(cuda::std::to_underlying(~v) == ~0x1u);
}
}