cuda_h_wrapper.hpp
1 /*
2  * Copyright (c) 2024-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 
25 #ifdef KVIKIO_CUDA_FOUND
26 #include <cuda.h>
27 #else
28 
29 // If CUDA isn't defined, we define some of the data types here.
30 // Notice, the functions and constant values don't need to match the CUDA
31 // definitions, but the types *do*, since downstream libraries dlsym()-ing
32 // the symbols at runtime rely on accurate type definitions. If we mismatch
33 // here, then those libraries will get "mismatched type alias redefinition"
34 // errors when they include our headers.
35 
36 #if defined(_WIN64) || defined(__LP64__)
37 // Don't use uint64_t, we want to match the driver headers exactly
38 using CUdeviceptr = unsigned long long;
39 #else
40 using CUdeviceptr = unsigned int;
41 #endif
42 static_assert(sizeof(CUdeviceptr) == sizeof(void*));
43 
44 using CUresult = int;
45 using CUdevice = int;
46 using CUcontext = struct CUctx_st*;
47 using CUstream = struct CUstream_st*;
48 
49 #define CUDA_ERROR_STUB_LIBRARY 0
50 #define CUDA_SUCCESS 0
51 #define CUDA_ERROR_INVALID_VALUE 0
52 #define CU_POINTER_ATTRIBUTE_CONTEXT 0
53 #define CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL 0
54 #define CU_POINTER_ATTRIBUTE_DEVICE_POINTER 0
55 #define CU_MEMHOSTALLOC_PORTABLE 0
56 #define CU_STREAM_DEFAULT 0
57 
58 CUresult cuInit(...);
59 CUresult cuMemHostAlloc(...);
60 CUresult cuMemFreeHost(...);
61 CUresult cuMemcpyHtoDAsync(...);
62 CUresult cuMemcpyDtoHAsync(...);
63 CUresult cuMemcpyBatchAsync(...);
64 CUresult cuPointerGetAttribute(...);
65 CUresult cuPointerGetAttributes(...);
66 CUresult cuCtxPushCurrent(...);
67 CUresult cuCtxPopCurrent(...);
68 CUresult cuCtxGetCurrent(...);
69 CUresult cuCtxGetDevice(...);
70 CUresult cuMemGetAddressRange(...);
71 CUresult cuGetErrorName(...);
72 CUresult cuGetErrorString(...);
73 CUresult cuDeviceGet(...);
74 CUresult cuDeviceGetCount(...);
75 CUresult cuDeviceGetAttribute(...);
76 CUresult cuDevicePrimaryCtxRetain(...);
77 CUresult cuDevicePrimaryCtxRelease(...);
78 CUresult cuStreamCreate(...);
79 CUresult cuStreamDestroy(...);
80 CUresult cuStreamSynchronize(...);
81 CUresult cuDriverGetVersion(...);
82 
83 enum CUdevice_attribute {
84  CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES,
85 };
86 
87 enum CUmemcpySrcAccessOrder_enum {
88  CU_MEMCPY_SRC_ACCESS_ORDER_STREAM,
89 };
90 
92  int srcAccessOrder;
93 };
94 
95 #endif