All Classes Files Functions Enumerations Enumerator Pages
stream.hpp
1 /*
2  * Copyright (c) 2023-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <sys/types.h>
19 #include <cstdlib>
20 #include <tuple>
21 #include <utility>
22 
23 #include <kvikio/shim/cuda.hpp>
24 
25 namespace kvikio {
26 
46 class StreamFuture {
47  private:
48  struct ArgByVal {
49  std::size_t size;
50  off_t file_offset;
51  off_t devPtr_offset;
52  ssize_t bytes_done;
53  };
54 
55  void* _devPtr_base{nullptr};
56  CUstream _stream{nullptr};
57  ArgByVal* _val{nullptr};
58  bool _stream_synchronized{false};
59 
60  public:
61  StreamFuture() noexcept = default;
62 
64  void* devPtr_base, std::size_t size, off_t file_offset, off_t devPtr_offset, CUstream stream);
65 
69  StreamFuture(const StreamFuture&) = delete;
70  StreamFuture& operator=(StreamFuture& o) = delete;
71  StreamFuture(StreamFuture&& o) noexcept;
72  StreamFuture& operator=(StreamFuture&& o) noexcept;
73 
80  std::tuple<void*, std::size_t*, off_t*, off_t*, ssize_t*, CUstream> get_args() const;
81 
89  std::size_t check_bytes_done();
90 
95  ~StreamFuture() noexcept;
96 };
97 
98 } // namespace kvikio
Future of an asynchronous IO operation.
Definition: stream.hpp:46
StreamFuture(const StreamFuture &)=delete
StreamFuture support move semantic but isn't copyable.
~StreamFuture() noexcept
Free the by-value arguments and make sure the associated CUDA stream has been synchronized.
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.