driver.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <vector>
8 
9 #include <kvikio/shim/cufile.hpp>
10 #include <kvikio/shim/cufile_h_wrapper.hpp>
11 
12 namespace kvikio {
13 
14 #ifdef KVIKIO_CUFILE_FOUND
15 
16 class DriverInitializer {
17  // Optional, if not used cuFiles opens the driver automatically
18  public:
19  DriverInitializer();
20 
21  DriverInitializer(DriverInitializer const&) = delete;
22  DriverInitializer& operator=(DriverInitializer const&) = delete;
23  DriverInitializer(DriverInitializer&&) noexcept = delete;
24  DriverInitializer& operator=(DriverInitializer&&) noexcept = delete;
25 
26  ~DriverInitializer() noexcept;
27 };
28 
29 class DriverProperties {
30  private:
31  CUfileDrvProps_t _props{};
32  bool _initialized{false};
33 
34  // Because Cython does not handle exceptions in the default
35  // constructor, we initialize `_props` lazily.
36  void lazy_init();
37 
38  public:
39  DriverProperties() = default;
40 
41  bool is_gds_available();
42 
43  [[nodiscard]] unsigned int get_nvfs_major_version();
44 
45  [[nodiscard]] unsigned int get_nvfs_minor_version();
46 
47  [[nodiscard]] bool get_nvfs_allow_compat_mode();
48 
49  [[nodiscard]] bool get_nvfs_poll_mode();
50 
51  [[nodiscard]] std::size_t get_nvfs_poll_thresh_size();
52 
53  void set_nvfs_poll_mode(bool enable);
54 
55  void set_nvfs_poll_thresh_size(std::size_t size_in_kb);
56 
57  [[nodiscard]] std::vector<CUfileDriverControlFlags> get_nvfs_statusflags();
58 
59  [[nodiscard]] std::size_t get_max_device_cache_size();
60 
61  void set_max_device_cache_size(std::size_t size_in_kb);
62 
63  [[nodiscard]] std::size_t get_per_buffer_cache_size();
64 
65  [[nodiscard]] std::size_t get_max_pinned_memory_size();
66 
67  void set_max_pinned_memory_size(std::size_t size_in_kb);
68 
69  [[nodiscard]] std::size_t get_max_batch_io_size();
70 };
71 
72 #else
74  // Implement a non-default constructor to avoid `unused variable` warnings downstream
76 };
77 
79  // Implement a non-default constructor to avoid `unused variable` warnings downstream
81 
82  static bool is_gds_available();
83 
84  [[nodiscard]] static unsigned int get_nvfs_major_version();
85 
86  [[nodiscard]] static unsigned int get_nvfs_minor_version();
87 
88  [[nodiscard]] static bool get_nvfs_allow_compat_mode();
89 
90  [[nodiscard]] static bool get_nvfs_poll_mode();
91 
92  [[nodiscard]] static std::size_t get_nvfs_poll_thresh_size();
93 
94  static void set_nvfs_poll_mode(bool enable);
95 
96  static void set_nvfs_poll_thresh_size(std::size_t size_in_kb);
97 
98  [[nodiscard]] static std::vector<CUfileDriverControlFlags> get_nvfs_statusflags();
99 
100  [[nodiscard]] static std::size_t get_max_device_cache_size();
101 
102  static void set_max_device_cache_size(std::size_t size_in_kb);
103 
104  [[nodiscard]] static std::size_t get_per_buffer_cache_size();
105 
106  [[nodiscard]] static std::size_t get_max_pinned_memory_size();
107 
108  static void set_max_pinned_memory_size(std::size_t size_in_kb);
109 
110  [[nodiscard]] std::size_t get_max_batch_io_size();
111 };
112 #endif
113 
114 } // namespace kvikio
KvikIO namespace.
Definition: batch.hpp:16