cufile_h_wrapper.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <sys/types.h>
8 
9 #include <cuda.h>
10 
18 #ifdef KVIKIO_CUFILE_FOUND
19 #include <cufile.h>
20 #else
21 
22 // If cuFile isn't defined, we define some of the data types here.
23 // Notice, this doesn't need to be ABI compatible with the cufile definitions.
24 
25 using CUfileHandle_t = void*;
26 using CUfileOpError = int;
27 #define CUFILE_ERRSTR(x) ("KvikIO not compiled with cuFile.h")
28 #define CUFILEOP_BASE_ERR 5000
29 #define CU_FILE_SUCCESS 0
30 #define CU_FILE_CUDA_DRIVER_ERROR 1
31 
32 struct CUfileError_t {
33  CUfileOpError err; // cufile error
34  CUresult cu_err; // cuda driver error
35 };
36 
37 using CUfileDriverControlFlags_t = enum CUfileDriverControlFlags {
38  CU_FILE_USE_POLL_MODE = 0,
39  CU_FILE_ALLOW_COMPAT_MODE = 1
40 };
41 
42 enum CUfileFileHandleType { CU_FILE_HANDLE_TYPE_OPAQUE_FD = 1 };
43 
44 struct CUfileDescr_t {
45  enum CUfileFileHandleType type;
46  struct handle_t {
47  int fd;
48  } handle;
49 };
50 
51 inline static char const* cufileop_status_error(CUfileOpError err) { return CUFILE_ERRSTR(err); };
52 CUfileError_t cuFileHandleRegister(...);
53 CUfileError_t cuFileHandleDeregister(...);
54 ssize_t cuFileRead(...);
55 ssize_t cuFileWrite(...);
56 CUfileError_t cuFileBufRegister(...);
57 CUfileError_t cuFileBufDeregister(...);
58 CUfileError_t cuFileDriverOpen(...);
59 CUfileError_t cuFileDriverClose(...);
60 CUfileError_t cuFileDriverGetProperties(...);
61 CUfileError_t cuFileDriverSetPollMode(...);
62 CUfileError_t cuFileDriverSetMaxCacheSize(...);
63 CUfileError_t cuFileDriverSetMaxPinnedMemSize(...);
64 
65 #endif
66 
67 // If some cufile APIs aren't defined, we define some of the data types here.
68 // Notice, this doesn't need to be ABI compatible with the cufile definitions and
69 // the lack of definitions is not a problem because the linker will never look for
70 // these symbols because the "real" function calls are made through the shim instance.
71 
72 #ifndef KVIKIO_CUFILE_VERSION_API_FOUND
73 CUfileError_t cuFileGetVersion(...);
74 #endif