I'm experimenting with hip/ROCm
and I'm exploring the cross-platform capabilities.
While, I'm impressed with how welcoming is to port CUDA implementations on a AMD-gpu. I'm having a difficult time doing the opposite. More specifically, I'm failing to compile with CMake
and hipcc
(here a wrapper for the nvcc
compiler) to build hip-applications on a NVidia-platform.
For example, I wrote a simple Sgemm
example using the respective hipblas
library.
The following cmakelists.txt
manages to compile my example it without much hassle on a AMD-platform:
cmake_minimum_required(VERSION 3.16)
project(myPrototypes VERSION 1.0.0 LANGUAGES CXX)
# Define ROCM_PATH if not defined
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}")
set(CMAKE_MODULE_PATH "${ROCM_PATH}/hip/cmake")
# Find hip
find_package(HIP MODULE REQUIRED)
find_package(hipblas REQUIRED)
# Generate a compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set compilation standard
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Library:
add_library(hip_sampleLib SHARED hip_sampleLib.hip.cpp hip_sampleLib.h)
target_link_libraries(hip_sampleLib PRIVATE roc::hipblas)
# Executables:
add_executable(test_sampleLib.run test_sampleLib.cpp)
target_link_libraries(test_sampleLib.run hip_sampleLib)
However, on a NVidia platform I get:
$ cmake ..
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: $HOME/Depots/devlibrary/hip_library/build
$ make
[ 25%] Linking CXX shared library libhip_sampleLib.so
> nvcc fatal : "Don't know what to do with '/opt/rocm-5.5.0/lib/libhipblas.so.2.2'"
make[2]: *** [CMakeFiles/hip_sampleLib.dir/build.make:98: libhip_sampleLib.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/hip_sampleLib.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
For start, I made sure that my snippet can be compiled in the classical manner:
hipcc -o hipblas_sgemm.run hipblas_sgemm.cpp -I/opt/rocm/hipblas/include/ -L/opt/rocm/hipblas/lib -lhipblas
Then, I proceed to generate the compile_commands.json
from CMake. However nothing suspicious jumped from sight. Thus it seems to me that the nvcc
compiler is simply not able to deal with libhipblas.so
because to the suffix so.2.2. (I find this very odd.)
Therefore my questions are:
- Could this be a weakness of nvcc compiler?
If so, do anyone can suggest a work around with CMake?