|
| 1 | +#include <occa/defines.hpp> |
| 2 | + |
| 3 | +#ifndef OCCA_MODES_CUDA_POLYFILL_HEADER |
| 4 | +#define OCCA_MODES_CUDA_POLYFILL_HEADER |
| 5 | + |
| 6 | +#if OCCA_CUDA_ENABLED |
| 7 | +# include <cuda.h> |
| 8 | +#else |
| 9 | + |
| 10 | +#define CUDA_VERSION 0 |
| 11 | + |
| 12 | +// Wrap in the occa namespace so as long as we don't use ::CUmodule, the two |
| 13 | +// - CUmodule |
| 14 | +// - occa::CUmodule |
| 15 | +// are indistinguisable inside the occa namespace |
| 16 | +namespace occa { |
| 17 | + //---[ Types ]------------------------ |
| 18 | + struct _CUdeviceptr {}; |
| 19 | + typedef struct _CUcontext* CUcontext; |
| 20 | + typedef int CUdevice; |
| 21 | + typedef struct _CUdeviceptr* CUdeviceptr; |
| 22 | + typedef struct _CUevent* CUevent; |
| 23 | + typedef struct _CUfunction* CUfunction; |
| 24 | + typedef struct _CUfunction_attribute* CUfunction_attribute; |
| 25 | + typedef struct _CUmodule* CUmodule; |
| 26 | + typedef struct _CUstream* CUstream; |
| 27 | + |
| 28 | + //---[ Enums ]------------------------ |
| 29 | + static const int CU_CTX_SCHED_AUTO = 0; |
| 30 | + static const int CU_DEVICE_CPU = 0; |
| 31 | + static const int CU_EVENT_DEFAULT = 0; |
| 32 | + static const int CU_MEM_ATTACH_GLOBAL = 0; |
| 33 | + static const int CU_MEM_ATTACH_HOST = 0; |
| 34 | + static const int CU_STREAM_DEFAULT = 0; |
| 35 | + |
| 36 | + static const CUfunction_attribute CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK = NULL; |
| 37 | + |
| 38 | + enum CUresult { |
| 39 | + CUDA_SUCCESS = 0, |
| 40 | + CUDA_ERROR_INVALID_VALUE, |
| 41 | + CUDA_ERROR_OUT_OF_MEMORY, |
| 42 | + CUDA_ERROR_NOT_INITIALIZED, |
| 43 | + CUDA_ERROR_DEINITIALIZED, |
| 44 | + CUDA_ERROR_PROFILER_DISABLED, |
| 45 | + CUDA_ERROR_PROFILER_NOT_INITIALIZED, |
| 46 | + CUDA_ERROR_PROFILER_ALREADY_STARTED, |
| 47 | + CUDA_ERROR_PROFILER_ALREADY_STOPPED, |
| 48 | + CUDA_ERROR_NO_DEVICE, |
| 49 | + CUDA_ERROR_INVALID_DEVICE, |
| 50 | + CUDA_ERROR_INVALID_IMAGE, |
| 51 | + CUDA_ERROR_INVALID_CONTEXT, |
| 52 | + CUDA_ERROR_CONTEXT_ALREADY_CURRENT, |
| 53 | + CUDA_ERROR_MAP_FAILED, |
| 54 | + CUDA_ERROR_UNMAP_FAILED, |
| 55 | + CUDA_ERROR_ARRAY_IS_MAPPED, |
| 56 | + CUDA_ERROR_ALREADY_MAPPED, |
| 57 | + CUDA_ERROR_NO_BINARY_FOR_GPU, |
| 58 | + CUDA_ERROR_ALREADY_ACQUIRED, |
| 59 | + CUDA_ERROR_NOT_MAPPED, |
| 60 | + CUDA_ERROR_NOT_MAPPED_AS_ARRAY, |
| 61 | + CUDA_ERROR_NOT_MAPPED_AS_POINTER, |
| 62 | + CUDA_ERROR_ECC_UNCORRECTABLE, |
| 63 | + CUDA_ERROR_UNSUPPORTED_LIMIT, |
| 64 | + CUDA_ERROR_CONTEXT_ALREADY_IN_USE, |
| 65 | + CUDA_ERROR_PEER_ACCESS_UNSUPPORTED, |
| 66 | + CUDA_ERROR_INVALID_SOURCE, |
| 67 | + CUDA_ERROR_FILE_NOT_FOUND, |
| 68 | + CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, |
| 69 | + CUDA_ERROR_SHARED_OBJECT_INIT_FAILED, |
| 70 | + CUDA_ERROR_OPERATING_SYSTEM, |
| 71 | + CUDA_ERROR_INVALID_HANDLE, |
| 72 | + CUDA_ERROR_NOT_FOUND, |
| 73 | + CUDA_ERROR_NOT_READY, |
| 74 | + CUDA_ERROR_LAUNCH_FAILED, |
| 75 | + CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES, |
| 76 | + CUDA_ERROR_LAUNCH_TIMEOUT, |
| 77 | + CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING, |
| 78 | + CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED, |
| 79 | + CUDA_ERROR_PEER_ACCESS_NOT_ENABLED, |
| 80 | + CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE, |
| 81 | + CUDA_ERROR_CONTEXT_IS_DESTROYED, |
| 82 | + CUDA_ERROR_ASSERT, |
| 83 | + CUDA_ERROR_TOO_MANY_PEERS, |
| 84 | + CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED, |
| 85 | + CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED, |
| 86 | + CUDA_ERROR_NOT_PERMITTED, |
| 87 | + CUDA_ERROR_NOT_SUPPORTED, |
| 88 | + CUDA_ERROR_INVALID_PTX, |
| 89 | + CUDA_ERROR_ILLEGAL_ADDRESS, |
| 90 | + CUDA_ERROR_HARDWARE_STACK_ERROR, |
| 91 | + CUDA_ERROR_ILLEGAL_INSTRUCTION, |
| 92 | + CUDA_ERROR_MISALIGNED_ADDRESS, |
| 93 | + CUDA_ERROR_INVALID_ADDRESS_SPACE, |
| 94 | + CUDA_ERROR_INVALID_PC, |
| 95 | + CUDA_ERROR_NVLINK_UNCORRECTABLE, |
| 96 | + OCCA_CUDA_IS_NOT_ENABLED |
| 97 | + }; |
| 98 | + |
| 99 | + //---[ Methods ]---------------------- |
| 100 | + inline CUresult cuInit(unsigned int Flags) { |
| 101 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 102 | + } |
| 103 | + |
| 104 | + inline CUresult cuFuncGetAttribute(int *pi, CUfunction_attribute attrib, CUfunction hfunc) { |
| 105 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 106 | + } |
| 107 | + |
| 108 | + inline CUresult cuLaunchKernel(CUfunction f, |
| 109 | + unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, |
| 110 | + unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, |
| 111 | + unsigned int sharedMemBytes, |
| 112 | + CUstream hStream, |
| 113 | + void **kernelParams, |
| 114 | + void **extra) { |
| 115 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 116 | + } |
| 117 | + |
| 118 | + // ---[ Context ]------------------- |
| 119 | + inline CUresult cuCtxCreate(CUcontext *pctx, unsigned int flags, CUdevice dev) { |
| 120 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 121 | + } |
| 122 | + |
| 123 | + inline CUresult cuCtxDestroy(CUcontext ctx) { |
| 124 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 125 | + } |
| 126 | + |
| 127 | + inline CUresult cuCtxEnablePeerAccess(CUcontext peerContext, unsigned int Flags) { |
| 128 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 129 | + } |
| 130 | + |
| 131 | + inline CUresult cuCtxSetCurrent(CUcontext ctx) { |
| 132 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 133 | + } |
| 134 | + |
| 135 | + // ---[ Device ]-------------------- |
| 136 | + inline CUresult cuDeviceCanAccessPeer(int *canAccessPeer, CUdevice dev, CUdevice peerDev) { |
| 137 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 138 | + } |
| 139 | + |
| 140 | + inline CUresult cuDeviceComputeCapability(int *major, int *minor, CUdevice dev) { |
| 141 | + // [Deprecated] |
| 142 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 143 | + } |
| 144 | + |
| 145 | + inline CUresult cuDeviceGet(CUdevice *device, int ordinal) { |
| 146 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 147 | + } |
| 148 | + |
| 149 | + inline CUresult cuDeviceGetCount(int *count) { |
| 150 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 151 | + } |
| 152 | + |
| 153 | + inline CUresult cuDeviceGetName(char *name, int len, CUdevice dev) { |
| 154 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 155 | + } |
| 156 | + |
| 157 | + inline CUresult cuDeviceTotalMem(size_t *bytes, CUdevice dev) { |
| 158 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 159 | + } |
| 160 | + |
| 161 | + // ---[ Event ]--------------------- |
| 162 | + inline CUresult cuEventCreate(CUevent *phEvent, unsigned int Flags) { |
| 163 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 164 | + } |
| 165 | + |
| 166 | + inline CUresult cuEventDestroy(CUevent hEvent) { |
| 167 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 168 | + } |
| 169 | + |
| 170 | + inline CUresult cuEventElapsedTime(float *pMilliseconds, CUevent hStart, CUevent hEnd) { |
| 171 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 172 | + } |
| 173 | + |
| 174 | + inline CUresult cuEventRecord(CUevent hEvent, CUstream hStream) { |
| 175 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 176 | + } |
| 177 | + |
| 178 | + inline CUresult cuEventSynchronize(CUevent hEvent) { |
| 179 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 180 | + } |
| 181 | + |
| 182 | + |
| 183 | + // ---[ Memory ]-------------------- |
| 184 | + inline CUresult cuMemAlloc(CUdeviceptr *dptr, size_t bytesize) { |
| 185 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 186 | + } |
| 187 | + |
| 188 | + inline CUresult cuMemAllocHost(void **pp, size_t bytesize) { |
| 189 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 190 | + } |
| 191 | + |
| 192 | + inline CUresult cuMemAllocManaged(CUdeviceptr *dptr, size_t bytesize, unsigned int flags) { |
| 193 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 194 | + } |
| 195 | + |
| 196 | + inline CUresult cuMemFree(CUdeviceptr dptr) { |
| 197 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 198 | + } |
| 199 | + |
| 200 | + inline CUresult cuMemFreeHost(void *p) { |
| 201 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 202 | + } |
| 203 | + |
| 204 | + inline CUresult cuMemHostGetDevicePointer(CUdeviceptr *dptr, void *p, unsigned int Flags) { |
| 205 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 206 | + } |
| 207 | + |
| 208 | + inline CUresult cuMemPrefetchAsync(CUdeviceptr *devPtr, size_t count, CUdevice dstDevice, CUstream hStream) { |
| 209 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 210 | + } |
| 211 | + |
| 212 | + inline CUresult cuMemcpyDtoD(CUdeviceptr dstDevice, const CUdeviceptr srcDevice, size_t ByteCount) { |
| 213 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 214 | + } |
| 215 | + |
| 216 | + inline CUresult cuMemcpyDtoDAsync(CUdeviceptr dstDevice, const CUdeviceptr srcDevice, size_t ByteCount, CUstream hstream) { |
| 217 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 218 | + } |
| 219 | + |
| 220 | + inline CUresult cuMemcpyDtoH(void *dstHost, const CUdeviceptr srcDevice, size_t ByteCount) { |
| 221 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 222 | + } |
| 223 | + |
| 224 | + inline CUresult cuMemcpyDtoHAsync(void *dstHost, const CUdeviceptr srcDevice, size_t ByteCount, CUstream hstream) { |
| 225 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 226 | + } |
| 227 | + |
| 228 | + inline CUresult cuMemcpyHtoD(CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount) { |
| 229 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 230 | + } |
| 231 | + |
| 232 | + inline CUresult cuMemcpyHtoDAsync(CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount, CUstream hstream) { |
| 233 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 234 | + } |
| 235 | + |
| 236 | + inline CUresult cuMemcpyPeer(CUdeviceptr dstDevice, CUcontext dstContext, |
| 237 | + CUdeviceptr srcDevice, CUcontext srcContext, |
| 238 | + size_t ByteCount) { |
| 239 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 240 | + } |
| 241 | + |
| 242 | + inline CUresult cuMemcpyPeerAsync(CUdeviceptr dstDevice, CUcontext dstContext, |
| 243 | + CUdeviceptr srcDevice, CUcontext srcContext, |
| 244 | + size_t ByteCount, CUstream hStream) { |
| 245 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 246 | + } |
| 247 | + |
| 248 | + // Version-dependent methods: |
| 249 | + // inline CUresult cuMemAdvise(CUdeviceptr devPtr, size_t count, CUmem_advice advice, CUdevice device) |
| 250 | + |
| 251 | + // ---[ Module ]-------------------- |
| 252 | + inline CUresult cuModuleGetFunction(CUfunction *hfunc, CUmodule hmod, const char *name) { |
| 253 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 254 | + } |
| 255 | + |
| 256 | + inline CUresult cuModuleLoad(CUmodule *module, const char *fname) { |
| 257 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 258 | + } |
| 259 | + |
| 260 | + inline CUresult cuModuleUnload(CUmodule hmod) { |
| 261 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 262 | + } |
| 263 | + |
| 264 | + // ---[ Stream ]-------------------- |
| 265 | + inline CUresult cuStreamCreate(CUstream *phStream, unsigned int Flags) { |
| 266 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 267 | + } |
| 268 | + |
| 269 | + inline CUresult cuStreamDestroy(CUstream hStream) { |
| 270 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 271 | + } |
| 272 | + |
| 273 | + inline CUresult cuStreamSynchronize(CUstream hStream) { |
| 274 | + return OCCA_CUDA_IS_NOT_ENABLED; |
| 275 | + } |
| 276 | +} |
| 277 | + |
| 278 | +#endif |
| 279 | +#endif |
0 commit comments