cufile.hpp
1 /*
2  * Copyright (c) 2022-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 <kvikio/shim/cufile_h_wrapper.hpp>
19 #include <kvikio/shim/utils.hpp>
20 
21 namespace kvikio {
22 
30 class cuFileAPI {
31  public:
32  decltype(cuFileHandleRegister)* HandleRegister{nullptr};
33  decltype(cuFileHandleDeregister)* HandleDeregister{nullptr};
34  decltype(cuFileRead)* Read{nullptr};
35  decltype(cuFileWrite)* Write{nullptr};
36  decltype(cuFileBufRegister)* BufRegister{nullptr};
37  decltype(cuFileBufDeregister)* BufDeregister{nullptr};
38  decltype(cuFileDriverGetProperties)* DriverGetProperties{nullptr};
39  decltype(cuFileDriverSetPollMode)* DriverSetPollMode{nullptr};
40  decltype(cuFileDriverSetMaxCacheSize)* DriverSetMaxCacheSize{nullptr};
41  decltype(cuFileDriverSetMaxPinnedMemSize)* DriverSetMaxPinnedMemSize{nullptr};
42  decltype(cuFileBatchIOSetUp)* BatchIOSetUp{nullptr};
43  decltype(cuFileBatchIOSubmit)* BatchIOSubmit{nullptr};
44  decltype(cuFileBatchIOGetStatus)* BatchIOGetStatus{nullptr};
45  decltype(cuFileBatchIOCancel)* BatchIOCancel{nullptr};
46  decltype(cuFileBatchIODestroy)* BatchIODestroy{nullptr};
47  decltype(cuFileReadAsync)* ReadAsync{nullptr};
48  decltype(cuFileWriteAsync)* WriteAsync{nullptr};
49  decltype(cuFileStreamRegister)* StreamRegister{nullptr};
50  decltype(cuFileStreamDeregister)* StreamDeregister{nullptr};
51 
52  private:
53  // Don't call driver open and close directly, use `.driver_open()` and `.driver_close()`.
54  decltype(cuFileDriverOpen)* DriverOpen{nullptr};
55  decltype(cuFileDriverClose)* DriverClose{nullptr};
56 
57  // Don't call `GetVersion` directly, use `cuFileAPI::instance().version`.
58  decltype(cuFileGetVersion)* GetVersion{nullptr};
59 
60  public:
61  int version{0};
62 
63  private:
64  cuFileAPI();
65 
66  public:
67  cuFileAPI(cuFileAPI const&) = delete;
68  void operator=(cuFileAPI const&) = delete;
69  cuFileAPI(cuFileAPI const&&) = delete;
70  void operator=(cuFileAPI const&&) = delete;
71 
72  KVIKIO_EXPORT static cuFileAPI& instance();
73 
80  void driver_open();
81 
85  void driver_close();
86 };
87 
95 #ifdef KVIKIO_CUFILE_FOUND
96 bool is_cufile_library_available() noexcept;
97 #else
98 constexpr bool is_cufile_library_available() noexcept { return false; }
99 #endif
100 
109 bool is_cufile_available() noexcept;
110 
122 int cufile_version() noexcept;
123 
133 bool is_batch_api_available() noexcept;
134 
144 bool is_stream_api_available() noexcept;
145 
146 } // namespace kvikio
Shim layer of the cuFile C-API.
Definition: cufile.hpp:30
void driver_open()
Open the cuFile driver.
void driver_close()
Close the cuFile driver.
KvikIO namespace.
Definition: batch.hpp:27
constexpr bool is_cufile_library_available() noexcept
Check if the cuFile library is available.
Definition: cufile.hpp:98
bool is_cufile_available() noexcept
Check if the cuFile is available and expected to work.
bool is_stream_api_available() noexcept
Check if cuFile's stream (async) API is available.
bool is_batch_api_available() noexcept
Check if cuFile's batch API is available.
int cufile_version() noexcept
Get cufile version (or zero if older than v1.8).