ROCm / HIP

HIP: C++ Heterogeneous-Compute Interface for Portability
https://rocmdocs.amd.com/projects/HIP/
MIT License
3.62k stars 521 forks source link

[problem] HIPCC works, HIP with CMake - doesnt #3145

Open HardMax71 opened 1 year ago

HardMax71 commented 1 year ago

Hi, i started using HIP recently and found out next problem (or bug, no idea):

  1. Installed HIP 4.5.0 for Ubuntu 22.04 as manual tells to do
  2. Called hipconfig --full Result:
    
    max@max-IdeaPad-L340-15IRH-Gaming:~/Desktop/HIP/samples/0_Intro/square$ hipconfig --full
    HIP version  : 4.4.21401-bedc5f61

== hipconfig HIP_PATH : /opt/rocm/hip ROCM_PATH : /opt/rocm HIP_COMPILER : clang HIP_PLATFORM : nvidia HIP_RUNTIME : rocclr CPP_CONFIG : -DHIP_PLATFORM_NVCC= -DHIP_PLATFORM_NVIDIA= -I/opt/rocm/hip/include -I/usr/local/cuda/include

== nvcc CUDA_PATH : /usr/local/cuda nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Mon_Oct_24_19:12:58_PDT_2022 Cuda compilation tools, release 12.0, V12.0.76 Build cuda_12.0.r12.0/compiler.31968024_0

=== Environment Variables PATH=/home/max/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/rocm/bin:/opt/rocm/bin:/usr/local/cuda/bin HIP_CLANG_PATH=/lib/llvm-14/bin/ HIP_PATH=/opt/rocm/hip HIP_PLATFORM=nvidia

== Linux Kernel Hostname : max-IdeaPad-L340-15IRH-Gaming Linux max-IdeaPad-L340-15IRH-Gaming 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy


3. Installed [examples](https://github.com/ROCm-Developer-Tools/HIP/tree/master/samples) 
4. Went to `0_Intro/square` -> `make` -> `./square.out`
Result:

max@max-IdeaPad-L340-15IRH-Gaming:~/Desktop/HIP/samples/0_Intro/square$ ./square.out info: running on device NVIDIA GeForce GTX 1650 info: allocate host mem ( 7.63 MB) info: allocate device mem ( 7.63 MB) info: copy Host2Device info: launch 'vector_square' kernel info: copy Device2Host info: check result PASSED!

5. Tried to regenerate makefile via `cmake .`. 
Result:

max@max-IdeaPad-L340-15IRH-Gaming:~/Desktop/HIP/samples/0_Intro/square$ cmake . CMake Error at CMakeLists.txt:48 (find_package): By not providing "Findhip.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "hip", but CMake did not find one.

Could not find a package configuration file provided by "hip" with any of the following names:

hipConfig.cmake
hip-config.cmake

Add the installation prefix of "hip" to CMAKE_PREFIX_PATH or set "hip_DIR" to a directory containing one of the above files. If "hip" provides a separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!


5. Followed [advice](https://github.com/ROCm-Developer-Tools/HIP/tree/master/samples/2_Cookbook/12_cmake_hip_add_executable#including-findhip-cmake-module-in-the-project), added `if (not defined ..)..` part.
Result:

<..copyright stuff..> project(square)

cmake_minimum_required(VERSION 3.10)

if(NOT DEFINED HIP_PATH) if(NOT DEFINED ENV{HIP_PATH}) set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed") else() set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed") endif() endif() set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})

if (NOT DEFINED ROCM_PATH ) set ( ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory." ) endif ()

Search for rocm in common locations

list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/hip ${ROCM_PATH})

create square.cpp

execute_process(COMMAND sh -c "${ROCM_PATH}/hip/bin/hipify-perl square.cu > square.cpp")

Find hip

set(CMAKE_MODULE_PATH "/opt/rocm/hip/cmake" ${CMAKE_MODULE_PATH}) find_package(hip REQUIRED)

Set compiler and linker

set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE}) set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})

Create the excutable

add_executable(square square.cpp)

Link with HIP

target_link_libraries(square hip::host)


Called it: 

max@max-IdeaPad-L340-15IRH-Gaming:~/Desktop/HIP/samples/0_Intro/square$ cmake . CMake Error at CMakeLists.txt:48 (find_package): By not providing "Findhip.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "hip", but CMake did not find one.

Could not find a package configuration file provided by "hip" with any of the following names:

hipConfig.cmake
hip-config.cmake

Add the installation prefix of "hip" to CMAKE_PREFIX_PATH or set "hip_DIR" to a directory containing one of the above files. If "hip" provides a separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred! See also "/home/max/Desktop/HIP/samples/0_Intro/square/CMakeFiles/CMakeOutput.log".


7. Removed cache files from CMake, wrote `hipcc square.cu -o square` and executed.

Result:

max@max-IdeaPad-L340-15IRH-Gaming:~/Desktop/HIP/samples/0_Intro/square$ ./square.out info: running on device NVIDIA GeForce GTX 1650 info: allocate host mem ( 7.63 MB) info: allocate device mem ( 7.63 MB) info: copy Host2Device info: launch 'vector_square' kernel info: copy Device2Host info: check result PASSED!



Yet, HIPCC works, and even Makefile +HIPCC, but CMake + HIPCC - do not. I tried complete deleting (everything, including CUDA & LLVM) and reinstalling to default positions, but it didn't help to solve the problem. 

Are there any other ways to explicitly tell CMake where to find HIP?
jatinx commented 1 year ago

Make sure that FindHIP.cmake exists in the directory, when you point CMAKE_MODULE_PATH to it.

wme7 commented 1 year ago

I have the same issue !

