From 894ea5c18b477fda9acc006c0d60a4803acf1a76 Mon Sep 17 00:00:00 2001 From: Malcolm Roberts Date: Tue, 24 Aug 2021 10:34:33 -0600 Subject: [PATCH] Cmake fixes for clients and backends --- CHANGELOG.md | 7 ++++--- CMakeLists.txt | 24 +++++++++++----------- clients/CMakeLists.txt | 25 ++++++++++++++++------- clients/rider/CMakeLists.txt | 27 +++++++++++++++++-------- clients/rider/rider.cpp | 1 + clients/samples/CMakeLists.txt | 25 ++++++++++++++--------- clients/tests/CMakeLists.txt | 37 ++++++++++++++++++++++------------ clients/tests/simple_test.cpp | 10 ++++----- cmake/dependencies.cmake | 16 ++++++++++----- library/CMakeLists.txt | 5 +++++ 10 files changed, 115 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 542bbbe..8db09c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,16 @@ Partial documentation for hipFFT is available at [hipFFT]. - Added support for Windows 10 as a build target. ### Changed -- Packaging split into a runtime package called hipfft and a development package called hipfft-devel. - The development package depends on runtime. The runtime package suggests the development package - for all supported OSes except CentOS 7 to aid in the transition. The suggests feature in packaging +- Packaging split into a runtime package called hipfft and a development package called hipfft-devel. + The development package depends on runtime. The runtime package suggests the development package + for all supported OSes except CentOS 7 to aid in the transition. The suggests feature in packaging is introduced as a deprecated feature and will be removed in a future rocm release. ## [(Unreleased) hipFFT 1.0.4 for ROCm 4.4.0] ### Fixed - Add calls to rocFFT setup/cleanup. +- Cmake fixes for clients and backend support. ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b4021..f34ebdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,20 +80,20 @@ string( TOUPPER "${BUILD_WITH_COMPILER}" BUILD_WITH_COMPILER ) string( TOUPPER "${BUILD_WITH_LIB}" BUILD_WITH_LIB ) if (BUILD_WITH_COMPILER STREQUAL "HIP-NVCC" ) - set (BUILD_WITH_LIB "CUDA") # This may change after rocFFT fully support on NV platform + set (BUILD_WITH_LIB "CUDA") set( HIP_PLATFORM "nvidia" ) - set( CMAKE_C_COMPILE_OPTIONS_PIC "-Xcompiler ${CMAKE_C_COMPILE_OPTIONS_PIC}" ) - set( CMAKE_CXX_COMPILE_OPTIONS_PIC "-Xcompiler ${CMAKE_CXX_COMPILE_OPTIONS_PIC}" ) - set( CMAKE_SHARED_LIBRARY_C_FLAGS "-Xlinker ${CMAKE_SHARED_LIBRARY_C_FLAGS}" ) - set( CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Xlinker ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" ) - set( CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Xlinker -soname," ) - set( CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-Xlinker -soname," ) - - set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Xlinker -rpath," ) - set( CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-Xlinker -rpath," ) - set( CMAKE_EXECUTABLE_RUNTIME_C_FLAG "-Xlinker -rpath," ) - set( CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Xlinker -rpath," ) + set( CMAKE_CXX_COMPILE_OPTIONS_PIC "-Xcompiler=${CMAKE_CXX_COMPILE_OPTIONS_PIC}" ) + + set( CMAKE_SHARED_LIBRARY_C_FLAGS "-Xlinker=${CMAKE_SHARED_LIBRARY_C_FLAGS}" ) + set( CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Xlinker=${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" ) + set( CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Xlinker=-soname," ) + set( CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-Xlinker=-soname," ) + + set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Xlinker=-rpath," ) + set( CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-Xlinker=-rpath," ) + set( CMAKE_EXECUTABLE_RUNTIME_C_FLAG "-Xlinker=-rpath," ) + set( CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Xlinker=-rpath," ) set( CMAKE_C_COMPILE_OPTIONS_VISIBILITY "-Xcompiler='${CMAKE_C_COMPILE_OPTIONS_VISIBILITY}'" ) set( CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY "-Xcompiler='${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY}'" ) diff --git a/clients/CMakeLists.txt b/clients/CMakeLists.txt index 1884a07..68ad9bb 100644 --- a/clients/CMakeLists.txt +++ b/clients/CMakeLists.txt @@ -26,15 +26,25 @@ 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" ) + 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" ) + 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 +# 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 ) - set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) + set( CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) endif() # This project may compile dependencies for clients @@ -44,12 +54,13 @@ list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) include( build-options ) -# This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on all the time +# This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on +# all the time # This tells cmake to create a compile_commands.json file that can be used with clang tooling or vim set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) -# if hipfft is not a target, then we know clients are built separately from the library and we must search -# for the hipfft package +# if hipfft is not a target, then we know clients are built separately from the library and we must +# search for the hipfft package if( NOT TARGET hipfft ) find_package( hipfft REQUIRED CONFIG PATHS ) endif( ) diff --git a/clients/rider/CMakeLists.txt b/clients/rider/CMakeLists.txt index 4415845..de1fc7d 100644 --- a/clients/rider/CMakeLists.txt +++ b/clients/rider/CMakeLists.txt @@ -25,10 +25,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5) find_package( Boost COMPONENTS program_options REQUIRED) set( Boost_USE_STATIC_LIBS OFF ) -if(NOT Boost_LIBRARIES) - # Fixes a bug in Boost's CMAKE where Boost_LIBRARIES is not set. - set(Boost_LIBRARIES Boost::program_options) -endif() set( hipfft_rider_source rider.cpp ) set( hipfft_rider_includes rider.h ) @@ -44,17 +40,32 @@ target_include_directories( hipfft-rider $ $ ) - + if( NOT CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" ) - find_package( hip REQUIRED ) - target_link_libraries( hipfft-rider PRIVATE hip::host ) + if( NOT BUILD_WITH_LIB STREQUAL "CUDA" ) + find_package( HIP REQUIRED ) + target_link_libraries( hipfft-rider PRIVATE hip::host ) + else() + + target_compile_definitions( hipfft-rider PRIVATE __HIP_PLATFORM_NVIDIA__) + target_include_directories( hipfft-rider PRIVATE ${HIP_INCLUDE_DIRS}) + endif() +else() + if( BUILD_WITH_LIB STREQUAL "CUDA" ) + # NVCC doesn't like linking with files that don't end in .so, so + # we add a hack to remove the version number as the suffix. + string(REGEX REPLACE + \.${boost_program_options_VERSION} "" + Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE + ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}) + endif() endif() if ( BUILD_WITH_LIB STREQUAL "CUDA" ) target_link_libraries( hipfft-rider PRIVATE ${CUDA_LIBRARIES} ) endif() -target_link_libraries( hipfft-rider PRIVATE hip::hipfft ${Boost_LIBRARIES} ) +target_link_libraries( hipfft-rider PRIVATE hip::hipfft ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE} ) set_target_properties( hipfft-rider PROPERTIES DEBUG_POSTFIX "-d" CXX_EXTENSIONS NO ) set_target_properties( hipfft-rider PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) diff --git a/clients/rider/rider.cpp b/clients/rider/rider.cpp index 4d0f8dd..8828117 100644 --- a/clients/rider/rider.cpp +++ b/clients/rider/rider.cpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #include +#include #include #include #include diff --git a/clients/samples/CMakeLists.txt b/clients/samples/CMakeLists.txt index 46d9202..5a882c6 100644 --- a/clients/samples/CMakeLists.txt +++ b/clients/samples/CMakeLists.txt @@ -45,22 +45,29 @@ foreach( sample ${sample_list} ) set_target_properties( ${sample} PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON ) - target_include_directories( ${sample} - PRIVATE $ - $ - $ - ) - + target_link_libraries( ${sample} PRIVATE hip::hipfft ) + if( NOT CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" ) - find_package( hip REQUIRED ) - target_link_libraries( ${sample} PRIVATE hip::host ) + find_package( HIP MODULE REQUIRED ) + if( NOT BUILD_WITH_LIB STREQUAL "CUDA" ) + target_link_libraries( ${sample} PRIVATE hip::host ) + else() + target_compile_definitions( ${sample} PRIVATE __HIP_PLATFORM_NVIDIA__) + target_include_directories( ${sample} PRIVATE ${HIP_INCLUDE_DIRS}) + endif() endif() if ( BUILD_WITH_LIB STREQUAL "CUDA" ) target_link_libraries( ${sample} PRIVATE ${CUDA_LIBRARIES} ) endif() - target_link_libraries( ${sample} PRIVATE hip::hipfft ) + target_include_directories( ${sample} + PRIVATE + $ + $ + $ + ${HIP_ROOT_DIR} + ) set_target_properties( ${sample} PROPERTIES DEBUG_POSTFIX "-d" CXX_EXTENSIONS NO ) set_target_properties( ${sample} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index e2ccff3..2b965e2 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -23,11 +23,6 @@ find_package( Boost COMPONENTS program_options REQUIRED) set( Boost_USE_STATIC_LIBS OFF ) -if(NOT Boost_LIBRARIES) - # Fixes a bug in Boost's CMAKE where Boost_LIBRARIES is not set. - set(Boost_LIBRARIES Boost::program_options) -endif() - find_package( FFTW 3.0 REQUIRED MODULE COMPONENTS FLOAT DOUBLE ) set( THREADS_PREFER_PTHREAD_FLAG ON ) @@ -74,12 +69,6 @@ target_include_directories( $ ) -target_link_libraries( hipfft-test - PRIVATE - ${FFTW_LIBRARIES} - ${Boost_LIBRARIES} - Threads::Threads - ) if( GTEST_FOUND ) target_include_directories( hipfft-test PRIVATE $ ) @@ -91,14 +80,36 @@ else() endif() if( NOT CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" ) - find_package( hip REQUIRED ) - target_link_libraries( hipfft-test PRIVATE hip::host ) + if( NOT BUILD_WITH_LIB STREQUAL "CUDA" ) + find_package( HIP MODULE REQUIRED ) + target_link_libraries( hipfft-test PRIVATE hip::host ) + else() + target_compile_definitions( hipfft-test PRIVATE __HIP_PLATFORM_NVIDIA__) + target_include_directories( hipfft-test PRIVATE ${HIP_INCLUDE_DIRS}) + endif() +else() + if( BUILD_WITH_LIB STREQUAL "CUDA" ) + # NVCC doesn't like linking with files that don't end in .so, so + # we add a hack to remove the version number as the suffix. + string(REGEX REPLACE + \.${boost_program_options_VERSION} "" + Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE + ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}) + endif() endif() if ( BUILD_WITH_LIB STREQUAL "CUDA" ) target_link_libraries( hipfft-test PRIVATE ${CUDA_LIBRARIES} ) + target_compile_definitions( hipfft-test PUBLIC _CUFFT_BACKEND ) endif() +target_link_libraries( hipfft-test + PRIVATE + ${FFTW_LIBRARIES} + ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE} + Threads::Threads + ) + target_link_libraries( hipfft-test PRIVATE hip::hipfft ) set_target_properties( hipfft-test PROPERTIES DEBUG_POSTFIX "-d" CXX_EXTENSIONS NO ) diff --git a/clients/tests/simple_test.cpp b/clients/tests/simple_test.cpp index 9d97514..bac3cf4 100644 --- a/clients/tests/simple_test.cpp +++ b/clients/tests/simple_test.cpp @@ -94,7 +94,7 @@ TEST(hipfftTest, CheckBufferSizeC2C) size_t workSize = 0; EXPECT_TRUE(hipfftMakePlan1d(plan, n, HIPFFT_C2C, 1, &workSize) == HIPFFT_SUCCESS); -#ifndef __HIP_PLATFORM_NVCC__ +#ifndef _CUFFT_BACKEND // No extra work buffer for C2C EXPECT_TRUE(0 == workSize); #endif @@ -110,7 +110,7 @@ TEST(hipfftTest, CheckBufferSizeR2C) EXPECT_TRUE(hipfftMakePlan1d(plan, n, HIPFFT_R2C, 1, &workSize) == HIPFFT_SUCCESS); -#ifndef __HIP_PLATFORM_NVCC__ +#ifndef _CUFFT_BACKEND if(n % 2 == 0) { EXPECT_TRUE(workSize == 0); @@ -132,7 +132,7 @@ TEST(hipfftTest, CheckBufferSizeC2R) EXPECT_TRUE(hipfftMakePlan1d(plan, n, HIPFFT_C2R, 1, &workSize) == HIPFFT_SUCCESS); -#ifndef __HIP_PLATFORM_NVCC__ +#ifndef _CUFFT_BACKEND if(n % 2 == 0) { EXPECT_TRUE(workSize == 0); @@ -155,7 +155,7 @@ TEST(hipfftTest, CheckBufferSizeD2Z) EXPECT_TRUE(hipfftMakePlan1d(plan, n, HIPFFT_D2Z, batch, &workSize) == HIPFFT_SUCCESS); -#ifndef __HIP_PLATFORM_NVCC__ +#ifndef _CUFFT_BACKEND if(n % 2 == 0) { EXPECT_TRUE(workSize == 0); @@ -179,7 +179,7 @@ TEST(hipfftTest, CheckBufferSizeZ2D) EXPECT_TRUE(hipfftMakePlan1d(plan, n, HIPFFT_Z2D, batch, &workSize) == HIPFFT_SUCCESS); -#ifndef __HIP_PLATFORM_NVCC__ +#ifndef _CUFFT_BACKEND if(n % 2 == 0) { EXPECT_TRUE(workSize == 0); diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 066f3c2..022e3e4 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -25,13 +25,19 @@ find_package(Git REQUIRED) # HIP -if(NOT BUILD_WITH_LIB STREQUAL "CUDA") - find_package(hip REQUIRED) +if( NOT CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" ) + if( NOT BUILD_WITH_LIB STREQUAL "CUDA" ) + find_package( HIP REQUIRED ) + list( APPEND HIP_INCLUDE_DIRS "${HIP_ROOT_DIR}/include" ) + endif() else() - find_package(HIP REQUIRED) - list( APPEND HIP_INCLUDE_DIRS "${HIP_ROOT_DIR}/include" ) + if( BUILD_WITH_LIB STREQUAL "CUDA" ) + set(HIP_INCLUDE_DIRS "${HIP_ROOT_DIR}/include") + else() + find_package( HIP REQUIRED ) + endif() endif() - + # Either rocfft or cufft is required if(NOT BUILD_WITH_LIB STREQUAL "CUDA") find_package(rocfft REQUIRED) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 45e812b..400c497 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -104,6 +104,11 @@ set_target_properties( hipfft PROPERTIES CXX_EXTENSIONS NO ) set_target_properties( hipfft PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) set_target_propertieS( hipfft PROPERTIES DEBUG_POSTFIX "-d" ) +if (BUILD_WITH_COMPILER STREQUAL "HIP-NVCC" ) + set_property(TARGET hipfft PROPERTY POSITION_INDEPENDENT_CODE ON) + set ( CXX_FLAGS "${CXX_FLAGS} -Xcompiler=-fPIC" ) +endif() + #TODO: # hipcc(with nvcc backend) build has problem for share library visibility, # need to figure out the reason and enable visibility "hidden" for nvcc eventually.