ROCm / ROCm

AMD ROCm™ Software - GitHub Home

Home Page:https://rocm.docs.amd.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Issue]: OpenMP interop incorrectly reports runtime as `cuda` for AMD GPUs

Thyre opened this issue · comments

Problem Description

While building a test case while working around #2896, I've stumbled upon another issue with OpenMP interops.
Simply printing the output of omp_get_interop_[x] reveals that the runtime reports having cuda when an AMD GPU with ROCm is used. The reasons can probably be found in omp.h#L137 and here InterOPAPI.cpp#L224. Regardless of the GPU type, the struct is always initialized with CUDA as default and never overwritten (see InteropAPI.h#L28)

To reproduce, one can use this simple test case:

#include <omp.h>
#include <stdio.h>

const char* interop_int_to_string( const int interop_int )
{
    switch( interop_int )
    {
        case 1:
            return "cuda";
        case 2:
            return "cuda_driver";
        case 3:
            return "opencl";
        case 4:
            return "sycl";
        case 5:
            return "hip";
        case 6:
            return "level_zero";
        default:
            return "unknown";
    }
}

int main( int argc, char** argv )
{
    omp_interop_t iobj = omp_interop_none;
    #pragma omp interop init(targetsync: iobj)

    int err;
    int interop_int = omp_get_interop_int( iobj, omp_ipr_fr_id, &err );

    if( err )
    {
        fprintf( stderr, "omp_get_interop_int failed: %d\n", err );
        return -1;
    }

    printf( "omp_get_interop_int returned %s\n", interop_int_to_string( interop_int ) );

    const char* interop_vendor = omp_get_interop_str( iobj, omp_ipr_vendor_name, &err );
    if( err )
    {
        fprintf( stderr, "omp_get_interop_str failed: %d\n", err );
        return -1;
    }

    printf( "omp_get_interop_str returned %s\n", interop_vendor );

    const char* interop_fr_name = omp_get_interop_str( iobj, omp_ipr_fr_name, &err );
    if( err )
    {
        fprintf( stderr, "omp_get_interop_str failed: %d\n", err );
        return -1;
    }

    printf( "omp_get_interop_str returned %s\n", interop_fr_name );

    #pragma omp interop destroy(iobj)
    return 0;
}

Here's the output of different compilers:

ROCm 6.0.2:

$ amdclang -fopenmp --offload-arch=gfx1101 print_interop.c
$ ./a.out
omp_get_interop_int returned cuda
omp_get_interop_str returned cuda
omp_get_interop_str failed: -5

LLVM 17.0.6:

$ clang -fopenmp --offload-arch=gfx1101 print_interop.c --rocm-path=/opt/apps/software/ROCm/6.0.2/
$ ./a.out
omp_get_interop_int returned cuda
omp_get_interop_str returned cuda
omp_get_interop_str failed: -5

oneAPI 2024.0 (with Intel Arc iGPU):

$ icx -fiopenmp -fopenmp-targets=spir64 print_interop.c
$ ./a.out
omp_get_interop_int returned level_zero
omp_get_interop_str returned intel
omp_get_interop_str returned level_zero

NVHPC 24.1 (with NVIDIA GPU):

$ nvc -mp=gpu print_interop.c
"print_interop.c", line 28: error: invalid text in pragma
      #pragma omp interop init(targetsync: iobj)
                          ^

1 error detected in the compilation of "print_interop.c".

Operating System

Ubuntu 22.04.3 LTS

CPU

Intel Core i7-12700

GPU

AMD Radeon RX 7900 XT

ROCm Version

ROCm 6.0.0

ROCm Component

llvm-project

Steps to Reproduce

No response

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

Internal ticket has been created for investigation.

Working on it:
Will be resolved by llvm/llvm-project#88000