Skip to content

Commit

Permalink
cmake update (ROCm#119)
Browse files Browse the repository at this point in the history
* fixed return value

* boost removed as it is not required

* deprecate hcc, cmake updated

* enabled c++14
  • Loading branch information
ntrost57 authored Jun 15, 2020
1 parent fc707c1 commit 4ac714f
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 127 deletions.
14 changes: 6 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else()
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories")
endif()

list( APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip )
list( APPEND CMAKE_PREFIX_PATH /opt/rocm/hip )

# CMake modules
list(APPEND CMAKE_MODULE_PATH
Expand All @@ -57,6 +57,11 @@ project(hipsparse LANGUAGES CXX Fortran)
# Force library install path to lib (CentOS 7 defaults to lib64)
set(CMAKE_INSTALL_LIBDIR "lib" CACHE INTERNAL "Installation directory for libraries" FORCE)

# Build flags
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Build options
option(BUILD_SHARED_LIBS "Build hipSPARSE as a shared library" ON)
option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF)
Expand All @@ -71,13 +76,6 @@ include(cmake/Dependencies.cmake)
rocm_setup_version(VERSION 1.7.1)
set(hipsparse_SOVERSION 0.1)

# Look for libamdhip64
find_library(
LIBAMDHIP64_LIBRARY
NAMES libamdhip64.so
HINTS "${CMAKE_PREFIX_PATH}/lib" )
message("amdhip64: ${LIBAMDHIP64_LIBRARY}")

# hipSPARSE library
add_subdirectory(library)

Expand Down
15 changes: 12 additions & 3 deletions clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT TARGET hipsparse)
find_package(hipsparse REQUIRED CONFIG PATHS /opt/rocm/hipsparse)
endif()

# Hip headers required of all clients; clients use hip to allocate device memory
find_package(HIP REQUIRED)
option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF)
option(BUILD_CLIENTS_SAMPLES "Build examples" ON)
endif()

# Build flags
set(CMAKE_CXX_STANDARD 11)
Expand All @@ -62,6 +62,15 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# If OpenMP is available, we can use it to speed up some tests
find_package(OpenMP QUIET)

if(OPENMP_FOUND)
if(NOT TARGET OpenMP::OpenMP_CXX)
# OpenMP cmake fix for cmake <= 3.9
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
endif()

if(BUILD_CLIENTS_SAMPLES)
add_subdirectory(samples)
endif()
Expand Down
54 changes: 20 additions & 34 deletions clients/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,17 @@ function(add_hipsparse_example EXAMPLE_SOURCE)
get_filename_component(EXAMPLE_TARGET ${EXAMPLE_SOURCE} NAME_WE)
add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCE} ${HIPSPARSE_CLIENTS_COMMON})

# hipSPARSE headers
target_include_directories(${EXAMPLE_TARGET}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${HIP_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/library/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
)
# Include common client headers
target_include_directories(${EXAMPLE_TARGET} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

# hipSPARSE library
if(NOT TARGET hipsparse)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${HIPSPARSE_LIBRARIES})
else()
target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::hipsparse)
endif()
# Linker dependencies
target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::hipsparse)

if(NOT BUILD_CUDA)
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE __HIP_PLATFORM_HCC__)
if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" )
target_link_libraries( ${EXAMPLE_TARGET} PRIVATE ${HIP_LIBRARIES} )
endif( )
if ( LIBAMDHIP64_LIBRARY )
target_include_directories(${EXAMPLE_TARGET} PRIVATE ${ROCM_PATH}/hip/include)
target_link_libraries( ${EXAMPLE_TARGET} PRIVATE hip::amdhip64 )
else ( )
target_include_directories(${EXAMPLE_TARGET} PRIVATE ${ROCM_PATH}/hsa/include)
get_target_property( HIP_HCC_LOCATION hip::hip_hcc IMPORTED_LOCATION_RELEASE )
target_link_libraries( ${EXAMPLE_TARGET} PRIVATE ${HIP_HCC_LOCATION} )
endif( )
target_link_libraries(${EXAMPLE_TARGET} PRIVATE hip::host)
else()
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE __HIP_PLATFORM_NVCC__)
target_include_directories(${EXAMPLE_TARGET} PRIVATE ${HIP_INCLUDE_DIRS})
target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${CUDA_LIBRARIES})
endif()

