public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite
@ 2021-05-26 12:06 Jakub Jelinek
  2021-05-26 17:40 ` Tobias Burnus
  2023-05-04  7:54 ` libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite) Thomas Schwinge
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Jelinek @ 2021-05-26 12:06 UTC (permalink / raw)
  To: Thomas Schwinge, Tobias Burnus; +Cc: gcc-patches

Hi!

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.

Tested on x86_64-linux with nvptx offloading --without-cuda-driver where it
fixes many FAILs, but I don't have full cuda installed to test whether it
doesn't disable any tests even when cuda is available.

2021-05-26  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.

--- libgomp/testsuite/lib/libgomp.exp.jj	2021-05-25 13:43:02.800121273 +0200
+++ libgomp/testsuite/lib/libgomp.exp	2021-05-26 12:18:56.562556244 +0200
@@ -479,3 +479,56 @@ proc check_effective_target_openacc_rade
     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" ]
+}
--- libgomp/testsuite/libgomp.oacc-fortran/host_data-4.f90.jj	2020-01-15 11:05:22.016099296 +0100
+++ libgomp/testsuite/libgomp.oacc-fortran/host_data-4.f90	2021-05-26 12:30:46.839676386 +0200
@@ -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
--- libgomp/testsuite/libgomp.oacc-fortran/host_data-2.f90.jj	2020-01-15 11:05:22.016099296 +0100
+++ libgomp/testsuite/libgomp.oacc-fortran/host_data-2.f90	2021-05-26 12:30:46.840676372 +0200
@@ -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
--- libgomp/testsuite/libgomp.oacc-fortran/host_data-3.f.jj	2020-01-15 11:05:22.016099296 +0100
+++ libgomp/testsuite/libgomp.oacc-fortran/host_data-3.f	2021-05-26 12:30:46.840676372 +0200
@@ -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"
 
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-70.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-70.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-90.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-90.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-75.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-75.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c.jj	2020-01-15 11:05:22.006099448 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c.jj	2020-01-15 11:05:22.005099463 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-69.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-69.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-74.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-74.c	2021-05-26 12:30:46.840676372 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c.jj	2020-01-15 11:05:22.005099463 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-81.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-81.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c.jj	2020-01-15 11:05:22.005099463 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-72.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-72.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c.jj	2020-01-15 11:05:22.004099478 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c	2021-05-26 12:30:46.841676358 +0200
@@ -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
 
--- libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c.jj	2020-01-15 11:05:22.005099463 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/pr87835.c.jj	2020-01-15 11:05:22.012099357 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/pr87835.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-82.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-82.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-73.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-73.c	2021-05-26 12:30:46.841676358 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-83.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-83.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-78.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-78.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-76.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-76.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c.jj	2020-01-15 11:05:22.010099387 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c.jj	2020-02-08 21:30:00.156978896 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c.jj	2020-01-15 11:05:22.009099402 +0100
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c	2021-05-26 12:30:46.842676343 +0200
@@ -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>

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite
  2021-05-26 12:06 [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite Jakub Jelinek
@ 2021-05-26 17:40 ` Tobias Burnus
  2023-05-04  7:54 ` libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite) Thomas Schwinge
  1 sibling, 0 replies; 4+ messages in thread
From: Tobias Burnus @ 2021-05-26 17:40 UTC (permalink / raw)
  To: Jakub Jelinek, Thomas Schwinge; +Cc: gcc-patches

On 26.05.21 14:06, Jakub Jelinek wrote:
> 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. [...]
> The following patch adds 3 new effective targets and uses them in tests that
> needs those.
>
> Tested on x86_64-linux with nvptx offloading --without-cuda-driver where it
> fixes many FAILs, but I don't have full cuda installed to test whether it
> doesn't disable any tests even when cuda is available.

