1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
<center><a href="https://gitlab.com/petsc/petsc/-/blob/966382dc56242773704ef5f5cee7aa2db3ebc577/include/petscdevice_cuda.h">Actual source code: petscdevice_cuda.h</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-04-30T18:14:50+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1"> 1: </a><font color="#A020F0">#pragma once</font>
<a name="line3"> 3: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line4"> 4: </a><font color="#A020F0">#include <petscpkg_version.h></font>
<a name="line6"> 6: </a><font color="#A020F0">#if defined(__NVCC__) || defined(__CUDACC__)</font>
<a name="line7"> 7: </a><strong><font color="#228B22"> #define PETSC_USING_NVCC 1</font></strong>
<a name="line8"> 8: </a><font color="#A020F0">#endif</font>
<a name="line10"> 10: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CUDA)</font>
<a name="line11"> 11: </a>PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN(<font color="#666666">"-Wdeprecated-declarations"</font>)
<a name="line12"> 12: </a><font color="#A020F0"> #include <cuda.h></font>
<a name="line13"> 13: </a><font color="#A020F0"> #include <cuda_runtime.h></font>
<a name="line14"> 14: </a><font color="#A020F0"> #include <cublas_v2.h></font>
<a name="line15"> 15: </a><font color="#A020F0"> #include <cusolverDn.h></font>
<a name="line16"> 16: </a><font color="#A020F0"> #include <cusolverSp.h></font>
<a name="line17"> 17: </a><font color="#A020F0"> #include <cufft.h></font>
<a name="line18"> 18: </a><strong><font color="#4169E1"><a name="ETSC_PRAGMA_DIAGNOSTIC_IGNORED_END"></a>PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END()</font></strong>
<a name="line20"> 20: </a><font color="#B22222">/* cuBLAS does not have cublasGetErrorName(). We create one on our own. */</font>
<a name="line21"> 21: </a><strong><font color="#4169E1">PETSC_EXTERN const char *PetscCUBLASGetErrorName(cublasStatus_t)</font></strong>; <font color="#B22222">/* PETSC_EXTERN since it is exposed by the CHKERRCUBLAS macro */</font>
<a name="line22"> 22: </a><strong><font color="#4169E1">PETSC_EXTERN const char *PetscCUSolverGetErrorName(cusolverStatus_t)</font></strong>;
<a name="line23"> 23: </a><strong><font color="#4169E1">PETSC_EXTERN const char *PetscCUFFTGetErrorName(cufftResult)</font></strong>;
<a name="line25"> 25: </a> <font color="#B22222">/* REMOVE ME */</font>
<a name="line26"> 26: </a><strong><font color="#228B22"> #define WaitForCUDA() cudaDeviceSynchronize()</font></strong>
<a name="line28"> 28: </a> <font color="#B22222">/* CUDART_VERSION = 1000 x major + 10 x minor version */</font>
<a name="line30"> 30: </a> <font color="#B22222">/* Could not find exactly which CUDART_VERSION introduced cudaGetErrorName. At least it was in CUDA 8.0 (Sep. 2016) */</font>
<a name="line31"> 31: </a><font color="#A020F0"> #if PETSC_PKG_CUDA_VERSION_GE(8, 0, 0)</font>
<a name="line32"> 32: </a><strong><font color="#228B22"> #define PetscCallCUDAVoid(...) \</font></strong>
<a name="line33"> 33: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line34"> 34: </a><strong><font color="#228B22"> const cudaError_t _p_cuda_err__ = __VA_ARGS__; \</font></strong>
<a name="line35"> 35: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheckAbort.html">PetscCheckAbort</a>(_p_cuda_err__ == cudaSuccess, <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuda error %d (%s) : %s"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cuda_err__, cudaGetErrorName(_p_cuda_err__), cudaGetErrorString(_p_cuda_err__)); \</font></strong>
<a name="line36"> 36: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line38"> 38: </a><strong><font color="#228B22"> #define PetscCallCUDA(...) \</font></strong>
<a name="line39"> 39: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line40"> 40: </a><strong><font color="#228B22"> const cudaError_t _p_cuda_err__ = __VA_ARGS__; \</font></strong>
<a name="line41"> 41: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheck.html">PetscCheck</a>(_p_cuda_err__ == cudaSuccess, <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuda error %d (%s) : %s"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cuda_err__, cudaGetErrorName(_p_cuda_err__), cudaGetErrorString(_p_cuda_err__)); \</font></strong>
<a name="line42"> 42: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line43"> 43: </a><font color="#A020F0"> #else </font><font color="#B22222">/* PETSC_PKG_CUDA_VERSION_GE(8,0,0) */</font><font color="#A020F0"></font>
<a name="line44"> 44: </a><strong><font color="#228B22"> #define PetscCallCUDA(...) \</font></strong>
<a name="line45"> 45: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line46"> 46: </a><strong><font color="#228B22"> const cudaError_t _p_cuda_err__ = __VA_ARGS__; \</font></strong>
<a name="line47"> 47: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheck.html">PetscCheck</a>(_p_cuda_err__ == cudaSuccess, <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuda error %d"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cuda_err__); \</font></strong>
<a name="line48"> 48: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line50"> 50: </a><strong><font color="#228B22"> #define PetscCallCUDAVoid(...) \</font></strong>
<a name="line51"> 51: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line52"> 52: </a><strong><font color="#228B22"> const cudaError_t _p_cuda_err__ = __VA_ARGS__; \</font></strong>
<a name="line53"> 53: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheckAbort.html">PetscCheckAbort</a>(_p_cuda_err__ == cudaSuccess, <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuda error %d"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cuda_err__); \</font></strong>
<a name="line54"> 54: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line55"> 55: </a><font color="#A020F0"> #endif </font><font color="#B22222">/* PETSC_PKG_CUDA_VERSION_GE(8,0,0) */</font><font color="#A020F0"></font>
<a name="line56"> 56: </a><strong><font color="#228B22"> #define CHKERRCUDA(...) PetscCallCUDA(__VA_ARGS__)</font></strong>
<a name="line58"> 58: </a><strong><font color="#228B22"> #define PetscCUDACheckLaunch \</font></strong>
<a name="line59"> 59: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line60"> 60: </a><strong><font color="#228B22"> </font><font color="#B22222">/* Check synchronous errors, i.e. pre-launch */</font><font color="#228B22"> \</font></strong>
<a name="line61"> 61: </a><strong><font color="#228B22"> PetscCallCUDA(cudaGetLastError()); \</font></strong>
<a name="line62"> 62: </a><strong><font color="#228B22"> </font><font color="#B22222">/* Check asynchronous errors, i.e. kernel failed (ULF) */</font><font color="#228B22"> \</font></strong>
<a name="line63"> 63: </a><strong><font color="#228B22"> PetscCallCUDA(cudaDeviceSynchronize()); \</font></strong>
<a name="line64"> 64: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line66"> 66: </a><strong><font color="#228B22"> #define PetscCallCUBLAS(...) \</font></strong>
<a name="line67"> 67: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line68"> 68: </a><strong><font color="#228B22"> const cublasStatus_t _p_cublas_stat__ = __VA_ARGS__; \</font></strong>
<a name="line69"> 69: </a><strong><font color="#228B22"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(_p_cublas_stat__ != CUBLAS_STATUS_SUCCESS)) { \</font></strong>
<a name="line70"> 70: </a><strong><font color="#228B22"> const char *name = PetscCUBLASGetErrorName(_p_cublas_stat__); \</font></strong>
<a name="line71"> 71: </a><strong><font color="#228B22"> if (((_p_cublas_stat__ == CUBLAS_STATUS_NOT_INITIALIZED) || (_p_cublas_stat__ == CUBLAS_STATUS_ALLOC_FAILED)) && <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_CUDA</a>)) { \</font></strong>
<a name="line72"> 72: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU_RESOURCE</a>, \</font></strong>
<a name="line73"> 73: </a><strong><font color="#228B22"> </font><font color="#666666">"cuBLAS error %d (%s). "</font><font color="#228B22"> \</font></strong>
<a name="line74"> 74: </a><strong><font color="#228B22"> </font><font color="#666666">"Reports not initialized or alloc failed; "</font><font color="#228B22"> \</font></strong>
<a name="line75"> 75: </a><strong><font color="#228B22"> </font><font color="#666666">"this indicates the GPU may have run out resources"</font><font color="#228B22">, \</font></strong>
<a name="line76"> 76: </a><strong><font color="#228B22"> (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cublas_stat__, name); \</font></strong>
<a name="line77"> 77: </a><strong><font color="#228B22"> } else { \</font></strong>
<a name="line78"> 78: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuBLAS error %d (%s)"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cublas_stat__, name); \</font></strong>
<a name="line79"> 79: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line80"> 80: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line81"> 81: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line82"> 82: </a><strong><font color="#228B22"> #define CHKERRCUBLAS(...) PetscCallCUBLAS(__VA_ARGS__)</font></strong>
<a name="line84"> 84: </a><font color="#A020F0"> #if (CUSPARSE_VER_MAJOR > 10 || CUSPARSE_VER_MAJOR == 10 && CUSPARSE_VER_MINOR >= 2) </font><font color="#B22222">/* According to cuda/10.1.168 on OLCF Summit */</font><font color="#A020F0"></font>
<a name="line85"> 85: </a><strong><font color="#228B22"> #define PetscCallCUSPARSE(...) \</font></strong>
<a name="line86"> 86: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line87"> 87: </a><strong><font color="#228B22"> const cusparseStatus_t _p_cusparse_stat__ = __VA_ARGS__; \</font></strong>
<a name="line88"> 88: </a><strong><font color="#228B22"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(_p_cusparse_stat__)) { \</font></strong>
<a name="line89"> 89: </a><strong><font color="#228B22"> const char *name = cusparseGetErrorName(_p_cusparse_stat__); \</font></strong>
<a name="line90"> 90: </a><strong><font color="#228B22"> const char *descr = cusparseGetErrorString(_p_cusparse_stat__); \</font></strong>
<a name="line91"> 91: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheck.html">PetscCheck</a>((_p_cusparse_stat__ != CUSPARSE_STATUS_NOT_INITIALIZED) && (_p_cusparse_stat__ != CUSPARSE_STATUS_ALLOC_FAILED), <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU_RESOURCE</a>, \</font></strong>
<a name="line92"> 92: </a><strong><font color="#228B22"> </font><font color="#666666">"cuSPARSE errorcode %d (%s) : %s.; "</font><font color="#228B22"> \</font></strong>
<a name="line93"> 93: </a><strong><font color="#228B22"> </font><font color="#666666">"this indicates the GPU has run out resources"</font><font color="#228B22">, \</font></strong>
<a name="line94"> 94: </a><strong><font color="#228B22"> (int)_p_cusparse_stat__, name, descr); \</font></strong>
<a name="line95"> 95: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuSPARSE errorcode %d (%s) : %s"</font><font color="#228B22">, (int)_p_cusparse_stat__, name, descr); \</font></strong>
<a name="line96"> 96: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line97"> 97: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line98"> 98: </a><font color="#A020F0"> #else </font><font color="#B22222">/* (CUSPARSE_VER_MAJOR > 10 || CUSPARSE_VER_MAJOR == 10 && CUSPARSE_VER_MINOR >= 2) */</font><font color="#A020F0"></font>
<a name="line99"> 99: </a><strong><font color="#228B22"> #define PetscCallCUSPARSE(...) \</font></strong>
<a name="line100">100: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line101">101: </a><strong><font color="#228B22"> const cusparseStatus_t _p_cusparse_stat__ = __VA_ARGS__; \</font></strong>
<a name="line102">102: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/PetscCheck.html">PetscCheck</a>(_p_cusparse_stat__ == CUSPARSE_STATUS_SUCCESS, <a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuSPARSE errorcode %d"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cusparse_stat__); \</font></strong>
<a name="line103">103: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line104">104: </a><font color="#A020F0"> #endif </font><font color="#B22222">/* (CUSPARSE_VER_MAJOR > 10 || CUSPARSE_VER_MAJOR == 10 && CUSPARSE_VER_MINOR >= 2) */</font><font color="#A020F0"></font>
<a name="line105">105: </a><strong><font color="#228B22"> #define CHKERRCUSPARSE(...) PetscCallCUSPARSE(__VA_ARGS__)</font></strong>
<a name="line107">107: </a><strong><font color="#228B22"> #define PetscCallCUSOLVER(...) \</font></strong>
<a name="line108">108: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line109">109: </a><strong><font color="#228B22"> const cusolverStatus_t _p_cusolver_stat__ = __VA_ARGS__; \</font></strong>
<a name="line110">110: </a><strong><font color="#228B22"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(_p_cusolver_stat__ != CUSOLVER_STATUS_SUCCESS)) { \</font></strong>
<a name="line111">111: </a><strong><font color="#228B22"> const char *name = PetscCUSolverGetErrorName(_p_cusolver_stat__); \</font></strong>
<a name="line112">112: </a><strong><font color="#228B22"> if (((_p_cusolver_stat__ == CUSOLVER_STATUS_NOT_INITIALIZED) || (_p_cusolver_stat__ == CUSOLVER_STATUS_ALLOC_FAILED) || (_p_cusolver_stat__ == CUSOLVER_STATUS_INTERNAL_ERROR)) && <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_CUDA</a>)) { \</font></strong>
<a name="line113">113: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU_RESOURCE</a>, \</font></strong>
<a name="line114">114: </a><strong><font color="#228B22"> </font><font color="#666666">"cuSolver error %d (%s). "</font><font color="#228B22"> \</font></strong>
<a name="line115">115: </a><strong><font color="#228B22"> </font><font color="#666666">"This indicates the GPU may have run out resources"</font><font color="#228B22">, \</font></strong>
<a name="line116">116: </a><strong><font color="#228B22"> (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cusolver_stat__, name); \</font></strong>
<a name="line117">117: </a><strong><font color="#228B22"> } else { \</font></strong>
<a name="line118">118: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuSolver error %d (%s)"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cusolver_stat__, name); \</font></strong>
<a name="line119">119: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line120">120: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line121">121: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line122">122: </a><strong><font color="#228B22"> #define CHKERRCUSOLVER(...) PetscCallCUSOLVER(__VA_ARGS__)</font></strong>
<a name="line124">124: </a><strong><font color="#228B22"> #define PetscCallCUFFT(...) \</font></strong>
<a name="line125">125: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line126">126: </a><strong><font color="#228B22"> const cufftResult_t _p_cufft_stat__ = __VA_ARGS__; \</font></strong>
<a name="line127">127: </a><strong><font color="#228B22"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(_p_cufft_stat__ != CUFFT_SUCCESS)) { \</font></strong>
<a name="line128">128: </a><strong><font color="#228B22"> const char *name = PetscCUFFTGetErrorName(_p_cufft_stat__); \</font></strong>
<a name="line129">129: </a><strong><font color="#228B22"> if (((_p_cufft_stat__ == CUFFT_SETUP_FAILED) || (_p_cufft_stat__ == CUFFT_ALLOC_FAILED)) && <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_CUDA</a>)) { \</font></strong>
<a name="line130">130: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU_RESOURCE</a>, \</font></strong>
<a name="line131">131: </a><strong><font color="#228B22"> </font><font color="#666666">"cuFFT error %d (%s). "</font><font color="#228B22"> \</font></strong>
<a name="line132">132: </a><strong><font color="#228B22"> </font><font color="#666666">"Reports not initialized or alloc failed; "</font><font color="#228B22"> \</font></strong>
<a name="line133">133: </a><strong><font color="#228B22"> </font><font color="#666666">"this indicates the GPU has run out resources"</font><font color="#228B22">, \</font></strong>
<a name="line134">134: </a><strong><font color="#228B22"> (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cufft_stat__, name); \</font></strong>
<a name="line135">135: </a><strong><font color="#228B22"> } else { \</font></strong>
<a name="line136">136: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuFFT error %d (%s)"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_cufft_stat__, name); \</font></strong>
<a name="line137">137: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line138">138: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line139">139: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line140">140: </a><strong><font color="#228B22"> #define CHKERRCUFFT(...) PetscCallCUFFT(__VA_ARGS__)</font></strong>
<a name="line142">142: </a><strong><font color="#228B22"> #define PetscCallCURAND(...) \</font></strong>
<a name="line143">143: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line144">144: </a><strong><font color="#228B22"> const curandStatus_t _p_curand_stat__ = __VA_ARGS__; \</font></strong>
<a name="line145">145: </a><strong><font color="#228B22"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(_p_curand_stat__ != CURAND_STATUS_SUCCESS)) { \</font></strong>
<a name="line146">146: </a><strong><font color="#228B22"> if (((_p_curand_stat__ == CURAND_STATUS_INITIALIZATION_FAILED) || (_p_curand_stat__ == CURAND_STATUS_ALLOCATION_FAILED)) && <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_CUDA</a>)) { \</font></strong>
<a name="line147">147: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU_RESOURCE</a>, \</font></strong>
<a name="line148">148: </a><strong><font color="#228B22"> </font><font color="#666666">"cuRAND error %d. "</font><font color="#228B22"> \</font></strong>
<a name="line149">149: </a><strong><font color="#228B22"> </font><font color="#666666">"Reports not initialized or alloc failed; "</font><font color="#228B22"> \</font></strong>
<a name="line150">150: </a><strong><font color="#228B22"> </font><font color="#666666">"this indicates the GPU has run out resources"</font><font color="#228B22">, \</font></strong>
<a name="line151">151: </a><strong><font color="#228B22"> (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_curand_stat__); \</font></strong>
<a name="line152">152: </a><strong><font color="#228B22"> } else { \</font></strong>
<a name="line153">153: </a><strong><font color="#228B22"> <a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_GPU</a>, </font><font color="#666666">"cuRand error %d"</font><font color="#228B22">, (<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)_p_curand_stat__); \</font></strong>
<a name="line154">154: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line155">155: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line156">156: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line157">157: </a><strong><font color="#228B22"> #define CHKERRCURAND(...) PetscCallCURAND(__VA_ARGS__)</font></strong>
<a name="line159">159: </a>PETSC_EXTERN cudaStream_t PetscDefaultCudaStream; <font color="#B22222">// The default stream used by PETSc</font>
<a name="line160">160: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PetscCUBLASGetHandle(cublasHandle_t *)</font></strong>;
<a name="line161">161: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PetscCUSOLVERDnGetHandle(cusolverDnHandle_t *)</font></strong>;
<a name="line162">162: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PetscGetCurrentCUDAStream(cudaStream_t *)</font></strong>;
<a name="line164">164: </a><font color="#A020F0">#endif // PETSC_HAVE_CUDA</font>
<a name="line166">166: </a><font color="#B22222">// these can also be defined in petscdevice_hip.h so we undef and define them *only* if the</font>
<a name="line167">167: </a><font color="#B22222">// current compiler is NVCC. In this case if petscdevice_hip.h is included first, the macros</font>
<a name="line168">168: </a><font color="#B22222">// would already be defined, but they would be empty since we cannot be using HCC at the same</font>
<a name="line169">169: </a><font color="#B22222">// time.</font>
<a name="line170">170: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USING_NVCC)</font>
<a name="line171">171: </a><strong><font color="#228B22"> #undef PETSC_HOST_DECL</font></strong>
<a name="line172">172: </a><strong><font color="#228B22"> #undef PETSC_DEVICE_DECL</font></strong>
<a name="line173">173: </a><strong><font color="#228B22"> #undef PETSC_KERNEL_DECL</font></strong>
<a name="line174">174: </a><strong><font color="#228B22"> #undef PETSC_SHAREDMEM_DECL</font></strong>
<a name="line175">175: </a><strong><font color="#228B22"> #undef PETSC_FORCEINLINE</font></strong>
<a name="line176">176: </a><strong><font color="#228B22"> #undef PETSC_CONSTMEM_DECL</font></strong>
<a name="line178">178: </a><strong><font color="#228B22"> #define PETSC_HOST_DECL __host__</font></strong>
<a name="line179">179: </a><strong><font color="#228B22"> #define PETSC_DEVICE_DECL __device__</font></strong>
<a name="line180">180: </a><strong><font color="#228B22"> #define PETSC_KERNEL_DECL __global__</font></strong>
<a name="line181">181: </a><strong><font color="#228B22"> #define PETSC_SHAREDMEM_DECL __shared__</font></strong>
<a name="line182">182: </a><strong><font color="#228B22"> #define PETSC_FORCEINLINE __forceinline__</font></strong>
<a name="line183">183: </a><strong><font color="#228B22"> #define PETSC_CONSTMEM_DECL __constant__</font></strong>
<a name="line184">184: </a><font color="#A020F0">#endif</font>
<a name="line186">186: </a><font color="#A020F0">#ifndef PETSC_HOST_DECL // use HOST_DECL as canary</font>
<a name="line187">187: </a><strong><font color="#228B22"> #define PETSC_HOST_DECL</font></strong>
<a name="line188">188: </a><strong><font color="#228B22"> #define PETSC_DEVICE_DECL</font></strong>
<a name="line189">189: </a><strong><font color="#228B22"> #define PETSC_KERNEL_DECL</font></strong>
<a name="line190">190: </a><strong><font color="#228B22"> #define PETSC_SHAREDMEM_DECL</font></strong>
<a name="line191">191: </a><strong><font color="#228B22"> #define PETSC_FORCEINLINE inline</font></strong>
<a name="line192">192: </a><strong><font color="#228B22"> #define PETSC_CONSTMEM_DECL</font></strong>
<a name="line193">193: </a><font color="#A020F0">#endif</font>
<a name="line195">195: </a><font color="#A020F0">#ifndef PETSC_DEVICE_DEFINED_DECLS_PRIVATE</font>
<a name="line196">196: </a><strong><font color="#228B22"> #define PETSC_DEVICE_DEFINED_DECLS_PRIVATE</font></strong>
<a name="line197">197: </a><strong><font color="#228B22"> #define PETSC_HOSTDEVICE_DECL PETSC_HOST_DECL PETSC_DEVICE_DECL</font></strong>
<a name="line198">198: </a><strong><font color="#228B22"> #define PETSC_DEVICE_INLINE_DECL PETSC_DEVICE_DECL PETSC_FORCEINLINE</font></strong>
<a name="line199">199: </a><strong><font color="#228B22"> #define PETSC_HOSTDEVICE_INLINE_DECL PETSC_HOSTDEVICE_DECL PETSC_FORCEINLINE</font></strong>
<a name="line200">200: </a><font color="#A020F0">#endif</font>
</pre>
</body>
</html>
|