Expand All @@ -69,11 +49,17 @@ endfunction()
add_hipsparse_example(example_handle.cpp)
add_hipsparse_example(example_csrmv.cpp)
add_hipsparse_example(example_hybmv.cpp)
add_hipsparse_example(example_fortran_auxiliary.f90)
add_hipsparse_example(example_fortran_csrsv2.f90)
add_hipsparse_example(example_fortran_csric02.f90)
add_hipsparse_example(example_fortran_csrilu02.f90)
add_hipsparse_example(example_fortran_csrsm2.f90)
add_hipsparse_example(example_fortran_dotci.f90)
add_hipsparse_example(example_fortran_roti.f90)
add_hipsparse_example(example_fortran_spmv.f90)

# Fortran examples
if(TARGET hipsparse)
# Compile Fortran examples only if built directly with package
# else the Fortran module file is not generated
add_hipsparse_example(example_fortran_auxiliary.f90)
add_hipsparse_example(example_fortran_csrsv2.f90)
add_hipsparse_example(example_fortran_csric02.f90)
add_hipsparse_example(example_fortran_csrilu02.f90)
add_hipsparse_example(example_fortran_csrsm2.f90)
add_hipsparse_example(example_fortran_dotci.f90)
add_hipsparse_example(example_fortran_roti.f90)
add_hipsparse_example(example_fortran_spmv.f90)
endif()
48 changes: 11 additions & 37 deletions clients/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#
# ########################################################################

find_package(GTest REQUIRED)

