This is a follow up to my previous commit - now trying more
seriously using the real HIP (not some own wrapper) with Nvidia.

Well, that failed first due to some deprecation warning, which
could be silenced. And then due to errors which seem to be bugs
in the HIP implementation for Nvidia/CUDA.

In any case, with the attached changes, this testcase now PASS
when I use the HIP header files from ROCm 6.4.0 (just copied
/opt/rocm/include from the AMD GPU system to my Nvidia GPU
system). Thus, in principle, this test now works.

I guess, the more likely actual testing will either skip the
test completely or use the HIP-header-not-available fallback,
which is fine as well.
(The tests use different file names + #include such that
the test filename tells you which variant worked and which
was skipped.)

Committed asr16-115-g8ef0518bce489c Tobias PS: The affected testcases are (deprecation warning, only) libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c and (work around required in addition) testsuite/libgomp.c/interop-hipblas-nvidia-full.c
commit 8ef0518bce489c4c0c252a0e0c44193c5f7cf777
Author: Tobias Burnus <tbur...@baylibre.com>
Date:   Thu Apr 24 18:26:30 2025 +0200

    libgomp/testsuite: Fix hip_header_nvidia check, add workaround to test
    
    This is all about using the AMD's HIP header files with
    __HIP_PLATFORM_NVIDIA__ defined, i.e. HIP with Nvidia/CUDA; in that case,
    HIP is a thin layer on top of CUDA.
    
    First, the check_effective_target_gomp_hip_header_nvidia check failed;
    to fix it, -Wno-deprecated-declarations was added - and likewise to the
    two affected testcases that actually used the HIP headers on Nvidia.
    
    Doing so, the HIP tested was successful but the HIP-BLAS one showed two
    issues:
    
    * One seems to be related to include search paths as the HIP header uses
      #include "library_types.h" to include that CUDA header. Seemingly, it
      tried to included (again) the HIP header hip/library_types.h, not the
      CUDA one. I guess, some tweaking of -isystem vs. -I could have
      prevented this, but the simpler workaround was to just explicitly
      include the CUDA one before the HIP header files.
    
    * Once done, everything compiled but linking failed as the association
      between three HIP-BLAS functions and their CUDA-BLAS ones did not
      work. Solution: Just add three #define for mapping them.
    
    libgomp/ChangeLog:
    
            * testsuite/lib/libgomp.exp
            (check_effective_target_gomp_hip_header_nvidia): Compile with
            "-Wno-deprecated-declarations".
            * testsuite/libgomp.c/interop-hip-nvidia-full.c: Likewise.
            * testsuite/libgomp.c/interop-hipblas-nvidia-full.c: Likewise.
            * testsuite/libgomp.c/interop-hipblas.h: Add workarounds
            when using the HIP headers with __HIP_PLATFORM_NVIDIA__.
---
 libgomp/testsuite/lib/libgomp.exp                         |  2 +-
 libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c     |  2 +-
 libgomp/testsuite/libgomp.c/interop-hipblas-nvidia-full.c |  2 +-
 libgomp/testsuite/libgomp.c/interop-hipblas.h             | 14 +++++++++++++-
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index a057394ca13..54f2f708b1b 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -664,21 +664,21 @@ int main() {
 proc check_effective_target_gomp_hip_header_nvidia { } {
     return [check_no_compiler_messages gomp_hip_header_nvidia assembly {
 #define __HIP_PLATFORM_NVIDIA__
 #include <hip/hip_runtime_api.h>
 int main() {
     hipDevice_t dev;
     hipError_t r = hipDeviceGet (&dev, 0);
     if (r != hipSuccess)
 	return 1;
     return 0;
-} }]
+} } "-Wno-deprecated-declarations"]
 }
 
 # Return 1 if the Fortran hipfort module is available (no link check)
 
 proc check_effective_target_gomp_hipfort_module { } {
     return [check_no_compiler_messages gomp_hipfort_module assembly {
 ! Fortran
 use hipfort
 implicit none
 integer(kind(hipSuccess)) :: r
diff --git a/libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c b/libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c
index 324504feb22..79af47dc076 100644
--- a/libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c
+++ b/libgomp/testsuite/libgomp.c/interop-hip-nvidia-full.c
@@ -1,8 +1,8 @@
 /* { dg-require-effective-target openacc_cudart } */
 /* { dg-require-effective-target openacc_cuda } */
 /* { dg-require-effective-target gomp_hip_header_nvidia } */
-/* { dg-additional-options "-lcuda -lcudart" } */
+/* { dg-additional-options "-lcuda -lcudart -Wno-deprecated-declarations" } */
 
 #define __HIP_PLATFORM_NVIDIA__ 1
 
 #include "interop-hip.h"
diff --git a/libgomp/testsuite/libgomp.c/interop-hipblas-nvidia-full.c b/libgomp/testsuite/libgomp.c/interop-hipblas-nvidia-full.c
index c195d2486f6..ed428c6c760 100644
--- a/libgomp/testsuite/libgomp.c/interop-hipblas-nvidia-full.c
+++ b/libgomp/testsuite/libgomp.c/interop-hipblas-nvidia-full.c
@@ -1,7 +1,7 @@
 /* { dg-require-effective-target openacc_cublas } */
 /* { dg-require-effective-target gomp_hip_header_nvidia } */
-/* { dg-additional-options "-lcublas" } */
+/* { dg-additional-options "-lcublas -Wno-deprecated-declarations" } */
 
 #define __HIP_PLATFORM_NVIDIA__ 1
 
 #include "interop-hipblas.h"
diff --git a/libgomp/testsuite/libgomp.c/interop-hipblas.h b/libgomp/testsuite/libgomp.c/interop-hipblas.h
index 11cb4d28030..d7cb174b9e1 100644
--- a/libgomp/testsuite/libgomp.c/interop-hipblas.h
+++ b/libgomp/testsuite/libgomp.c/interop-hipblas.h
@@ -17,21 +17,33 @@ Based on the interop example in OpenMP's example document  */
 #if defined(__HIP_PLATFORM_AMD__) && defined(__HIP_PLATFORM_NVIDIA__)
   #error "Either __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__ must be defined"
 #endif
 
 
 #include <assert.h>
 #include <omp.h>
 #include "../libgomp.c-c++-common/on_device_arch.h"
 
 
-#if __has_include(<hipblas/hipblas.h>) && !defined(USE_HIP_FALLBACK_HEADER)
+#if __has_include(<hipblas/hipblas.h>) && (__has_include(<library_types.h>) || !defined(__HIP_PLATFORM_NVIDIA__)) && !defined(USE_HIP_FALLBACK_HEADER)
+  #ifdef __HIP_PLATFORM_NVIDIA__
+    /* There seems to be an issue with hip/library_types.h including
+       CUDA's "library_types.h". Include CUDA's one explicitly here.
+       Could possibly worked around by using -isystem vs. -I.  */
+    #include <library_types.h>
+
+    /* For some reasons, the following symbols do not seem to get
+       mapped from HIP to CUDA, causing link errors.  */
+    #define hipblasSetStream cublasSetStream_v2
+    #define hipblasDaxpy cublasDaxpy_v2
+    #define hipblasCreate cublasCreate_v2
+  #endif
   #include <hipblas/hipblas.h>
 
 #elif defined(__HIP_PLATFORM_AMD__)
   /* Add a poor man's fallback declaration.  */
   #if !defined(USE_HIP_FALLBACK_HEADER)
     #warning "Using fallback declaration for <hipblas/hipblas.h> for __HIP_PLATFORM_AMD__"
   #endif
 
   typedef enum
   {

Reply via email to