stream.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 <sys/types.h>
8 #include <cstdlib>
9 #include <tuple>
10 #include <utility>
11 
12 #include <kvikio/shim/cuda.hpp>
13 
14 namespace kvikio {
15 
35 class StreamFuture {
36  private:
37  struct ArgByVal {
38  std::size_t size;
39  off_t file_offset;
40  off_t devPtr_offset;
41  ssize_t bytes_done;
42  };
43 
44  void* _devPtr_base{nullptr};
45  CUstream _stream{nullptr};
46  ArgByVal* _val{nullptr};
47  bool _stream_synchronized{false};
48 
49  public:
50  StreamFuture() noexcept = default;
51 
53  void* devPtr_base, std::size_t size, off_t file_offset, off_t devPtr_offset, CUstream stream);
54 
58  StreamFuture(StreamFuture const&) = delete;
59  StreamFuture& operator=(StreamFuture& o) = delete;
60  StreamFuture(StreamFuture&& o) noexcept;
61  StreamFuture& operator=(StreamFuture&& o) noexcept;
62 
69  std::tuple<void*, std::size_t*, off_t*, off_t*, ssize_t*, CUstream> get_args() const;
70 
78  std::size_t check_bytes_done();
79 
84  ~StreamFuture() noexcept;
85 };
86 
87 } // namespace kvikio
Future of an asynchronous IO operation.
Definition: stream.hpp:35
~StreamFuture() noexcept
Free the by-value arguments and make sure the associated CUDA stream has been synchronized.
StreamFuture(StreamFuture const &)=delete
StreamFuture support move semantic but isn't copyable.
std::tuple< void *, std::size_t *, off_t *, off_t *, ssize_t *, CUstream > get_args() const
Return the arguments of the future call.
std::size_t check_bytes_done()
Return the number of bytes read or written by the future operation.
KvikIO namespace.
Definition: batch.hpp:16