# Download some test matrices
set(TEST_MATRICES
SNAP/amazon0312
Expand Down Expand Up @@ -128,9 +130,6 @@ foreach(i RANGE 0 ${len1})
endif()
endforeach()


find_package(GTest REQUIRED)

set(HIPSPARSE_TEST_SOURCES
hipsparse_gtest_main.cpp
test_axpyi.cpp
Expand Down Expand Up @@ -188,50 +187,25 @@ set(HIPSPARSE_CLIENTS_COMMON

add_executable(hipsparse-test ${HIPSPARSE_TEST_SOURCES} ${HIPSPARSE_CLIENTS_COMMON})

# Set GOOGLE_TEST definition
target_compile_definitions(hipsparse-test PRIVATE GOOGLE_TEST)

if(OPENMP_FOUND)
target_compile_options(hipsparse-test PRIVATE ${OpenMP_CXX_FLAGS})
endif()

target_include_directories(hipsparse-test
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)

target_include_directories(hipsparse-test
SYSTEM
PRIVATE
$<BUILD_INTERFACE:${GTEST_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${HIP_INCLUDE_DIRS}>
)

if(NOT TARGET hipsparse)
target_link_libraries(hipsparse-test PRIVATE ${HIPSPARSE_LIBRARIES})
else()
target_link_libraries(hipsparse-test PRIVATE roc::hipsparse)
endif()
# Internal common header
target_include_directories(hipsparse-test PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(hipsparse-test PRIVATE ${GTEST_BOTH_LIBRARIES} Threads::Threads)
# Target link libraries
target_link_libraries(hipsparse-test PRIVATE GTest::GTest roc::hipsparse)

# Add OpenMP if available
if(OPENMP_FOUND)
target_link_libraries(hipsparse-test PRIVATE ${OpenMP_CXX_FLAGS})
target_link_libraries(hipsparse-test PRIVATE OpenMP::OpenMP_CXX)
endif()

if(NOT BUILD_CUDA)
target_compile_definitions(hipsparse-test PRIVATE __HIP_PLATFORM_HCC__)
if ( LIBAMDHIP64_LIBRARY )
target_include_directories(hipsparse-test PRIVATE ${ROCM_PATH}/hip/include)
target_link_libraries( hipsparse-test PRIVATE hip::amdhip64 )
else ( )
target_include_directories(hipsparse-test PRIVATE ${ROCM_PATH}/hsa/include)
get_target_property( HIP_HCC_LOCATION hip::hip_hcc IMPORTED_LOCATION_RELEASE )
target_link_libraries( hipsparse-test PRIVATE ${HIP_HCC_LOCATION} )
endif( )
target_link_libraries(hipsparse-test PRIVATE hip::host)
else()
target_compile_definitions(hipsparse-test PRIVATE __HIP_PLATFORM_NVCC__)
target_include_directories(hipsparse-test PRIVATE ${HIP_INCLUDE_DIRS})
target_link_libraries(hipsparse-test PRIVATE ${CUDA_LIBRARIES})
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ else()
endif()

# ROCm cmake package
set(PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern)
find_package(ROCM QUIET CONFIG PATHS ${CMAKE_PREFIX_PATH})
if(NOT ROCM_FOUND)
set(PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern)
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
${PROJECT_EXTERN_DIR}/rocm-cmake-${rocm_cmake_tag}.zip STATUS status LOG log)
Expand Down
2 changes: 1 addition & 1 deletion deps/external-gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ message( STATUS "Configuring gtest external dependency" )
include( ExternalProject )

# set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>/package )
set( PREFIX_GTEST ${CMAKE_INSTALL_PREFIX} CACHE PATH "Location where boost should install, defaults to /usr/local" )
set( PREFIX_GTEST ${CMAKE_INSTALL_PREFIX} CACHE PATH "Location where gtest should install, defaults to /usr/local" )
set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=${PREFIX_GTEST} )
append_cmake_cli_arguments( gtest_cmake_args gtest_cmake_args )

Expand Down
2 changes: 0 additions & 2 deletions docker/dockerfile-build-nvidia-cuda
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ARG REPO_RADEON=repo.radeon.com
# Dependencies:
# * hcc-config.cmake: pkg-config
# * hipsparse-test: googletest
# * hipsparse-bench: libboost-program-options-dev
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends curl && \
curl -sL http://${REPO_RADEON}/rocm/apt/debian/rocm.gpg.key | apt-key add - && \
echo deb [arch=amd64] http://${REPO_RADEON}/rocm/apt/debian/ xenial main | tee /etc/apt/sources.list.d/rocm.list && \
Expand All @@ -24,7 +23,6 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
cmake \
pkg-config \
libnuma1 \
libboost-program-options-dev \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
1 change: 0 additions & 1 deletion docker/dockerfile-build-sles
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ RUN zypper -n --no-gpg-checks install \
python3-pip \
dpkg \
libcxxtools9 \
libboost_program_options1_66_0-devel \
libnuma1 \
rpm-build \
wget \
Expand Down
15 changes: 5 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ install_packages( )
local library_dependencies_fedora=( "make" "cmake" "gcc-c++" "libcxx-devel" "rpm-build" "numactl-libs" )
local library_dependencies_sles=( "make" "cmake" "gcc-c++" "libcxxtools9" "rpm-build" "pkg-config" "dpkg" )

local client_dependencies_ubuntu=( "libboost-program-options-dev" )
local client_dependencies_centos_6=( "gcc-gfortran" "boost-devel" )
local client_dependencies_centos_7=( "devtoolset-7-gcc-gfortran" "boost-devel" )
local client_dependencies_centos_8=( "gcc-gfortran" "boost-devel" )
local client_dependencies_fedora=( "gcc-gfortran" "boost-devel" )
local client_dependencies_sles=( "gcc-fortran" "libboost_program_options1_66_0-devel" )
local client_dependencies_centos_6=( "gcc-gfortran" )
local client_dependencies_centos_7=( "devtoolset-7-gcc-gfortran" )
local client_dependencies_centos_8=( "gcc-gfortran" )
local client_dependencies_fedora=( "gcc-gfortran" )
local client_dependencies_sles=( "gcc-fortran" )

if [[ ( "${ID}" == "centos" ) || ( "${ID}" == "rhel" ) ]]; then
if [[ "${VERSION_ID}" == "6" ]]; then
Expand All @@ -154,10 +153,6 @@ install_packages( )
ubuntu)
elevate_if_not_root apt update
install_apt_packages "${library_dependencies_ubuntu[@]}"

if [[ "${build_clients}" == true ]]; then
install_apt_packages "${client_dependencies_ubuntu[@]}"
fi
;;

centos|rhel)
Expand Down
43 changes: 13 additions & 30 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ endif()

# Configure a header file to pass the hipSPARSE version
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/hipsparse-version.h.in"
"${PROJECT_BINARY_DIR}/include/hipsparse-version.h"
)
"${PROJECT_BINARY_DIR}/include/hipsparse-version.h")