I just build HIP on a Nvidia platform following the instructions in ROCm/HIP. Currently, I'm working on CentOS 8, thus I'm using the package manager method by setting an /etc/yum.repos.d/rocm.repo.

Form there, I called:

sudo dnf install hip-runtime-nvidia hip-devel

and successfully installed the hipcc and hipconfig apps on /opt/rocm/bin.

I realized that I also need to export the following enviroment variables so that hipcc works as a mask for the nvcc compiler:

export HIP_COMPILER=nvcc
export HIP_PLATFORM=nvidia
export HIP_RUNTIME=cuda

For reference when I call hipconfig --full it ourputs:

HIP version  : 5.4.22801-aaa1e3d8

== hipconfig
HIP_PATH     : /opt/rocm-5.4.0
ROCM_PATH    : /opt/rocm
HIP_COMPILER : nvcc
HIP_PLATFORM : nvidia
HIP_RUNTIME  : cuda
CPP_CONFIG   :  -D__HIP_PLATFORM_NVCC__= -D__HIP_PLATFORM_NVIDIA__= -I/opt/rocm-5.4.0/include -I/usr/local/cuda/include

== nvcc
CUDA_PATH   : /usr/local/cuda
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

=== Environment Variables
PATH=/home/mdiaz/.pyenv/shims:/home/mdiaz/.pyenv/bin:/opt/rocm/bin:/usr/local/cuda-11.8/bin:/usr/lib64:/usr/local/bin:/home/mdiaz/miniconda3/bin:/home/mdiaz/miniconda3/condabin:/home/mdiaz/.pyenv/bin:/usr/local/cuda-11.8/bin:/usr/lib64:/usr/local/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/mdiaz/bin:/var/lib/snapd/snap/bin
LD_LIBRARY_PATH=/opt/rocm/lib:/opt/rocm/lib64:/usr/local/cuda-11.8/lib64:/usr/lib64:/usr/local/lib:/usr/local/cuda-11.8/lib64:/usr/lib64:/usr/local/lib:
HIP_PLATFORM=nvidia
HIP_RUNTIME=cuda
HIP_COMPILER=nvcc

== Linux Kernel
Hostname     : nbk206.cenaero.be
Linux nbk206.cenaero.be 4.18.0-448.el8.x86_64 #1 SMP Wed Jan 18 15:02:46 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOSStream
Description:    CentOS Stream release 8
Release:    8
Codename:   n/a

Until here, hipcc is able to compile directly any example as hipcc -o exename source.cpp.

Then I moved to test the HIP-samples using CMAKE, plus indicating my CMAKE_MODULE_PATH to my FindHIP.cmake. Here, I run out of luck, as I'm not able to get my targets correctly generated. Instead I get a output that reads:

-- The C compiler identification is GNU 8.5.0
-- The CXX compiler identification is GNU 8.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found HIP: /opt/rocm-5.4.0/hip (found version "5.4.22801-aaa1e3d8") 
-- Configuring done
CMake Error at CMakeLists.txt:19 (add_executable):
  Target "hip_vectorAdd.run" links to target "hip::device" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at CMakeLists.txt:23 (add_executable):
  Target "hip_saxpy.run" links to target "hip::device" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at CMakeLists.txt:27 (add_executable):
  Target "hip_matrixTranspose.run" links to target "hip::device" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Using CMake is fundamental to me, as I'm interested in building cross platform applications. Not having HIP well configured to do this is a big miss!

At this point, I suspect that something in my installation is missing. However, I have lost a lot of time trying to figure out. Thus I posse the issue to the developers for their help.

Best regards,

acxz commented 1 year ago

Related issue: https://github.com/ROCm-Developer-Tools/HIP/issues/527

wme7 commented 1 year ago

Hi everyone,

I can see that this still an issue for many new comers of HIP/ROCm.

UPDATE: I managed find a simple workaround on CMake (< 3.16) level that helps me compile Libs/Apps using hipcc on either __HIP_PLATFORM__ = amd / nvidia. However, it comes at the price of always relying on the platform-specific Libraries (i.e. using cuBlas and rocBlas on their specific platform).

I leave you here with an example of my strategy on this git-repo.

I also leave the links to the discussions with AMD-devs that led me to it here and there

DISCLAIMER: I currently use them to develop on LUMI and my own Nvidia-based workstation.

REMARK: I must advice that this strategy, although not perfect, works for me in order to use the lowest level features of CUDA and HIP for my current project (because I with to exploid the maximum capabilities of hardware). However, you with to avoid this pain and use C++ level features to access GPUs power with a reasonable output/effort; I need to stress that you better off by using Kokkos API.

happy coding ! -M

ppanchad-amd commented 3 months ago

@HardMax71 Can you please test with latest ROCm 6.0.2 (HIP 6.0.32831)? If resolved, please close ticket. Thanks!

HardMax71 commented 3 months ago

@ppanchad-amd i would like to, but currently i do not have any AMD GPU to test it :( I can close this issue too, but maybe someone else will test it? 🥺

ppanchad-amd commented 2 months ago

@wme7 Can you please test with latest ROCm 6.1.0 (HIP 6.1) to check if issue is resolved? Thanks!

wme7 commented 2 months ago

It would be great if this is resolved in HIP 6.1! I'll test later on the week because I need to clean and put up-to-date my CentOS system.

harkgill-amd commented 2 days ago

Hi @wme7, did you get a chance to test building with CMake out on ROCm 6.1.2? I was able to build the sample without any issues.

-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/rocm-6.1.2/share/hip/samples/0_Intro/square
wme7 commented 1 day ago

My apologies, I almost forgot ! ... but I can confirm that with ROCm 6.1.2 is working : )