diff --git a/CMakeLists.txt b/CMakeLists.txt index df76c6ebc..3865fae40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,14 +10,6 @@ set( CMAKE_CXX_STANDARD 14 ) # Without this line, it will add -std=gnu++14 instead, which has some issues. set( CMAKE_CXX_EXTENSIONS OFF ) -# Consider removing this in the future -# This should appear before the project command, because it does not use FORCE -if( WIN32 ) - set( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories" ) -else( ) - set( CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories" ) -endif( ) - # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE ) @@ -107,7 +99,7 @@ endif( ) # This finds the rocm-cmake project, and installs it if not found # rocm-cmake contains common cmake code for rocm projects to help setup and install set( PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern ) -find_package( ROCM CONFIG QUIET PATHS /opt/rocm ) +find_package( ROCM CONFIG QUIET PATHS ${ROCM_PATH} /opt/rocm ) if( NOT ROCM_FOUND ) set( rocm_cmake_tag "master" CACHE STRING "rocm-cmake tag to download" ) file( DOWNLOAD https://github.com/RadeonOpenCompute/rocm-cmake/archive/${rocm_cmake_tag}.zip @@ -139,6 +131,10 @@ include( ROCMInstallTargets ) include( ROCMPackageConfigHelpers ) include( ROCMInstallSymlinks ) +include (cmake/os-detection.cmake) +get_os_id(OS_ID) +message (STATUS "OS detected is ${OS_ID}") + # Versioning via rocm-cmake set ( VERSION_STRING "2.7.0" ) rocm_setup_version( VERSION ${VERSION_STRING} ) @@ -148,7 +144,7 @@ rocm_setup_version( VERSION ${VERSION_STRING} ) list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) # NOTE: workaround until hcc & hip cmake modules fixes symlink logic in their config files; remove when fixed -list( APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip ) +list( APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/hcc ${ROCM_PATH}/hip /opt/rocm/hcc /opt/rocm/hip ) option( BUILD_VERBOSE "Output additional build information" OFF ) @@ -162,12 +158,12 @@ set(CMAKE_INSTALL_LIBDIR "lib" CACHE INTERNAL "Installation directory for librar # Find HCC/HIP dependencies if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" ) - find_package( hcc REQUIRED CONFIG PATHS /opt/rocm ) - find_package( hip REQUIRED CONFIG PATHS /opt/rocm ) + find_package( hcc REQUIRED CONFIG PATHS ${ROCM_PATH} /opt/rocm ) + find_package( hip REQUIRED CONFIG PATHS ${ROCM_PATH} /opt/rocm ) endif( ) -find_package( rocblas REQUIRED CONFIG PATHS /opt/rocm ) +find_package( rocblas REQUIRED CONFIG PATHS ${ROCM_PATH} /opt/rocm ) include_directories( ${rocblas_INCLUDE_DIR} ) diff --git a/clients/CMakeLists.txt b/clients/CMakeLists.txt index bc6a72005..8c5a51112 100755 --- a/clients/CMakeLists.txt +++ b/clients/CMakeLists.txt @@ -5,14 +5,6 @@ # The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5 cmake_minimum_required( VERSION 3.5 ) -# Consider removing this in the future -# This should appear before the project command, because it does not use FORCE -if( WIN32 ) - set( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories" ) -else( ) - set( CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories" ) -endif( ) - # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE ) @@ -22,12 +14,13 @@ endif() # This project may compile dependencies for clients project( rocsolver-clients LANGUAGES CXX ) -if(EXISTS /etc/redhat-release) +if(OS_ID_rhel OR OS_ID_centos OR OS_ID_sles) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp=libgomp -pthread") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -pthread") endif() + set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -40,12 +33,12 @@ include( build-options ) set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) if( NOT TARGET rocsolver ) - find_package( rocsolver REQUIRED CONFIG PATHS /opt/rocm/rocsolver ) + find_package( rocsolver REQUIRED CONFIG PATHS ${ROCM_PATH}/rocsolver /opt/rocm/rocsolver ) endif( ) # Hip headers required of all clients; clients use hip to allocate device memory -list( APPEND CMAKE_PREFIX_PATH /opt/rocm ) -find_package( hip REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH} ) +list( APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} /opt/rocm ) +find_package( hip REQUIRED CONFIG PATHS ${ROCM_PATH} ) # Quietly look for CUDA, but if not found it's not an error # The presense of hip is not sufficient to determine if we want a rocm or cuda backend diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index a432d7330..c3c768bd6 100755 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -75,15 +75,19 @@ if( OS_ID_rhel OR OS_ID_centos OR OS_ID_sles) set( OPENMP_LIBRARY /usr/lib64/gcc/x86_64-suse-linux/7/libgomp.so ) endif() - if(EXISTS /opt/rocm/hcc/lib/clang/10.0.0/include/immintrin.h) + message(STATUS "RocmPath: ${ROCM_PATH}") + if(EXISTS "${ROCM_PATH}/hcc/lib/clang/10.0.0/include/immintrin.h") + set( CLANG_INCLUDE_DIR ${ROCM_PATH}/hcc/lib/clang/10.0.0/include ) + elseif (EXISTS "${ROCM_PATH}/hcc/lib/clang/9.0.0/include/immintrin.h") + set( CLANG_INCLUDE_DIR ${ROCM_PATH}/hcc/lib/clang/9.0.0/include ) + elseif (EXISTS "/opt/rocm/hcc/lib/clang/10.0.0/include/immintrin.h") set( CLANG_INCLUDE_DIR /opt/rocm/hcc/lib/clang/10.0.0/include ) - elseif (EXISTS /opt/rocm/hcc/lib/clang/9.0.0/include/immintrin.h) + elseif (EXISTS "/opt/rocm/hcc/lib/clang/9.0.0/include/immintrin.h") set( CLANG_INCLUDE_DIR /opt/rocm/hcc/lib/clang/9.0.0/include ) else() error("cannot find immintrin.h") endif() - # External header includes included as system files target_include_directories( rocsolver-bench SYSTEM PRIVATE @@ -112,7 +116,8 @@ else() target_link_libraries( rocsolver-bench PRIVATE ${Boost_LIBRARIES} cblas lapack roc::rocsolver ) endif() -target_link_libraries( rocsolver-bench PRIVATE /opt/rocm/rocblas/lib/librocblas.so ) #${ROCBLAS_LIBRARY}) +#target_link_libraries( rocsolver-bench PRIVATE /opt/rocm/rocblas/lib/librocblas.so ) #${ROCBLAS_LIBRARY}) +target_link_libraries( rocsolver-bench PRIVATE roc::rocblas ) #${ROCBLAS_LIBRARY}) get_target_property( HIPHCC_LOCATION hip::hip_hcc IMPORTED_LOCATION_RELEASE ) diff --git a/clients/gtest/CMakeLists.txt b/clients/gtest/CMakeLists.txt index c3fba74f5..ba302c2a6 100755 --- a/clients/gtest/CMakeLists.txt +++ b/clients/gtest/CMakeLists.txt @@ -91,9 +91,14 @@ if( OS_ID_rhel OR OS_ID_centos OR OS_ID_sles) set( OPENMP_LIBRARY /usr/lib64/gcc/x86_64-suse-linux/7/libgomp.so ) endif() - if(EXISTS /opt/rocm/hcc/lib/clang/10.0.0/include/immintrin.h) + message(STATUS "RocmPath: ${ROCM_PATH}") + if(EXISTS "${ROCM_PATH}/hcc/lib/clang/10.0.0/include/immintrin.h") + set( CLANG_INCLUDE_DIR ${ROCM_PATH}/hcc/lib/clang/10.0.0/include ) + elseif (EXISTS "${ROCM_PATH}/hcc/lib/clang/9.0.0/include/immintrin.h") + set( CLANG_INCLUDE_DIR ${ROCM_PATH}/hcc/lib/clang/9.0.0/include ) + elseif (EXISTS "/opt/rocm/hcc/lib/clang/10.0.0/include/immintrin.h") set( CLANG_INCLUDE_DIR /opt/rocm/hcc/lib/clang/10.0.0/include ) - elseif (EXISTS /opt/rocm/hcc/lib/clang/9.0.0/include/immintrin.h) + elseif (EXISTS "/opt/rocm/hcc/lib/clang/9.0.0/include/immintrin.h") set( CLANG_INCLUDE_DIR /opt/rocm/hcc/lib/clang/9.0.0/include ) else() error("cannot find immintrin.h") @@ -129,7 +134,8 @@ else() target_link_libraries( rocsolver-test PRIVATE ${GTEST_LIBRARIES} ${Boost_LIBRARIES} cblas lapack roc::rocsolver ) endif() -target_link_libraries( rocsolver-test PRIVATE /opt/rocm/rocblas/lib/librocblas.so ) #${ROCBLAS_LIBRARY}) +target_link_libraries( rocsolver-test PRIVATE roc::rocblas ) #${ROCBLAS_LIBRARY}) +#target_link_libraries( rocsolver-test PRIVATE /opt/rocm/rocblas/lib/librocblas.so ) #${ROCBLAS_LIBRARY}) get_target_property( HIPHCC_LOCATION hip::hip_hcc IMPORTED_LOCATION_RELEASE ) diff --git a/cmake/os-detection.cmake b/cmake/os-detection.cmake new file mode 100644 index 000000000..76a9d4dcd --- /dev/null +++ b/cmake/os-detection.cmake @@ -0,0 +1,31 @@ +# ######################################################################## +# Copyright 2019 Advanced Micro Devices, Inc. +# ######################################################################## + +function (get_os_id OS_ID) + set(_os_id "unknown") + + if (EXISTS "/etc/os-release") + read_key("ID" _os_id) + endif() + + if (_os_id STREQUAL "opensuse-leap") + set(_os_id "sles") + endif() + + set(${OS_ID} ${_os_id} PARENT_SCOPE) + set(${OS_ID}_${_os_id} TRUE PARENT_SCOPE) +endfunction() + + +function (read_key KEYVALUE OUTPUT) + #finds the line with the keyvalue + file (STRINGS /etc/os-release _keyvalue_line REGEX "^${KEYVALUE}=") + + #remove keyvalue= + string (REGEX REPLACE "^${KEYVALUE}=\"?(.*)" "\\1" _output "${_keyvalue_line}") + + #remove trailing quote + string (REGEX REPLACE "\"$" "" _output "${_output}") + set(${OUTPUT} ${_output} PARENT_SCOPE) +endfunction ()