Fix expectation and types in acc_get_property tests
authorFrederik Harwath <frederik@codesourcery.com>
Mon, 20 Jan 2020 13:07:03 +0000 (14:07 +0100)
committerFrederik Harwath <frederik@codesourcery.com>
Fri, 24 Jan 2020 08:14:51 +0000 (09:14 +0100)
* Weaken expectation concerning acc_property_free_memory.
  Do not expect the value returned by CUDA since that value might have
  changed in the meantime.
* Use correct type for the results of calls to acc_get_property in tests.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-aux.c
(expect_device_properties): Remove "expected_free_mem" argument,
change "expected_total_mem" argument type to size_t;
change types of acc_get_property results to size_t,
adapt format strings.
* testsuite/libgomp.oacc-c-c++-common/acc_get_property.c:
Use %zu instead of %zd to print size_t values.
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-2.c: Adapt and
rename to ...
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c: ... this.
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-3.c: Adapt and
rename to ...
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-host.c: ... this.

Reviewed-by: Thomas Schwinge <thomas@codesourcery.com>
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-2.c [deleted file]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-3.c [deleted file]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-aux.c
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-host.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property.c

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-2.c
deleted file mode 100644 (file)
index 4dd13c4..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Test the `acc_get_property' and '`acc_get_property_string' library
-   functions on Nvidia devices by comparing property values with
-   those obtained through the CUDA API. */
-/* { dg-additional-sources acc_get_property-aux.c } */
-/* { dg-additional-options "-lcuda -lcudart" } */
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
-
-#include <openacc.h>
-#include <cuda.h>
-#include <cuda_runtime_api.h>
-#include <string.h>
-#include <stdio.h>
-
-void expect_device_properties
-(acc_device_t dev_type, int dev_num,
- int expected_total_mem, int expected_free_mem,
- const char* expected_vendor, const char* expected_name,
- const char* expected_driver);
-
-int main ()
-{
-  int dev_count;
-  cudaGetDeviceCount (&dev_count);
-
-  for (int dev_num = 0; dev_num < dev_count; ++dev_num)
-    {
-      if (cudaSetDevice (dev_num) != cudaSuccess)
-       {
-         fprintf (stderr, "cudaSetDevice failed.\n");
-         abort ();
-       }
-
-      printf("Checking device %d\n", dev_num);
-
-      const char *vendor = "Nvidia";
-      size_t free_mem;
-      size_t total_mem;
-      if (cudaMemGetInfo(&free_mem, &total_mem) != cudaSuccess)
-       {
-         fprintf (stderr, "cudaMemGetInfo failed.\n");
-         abort ();
-       }
-
-      struct cudaDeviceProp p;
-      if (cudaGetDeviceProperties(&p, dev_num) != cudaSuccess)
-       {
-         fprintf (stderr, "cudaGetDeviceProperties failed.\n");
-         abort ();
-       }
-
-      int driver_version;
-      if (cudaDriverGetVersion(&driver_version) != cudaSuccess)
-       {
-         fprintf (stderr, "cudaDriverGetVersion failed.\n");
-         abort ();
-       }
-      /* The version string should contain the version of the CUDA Toolkit
-        in the same MAJOR.MINOR format that is used by Nvidia.
-        The format string below is the same that is used by the deviceQuery
-        program, which belongs to Nvidia's CUDA samples, to print the version. */
-      char driver[30];
-      snprintf (driver, sizeof driver, "CUDA Driver %u.%u",
-               driver_version / 1000, driver_version % 1000 / 10);
-
-      expect_device_properties(acc_device_nvidia, dev_num,
-                              total_mem, free_mem, vendor, p.name, driver);
-    }
-}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-3.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-3.c
deleted file mode 100644 (file)
index 9256500..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Test the `acc_get_property' and '`acc_get_property_string' library
-   functions for the host device. */
-/* { dg-additional-sources acc_get_property-aux.c } */
-/* { dg-do run } */
-
-#include <openacc.h>
-#include <stdio.h>
-
-void expect_device_properties
-(acc_device_t dev_type, int dev_num,
- int expected_total_mem, int expected_free_mem,
- const char* expected_vendor, const char* expected_name,
- const char* expected_driver);
-
-int main()
-{
-  printf ("Checking acc_device_host device properties\n");
-  expect_device_properties (acc_device_host, 0, 0, 0, "GNU", "GOMP", "1.0");
-}
index 952bdbf6aeab148c943f387d6662359fe67b4ad0..6bb0125014829279cf405ed3d86235f2ad66e16c 100644 (file)
@@ -8,9 +8,8 @@
 
 void expect_device_properties
 (acc_device_t dev_type, int dev_num,
- int expected_total_mem, int expected_free_mem,
- const char* expected_vendor, const char* expected_name,
- const char* expected_driver)
+ size_t expected_memory, const char* expected_vendor,
+ const char* expected_name, const char* expected_driver)
 {
   const char *vendor = acc_get_property_string (dev_num, dev_type,
                                                acc_property_vendor);
@@ -21,22 +20,23 @@ void expect_device_properties
       abort ();
     }
 
-  int total_mem = acc_get_property (dev_num, dev_type,
-                                   acc_property_memory);
-  if (total_mem != expected_total_mem)
+  size_t total_mem = acc_get_property (dev_num, dev_type,
+                                      acc_property_memory);
+  if (total_mem != expected_memory)
     {
-      fprintf (stderr, "Expected acc_property_memory to equal %d, "
-              "but was %d.\n", expected_total_mem, total_mem);
+      fprintf (stderr, "Expected acc_property_memory to equal %zu, "
+              "but was %zu.\n", expected_memory, total_mem);
       abort ();
 
     }
 