# Public hipSPARSE headers
set(hipsparse_headers_public
include/hipsparse.h
${PROJECT_BINARY_DIR}/include/hipsparse-version.h
)
${PROJECT_BINARY_DIR}/include/hipsparse-version.h)

source_group("Header Files\\Public" FILES ${hipsparse_headers_public})

Expand All @@ -62,33 +60,21 @@ add_library(hipsparse_fortran OBJECT ${hipsparse_f90_source})
add_library(hipsparse ${hipsparse_source} ${hipsparse_headers_public})
add_library(roc::hipsparse ALIAS hipsparse)

# Target compile definitions
if(NOT BUILD_CUDA)
target_compile_definitions(hipsparse PRIVATE __HIP_PLATFORM_HCC__)
else()
target_compile_definitions(hipsparse PRIVATE __HIP_PLATFORM_NVCC__)
endif()

# Target compile features
target_compile_features(hipsparse PRIVATE cxx_nullptr)

# Target include directories
target_include_directories(hipsparse
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include>
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/library/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${HIP_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>
)

if(BUILD_CUDA)
target_include_directories(hipsparse PUBLIC $<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>)
endif()
$<INSTALL_INTERFACE:include>)

# Target link libraries
if(NOT BUILD_CUDA)
target_link_libraries(hipsparse PRIVATE ${ROCSPARSE_LIBRARIES})
target_link_libraries(hipsparse PRIVATE roc::rocsparse hip::host)
else()
target_compile_definitions(hipsparse PRIVATE __HIP_PLATFORM_NVCC__)
target_include_directories(hipsparse
PUBLIC
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${HIP_INCLUDE_DIRS}>)
target_link_libraries(hipsparse PRIVATE ${CUDA_cusparse_LIBRARY})
endif()

Expand All @@ -99,7 +85,6 @@ set_target_properties(hipsparse PROPERTIES CXX_VISIBILITY_PRESET "hidden" VISIBI
set_target_properties(hipsparse PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging")
set_target_propertieS(hipsparse PROPERTIES DEBUG_POSTFIX "-d")

# TODO ??
# Following boost conventions of prefixing 'lib' on static built libraries
if(NOT BUILD_SHARED_LIBS)
set_target_properties(hipsparse PROPERTIES PREFIX "lib")
Expand All @@ -114,8 +99,7 @@ rocm_install_targets(TARGETS hipsparse
INCLUDE
${CMAKE_SOURCE_DIR}/library/include
${CMAKE_BINARY_DIR}/include
PREFIX hipsparse
)
PREFIX hipsparse)

# Export targets
if(NOT BUILD_CUDA)
Expand All @@ -134,8 +118,8 @@ rocm_install_symlink_subdir(hipsparse)

# Package specific CPACK vars
if(NOT BUILD_CUDA)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "rocsparse (>= 1.1.10)")
set(CPACK_RPM_PACKAGE_REQUIRES "rocsparse >= 1.1.10")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "rocsparse (>= 1.12.10)")
set(CPACK_RPM_PACKAGE_REQUIRES "rocsparse >= 1.12.10")
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE.md")

Expand All @@ -158,5 +142,4 @@ rocm_create_package(
DESCRIPTION "Radeon Open Compute SPARSE library"
MAINTAINER "Nico Trost"
LDCONFIG
LDCONFIG_DIR ${HIPSPARSE_CONFIG_DIR}
)
LDCONFIG_DIR ${HIPSPARSE_CONFIG_DIR})
1 change: 1 addition & 0 deletions library/src/hcc_detail/hipsparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6927,6 +6927,7 @@ hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle,
cscRowInd,
(rocsparse_double_complex*)A,
ld));
return HIPSPARSE_STATUS_SUCCESS;
}

hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle,
Expand Down

0 comments on commit 4ac714f

Please sign in to comment.