Actual source code: deviceimpl.h

  1: #ifndef PETSCDEVICEIMPL_H
  2: #define PETSCDEVICEIMPL_H

  4: #include <petscdevice.h>
  5: #include <petsc/private/petscimpl.h>

  7: /* logging support */
  8: PETSC_INTERN PetscLogEvent CUBLAS_HANDLE_CREATE;
  9: PETSC_INTERN PetscLogEvent CUSOLVER_HANDLE_CREATE;
 10: PETSC_INTERN PetscLogEvent HIPSOLVER_HANDLE_CREATE;
 11: PETSC_INTERN PetscLogEvent HIPBLAS_HANDLE_CREATE;

 13: PETSC_INTERN PetscLogEvent DCONTEXT_Create;
 14: PETSC_INTERN PetscLogEvent DCONTEXT_Destroy;
 15: PETSC_INTERN PetscLogEvent DCONTEXT_ChangeStream;
 16: PETSC_INTERN PetscLogEvent DCONTEXT_SetDevice;
 17: PETSC_INTERN PetscLogEvent DCONTEXT_SetUp;
 18: PETSC_INTERN PetscLogEvent DCONTEXT_Duplicate;
 19: PETSC_INTERN PetscLogEvent DCONTEXT_QueryIdle;
 20: PETSC_INTERN PetscLogEvent DCONTEXT_WaitForCtx;
 21: PETSC_INTERN PetscLogEvent DCONTEXT_Fork;
 22: PETSC_INTERN PetscLogEvent DCONTEXT_Join;
 23: PETSC_INTERN PetscLogEvent DCONTEXT_Sync;
 24: PETSC_INTERN PetscLogEvent DCONTEXT_Mark;

 26: /* type cast macros for some additional type-safety in C++ land */
 27: #if defined(__cplusplus)
 28:   #define PetscStreamTypeCast(...)     static_cast<PetscStreamType>(__VA_ARGS__)
 29:   #define PetscDeviceTypeCast(...)     static_cast<PetscDeviceType>(__VA_ARGS__)
 30:   #define PetscDeviceInitTypeCast(...) static_cast<PetscDeviceInitType>(__VA_ARGS__)
 31: #else
 32:   #define PetscStreamTypeCast(...)     ((PetscStreamType)(__VA_ARGS__))
 33:   #define PetscDeviceTypeCast(...)     ((PetscDeviceType)(__VA_ARGS__))
 34:   #define PetscDeviceInitTypeCast(...) ((PetscDeviceInitType)(__VA_ARGS__))
 35: #endif

 37: #if defined(PETSC_CLANG_STATIC_ANALYZER)
 38: template <typename T>
 40: template <typename T, typename U>
 41: void PetscCheckCompatibleDeviceTypes(T, int, U, int);
 42: template <typename T>
 44: template <typename T>
 46: template <typename T, typename U>
 47: void PetscCheckCompatibleDevices(T, int, U, int);
 48: template <typename T>
 50: template <typename T>
 52: template <typename T, typename U>
 53: void PetscCheckCompatibleDeviceContexts(T, int, U, int);
 54: #elif PetscDefined(HAVE_CXX) && (PetscDefined(USE_DEBUG) || PetscDefined(DEVICE_KEEP_ERROR_CHECKING_MACROS))
 56:     do { \
 57:       PetscDeviceType pvdt_dtype_ = PetscDeviceTypeCast(dtype); \
 58:       int             pvdt_argno_ = (int)(argno); \
 59:       PetscCheck(((int)pvdt_dtype_ >= (int)PETSC_DEVICE_HOST) && ((int)pvdt_dtype_ <= (int)PETSC_DEVICE_MAX), PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDeviceType '%d': Argument #%d", pvdt_dtype_, pvdt_argno_); \
 60:       if (PetscUnlikely(!PetscDeviceConfiguredFor_Internal(pvdt_dtype_))) { \
 61:         PetscCheck((int)pvdt_dtype_ != (int)PETSC_DEVICE_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Invalid PetscDeviceType '%s': Argument #%d", PetscDeviceTypes[pvdt_dtype_], pvdt_argno_); \
 62:         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, \
 63:                 "Not configured for PetscDeviceType '%s': Argument #%d;" \
 64:                 " run configure --help %s for available options", \
 65:                 PetscDeviceTypes[pvdt_dtype_], pvdt_argno_, PetscDeviceTypes[pvdt_dtype_]); \
 66:       } \
 67:     } while (0)

 69:   #define PetscCheckCompatibleDeviceTypes(dtype1, argno1, dtype2, argno2) \
 70:     do { \
 71:       PetscDeviceType pccdt_dtype1_ = PetscDeviceTypeCast(dtype1); \
 72:       PetscDeviceType pccdt_dtype2_ = PetscDeviceTypeCast(dtype2); \
 75:       PetscCheck(pccdt_dtype1_ == pccdt_dtype2_, PETSC_COMM_SELF, PETSC_ERR_ARG_NOTSAMETYPE, "PetscDeviceTypes are incompatible: Arguments #%d and #%d. Expected PetscDeviceType '%s' but have '%s' instead", argno1, argno2, PetscDeviceTypes[pccdt_dtype1_], PetscDeviceTypes[pccdt_dtype2_]); \
 76:     } while (0)

 79:     do { \
 80:       PetscDevice pvd_dev_   = dev; \
 81:       int         pvd_argno_ = (int)(argno); \
 84:       PetscCheck(pvd_dev_->id >= 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid PetscDevice: Argument #%d; id %" PetscInt_FMT " < 0", pvd_argno_, pvd_dev_->id); \
 85:       PetscCheck(pvd_dev_->refcnt >= 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid PetscDevice: Argument #%d; negative reference count %" PetscInt_FMT, pvd_argno_, pvd_dev_->refcnt); \
 86:     } while (0)

 89:     do { \
 90:       PetscDeviceAttribute pvda_attr_  = (dattr); \
 91:       int                  pvda_argno_ = (int)(argno); \
 92:       PetscCheck((((int)pvda_attr_) >= 0) && (pvda_attr_ <= PETSC_DEVICE_ATTR_MAX), PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDeviceAttribute '%d': Argument #%d", (int)pvda_attr_, pvda_argno_); \
 93:       PetscCheck(pvda_attr_ != PETSC_DEVICE_ATTR_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Invalid PetscDeviceAttribute '%s': Argument #%d", PetscDeviceAttributes[pvda_attr_], pvda_argno_); \
 94:     } while (0)

 96:   /*
 97:   for now just checks strict equality, but this can be changed as some devices (i.e. kokkos and
 98:   any cupm should be compatible once implemented)
 99: */
100:   #define PetscCheckCompatibleDevices(dev1, argno1, dev2, argno2) \
101:     do { \
102:       PetscDevice pccd_dev1_ = (dev1), pccd_dev2_ = (dev2); \
103:       int         pccd_argno1_ = (int)(argno1), pccd_argno2_ = (int)(argno2); \
106:       PetscCheckCompatibleDeviceTypes(pccd_dev1_->type, pccd_argno1_, pccd_dev2_->type, pccd_argno2_); \
107:     } while (0)

110:     do { \
111:       PetscStreamType pvst_stype_ = PetscStreamTypeCast(stype); \
112:       int             pvst_argno_ = (int)(argno); \
113:       PetscCheck(((int)pvst_stype_ >= 0) && ((int)pvst_stype_ <= (int)PETSC_STREAM_MAX), PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscStreamType '%d': Argument #%d", pvst_stype_, pvst_argno_); \
114:       PetscCheck((int)pvst_stype_ != (int)PETSC_STREAM_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Invalid PetscStreamType '%s': Argument #%d", PetscStreamTypes[pvst_stype_], pvst_argno_); \
115:     } while (0)

118:     do { \
119:       PetscDeviceContext pvdc_dctx_  = dctx; \
120:       int                pvdc_argno_ = (int)(argno); \
123:       if (pvdc_dctx_->device) { \
125:       } else { \
126:         PetscCheck(!pvdc_dctx_->setup, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, \
127:                    "Invalid PetscDeviceContext: Argument #%d; " \
128:                    "PetscDeviceContext is setup but has no PetscDevice", \
129:                    pvdc_argno_); \
130:       } \
131:       PetscCheck(((PetscObject)pvdc_dctx_)->id >= 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid PetscDeviceContext: Argument #%d; id %" PetscInt64_FMT " < 1", pvdc_argno_, ((PetscObject)pvdc_dctx_)->id); \
132:       PetscCheck(pvdc_dctx_->numChildren <= pvdc_dctx_->maxNumChildren, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "Invalid PetscDeviceContext: Argument #%d; number of children %" PetscInt_FMT " > max number of children %" PetscInt_FMT, pvdc_argno_, \
133:                  pvdc_dctx_->numChildren, pvdc_dctx_->maxNumChildren); \
134:     } while (0)

136:   #define PetscCheckCompatibleDeviceContexts(dctx1, argno1, dctx2, argno2) \
137:     do { \
138:       PetscDeviceContext pccdc_dctx1_ = (dctx1), pccdc_dctx2_ = (dctx2); \
139:       int                pccdc_argno1_ = (int)(argno1), pccdc_argno2_ = (int)(argno2); \
142:       if (pccdc_dctx1_->device && pccdc_dctx2_->device) PetscCheckCompatibleDevices(pccdc_dctx1_->device, pccdc_argno1_, pccdc_dctx2_->device, pccdc_argno2_); \
143:     } while (0)
144: #else /* PetscDefined(USE_DEBUG) */
146:   #define PetscCheckCompatibleDeviceTypes(dtype1, argno1, dtype2, argno2)
149:   #define PetscCheckCompatibleDevices(dev1, argno1, dev2, argno2)
152:   #define PetscCheckCompatibleDeviceContexts(dctx1, argno1, dctx2, argno2)
153: #endif /* PetscDefined(USE_DEBUG) */

155: /* if someone is ready to rock with more than 128 GPUs on hand then we're in real trouble */
156: #define PETSC_DEVICE_MAX_DEVICES 128

158: /*
159:   the configure-time default device type, used as the initial the value of
160:   PETSC_DEVICE_DEFAULT() as well as what it is restored to during PetscFinalize()
161: */
162: #if PetscDefined(HAVE_HIP)
163:   #define PETSC_DEVICE_HARDWARE_DEFAULT_TYPE PETSC_DEVICE_HIP
164: #elif PetscDefined(HAVE_CUDA)
165:   #define PETSC_DEVICE_HARDWARE_DEFAULT_TYPE PETSC_DEVICE_CUDA
166: #elif PetscDefined(HAVE_SYCL)
167:   #define PETSC_DEVICE_HARDWARE_DEFAULT_TYPE PETSC_DEVICE_SYCL
168: #else
169:   #define PETSC_DEVICE_HARDWARE_DEFAULT_TYPE PETSC_DEVICE_HOST
170: #endif

172: #define PETSC_DEVICE_CONTEXT_DEFAULT_DEVICE_TYPE PETSC_DEVICE_HARDWARE_DEFAULT_TYPE
173: // REMOVE ME (change)
174: #define PETSC_DEVICE_CONTEXT_DEFAULT_STREAM_TYPE PETSC_STREAM_GLOBAL_BLOCKING

176: typedef struct _DeviceOps *DeviceOps;
177: struct _DeviceOps {
178:   /* the creation routine for the corresponding PetscDeviceContext, this is NOT intended
179:    * to be called by the PetscDevice itself */
180:   PetscErrorCode (*createcontext)(PetscDeviceContext);
181:   PetscErrorCode (*configure)(PetscDevice);
182:   PetscErrorCode (*view)(PetscDevice, PetscViewer);
183:   PetscErrorCode (*getattribute)(PetscDevice, PetscDeviceAttribute, void *);
184: };

186: struct _n_PetscDevice {
187:   struct _DeviceOps ops[1];
188:   void             *data;     /* placeholder */
189:   PetscInt          refcnt;   /* reference count for the device */
190:   PetscInt          id;       /* unique id per created PetscDevice */
191:   PetscInt          deviceId; /* the id of the underlying device, i.e. the return of
192:                                * cudaGetDevice() for example */
193:   PetscDeviceType   type;     /* type of device */
194: };

196: typedef struct _n_PetscEvent *PetscEvent;
197: struct _n_PetscEvent {
198:   PetscDeviceType  dtype;      // this cannot change for the lifetime of the event
199:   PetscObjectId    dctx_id;    // id of last dctx to record this event
200:   PetscObjectState dctx_state; // state of last dctx to record this event
201:   void            *data;       // event handle
202:   PetscErrorCode (*destroy)(PetscEvent);
203: };

205: typedef struct _DeviceContextOps *DeviceContextOps;
206: struct _DeviceContextOps {
207:   PetscErrorCode (*destroy)(PetscDeviceContext);
208:   PetscErrorCode (*changestreamtype)(PetscDeviceContext, PetscStreamType);
209:   PetscErrorCode (*setup)(PetscDeviceContext);
210:   PetscErrorCode (*query)(PetscDeviceContext, PetscBool *);
211:   PetscErrorCode (*waitforcontext)(PetscDeviceContext, PetscDeviceContext);
212:   PetscErrorCode (*synchronize)(PetscDeviceContext);
213:   PetscErrorCode (*getblashandle)(PetscDeviceContext, void *);
214:   PetscErrorCode (*getsolverhandle)(PetscDeviceContext, void *);
215:   PetscErrorCode (*getstreamhandle)(PetscDeviceContext, void *);
216:   PetscErrorCode (*begintimer)(PetscDeviceContext);
217:   PetscErrorCode (*endtimer)(PetscDeviceContext, PetscLogDouble *);
218:   PetscErrorCode (*memalloc)(PetscDeviceContext, PetscBool, PetscMemType, size_t, size_t, void **);                             // optional
219:   PetscErrorCode (*memfree)(PetscDeviceContext, PetscMemType, void **);                                                         // optional
220:   PetscErrorCode (*memcopy)(PetscDeviceContext, void *PETSC_RESTRICT, const void *PETSC_RESTRICT, size_t, PetscDeviceCopyMode); // optional
221:   PetscErrorCode (*memset)(PetscDeviceContext, PetscMemType, void *, PetscInt, size_t);                                         // optional
222:   PetscErrorCode (*createevent)(PetscDeviceContext, PetscEvent);                                                                // optional
223:   PetscErrorCode (*recordevent)(PetscDeviceContext, PetscEvent);                                                                // optional
224:   PetscErrorCode (*waitforevent)(PetscDeviceContext, PetscEvent);                                                               // optional
225: };

227: struct _p_PetscDeviceContext {
228:   PETSCHEADER(struct _DeviceContextOps);
229:   PetscDevice     device;         /* the device this context stems from */
230:   void           *data;           /* solver contexts, event, stream */
231:   PetscObjectId  *childIDs;       /* array containing ids of contexts currently forked from this one */
232:   PetscInt        numChildren;    /* how many children does this context expect to destroy */
233:   PetscInt        maxNumChildren; /* how many children can this context have room for without realloc'ing */
234:   PetscStreamType streamType;     /* how should this contexts stream behave around other streams? */
235:   PetscBool       setup;
236:   PetscBool       usersetdevice;
237: };

239: // ===================================================================================
240: //                            PetscDevice Internal Functions
241: // ===================================================================================
242: #if PetscDefined(HAVE_CXX)
243: PETSC_INTERN PetscErrorCode                PetscDeviceInitializeFromOptions_Internal(MPI_Comm);
244: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscDeviceGetDefaultForType_Internal(PetscDeviceType, PetscDevice *);

246: static inline PetscErrorCode PetscDeviceReference_Internal(PetscDevice device)
247: {
248:   PetscFunctionBegin;
249:   ++(device->refcnt);
250:   PetscFunctionReturn(PETSC_SUCCESS);
251: }

253: static inline PetscErrorCode PetscDeviceDereference_Internal(PetscDevice device)
254: {
255:   PetscFunctionBegin;
256:   --(device->refcnt);
257:   PetscAssert(device->refcnt >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "PetscDevice has negative reference count %" PetscInt_FMT, device->refcnt);
258:   PetscFunctionReturn(PETSC_SUCCESS);
259: }
260: #else /* PETSC_HAVE_CXX for PetscDevice Internal Functions */
261:   #define PetscDeviceInitializeFromOptions_Internal(comm)     PETSC_SUCCESS
262:   #define PetscDeviceGetDefaultForType_Internal(Type, device) (*(device) = PETSC_NULLPTR, PETSC_SUCCESS)
263:   #define PetscDeviceReference_Internal(device)               PETSC_SUCCESS
264:   #define PetscDeviceDereference_Internal(device)             PETSC_SUCCESS
265: #endif /* PETSC_HAVE_CXX for PetscDevice Internal Functions */

267: static inline PetscErrorCode PetscDeviceCheckDeviceCount_Internal(PetscInt count)
268: {
269:   PetscFunctionBegin;
270:   PetscAssert(count < PETSC_DEVICE_MAX_DEVICES, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Detected %" PetscInt_FMT " devices, which is larger than maximum supported number of devices %d", count, PETSC_DEVICE_MAX_DEVICES);
271:   PetscFunctionReturn(PETSC_SUCCESS);
272: }

274: /* More general form of PetscDeviceDefaultType_Internal(), as it calls the former using
275:  * the automatically selected default PetscDeviceType */
276: #define PetscDeviceGetDefault_Internal(device) PetscDeviceGetDefaultForType_Internal(PETSC_DEVICE_DEFAULT(), device)

278: static inline PETSC_CONSTEXPR_14 PetscBool PetscDeviceConfiguredFor_Internal(PetscDeviceType type)
279: {
280:   switch (type) {
281:   case PETSC_DEVICE_HOST:
282:     return PETSC_TRUE;
283:     /* casts are needed in C++ */
284:   case PETSC_DEVICE_CUDA:
285:     return (PetscBool)PetscDefined(HAVE_CUDA);
286:   case PETSC_DEVICE_HIP:
287:     return (PetscBool)PetscDefined(HAVE_HIP);
288:   case PETSC_DEVICE_SYCL:
289:     return (PetscBool)PetscDefined(HAVE_SYCL);
290:   case PETSC_DEVICE_MAX:
291:     return PETSC_FALSE;
292:     /* Do not add default case! Will make compiler warn on new additions to PetscDeviceType! */
293:   }
294:   PetscUnreachable();
295:   return PETSC_FALSE;
296: }

298: // ===================================================================================
299: //                     PetscDeviceContext Internal Functions
300: // ===================================================================================
301: #if PetscDefined(HAVE_CXX)
302: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscDeviceContextGetNullContext_Internal(PetscDeviceContext *);

304: static inline PetscErrorCode PetscDeviceContextGetBLASHandle_Internal(PetscDeviceContext dctx, void *handle)
305: {
306:   PetscFunctionBegin;
307:   /* we do error checking here as this routine is an entry-point */
309:   PetscUseTypeMethod(dctx, getblashandle, handle);
310:   PetscFunctionReturn(PETSC_SUCCESS);
311: }

313: static inline PetscErrorCode PetscDeviceContextGetSOLVERHandle_Internal(PetscDeviceContext dctx, void *handle)
314: {
315:   PetscFunctionBegin;
316:   /* we do error checking here as this routine is an entry-point */
318:   PetscUseTypeMethod(dctx, getsolverhandle, handle);
319:   PetscFunctionReturn(PETSC_SUCCESS);
320: }

322: static inline PetscErrorCode PetscDeviceContextGetStreamHandle_Internal(PetscDeviceContext dctx, void *handle)
323: {
324:   PetscFunctionBegin;
325:   /* we do error checking here as this routine is an entry-point */
327:   PetscUseTypeMethod(dctx, getstreamhandle, handle);
328:   PetscFunctionReturn(PETSC_SUCCESS);
329: }

331: static inline PetscErrorCode PetscDeviceContextBeginTimer_Internal(PetscDeviceContext dctx)
332: {
333:   PetscFunctionBegin;
334:   /* we do error checking here as this routine is an entry-point */
336:   PetscUseTypeMethod(dctx, begintimer);
337:   PetscFunctionReturn(PETSC_SUCCESS);
338: }

340: static inline PetscErrorCode PetscDeviceContextEndTimer_Internal(PetscDeviceContext dctx, PetscLogDouble *elapsed)
341: {
342:   PetscFunctionBegin;
343:   /* we do error checking here as this routine is an entry-point */
346:   PetscUseTypeMethod(dctx, endtimer, elapsed);
347:   PetscFunctionReturn(PETSC_SUCCESS);
348: }
349: #else /* PETSC_HAVE_CXX for PetscDeviceContext Internal Functions */
350:   #define PetscDeviceContextGetNullContext_Internal(dctx)          (*(dctx) = PETSC_NULLPTR, PETSC_SUCCESS)
351:   #define PetscDeviceContextGetBLASHandle_Internal(dctx, handle)   (*(handle) = PETSC_NULLPTR, PETSC_SUCCESS)
352:   #define PetscDeviceContextGetSOLVERHandle_Internal(dctx, handle) (*(handle) = PETSC_NULLPTR, PETSC_SUCCESS)
353:   #define PetscDeviceContextGetStreamHandle_Internal(dctx, handle) (*(handle) = PETSC_NULLPTR, PETSC_SUCCESS)
354:   #define PetscDeviceContextBeginTimer_Internal(dctx)              PETSC_SUCCESS
355:   #define PetscDeviceContextEndTimer_Internal(dctx, elapsed)       PETSC_SUCCESS
356: #endif /* PETSC_HAVE_CXX for PetscDeviceContext Internal Functions */

358: /* note, only does assertion checking in debug mode */
359: static inline PetscErrorCode PetscDeviceContextGetCurrentContextAssertType_Internal(PetscDeviceContext *dctx, PetscDeviceType type)
360: {
361:   PetscFunctionBegin;
362:   PetscCall(PetscDeviceContextGetCurrentContext(dctx));
363:   if (PetscDefined(USE_DEBUG)) {
364:     PetscDeviceType dtype;

367:     PetscCall(PetscDeviceContextGetDeviceType(*dctx, &dtype));
368:     PetscCheckCompatibleDeviceTypes(dtype, 1, type, 2);
369:   } else (void)type;
370:   PetscFunctionReturn(PETSC_SUCCESS);
371: }

373: static inline PetscErrorCode PetscDeviceContextGetOptionalNullContext_Internal(PetscDeviceContext *dctx)
374: {
375:   PetscFunctionBegin;
377:   if (!*dctx) PetscCall(PetscDeviceContextGetNullContext_Internal(dctx));
379:   PetscFunctionReturn(PETSC_SUCCESS);
380: }

382: /* Experimental API -- it will eventually become public */
383: #if PetscDefined(HAVE_CXX)
384: PETSC_EXTERN PetscErrorCode PetscDeviceRegisterMemory(const void *PETSC_RESTRICT, PetscMemType, size_t);
385: PETSC_EXTERN PetscErrorCode PetscDeviceGetAttribute(PetscDevice, PetscDeviceAttribute, void *);
386: PETSC_EXTERN PetscErrorCode PetscDeviceContextMarkIntentFromID(PetscDeviceContext, PetscObjectId, PetscMemoryAccessMode, const char name[]);
387:   #if defined(__cplusplus)
388: namespace
389: {

391: inline PetscErrorCode PetscDeviceContextMarkIntentFromID(PetscDeviceContext dctx, PetscObject obj, PetscMemoryAccessMode mode, const char name[])
392: {
393:   PetscFunctionBegin;
394:   PetscCall(PetscDeviceContextMarkIntentFromID(dctx, obj->id, mode, name));
395:   PetscFunctionReturn(PETSC_SUCCESS);
396: }

398: } // anonymous namespace
399:   #endif // __cplusplus
400: #else
401:   #define PetscDeviceRegisterMemory(void_ptr, PetscMemType, size)                                           PETSC_SUCCESS
402:   #define PetscDeviceGetAttribute(PetscDevice, PetscDeviceAttribute, void_star)                             ((*((int *)(void_star)) = 0), PETSC_SUCCESS)
403:   #define PetscDeviceContextMarkIntentFromID(PetscDeviceContext, PetscObjectId, PetscMemoryAccessMode, ptr) PETSC_SUCCESS
404: #endif

406: PETSC_INTERN PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext);
407: #if PetscDefined(HAVE_CUDA)
408: PETSC_INTERN PetscErrorCode PetscDeviceContextCreate_CUDA(PetscDeviceContext);
409: #endif
410: #if PetscDefined(HAVE_HIP)
411: PETSC_INTERN PetscErrorCode PetscDeviceContextCreate_HIP(PetscDeviceContext);
412: #endif
413: #if PetscDefined(HAVE_SYCL)
414: PETSC_INTERN PetscErrorCode PetscDeviceContextCreate_SYCL(PetscDeviceContext);
415: #endif

417: // Used for testing purposes, internal use ONLY
418: PETSC_EXTERN PetscErrorCode PetscGetMarkedObjectMap_Internal(size_t *, PetscObjectId **, PetscMemoryAccessMode **, size_t **, PetscEvent ***);
419: PETSC_EXTERN PetscErrorCode PetscRestoreMarkedObjectMap_Internal(size_t, PetscObjectId **, PetscMemoryAccessMode **, size_t **, PetscEvent ***);
420: #endif /* PETSCDEVICEIMPL_H */