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