-  int free_mem = acc_get_property (dev_num, dev_type,
+  size_t free_mem = acc_get_property (dev_num, dev_type,
                                   acc_property_free_memory);
-  if (free_mem != expected_free_mem)
+  if (free_mem > total_mem)
     {
-      fprintf (stderr, "Expected acc_property_free_memory to equal %d, "
-              "but was %d.\n", expected_free_mem, free_mem);
+      fprintf (stderr, "Expected acc_property_free_memory <= acc_property_memory"
+              ", but free memory was %zu and total memory was %zu.\n",
+              free_mem, total_mem);
       abort ();
     }
 
@@ -59,11 +59,11 @@ void expect_device_properties
     }
 
   int unknown_property = 16058;
-  int v = acc_get_property (dev_num, dev_type, (acc_device_property_t)unknown_property);
+  size_t v = acc_get_property (dev_num, dev_type, (acc_device_property_t)unknown_property);
   if (v != 0)
     {
       fprintf (stderr, "Expected value of unknown numeric property to equal 0, "
-              "but was %d.\n", v);
+              "but was %zu.\n", v);
       abort ();
     }
 
@@ -72,7 +72,7 @@ void expect_device_properties
   if (s != NULL)
     {
       fprintf (stderr, "Expected value of unknown string property to be NULL, "
-              "but was %d.\n", s);
+              "but was %s.\n", s);
       abort ();
     }
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-host.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-host.c
new file mode 100644 (file)
index 0000000..f1cd7cf
--- /dev/null
@@ -0,0 +1,18 @@
+/* Test the `acc_get_property' and '`acc_get_property_string' library
+   functions for the host device. */
+/* { dg-additional-sources acc_get_property-aux.c } */
+/* { dg-do run } */
+
+#include <openacc.h>
+#include <stdio.h>
+
+void expect_device_properties
+(acc_device_t dev_type, int dev_num,
+ size_t expected_memory, const char* expected_vendor,
+ const char* expected_name, const char* expected_driver);
+
+int main()
+{
+  printf ("Checking acc_device_host device properties\n");
+  expect_device_properties (acc_device_host, 0, 0, "GNU", "GOMP", "1.0");
+}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c
new file mode 100644 (file)
index 0000000..0dcaea7
--- /dev/null
@@ -0,0 +1,69 @@
+/* Test the `acc_get_property' and '`acc_get_property_string' library
+   functions on Nvidia devices by comparing property values with
+   those obtained through the CUDA API. */
+/* { dg-additional-sources acc_get_property-aux.c } */
+/* { dg-additional-options "-lcuda -lcudart" } */
+/* { dg-do run { target openacc_nvidia_accel_selected } } */
+
+#include <openacc.h>
+#include <cuda.h>
+#include <cuda_runtime_api.h>
+#include <string.h>
+#include <stdio.h>
+
+void expect_device_properties
+(acc_device_t dev_type, int dev_num,
+ size_t expected_memory, const char* expected_vendor,
+ const char* expected_name, const char* expected_driver);
+
+int main ()
+{
+  int dev_count;
+  cudaGetDeviceCount (&dev_count);
+
+  for (int dev_num = 0; dev_num < dev_count; ++dev_num)
+    {
+      if (cudaSetDevice (dev_num) != cudaSuccess)
+       {
+         fprintf (stderr, "cudaSetDevice failed.\n");
+         abort ();
+       }
+
+      printf("Checking device %d\n", dev_num);
+
+      const char *vendor = "Nvidia";
+      size_t free_mem;
+      size_t total_mem;
+      if (cudaMemGetInfo(&free_mem, &total_mem) != cudaSuccess)
+       {
+         fprintf (stderr, "cudaMemGetInfo failed.\n");
+         abort ();
+       }
+
+      struct cudaDeviceProp p;
+      if (cudaGetDeviceProperties(&p, dev_num) != cudaSuccess)
+       {
+         fprintf (stderr, "cudaGetDeviceProperties failed.\n");
+         abort ();
+       }
+
+      int driver_version;
+      if (cudaDriverGetVersion(&driver_version) != cudaSuccess)
+       {
+         fprintf (stderr, "cudaDriverGetVersion failed.\n");
+         abort ();
+       }
+      /* The version string should contain the version of the CUDA Toolkit
+        in the same MAJOR.MINOR format that is used by Nvidia.
+        The format string below is the same that is used by the deviceQuery
+        program, which belongs to Nvidia's CUDA samples, to print the version. */
+      char driver[30];
+      snprintf (driver, sizeof driver, "CUDA Driver %u.%u",
+               driver_version / 1000, driver_version % 1000 / 10);
+
+      /* Note that this check relies on the fact that the device numbering
+        used by the nvptx plugin agrees with the CUDA device ordering. */
+      expect_device_properties(acc_device_nvidia, dev_num,
+                              total_mem, vendor, p.name, driver);
+    }
+}
index 289d1bab7f81473b8a573b2515318ed7989fb9d8..388c66c1319a107a878aae0157c7b74a2b914853 100644 (file)
@@ -35,10 +35,10 @@ print_device_properties(acc_device_t type)
        }
 
       v = acc_get_property (i, type,  acc_property_memory);
-      printf ("    Total memory: %zd\n", v);
+      printf ("    Total memory: %zu\n", v);
 
       v = acc_get_property (i, type, acc_property_free_memory);
-      printf ("    Free memory: %zd\n", v);
+      printf ("    Free memory: %zu\n", v);
 
       s = acc_get_property_string (i, type, acc_property_name);
       printf ("    Name: %s\n", s);