1 static const char help[] = "Tests PetscDeviceContextDuplicate.\n\n"; 2 3 #include <petsc/private/deviceimpl.h> 4 #include "petscdevicetestcommon.h" 5 6 /* test duplication creates the same object type */ 7 static PetscErrorCode TestPetscDeviceContextDuplicate(PetscDeviceContext dctx) 8 { 9 PetscDevice origDevice; 10 PetscStreamType origStype; 11 PetscDeviceContext ddup; 12 13 PetscFunctionBegin; 14 PetscValidDeviceContext(dctx,1); 15 /* get everything we want first before any duplication */ 16 PetscCall(PetscDeviceContextGetStreamType(dctx,&origStype)); 17 PetscCall(PetscDeviceContextGetDevice(dctx,&origDevice)); 18 19 /* duplicate */ 20 PetscCall(PetscDeviceContextDuplicate(dctx,&ddup)); 21 PetscValidDeviceContext(ddup,2); 22 PetscCheckCompatibleDeviceContexts(dctx,1,ddup,2); 23 24 { 25 PetscDevice parDevice,dupDevice; 26 27 PetscCall(PetscDeviceContextGetDevice(dctx,&parDevice)); 28 PetscCall(AssertPetscDevicesValidAndEqual(parDevice,origDevice,"Parent PetscDevice after duplication does not match parent original PetscDevice")); 29 PetscCall(PetscDeviceContextGetDevice(ddup,&dupDevice)); 30 PetscCall(AssertPetscDevicesValidAndEqual(dupDevice,origDevice,"Duplicated PetscDevice does not match parent original PetscDevice")); 31 } 32 33 { 34 PetscStreamType parStype,dupStype; 35 36 PetscCall(PetscDeviceContextGetStreamType(dctx,&parStype)); 37 PetscCall(AssertPetscStreamTypesValidAndEqual(parStype,origStype,"Parent PetscStreamType after duplication does not match parent original PetscStreamType")); 38 PetscCall(PetscDeviceContextGetStreamType(ddup,&dupStype)); 39 PetscCall(AssertPetscStreamTypesValidAndEqual(dupStype,origStype,"Duplicated PetscStreamType '%s' does not match parent original PetscStreamType '%s'")); 40 } 41 42 PetscCall(PetscDeviceContextDestroy(&ddup)); 43 /* duplicate should not take the original down with it */ 44 PetscValidDeviceContext(dctx,1); 45 PetscFunctionReturn(0); 46 } 47 48 int main(int argc, char *argv[]) 49 { 50 PetscDeviceContext dctx; 51 52 PetscFunctionBeginUser; 53 PetscCall(PetscInitialize(&argc,&argv,NULL,help)); 54 55 /* basic creation and destruction */ 56 PetscCall(PetscDeviceContextCreate(&dctx)); 57 PetscCall(PetscDeviceContextSetFromOptions(PETSC_COMM_WORLD,"local_",dctx)); 58 PetscCall(PetscDeviceContextSetUp(dctx)); 59 PetscCall(TestPetscDeviceContextDuplicate(dctx)); 60 PetscCall(PetscDeviceContextDestroy(&dctx)); 61 62 PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 63 PetscCall(TestPetscDeviceContextDuplicate(dctx)); 64 65 PetscCall(PetscPrintf(PETSC_COMM_WORLD,"EXIT_SUCCESS\n")); 66 PetscCall(PetscFinalize()); 67 return 0; 68 } 69 70 /*TEST 71 72 build: 73 requires: defined(PETSC_HAVE_CXX) 74 75 testset: 76 TODO: broken in ci 77 requires: !device 78 suffix: no_device 79 filter: Error: grep -E -o -e ".*No support for this operation for this object type" -e ".*PETSc is not configured with device support.*" -e "^\[0\]PETSC ERROR:.*[0-9]{1} [A-z]+\(\)" 80 81 testset: 82 output_file: ./output/ExitSuccess.out 83 nsize: {{1 4}} 84 args: -local_device_context_stream_type {{global_blocking default_blocking global_nonblocking}} 85 test: 86 requires: cuda 87 suffix: cuda 88 test: 89 requires: hip 90 suffix: hip 91 92 TEST*/ 93