1 static const char help[] = "Tests creation and destruction of PetscDeviceContext.\n\n"; 2 3 #include "petscdevicetestcommon.h" 4 5 int main(int argc, char *argv[]) { 6 PetscDeviceContext dctx = NULL, ddup = NULL; 7 8 PetscFunctionBeginUser; 9 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 10 11 /* basic creation and destruction */ 12 PetscCall(PetscDeviceContextCreate(&dctx)); 13 PetscCall(AssertDeviceContextExists(dctx)); 14 PetscCall(PetscDeviceContextDestroy(&dctx)); 15 PetscCall(AssertDeviceContextDoesNotExist(dctx)); 16 /* double free is no-op */ 17 PetscCall(PetscDeviceContextDestroy(&dctx)); 18 PetscCall(AssertDeviceContextDoesNotExist(dctx)); 19 20 /* test global context returns a valid context */ 21 dctx = NULL; 22 PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 23 PetscCall(AssertDeviceContextExists(dctx)); 24 /* test locally setting to null doesn't clobber the global */ 25 dctx = NULL; 26 PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 27 PetscCall(AssertDeviceContextExists(dctx)); 28 29 /* test duplicate */ 30 PetscCall(PetscDeviceContextDuplicate(dctx, &ddup)); 31 /* both device contexts should exist */ 32 PetscCall(AssertDeviceContextExists(dctx)); 33 PetscCall(AssertDeviceContextExists(ddup)); 34 35 /* destroying the dup should leave the original untouched */ 36 PetscCall(PetscDeviceContextDestroy(&ddup)); 37 PetscCall(AssertDeviceContextDoesNotExist(ddup)); 38 PetscCall(AssertDeviceContextExists(dctx)); 39 40 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n")); 41 PetscCall(PetscFinalize()); 42 return 0; 43 } 44 45 /*TEST 46 47 build: 48 requires: defined(PETSC_HAVE_CXX) 49 50 testset: 51 output_file: ./output/ExitSuccess.out 52 nsize: {{1 2 4}} 53 args: -device_enable {{lazy eager}} 54 test: 55 requires: !device 56 suffix: host_no_device 57 test: 58 requires: device 59 args: -root_device_context_device_type host 60 suffix: host_with_device 61 test: 62 requires: cuda 63 args: -root_device_context_device_type cuda 64 suffix: cuda 65 test: 66 requires: hip 67 args: -root_device_context_device_type hip 68 suffix: hip 69 70 TEST*/ 71