]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc...
authorJakub Jelinek <jakub@redhat.com>
Thu, 27 May 2021 20:44:36 +0000 (22:44 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 27 May 2021 20:44:36 +0000 (22:44 +0200)
When gcc is configured for nvptx offloading with --without-cuda-driver
and full CUDA isn't installed, many libgomp.oacc-*/* tests fail,
some of them because cuda.h header can't be found, others because
the tests can't be linked against -lcuda, -lcudart or -lcublas.
I usually only have akmod-nvidia and xorg-x11-drv-nvidia-cuda rpms
installed, so libcuda.so.1 can be dlopened and the offloading works,
but linking against those libraries isn't possible nor are the
headers around (for the plugin itself there is the fallback
libgomp/plugin/cuda/cuda.h).

The following patch adds 3 new effective targets and uses them in tests that
needs those.

2021-05-27  Jakub Jelinek  <jakub@redhat.com>

* testsuite/lib/libgomp.exp (check_effective_target_openacc_cuda,
check_effective_target_openacc_cublas,
check_effective_target_openacc_cudart): New.
* testsuite/libgomp.oacc-fortran/host_data-4.f90: Require effective
target openacc_cublas.
* testsuite/libgomp.oacc-fortran/host_data-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/host_data-3.f: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-91.c: Require effective
target openacc_cuda.
* testsuite/libgomp.oacc-c-c++-common/lib-70.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-90.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-75.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-69.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-74.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-81.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-72.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-85.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/pr87835.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-73.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-83.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-78.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-76.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-84.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-79.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/host_data-1.c: Require effective
targets openacc_cublas and openacc_cudart.
* testsuite/libgomp.oacc-c-c++-common/context-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-3.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/context-4.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c:
Require effective target openacc_cudart.
* testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c: Add -DUSE_CUDA_H
for effective target openacc_cuda and add && defined USE_CUDA_H to
preprocessor conditionals.  Guard -lcuda also on openacc_cuda
effective target.

28 files changed:
libgomp/testsuite/lib/libgomp.exp
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c
libgomp/testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c
libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c
libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-69.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-70.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-72.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-73.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-74.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-75.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-76.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-78.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-81.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-82.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-83.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-90.c
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c
libgomp/testsuite/libgomp.oacc-c-c++-common/pr87835.c
libgomp/testsuite/libgomp.oacc-fortran/host_data-2.f90
libgomp/testsuite/libgomp.oacc-fortran/host_data-3.f
libgomp/testsuite/libgomp.oacc-fortran/host_data-4.f90

index 089c2bba9fc3e60dfbf2705a1dc4d7c40fe6a762..0f4eb6fd4ff2df504a3ea510c2fbe77f4c6b8c0d 100644 (file)
@@ -479,3 +479,56 @@ proc check_effective_target_openacc_radeon_accel_selected { } {
     return 0;
 }
 
+# Return 1 if cuda.h and -lcuda are available.
+
+proc check_effective_target_openacc_cuda { } {
+    return [check_no_compiler_messages openacc_cuda executable {
+#include <cuda.h>
+int main() {
+    CUdevice dev;
+    CUresult r = cuDeviceGet (&dev, 0);
+    if (r != CUDA_SUCCESS)
+       return 1;
+    return 0;
+} } "-lcuda" ]
+}
+
+# Return 1 if cublas_v2.h and -lcublas are available.
+
+proc check_effective_target_openacc_cublas { } {
+    return [check_no_compiler_messages openacc_cublas executable {
+#include <cuda.h>
+#include <cublas_v2.h>
+int main() {
+    cublasStatus_t s;
+    cublasHandle_t h;
+    CUdevice dev;
+    CUresult r = cuDeviceGet (&dev, 0);
+    if (r != CUDA_SUCCESS)
+       return 1;
+    s = cublasCreate (&h);
+    if (s != CUBLAS_STATUS_SUCCESS)
+       return 1;
+    return 0;
+} } "-lcuda -lcublas" ]
+}
+
+# Return 1 if cuda_runtime_api.h and -lcudart are available.
+
+proc check_effective_target_openacc_cudart { } {
+    return [check_no_compiler_messages openacc_cudart executable {
+#include <cuda.h>
+#include <cuda_runtime_api.h>
+int main() {
+    cudaError_t e;
+    int devn;
+    CUdevice dev;
+    CUresult r = cuDeviceGet (&dev, 0);
+    if (r != CUDA_SUCCESS)
+       return 1;
+    e = cudaGetDevice (&devn);
+    if (e != cudaSuccess)
+       return 1;
+    return 0;
+} } "-lcuda -lcudart" ]
+}
index 6334cfdd2f7310e0c813da9077900fb4b0388ac5..82239010d0f5e5ed436c7a95bda50ac43f788562 100644 (file)
@@ -4,6 +4,7 @@
 /* { dg-additional-sources acc_get_property-aux.c } */
 /* { dg-additional-options "-lcuda -lcudart" } */
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <openacc.h>
 #include <cuda.h>
index e780845a79300087df689df0e84a5085baa3817f..e91642c162e80b6b277da63dbfe2985ad026cc20 100644 (file)
@@ -1,9 +1,10 @@
 /* { dg-do run } */
-/* { dg-additional-options "-lcuda" { target openacc_nvidia_accel_selected } } */
+/* { dg-additional-options "-DUSE_CUDA_H" { target openacc_cuda } } */
+/* { dg-additional-options "-lcuda" { target { openacc_nvidia_accel_selected && openacc_cuda } } } */
 
 #include <openacc.h>
 #include <stdlib.h>
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
 #include "cuda.h"
 #endif
 
@@ -13,7 +14,7 @@
 int
 main (int argc, char **argv)
 {
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
     CUresult r;
     CUstream stream1;
 #endif
@@ -22,7 +23,7 @@ main (int argc, char **argv)
     int i;
     int nbytes;
 
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
     acc_init (acc_device_nvidia);
 #endif
 
@@ -216,7 +217,7 @@ main (int argc, char **argv)
     }
 
 
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
     r = cuStreamCreate (&stream1, CU_STREAM_NON_BLOCKING);
     if (r != CUDA_SUCCESS)
     {
@@ -650,7 +651,7 @@ main (int argc, char **argv)
     }
 
 
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
     r = cuStreamCreate (&stream1, CU_STREAM_NON_BLOCKING);
     if (r != CUDA_SUCCESS)
     {
@@ -902,7 +903,7 @@ main (int argc, char **argv)
             abort ();
     }
 
-#if defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia && defined USE_CUDA_H
     acc_shutdown (acc_device_nvidia);
 #endif
 
index 2e3b62ebbd26934b18a7f6ff942a99e2765344ba..3479fc7e549ac0e764fe9003824ab4f4c37da9a7 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
+/* { dg-require-effective-target openacc_cublas } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 6bdcfe7d42924e7c66ae7ef5cddb77700cada34b..db82b9097f6f1a8f6027e867173a2065cf6f0bfa 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
+/* { dg-require-effective-target openacc_cublas } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 8f14560ea8bcec77d03eada2f9b018828675ee95..b96f661cb7ca2d638a54eb02a3a872fb7fae2625 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
+/* { dg-require-effective-target openacc_cublas } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <stdio.h>
 #include <stdlib.h>
index b403a5cf5cb48d9096fe5fba249a6d0f0ce12f49..7bfd216136b6bbe1f6427c570f27faa1bd16523f 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
+/* { dg-require-effective-target openacc_cublas } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 21d2139af272cb0e4428a1bc698eeedb2fda5caa..20f7f049dcc426898b04d644be199be27800a0f1 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lm -lcuda -lcublas -lcudart -Wall -Wextra" } */
+/* { dg-require-effective-target openacc_cublas } */
+/* { dg-require-effective-target openacc_cudart } */
 
 #include <stdlib.h>
 #include <math.h>
index c10bebaab13687e711d5a0642f416c0c3e0ffa9b..00e0ca89f173f42e827359024c5025d59801959e 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <unistd.h>
index 912b266ec390430b151f3848b41ef09dd4aab87c..a2918c08a1248db56b7a5acf27ed2c839826ca0f 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index e383ba04d6995604d5e84e56758973b0a840ae59..99b62f1132a1a24e71e90a2d40e99ae8aebf2472 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <unistd.h>
index 43a8b7e6395731da7135399cf357a8a437a39bf7..5b4b3fdde31de37a6d07d85657765c46417c969f 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <unistd.h>
index 0efcf0d52229807eb50ad1bda4ff782c34485dc5..939f255f26c35cf2f70fc697acca66742f653a20 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 1942211874826e13875bbb8ae07f058f73c2400f..804ee3938ac3abdbabb076e503e3c4ee61487a5b 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <unistd.h>
index 11d9d621f87ff523d8016d2f3216a8921abc7f43..f9045266f1c4c363e03372e950ce6fa660ae3b87 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 4f58fb23cfe612ac026626cada638655ac0fd363..d8cba4db538a05ec592ddf4382924301e5368c51 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index b2e2687e4e765fd3c6fb7bb90d76007c7f09429c..b805d5f9b810afa4b9d19e870209c38fd2c41902 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index d5f18f00319cb07d0dc33a9189ce5faad2151177..958672c45e5f3db8d7678b8df20f277bdb4fdb91 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 9cf73b31964c315c3f2a67e90b9d7166ef69b287..a36f8e69a1868afb2228492f1b82a493d8cdb700 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index 51b7ee73b9cec71080653751a9ba08912dddf9d2..44ef1dbdc1760b82aad0b3288f2107c15aa37346 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdio.h>
 #include <stdlib.h>
index d793c743630044bcdcfbbcdbbbb9e670ff724e4f..c1ff76372fcbecb2bdc659f917d72b210c518214 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdlib.h>
 #include <unistd.h>
index 141c83b53dd69578823792c4f3a20f47772ee9b0..db250657ac5b7e3460ba812fb37759edefad8045 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdlib.h>
 #include <unistd.h>
index d17755bf3eb36e6f4d686681b89fc3916ba77084..5ca550585e9aff5c078c3dee4d3e188d7ea8e311 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <pthread.h>
 #include <stdio.h>
index 36fff089b83d856febf3f7f0cc638877d18f2e6a..d14226c026e433d4de8668eb4910d7de455fde89 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <stdlib.h>
 #include <unistd.h>
index 88c2c7763ccdef4e82a56ed11b52ae34b0dc31e8..e48f3074d58f0eac4913e359ce34c5506a0ad2aa 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda" } */
+/* { dg-require-effective-target openacc_cuda } */
 
 #include <openacc.h>
 #include <stdlib.h>
index ab70e4e8deae05f6338009653c5de99c84a0a131..fe1ae8ab50a557cc23b7040a4e06b569122deb87 100644 (file)
@@ -3,6 +3,7 @@
 
 ! { dg-do run { target openacc_nvidia_accel_selected } }
 ! { dg-additional-options "-lcublas -Wall -Wextra" }
+! { dg-require-effective-target openacc_cublas }
 
 program test
   implicit none
index 434c18c9889eaa7e788be45b9957a8cd7363665a..912bac68de750b0d8bb18d8a108bd620db196c05 100644 (file)
@@ -2,6 +2,7 @@
 
 ! { dg-do run { target openacc_nvidia_accel_selected } }
 ! { dg-additional-options "-lcublas -Wall -Wextra" }
+! { dg-require-effective-target openacc_cublas }
 
       include "cublas-fixed.h"
 
index e81a8b292c1d24a2ba03aae1c188dcf70f65ea38..0daba8bfcdcbf83ed5bbfa384743a59d71253179 100644 (file)
@@ -2,6 +2,7 @@
 
 ! { dg-do run { target openacc_nvidia_accel_selected } }
 ! { dg-additional-options "-lcublas -Wall -Wextra" }
+! { dg-require-effective-target openacc_cublas }
 
 module cublas
   interface