xref: /petsc/src/sys/objects/device/tests/ex5.c (revision d18748622689843e8c5ce717aabfcc708e80ab43)
1 static const char help[] = "Tests PetscDeviceGetAttribute().\n\n";
2 
3 #include "petscdevicetestcommon.h"
4 #include <petscviewer.h>
5 
6 int main(int argc, char *argv[]) {
7   PetscDevice device = NULL;
8   size_t      shmem  = 0;
9 
10   PetscFunctionBeginUser;
11   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
12 
13   PetscCall(PetscDeviceCreate(PETSC_DEVICE_DEFAULT(), PETSC_DECIDE, &device));
14   PetscCall(PetscDeviceConfigure(device));
15   PetscCall(PetscDeviceGetAttribute(device, PETSC_DEVICE_ATTR_SIZE_T_SHARED_MEM_PER_BLOCK, &shmem));
16   if (PetscDefined(HAVE_CXX) && ((shmem == 0) || (shmem == (size_t)-1))) {
17     // if no C++ then PetscDeviceGetAttribute defaults to 0
18     PetscCall(PetscDeviceView(device, PETSC_VIEWER_STDOUT_SELF));
19     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Maximum shared memory of %zu seems fishy", shmem);
20   }
21   PetscCall(PetscDeviceDestroy(&device));
22 
23   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n"));
24   PetscCall(PetscFinalize());
25   return 0;
26 }
27 
28 /*TEST
29 
30   build:
31    requires: defined(PETSC_HAVE_CXX)
32 
33   testset:
34    output_file: ./output/ExitSuccess.out
35    args: -device_enable {{lazy eager}}
36    test:
37      requires: !device
38      suffix: host_no_device
39    test:
40      requires: device
41      args: -default_device_type host
42      suffix: host_with_device
43    test:
44      requires: cuda
45      args: -default_device_type cuda
46      suffix: cuda
47    test:
48      requires: hip
49      args: -default_device_type hip
50      suffix: hip
51    test:
52      requires: sycl
53      args: -default_device_type sycl
54      suffix: sycl
55 
56 TEST*/
57