batch.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <cstddef>
8 #include <ctime>
9 #include <utility>
10 #include <vector>
11 
12 #include <kvikio/error.hpp>
13 #include <kvikio/file_handle.hpp>
14 #include <kvikio/shim/cufile.hpp>
15 
16 namespace kvikio {
17 
21 struct BatchOp {
22  // The file handle of the file to read or write
23  FileHandle& file_handle;
24  // Base address of buffer in device memory (host memory not supported).
25  void* devPtr_base;
26  // Offset in the file to read from or write to.
27  off_t file_offset;
28  // Offset relative to the `devPtr_base` pointer to write into or read from.
29  off_t devPtr_offset;
30  // Size in bytes to read or write.
31  size_t size;
32  // The operation type: CUFILE_READ or CUFILE_WRITE.
33  CUfileOpcode_t opcode;
34 };
35 
49 class BatchHandle {
50  private:
51  bool _initialized{false};
52  int _max_num_events{};
53  CUfileBatchHandle_t _handle{};
54 
55  public:
56  BatchHandle() noexcept = default;
57 
63  BatchHandle(int max_num_events);
64 
68  BatchHandle(BatchHandle const&) = delete;
69  BatchHandle& operator=(BatchHandle const&) = delete;
70  BatchHandle(BatchHandle&& o) noexcept;
71  ~BatchHandle() noexcept;
72 
73  [[nodiscard]] bool closed() const noexcept;
74 
78  void close() noexcept;
79 
86  void submit(std::vector<BatchOp> const& operations);
87 
98  std::vector<CUfileIOEvents_t> status(unsigned min_nr,
99  unsigned max_nr,
100  struct timespec* timeout = nullptr);
101 
102  void cancel();
103 };
104 
105 } // namespace kvikio
Handle of an cuFile batch using semantic.
Definition: batch.hpp:49
BatchHandle(int max_num_events)
Construct a batch handle.
void submit(std::vector< BatchOp > const &operations)
Submit a vector of batch operations.
BatchHandle(BatchHandle const &)=delete
BatchHandle support move semantic but isn't copyable.
void close() noexcept
Destroy the batch handle and free up resources.
std::vector< CUfileIOEvents_t > status(unsigned min_nr, unsigned max_nr, struct timespec *timeout=nullptr)
Get status of submitted operations.
Handle of an open file registered with cufile.
Definition: file_handle.hpp:33
KvikIO namespace.
Definition: batch.hpp:16
IO operation used when submitting batches.
Definition: batch.hpp:21