23 #include <kvikio/error.hpp>
24 #include <kvikio/file_handle.hpp>
25 #include <kvikio/shim/cufile.hpp>
44 CUfileOpcode_t opcode;
47 #ifdef KVIKIO_CUFILE_BATCH_API_FOUND
64 bool _initialized{
false};
65 int _max_num_events{};
66 CUfileBatchHandle_t _handle{};
69 BatchHandle() noexcept = default;
76 BatchHandle(
int max_num_events) : _initialized{
true}, _max_num_events{max_num_events}
78 CUFILE_TRY(cuFileAPI::instance().BatchIOSetUp(&_handle, max_num_events));
84 BatchHandle(
const BatchHandle&) =
delete;
85 BatchHandle& operator=(BatchHandle
const&) =
delete;
86 BatchHandle(BatchHandle&& o) noexcept
87 : _initialized{std::exchange(o._initialized,
false)},
88 _max_num_events{std::exchange(o._max_num_events, 0)}
90 _handle = std::exchange(o._handle, CUfileBatchHandle_t{});
92 ~BatchHandle() noexcept { close(); }
94 [[nodiscard]]
bool closed() const noexcept {
return !_initialized; }
101 if (closed()) {
return; }
102 _initialized =
false;
104 cuFileAPI::instance().BatchIODestroy(_handle);
113 void submit(
const std::vector<BatchOp>& operations)
115 if (convert_size2ssize(operations.size()) > _max_num_events) {
116 throw CUfileException(
"Cannot submit more than the max_num_events)");
118 std::vector<CUfileIOParams_t> io_batch_params;
119 io_batch_params.reserve(operations.size());
120 for (
const auto& op : operations) {
121 if (op.file_handle.is_compat_mode_on()) {
122 throw CUfileException(
"Cannot submit a FileHandle opened in compatibility mode");
125 io_batch_params.push_back(CUfileIOParams_t{.mode = CUFILE_BATCH,
126 .u = {.batch = {.devPtr_base = op.devPtr_base,
127 .file_offset = op.file_offset,
128 .devPtr_offset = op.devPtr_offset,
130 .fh = op.file_handle.handle(),
135 CUFILE_TRY(cuFileAPI::instance().BatchIOSubmit(
136 _handle, io_batch_params.size(), io_batch_params.data(), 0));
149 std::vector<CUfileIOEvents_t> status(
unsigned min_nr,
151 struct timespec* timeout =
nullptr)
153 std::vector<CUfileIOEvents_t> ret;
154 ret.resize(_max_num_events);
155 CUFILE_TRY(cuFileAPI::instance().BatchIOGetStatus(_handle, min_nr, &max_nr, &ret[0], timeout));
160 void cancel() { CUFILE_TRY(cuFileAPI::instance().BatchIOCancel(_handle)); }
171 throw CUfileException(
"BatchHandle requires cuFile's batch API, please build with CUDA v12.1+");
174 [[nodiscard]]
bool closed()
const noexcept {
return true; }
176 void close() noexcept {}
178 void submit(
const std::vector<BatchOp>& operations) {}
180 std::vector<CUfileIOEvents_t> status(
unsigned min_nr,
182 struct timespec* timeout =
nullptr)
184 return std::vector<CUfileIOEvents_t>{};
Handle of an open file registered with cufile.
IO operation used when submitting batches.