1 #include <petscsys.h> 2 #include <petscviewer.h> 3 #include <petsc/private/deviceimpl.h> 4 5 /* implementations for <include/petscdevice.h> */ 6 PetscErrorCode PetscDeviceCreate(PETSC_UNUSED PetscDeviceType type, PETSC_UNUSED PetscInt devid, PetscDevice *device) 7 { 8 PetscFunctionBegin; 9 PetscAssertPointer(device, 3); 10 *device = NULL; 11 PetscFunctionReturn(PETSC_SUCCESS); 12 } 13 14 PetscErrorCode PetscDeviceDestroy(PetscDevice *device) 15 { 16 PetscFunctionBegin; 17 PetscAssertPointer(device, 1); 18 if (*device) *device = NULL; 19 PetscFunctionReturn(PETSC_SUCCESS); 20 } 21 22 PetscErrorCode PetscDeviceConfigure(PETSC_UNUSED PetscDevice device) 23 { 24 PetscFunctionBegin; 25 PetscFunctionReturn(PETSC_SUCCESS); 26 } 27 28 PetscErrorCode PetscDeviceView(PETSC_UNUSED PetscDevice device, PetscViewer viewer) 29 { 30 PetscFunctionBegin; 31 if (viewer) PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 32 PetscFunctionReturn(PETSC_SUCCESS); 33 } 34 35 PetscErrorCode PetscDeviceGetType(PETSC_UNUSED PetscDevice device, PetscDeviceType *type) 36 { 37 PetscFunctionBegin; 38 PetscAssertPointer(type, 2); 39 *type = PETSC_DEVICE_DEFAULT(); 40 PetscFunctionReturn(PETSC_SUCCESS); 41 } 42 43 PetscErrorCode PetscDeviceGetDeviceId(PETSC_UNUSED PetscDevice device, PetscInt *id) 44 { 45 PetscFunctionBegin; 46 PetscAssertPointer(id, 2); 47 *id = 0; 48 PetscFunctionReturn(PETSC_SUCCESS); 49 } 50 51 PetscDeviceType PETSC_DEVICE_DEFAULT(void) 52 { 53 return PETSC_DEVICE_HOST; 54 } 55 56 PetscErrorCode PetscDeviceSetDefaultDeviceType(PetscDeviceType type) 57 { 58 PetscFunctionBegin; 59 PetscCheck(type == PETSC_DEVICE_HOST, PETSC_COMM_SELF, PETSC_ERR_USER_INPUT, "PetscDevice is disabled but specified PetscDeviceType %s is different than %s", PetscDeviceTypes[type], PetscDeviceTypes[PETSC_DEVICE_HOST]); 60 PetscFunctionReturn(PETSC_SUCCESS); 61 } 62 63 PetscErrorCode PetscDeviceInitialize(PETSC_UNUSED PetscDeviceType type) 64 { 65 PetscFunctionBegin; 66 PetscFunctionReturn(PETSC_SUCCESS); 67 } 68 69 PetscBool PetscDeviceInitialized(PetscDeviceType type) 70 { 71 return (type == PETSC_DEVICE_HOST) ? PETSC_TRUE : PETSC_FALSE; 72 } 73 74 PetscErrorCode PetscDeviceContextCreate(PetscDeviceContext *dctx) 75 { 76 PetscFunctionBegin; 77 PetscAssertPointer(dctx, 1); 78 *dctx = NULL; 79 PetscFunctionReturn(PETSC_SUCCESS); 80 } 81 82 PetscErrorCode PetscDeviceContextDestroy(PetscDeviceContext *dctx) 83 { 84 PetscFunctionBegin; 85 PetscAssertPointer(dctx, 1); 86 if (*dctx) *dctx = NULL; 87 PetscFunctionReturn(PETSC_SUCCESS); 88 } 89 90 PetscErrorCode PetscDeviceContextSetStreamType(PETSC_UNUSED PetscDeviceContext dctx, PETSC_UNUSED PetscStreamType type) 91 { 92 PetscFunctionBegin; 93 PetscFunctionReturn(PETSC_SUCCESS); 94 } 95 96 PetscErrorCode PetscDeviceContextGetStreamType(PETSC_UNUSED PetscDeviceContext dctx, PetscStreamType *type) 97 { 98 PetscFunctionBegin; 99 PetscAssertPointer(type, 2); 100 *type = PETSC_STREAM_DEFAULT; 101 PetscFunctionReturn(PETSC_SUCCESS); 102 } 103 104 PetscErrorCode PetscDeviceContextSetDevice(PETSC_UNUSED PetscDeviceContext dctx, PETSC_UNUSED PetscDevice device) 105 { 106 PetscFunctionBegin; 107 PetscFunctionReturn(PETSC_SUCCESS); 108 } 109 110 PetscErrorCode PetscDeviceContextGetDevice(PETSC_UNUSED PetscDeviceContext dctx, PetscDevice *device) 111 { 112 PetscFunctionBegin; 113 PetscAssertPointer(device, 2); 114 *device = NULL; 115 PetscFunctionReturn(PETSC_SUCCESS); 116 } 117 118 PetscErrorCode PetscDeviceContextGetDeviceType(PETSC_UNUSED PetscDeviceContext dctx, PetscDeviceType *type) 119 { 120 PetscFunctionBegin; 121 PetscAssertPointer(type, 2); 122 *type = PETSC_DEVICE_DEFAULT(); 123 PetscFunctionReturn(PETSC_SUCCESS); 124 } 125 126 PetscErrorCode PetscDeviceContextSetUp(PETSC_UNUSED PetscDeviceContext dctx) 127 { 128 PetscFunctionBegin; 129 PetscFunctionReturn(PETSC_SUCCESS); 130 } 131 132 PetscErrorCode PetscDeviceContextDuplicate(PETSC_UNUSED PetscDeviceContext dctx, PetscDeviceContext *dctxdup) 133 { 134 PetscFunctionBegin; 135 PetscAssertPointer(dctxdup, 2); 136 *dctxdup = NULL; 137 PetscFunctionReturn(PETSC_SUCCESS); 138 } 139 140 PetscErrorCode PetscDeviceContextQueryIdle(PETSC_UNUSED PetscDeviceContext dctx, PetscBool *idle) 141 { 142 PetscFunctionBegin; 143 PetscAssertPointer(idle, 2); 144 *idle = PETSC_TRUE; 145 PetscFunctionReturn(PETSC_SUCCESS); 146 } 147 148 PetscErrorCode PetscDeviceContextWaitForContext(PETSC_UNUSED PetscDeviceContext dctxa, PETSC_UNUSED PetscDeviceContext dctxb) 149 { 150 PetscFunctionBegin; 151 PetscFunctionReturn(PETSC_SUCCESS); 152 } 153 154 PetscErrorCode PetscDeviceContextForkWithStreamType(PETSC_UNUSED PetscDeviceContext dctx, PETSC_UNUSED PetscStreamType stype, PetscInt n, PetscDeviceContext **dsub) 155 { 156 PetscFunctionBegin; 157 PetscAssertPointer(dsub, 4); 158 PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Number of contexts merged %" PetscInt_FMT " < 0", n); 159 PetscCall(PetscMalloc1(n, dsub)); 160 PetscFunctionReturn(PETSC_SUCCESS); 161 } 162 163 PetscErrorCode PetscDeviceContextFork(PetscDeviceContext dctx, PetscInt n, PetscDeviceContext **dsub) 164 { 165 PetscFunctionBegin; 166 PetscCall(PetscDeviceContextForkWithStreamType(dctx, PETSC_STREAM_DEFAULT, n, dsub)); 167 PetscFunctionReturn(PETSC_SUCCESS); 168 } 169 170 PetscErrorCode PetscDeviceContextJoin(PETSC_UNUSED PetscDeviceContext dctx, PetscInt n, PetscDeviceContextJoinMode joinMode, PetscDeviceContext **dsub) 171 { 172 PetscFunctionBegin; 173 PetscAssertPointer(dsub, 4); 174 PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Number of contexts merged %" PetscInt_FMT " < 0", n); 175 if (joinMode == PETSC_DEVICE_CONTEXT_JOIN_DESTROY) PetscCall(PetscFree(*dsub)); 176 PetscFunctionReturn(PETSC_SUCCESS); 177 } 178 179 PetscErrorCode PetscDeviceContextSynchronize(PETSC_UNUSED PetscDeviceContext dctx) 180 { 181 PetscFunctionBegin; 182 PetscFunctionReturn(PETSC_SUCCESS); 183 } 184 185 PetscErrorCode PetscDeviceContextSetFromOptions(PETSC_UNUSED MPI_Comm comm, PETSC_UNUSED PetscDeviceContext dctx) 186 { 187 PetscFunctionBegin; 188 PetscFunctionReturn(PETSC_SUCCESS); 189 } 190 191 PetscErrorCode PetscDeviceContextView(PETSC_UNUSED PetscDeviceContext dctx, PETSC_UNUSED PetscViewer viewer) 192 { 193 PetscFunctionBegin; 194 PetscFunctionReturn(PETSC_SUCCESS); 195 } 196 197 PetscErrorCode PetscDeviceContextViewFromOptions(PETSC_UNUSED PetscDeviceContext dctx, PetscObject obj, const char name[]) 198 { 199 PetscFunctionBegin; 200 if (obj) PetscValidHeader(obj, 2); 201 PetscAssertPointer(name, 3); 202 PetscFunctionReturn(PETSC_SUCCESS); 203 } 204 205 PetscErrorCode PetscDeviceContextGetCurrentContext(PetscDeviceContext *dctx) 206 { 207 PetscFunctionBegin; 208 PetscAssertPointer(dctx, 1); 209 *dctx = NULL; 210 PetscFunctionReturn(PETSC_SUCCESS); 211 } 212 213 PetscErrorCode PetscDeviceContextSetCurrentContext(PETSC_UNUSED PetscDeviceContext dctx) 214 { 215 PetscFunctionBegin; 216 PetscFunctionReturn(PETSC_SUCCESS); 217 } 218 219 PetscErrorCode PetscDeviceContextGetStreamHandle(PETSC_UNUSED PetscDeviceContext dctx, void **handle) 220 { 221 PetscFunctionBegin; 222 PetscAssertPointer(handle, 2); 223 *handle = NULL; 224 PetscFunctionReturn(PETSC_SUCCESS); 225 } 226 227 PetscErrorCode PetscDeviceAllocate_Private(PETSC_UNUSED PetscDeviceContext dctx, PetscBool clear, PETSC_UNUSED PetscMemType mtype, size_t n, PETSC_UNUSED size_t alignment, void **PETSC_RESTRICT ptr) 228 { 229 PetscFunctionBegin; 230 PetscAssertPointer(ptr, 6); 231 PetscCall(PetscMallocA(1, clear, __LINE__, PETSC_FUNCTION_NAME, __FILE__, n, ptr)); 232 PetscFunctionReturn(PETSC_SUCCESS); 233 } 234 235 PetscErrorCode PetscDeviceDeallocate_Private(PETSC_UNUSED PetscDeviceContext dctx, void *PETSC_RESTRICT ptr) 236 { 237 PetscFunctionBegin; 238 PetscCall(PetscFree(ptr)); 239 PetscFunctionReturn(PETSC_SUCCESS); 240 } 241 242 PetscErrorCode PetscDeviceMemcpy(PETSC_UNUSED PetscDeviceContext dctx, void *PETSC_RESTRICT dest, const void *PETSC_RESTRICT src, size_t n) 243 { 244 PetscFunctionBegin; 245 PetscCall(PetscMemcpy(dest, src, n)); 246 PetscFunctionReturn(PETSC_SUCCESS); 247 } 248 249 PetscErrorCode PetscDeviceMemset(PETSC_UNUSED PetscDeviceContext dctx, PETSC_UNUSED void *ptr, PetscInt v, size_t n) 250 { 251 PetscFunctionBegin; 252 memset(ptr, (unsigned char)v, n); 253 PetscFunctionReturn(PETSC_SUCCESS); 254 } 255 256 /* implementations for <include/petsc/private/deviceimpl.h> */ 257 PetscErrorCode PetscDeviceInitializeFromOptions_Internal(PETSC_UNUSED MPI_Comm comm) 258 { 259 PetscFunctionBegin; 260 PetscFunctionReturn(PETSC_SUCCESS); 261 } 262 263 PetscErrorCode PetscDeviceGetDefaultForType_Internal(PETSC_UNUSED PetscDeviceType type, PetscDevice *device) 264 { 265 PetscFunctionBegin; 266 PetscAssertPointer(device, 2); 267 *device = NULL; 268 PetscFunctionReturn(PETSC_SUCCESS); 269 } 270 271 PetscErrorCode PetscDeviceContextGetNullContext_Internal(PetscDeviceContext *dctx) 272 { 273 PetscFunctionBegin; 274 PetscAssertPointer(dctx, 1); 275 *dctx = NULL; 276 PetscFunctionReturn(PETSC_SUCCESS); 277 } 278 279 PetscErrorCode PetscDeviceRegisterMemory(const void *PETSC_RESTRICT ptr, PetscMemType mtype, PETSC_UNUSED size_t size) 280 { 281 PetscFunctionBegin; 282 if (PetscMemTypeHost(mtype)) PetscAssertPointer(ptr, 1); 283 PetscFunctionReturn(PETSC_SUCCESS); 284 } 285 286 PetscErrorCode PetscDeviceGetAttribute(PETSC_UNUSED PetscDevice device, PETSC_UNUSED PetscDeviceAttribute attr, void *value) 287 { 288 PetscFunctionBegin; 289 PetscAssertPointer(value, 3); 290 *(int *)value = 0; 291 PetscFunctionReturn(PETSC_SUCCESS); 292 } 293 294 PetscErrorCode PetscGetMarkedObjectMap_Internal(size_t *nkeys, PetscObjectId **keys, PetscMemoryAccessMode **modes, size_t **ndeps, PetscEvent ***dependencies) 295 { 296 PetscFunctionBegin; 297 PetscAssertPointer(nkeys, 1); 298 PetscAssertPointer(keys, 2); 299 PetscAssertPointer(modes, 3); 300 PetscAssertPointer(ndeps, 4); 301 PetscAssertPointer(dependencies, 5); 302 *nkeys = 0; 303 *keys = NULL; 304 *modes = NULL; 305 *ndeps = NULL; 306 *dependencies = NULL; 307 PetscFunctionReturn(PETSC_SUCCESS); 308 } 309 310 PetscErrorCode PetscRestoreMarkedObjectMap_Internal(size_t nkeys, PETSC_UNUSED PetscObjectId **keys, PETSC_UNUSED PetscMemoryAccessMode **modes, PETSC_UNUSED size_t **ndeps, PETSC_UNUSED PetscEvent ***dependencies) 311 { 312 PetscFunctionBegin; 313 PetscAssertPointer(keys, 2); 314 PetscAssertPointer(modes, 3); 315 PetscAssertPointer(ndeps, 4); 316 PetscAssertPointer(dependencies, 5); 317 if (*keys) *keys = NULL; 318 if (*modes) *modes = NULL; 319 if (*ndeps) *ndeps = NULL; 320 if (*dependencies) *dependencies = NULL; 321 PetscFunctionReturn(PETSC_SUCCESS); 322 } 323