Skip to content

Commit

Permalink
Cmake fixes for clients and backends
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmroberts committed Aug 24, 2021
1 parent 440ddcb commit 894ea5c
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 62 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 12 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}'" )
Expand Down
25 changes: 18 additions & 7 deletions clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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( )
Expand Down
27 changes: 19 additions & 8 deletions clients/rider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -44,17 +40,32 @@ target_include_directories( hipfft-rider
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../library/include>
)

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" )
1 change: 1 addition & 0 deletions clients/rider/rider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// THE SOFTWARE.

#include <cmath>
#include <complex>
#include <cstddef>
#include <iostream>
#include <numeric>
Expand Down
25 changes: 16 additions & 9 deletions clients/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${hip_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../library/include>
)

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
$<BUILD_INTERFACE:${hip_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../library/include>
${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" )
Expand Down
37 changes: 24 additions & 13 deletions clients/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -74,12 +69,6 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocFFT/library/include>
)

target_link_libraries( hipfft-test
PRIVATE
${FFTW_LIBRARIES}
${Boost_LIBRARIES}
Threads::Threads
)

if( GTEST_FOUND )
target_include_directories( hipfft-test PRIVATE $<BUILD_INTERFACE:${GTEST_INCLUDE_DIRS}> )
Expand All @@ -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 )
Expand Down
10 changes: 5 additions & 5 deletions clients/tests/simple_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 894ea5c

Please sign in to comment.