1 #pragma once
2
3 /* this file needs to be the one to include petsc/private/deviceimpl.h since it needs to define
4 * a special macro to ensure that the error checking macros stay defined even in optimized
5 * builds
6 */
7 #if defined(PETSCDEVICEIMPL_H)
8 #error "must #include this file before petsc/private/deviceimpl.h"
9 #endif
10
11 #if !defined(PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS)
12 #define PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS 1
13 #endif
14 #include <petsc/private/deviceimpl.h>
15
AssertDeviceExists(PetscDevice device)16 static inline PetscErrorCode AssertDeviceExists(PetscDevice device)
17 {
18 PetscFunctionBegin;
19 PetscValidDevice(device, 1);
20 PetscFunctionReturn(PETSC_SUCCESS);
21 }
22
AssertDeviceDoesNotExist(PetscDevice device)23 static inline PetscErrorCode AssertDeviceDoesNotExist(PetscDevice device)
24 {
25 PetscFunctionBegin;
26 PetscCheck(!device, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDevice was not destroyed for type %s", PetscDeviceTypes[device->type]);
27 PetscFunctionReturn(PETSC_SUCCESS);
28 }
29
AssertDeviceContextExists(PetscDeviceContext dctx)30 static inline PetscErrorCode AssertDeviceContextExists(PetscDeviceContext dctx)
31 {
32 PetscFunctionBegin;
33 PetscValidDeviceContext(dctx, 1);
34 PetscFunctionReturn(PETSC_SUCCESS);
35 }
36
AssertDeviceContextDoesNotExist(PetscDeviceContext dctx)37 static inline PetscErrorCode AssertDeviceContextDoesNotExist(PetscDeviceContext dctx)
38 {
39 PetscFunctionBegin;
40 PetscCheck(!dctx, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDeviceContext was not destroyed");
41 PetscFunctionReturn(PETSC_SUCCESS);
42 }
43
AssertPetscStreamTypesValidAndEqual(PetscStreamType left,PetscStreamType right,const char * errStr)44 static inline PetscErrorCode AssertPetscStreamTypesValidAndEqual(PetscStreamType left, PetscStreamType right, const char *errStr)
45 {
46 PetscFunctionBegin;
47 PetscValidStreamType(left, 1);
48 PetscValidStreamType(right, 2);
49 PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscStreamTypes[left], PetscStreamTypes[right]);
50 PetscFunctionReturn(PETSC_SUCCESS);
51 }
52
AssertPetscDeviceTypesValidAndEqual(PetscDeviceType left,PetscDeviceType right,const char * errStr)53 static inline PetscErrorCode AssertPetscDeviceTypesValidAndEqual(PetscDeviceType left, PetscDeviceType right, const char *errStr)
54 {
55 PetscFunctionBegin;
56 PetscValidDeviceType(left, 1);
57 PetscValidDeviceType(right, 2);
58 PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscDeviceTypes[left], PetscDeviceTypes[right]);
59 PetscFunctionReturn(PETSC_SUCCESS);
60 }
61
AssertPetscDevicesValidAndEqual(PetscDevice left,PetscDevice right,const char * errStr)62 static inline PetscErrorCode AssertPetscDevicesValidAndEqual(PetscDevice left, PetscDevice right, const char *errStr)
63 {
64 PetscFunctionBegin;
65 PetscCheckCompatibleDevices(left, 1, right, 2);
66 PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "%s: %p != %p", errStr, (void *)left, (void *)right);
67 PetscFunctionReturn(PETSC_SUCCESS);
68 }
69
AssertPetscDeviceContextsValidAndEqual(PetscDeviceContext left,PetscDeviceContext right,const char * errStr)70 static inline PetscErrorCode AssertPetscDeviceContextsValidAndEqual(PetscDeviceContext left, PetscDeviceContext right, const char *errStr)
71 {
72 PetscFunctionBegin;
73 PetscCheckCompatibleDeviceContexts(left, 1, right, 2);
74 PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "%s", errStr);
75 PetscFunctionReturn(PETSC_SUCCESS);
76 }
77