21 #include <kvikio/error.hpp>
22 #include <kvikio/shim/cufile.hpp>
23 #include <kvikio/shim/cufile_h_wrapper.hpp>
28 [[nodiscard]]
inline bool get_driver_flag(
unsigned int prop,
unsigned int flag) noexcept
30 return (prop & (1U << flag)) != 0;
33 inline void set_driver_flag(
unsigned int& prop,
unsigned int flag,
bool val) noexcept
38 prop &= ~(1U << flag);
43 #ifdef KVIKIO_CUFILE_FOUND
45 class DriverInitializer {
48 DriverInitializer() { CUFILE_TRY(cuFileAPI::instance().DriverOpen()); }
50 DriverInitializer(DriverInitializer
const&) =
delete;
51 DriverInitializer& operator=(DriverInitializer
const&) =
delete;
52 DriverInitializer(DriverInitializer&&) noexcept = delete;
53 DriverInitializer& operator=(DriverInitializer&&) noexcept = delete;
58 CUFILE_TRY(cuFileAPI::instance().DriverClose());
59 }
catch (
const CUfileException& e) {
60 std::cerr <<
"Unable to close GDS file driver: ";
61 std::cerr << e.what();
62 std::cerr << std::endl;
67 class DriverProperties {
69 CUfileDrvProps_t _props{};
70 bool _initialized{
false};
76 if (_initialized) {
return; }
78 CUFILE_TRY(cuFileAPI::instance().DriverGetProperties(&_props));
82 DriverProperties() =
default;
84 bool is_gds_available()
87 return !(get_nvfs_major_version() == 0 && get_nvfs_minor_version() == 0);
90 [[nodiscard]]
unsigned int get_nvfs_major_version()
93 return _props.nvfs.major_version;
96 [[nodiscard]]
unsigned int get_nvfs_minor_version()
99 return _props.nvfs.minor_version;
102 [[nodiscard]]
bool get_nvfs_allow_compat_mode()
105 return detail::get_driver_flag(_props.nvfs.dcontrolflags, CU_FILE_ALLOW_COMPAT_MODE);
108 [[nodiscard]]
bool get_nvfs_poll_mode()
111 return detail::get_driver_flag(_props.nvfs.dcontrolflags, CU_FILE_USE_POLL_MODE);
114 [[nodiscard]] std::size_t get_nvfs_poll_thresh_size()
117 return _props.nvfs.poll_thresh_size;
120 void set_nvfs_poll_mode(
bool enable)
123 CUFILE_TRY(cuFileAPI::instance().DriverSetPollMode(enable, get_nvfs_poll_thresh_size()));
124 detail::set_driver_flag(_props.nvfs.dcontrolflags, CU_FILE_USE_POLL_MODE, enable);
127 void set_nvfs_poll_thresh_size(std::size_t size_in_kb)
130 CUFILE_TRY(cuFileAPI::instance().DriverSetPollMode(get_nvfs_poll_mode(), size_in_kb));
131 _props.nvfs.poll_thresh_size = size_in_kb;
134 [[nodiscard]] std::vector<CUfileDriverControlFlags> get_nvfs_statusflags()
137 std::vector<CUfileDriverControlFlags> ret;
138 if (detail::get_driver_flag(_props.nvfs.dcontrolflags, CU_FILE_USE_POLL_MODE)) {
139 ret.push_back(CU_FILE_USE_POLL_MODE);
141 if (detail::get_driver_flag(_props.nvfs.dcontrolflags, CU_FILE_ALLOW_COMPAT_MODE)) {
142 ret.push_back(CU_FILE_ALLOW_COMPAT_MODE);
147 [[nodiscard]] std::size_t get_max_device_cache_size()
150 return _props.max_device_cache_size;
153 void set_max_device_cache_size(std::size_t size_in_kb)
156 CUFILE_TRY(cuFileAPI::instance().DriverSetMaxCacheSize(size_in_kb));
157 _props.max_device_cache_size = size_in_kb;
160 [[nodiscard]] std::size_t get_per_buffer_cache_size()
163 return _props.per_buffer_cache_size;
166 [[nodiscard]] std::size_t get_max_pinned_memory_size()
169 return _props.max_device_pinned_mem_size;
172 void set_max_pinned_memory_size(std::size_t size_in_kb)
175 CUFILE_TRY(cuFileAPI::instance().DriverSetMaxPinnedMemSize(size_in_kb));
176 _props.max_device_pinned_mem_size = size_in_kb;
179 [[nodiscard]] std::size_t get_max_batch_io_size()
181 #ifdef KVIKIO_CUFILE_BATCH_API_FOUND
183 return _props.max_batch_io_size;
200 static bool is_gds_available() {
return false; }
202 [[nodiscard]]
static unsigned int get_nvfs_major_version()
207 [[nodiscard]]
static unsigned int get_nvfs_minor_version()
212 [[nodiscard]]
static bool get_nvfs_allow_compat_mode()
217 [[nodiscard]]
static bool get_nvfs_poll_mode()
222 [[nodiscard]]
static std::size_t get_nvfs_poll_thresh_size()
227 static void set_nvfs_poll_mode(
bool enable)
232 static void set_nvfs_poll_thresh_size(std::size_t size_in_kb)
237 [[nodiscard]]
static std::vector<CUfileDriverControlFlags> get_nvfs_statusflags()
242 [[nodiscard]]
static std::size_t get_max_device_cache_size()
247 static void set_max_device_cache_size(std::size_t size_in_kb)
252 [[nodiscard]]
static std::size_t get_per_buffer_cache_size()
257 [[nodiscard]]
static std::size_t get_max_pinned_memory_size()
262 static void set_max_pinned_memory_size(std::size_t size_in_kb)
267 [[nodiscard]] std::size_t get_max_batch_io_size()