All Classes Namespaces Functions Enumerations Enumerator Modules Pages
driver.hpp
1 /*
2  * Copyright (c) 2021-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 <vector>
19 
20 #include <kvikio/shim/cufile.hpp>
21 #include <kvikio/shim/cufile_h_wrapper.hpp>
22 
23 namespace kvikio {
24 
25 #ifdef KVIKIO_CUFILE_FOUND
26 
27 class DriverInitializer {
28  // Optional, if not used cuFiles opens the driver automatically
29  public:
30  DriverInitializer();
31 
32  DriverInitializer(DriverInitializer const&) = delete;
33  DriverInitializer& operator=(DriverInitializer const&) = delete;
34  DriverInitializer(DriverInitializer&&) noexcept = delete;
35  DriverInitializer& operator=(DriverInitializer&&) noexcept = delete;
36 
37  ~DriverInitializer() noexcept;
38 };
39 
40 class DriverProperties {
41  private:
42  CUfileDrvProps_t _props{};
43  bool _initialized{false};
44 
45  // Because Cython does not handle exceptions in the default
46  // constructor, we initialize `_props` lazily.
47  void lazy_init();
48 
49  public:
50  DriverProperties() = default;
51 
52  bool is_gds_available();
53 
54  [[nodiscard]] unsigned int get_nvfs_major_version();
55 
56  [[nodiscard]] unsigned int get_nvfs_minor_version();
57 
58  [[nodiscard]] bool get_nvfs_allow_compat_mode();
59 
60  [[nodiscard]] bool get_nvfs_poll_mode();
61 
62  [[nodiscard]] std::size_t get_nvfs_poll_thresh_size();
63 
64  void set_nvfs_poll_mode(bool enable);
65 
66  void set_nvfs_poll_thresh_size(std::size_t size_in_kb);
67 
68  [[nodiscard]] std::vector<CUfileDriverControlFlags> get_nvfs_statusflags();
69 
70  [[nodiscard]] std::size_t get_max_device_cache_size();
71 
72  void set_max_device_cache_size(std::size_t size_in_kb);
73 
74  [[nodiscard]] std::size_t get_per_buffer_cache_size();
75 
76  [[nodiscard]] std::size_t get_max_pinned_memory_size();
77 
78  void set_max_pinned_memory_size(std::size_t size_in_kb);
79 
80  [[nodiscard]] std::size_t get_max_batch_io_size();
81 };
82 
83 #else
85  // Implement a non-default constructor to avoid `unused variable` warnings downstream
87 };
88 
90  // Implement a non-default constructor to avoid `unused variable` warnings downstream
92 
93  static bool is_gds_available();
94 
95  [[nodiscard]] static unsigned int get_nvfs_major_version();
96 
97  [[nodiscard]] static unsigned int get_nvfs_minor_version();
98 
99  [[nodiscard]] static bool get_nvfs_allow_compat_mode();
100 
101  [[nodiscard]] static bool get_nvfs_poll_mode();
102 
103  [[nodiscard]] static std::size_t get_nvfs_poll_thresh_size();
104 
105  static void set_nvfs_poll_mode(bool enable);
106 
107  static void set_nvfs_poll_thresh_size(std::size_t size_in_kb);
108 
109  [[nodiscard]] static std::vector<CUfileDriverControlFlags> get_nvfs_statusflags();
110 
111  [[nodiscard]] static std::size_t get_max_device_cache_size();
112 
113  static void set_max_device_cache_size(std::size_t size_in_kb);
114 
115  [[nodiscard]] static std::size_t get_per_buffer_cache_size();
116 
117  [[nodiscard]] static std::size_t get_max_pinned_memory_size();
118 
119  static void set_max_pinned_memory_size(std::size_t size_in_kb);
120 
121  [[nodiscard]] std::size_t get_max_batch_io_size();
122 };
123 #endif
124 
125 } // namespace kvikio
KvikIO namespace.
Definition: batch.hpp:27