ROCm / hipfort

Fortran interfaces for ROCm libraries
https://rocm.docs.amd.com/projects/hipfort/en/latest/
Other
66 stars 34 forks source link

Configuration fails when trying to compile HIPFORT with a CUDA backend #154

Open drtpotter opened 3 months ago

drtpotter commented 3 months ago

Problem Description

I need to ensure that Hipfort works with an nvidia backend. However when I try to install hipfort-6.0.2 the CMAKE configuration fails when I set HIP_PLATFORM="nvidia".

I have an RTX 3060 and CUDA 12.4 installed via package manager and everything seems ok with the NVIDIA software stack.

Operating System

Ubuntu 22.04.4 LTS (Jammy Jellyfish)

CPU

AMD Ryzen 7 6800H

GPU

RTX 3060

ROCm Version

ROCm 6.0.2

ROCm Component

hipfort

Steps to Reproduce

  1. Install NVIDIA driver (Driver 550 installed)
  2. Install rocm 6.0.2 using amdgpu-install
  3. Install the hip-runtime-nvidia package (CUDA 12.4 installed, and I have an RTX 3060 with working drivers)
  4. Uninstall hipfort-dev using the package manager
  5. Download and unpack hipfort-rocm-6.0.2
  6. Change directory to unpacked sources
  7. Make a build directory

Run the following script from the build directory

FLAGS="-O2 -g -free -cpp -fPIC -fmax-errors=5 -fno-underscoring"

export HIP_PLATFORM="nvidia"

CFLAGS="--offload-arch=sm_86 -lcublas -lcusolver -lcufft"

cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DHIPFORT_COMPILER=$(which gfortran) -DCMAKE_Fortran_FLAGS="${FLAGS}" -DCMAKE_C_COMPILER=$(which gcc) -DCMAKE_CXX_COMPILER=$(which g++) -DCMAKE_Fortran_COMPILER=$(which gfortran)  .. 

I then get numerous configuration errors to say that another target already exists.

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)

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

No response

Additional Information

Environment variables

HIP_PLATFORM="nvidia"

cgmb commented 3 months ago

Hi @drtpotter, thanks for the report.

I think the issue is that the hipFORT build process is broken when hipconfig is set to the NVIDIA platform. I haven't used the hipFORT NVIDIA backend myself (yet), but my understanding is that when you build hipFORT, it actually builds for both the AMD and NVIDIA platforms (even when the hipconfig platform is amd).

At the very least, we could detect this situation and print a useful error message. I think that would be a useful improvement for the hipfort build scripts. Although, it would be better if hipfort could build with hipconfig in either mode. I think that should be possible.

For now, I believe that you need to specify the platform as NVIDIA when building projects that use hipFORT rather than when you're building hipFORT itself.

drtpotter commented 3 months ago

Hi Cory,

Yes that's quite correct! Could we please add a sentence to the documentation to say that you don't have to build hipfort this way in order to use the NVIDIA backend. It would save a bit of time for other folks.

Furthermore, while using CMAKE I found that specifying the HIP language in a project description seems to make compilation very unfriendly to an NVIDIA backend. In such cases I removed the HIP language, set the environment variable CXX to hipcc, HIP_PLATFORM to nvidia, and appended "-lcudart" to CMAKE_EXE_LINKER_FLAGS, like this.

if (DEFINED ENV{HIP_PLATFORM})
    if ($ENV{HIP_PLATFORM} STREQUAL "nvidia")
        message("Setting variables for nvidia")
        set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lcudart")  
    endif()
endif()