Added 863 files from NVIDIA/cccl sparse checkout: - c2h/ (27 files): Catch2 test helpers — generators, validators, runner - nvbench_helper/ (10 files): Benchmark harness utilities - cmake/ (29 files): CMake presets and build helpers - cudax/ (794 files): Experimental CUDA extensions - AGENTS.md: NVIDIA's official AI agent instructions for CCCL - CMakePresets.json: Standardized build configurations - cccl-version.json: Version tracking Also added CCCL_ASSET_MAP.md mapping all 4295 CCCL files to competition value and PRD items. cccl_upstream now covers 100% of competition-critical assets: - 27 tuning headers (SM80/90/100 benchmark data) - 32 dispatch headers (algorithm implementations) - 60 Thrust examples (correctness verification) - 217 CUB Catch2 tests (regression matrix) - 153 CUB benchmarks (parameter space search) - 18 CUB examples (API verification) - 27 test helpers + benchmark harness - 794 cudax experimental extensions
225 lines
7.1 KiB
Plaintext
225 lines
7.1 KiB
Plaintext
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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);
|
|
}
|