I tested it with ppc64le-linux and nvptx offloading and it did work as
expected: all three new effective-target checks run successfully and all
modified testcases link and run. (Albeit lib-74.c, lib-78.c, and
lib-81.c do fail at execution time, but that's a different issue.).

Hence, looks good to me.

Thanks,

Tobias

> 2021-05-26  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.
>
> --- libgomp/testsuite/lib/libgomp.exp.jj      2021-05-25 13:43:02.800121273 +0200
> +++ libgomp/testsuite/lib/libgomp.exp 2021-05-26 12:18:56.562556244 +0200
> @@ -479,3 +479,56 @@ proc check_effective_target_openacc_rade
>       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" ]
> +}
> --- libgomp/testsuite/libgomp.oacc-fortran/host_data-4.f90.jj 2020-01-15 11:05:22.016099296 +0100
> +++ libgomp/testsuite/libgomp.oacc-fortran/host_data-4.f90    2021-05-26 12:30:46.839676386 +0200
> @@ -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
> --- libgomp/testsuite/libgomp.oacc-fortran/host_data-2.f90.jj 2020-01-15 11:05:22.016099296 +0100
> +++ libgomp/testsuite/libgomp.oacc-fortran/host_data-2.f90    2021-05-26 12:30:46.840676372 +0200
> @@ -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
> --- libgomp/testsuite/libgomp.oacc-fortran/host_data-3.f.jj   2020-01-15 11:05:22.016099296 +0100
> +++ libgomp/testsuite/libgomp.oacc-fortran/host_data-3.f      2021-05-26 12:30:46.840676372 +0200
> @@ -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"
>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-91.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-70.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-70.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-90.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-90.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-75.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-75.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c.jj      2020-01-15 11:05:22.006099448 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c 2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c.jj        2020-01-15 11:05:22.005099463 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-1.c   2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-69.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-69.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-74.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-74.c      2021-05-26 12:30:46.840676372 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c.jj        2020-01-15 11:05:22.005099463 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-2.c   2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-81.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-81.c      2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c.jj        2020-01-15 11:05:22.005099463 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-3.c   2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-72.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-72.c      2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c      2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c.jj      2020-01-15 11:05:22.004099478 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c 2021-05-26 12:30:46.841676358 +0200
> @@ -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
>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c.jj        2020-01-15 11:05:22.005099463 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/context-4.c   2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/pr87835.c.jj  2020-01-15 11:05:22.012099357 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/pr87835.c     2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-82.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-82.c      2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-73.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-73.c      2021-05-26 12:30:46.841676358 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-83.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-83.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-78.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-78.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-76.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-76.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c.jj   2020-01-15 11:05:22.010099387 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c.jj   2020-02-08 21:30:00.156978896 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property-nvptx.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c.jj   2020-01-15 11:05:22.009099402 +0100
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c      2021-05-26 12:30:46.842676343 +0200
> @@ -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>
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite)
  2021-05-26 12:06 [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite Jakub Jelinek
  2021-05-26 17:40 ` Tobias Burnus
@ 2023-05-04  7:54 ` Thomas Schwinge
  2023-05-04  8:00   ` Jakub Jelinek
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Schwinge @ 2023-05-04  7:54 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Tobias Burnus

[-- Attachment #1: Type: text/plain, Size: 2241 bytes --]

Hi!

On 2021-05-26T14:06:53+0200, Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> When gcc is configured for nvptx offloading [...]
> 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 [...]

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

> --- libgomp/testsuite/lib/libgomp.exp.jj      2021-05-25 13:43:02.800121273 +0200
> +++ libgomp/testsuite/lib/libgomp.exp 2021-05-26 12:18:56.562556244 +0200

> +# 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>
> +[...]
> +} } "-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>
> +[...]
> +} } "-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>
> +[...]
> +} } "-lcuda -lcudart" ]
> +}

OK to push the attached
"libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes'"?


This does not adjust the 'libstdcxx_includes' usage in libitm and libvtv
testsuites -- maybe those should also get 'lang_include_flags' ported
(separately)?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-libgomp-C-testsuite-Use-lang_include_flags-instead-o.patch --]
[-- Type: text/x-diff, Size: 5618 bytes --]

From 9bb4ffee6932ee5f917344535026f75c3eadc093 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 4 May 2023 09:07:35 +0200
Subject: [PATCH] libgomp C++ testsuite: Use 'lang_include_flags' instead of
 'libstdcxx_includes'

With nvptx offloading configured, and supported, and CUDA available:

    $ make check-target-libgomp RUNTESTFLAGS="--all c.exp=context-1.c c++.exp=context-1.c"
    [...]
    Running [...]/libgomp.oacc-c/c.exp ...
    PASS: libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  (test for excess errors)
    PASS: libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  execution test
    PASS: libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  (test for excess errors)
    PASS: libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  execution test
    UNSUPPORTED: libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O2
    Running [...]/libgomp.oacc-c++/c++.exp ...
    PASS: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  (test for excess errors)
    PASS: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  execution test
    PASS: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  (test for excess errors)
    PASS: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  execution test
    UNSUPPORTED: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O2
    [...]

..., but for 'c++.exp=context-1.c' alone, we currently get all-UNSUPPORTED:

    $ make check-target-libgomp RUNTESTFLAGS_="--all c++.exp=context-1.c"
    [...]
    Running [...]/libgomp.oacc-c++/c++.exp ...
    UNSUPPORTED: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0
    UNSUPPORTED: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2
    UNSUPPORTED: libgomp.oacc-c++/../libgomp.oacc-c-c++-common/context-1.c -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O2
    [...]

That is, if 'c.exp' executes first, it does successfully evaluate
'dg-require-effective-target openacc_cublas' -- and does cache this result (so
it isn't reevaluated for 'c++.exp').  However, for 'c++.exp' alone (that is,
without the 'c.exp' result cached), we run into:

    spawn -ignore SIGHUP [xgcc] [...] -x c++ openacc_cublas2311907.c [...]
    In file included from /usr/include/cuda_fp16.h:3673,
                     from /usr/include/cublas_api.h:75,
                     from /usr/include/cublas_v2.h:65,
                     from openacc_cublas2311907.c:3:
    /usr/include/cuda_fp16.hpp:67:10: fatal error: utility: No such file or directory

We're missing include paths to C++/libstdc++ build-tree headers.

Fix this by using the mechanism introduced for Fortran in
r212268 (commit f707da16f714f7fe5a42391748212c84dfec639b) re
"libgomp.fortran/fortran.exp - add -fintrinsic-modules-path ${blddir}".

	libgomp/
	* testsuite/libgomp.c++/c++.exp: Use 'lang_include_flags' instead
	of 'libstdcxx_includes'.
	* testsuite/libgomp.oacc-c++/c++.exp: Likewise.
---
 libgomp/testsuite/libgomp.c++/c++.exp      | 7 +++----
 libgomp/testsuite/libgomp.oacc-c++/c++.exp | 7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
index f4884e2ffa7..5b9a5924ff3 100644
--- a/libgomp/testsuite/libgomp.c++/c++.exp
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -66,13 +66,12 @@ if { $lang_test_file_found } {
 
     set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
     if { [file exists $flags_file] } {
-	set libstdcxx_includes [exec sh $flags_file --build-includes]
-    } else {
-	set libstdcxx_includes ""
+	set lang_source_re {^.*\.[cC]$}
+	set lang_include_flags [exec sh $flags_file --build-includes]
     }
 
     # Main loop.
-    dg-runtest $tests "" "$libstdcxx_includes $DEFAULT_CFLAGS"
+    dg-runtest $tests "" $DEFAULT_CFLAGS
 }
 
 # See above.
diff --git a/libgomp/testsuite/libgomp.oacc-c++/c++.exp b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 42e0395f9a5..0b235ba47f3 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -72,9 +72,8 @@ if { $lang_test_file_found } {
 
     set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
     if { [file exists $flags_file] } {
-	set libstdcxx_includes [exec sh $flags_file --build-includes]
-    } else {
-	set libstdcxx_includes ""
+	set lang_source_re {^.*\.[cC]$}
+	set lang_include_flags [exec sh $flags_file --build-includes]
     }
 
     # Test with all available offload targets, and with offloading disabled.
@@ -147,7 +146,7 @@ if { $lang_test_file_found } {
 	    }
 	}
 
-	gcc-dg-runtest $tests "$tagopt" "$libstdcxx_includes"
+	gcc-dg-runtest $tests "$tagopt" ""
     }
     unset offload_target
 } else {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite)
  2023-05-04  7:54 ` libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite) Thomas Schwinge
@ 2023-05-04  8:00   ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-05-04  8:00 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: gcc-patches, Tobias Burnus

On Thu, May 04, 2023 at 09:54:03AM +0200, Thomas Schwinge wrote:
> 	libgomp/
> 	* testsuite/libgomp.c++/c++.exp: Use 'lang_include_flags' instead
> 	of 'libstdcxx_includes'.
> 	* testsuite/libgomp.oacc-c++/c++.exp: Likewise.

Ok, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-04  8:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26 12:06 [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite Jakub Jelinek
2021-05-26 17:40 ` Tobias Burnus
2023-05-04  7:54 ` libgomp C++ testsuite: Use 'lang_include_flags' instead of 'libstdcxx_includes' (was: [PATCH] libgomp: Add openacc_{cuda,cublas,cudart} effective targets and use them in openacc testsuite) Thomas Schwinge
2023-05-04  8:00   ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).