CMakeLists.txt 8.41 KB
Newer Older
Ashutosh Mishra's avatar
Ashutosh Mishra committed
1
cmake_minimum_required(VERSION 3.6.3)
2
3
4
#
#  Setup build environment
#
5
#  1) Setup cmake variable CMAKE_PREFIX_PATH to point to a root
6
#     directory that has ROCr header and ROCr libraries
7
#     
8
#     export CMAKE_PREFIX_PATH="Path to ROCr Header and ROCr libraries"
9
10
11
#     
#       e.g. export CMAKE_PREFIX_PATH=/opt/rocm/
#       e.g. export CMAKE_PREFIX_PATH=${HOME}/git/compute/out/ubuntu-16.04/16.04/
12
13
14
15
16
17
18
19
#
#  2) Make an new folder called build under root folder
#
#     mkdir build
#
#  3) Enter into folder of build, and run CMAKE to generate makefile
#     and make it
#
20
#     cd build
21
#     cmake  ..
22
23
#     make
#
24
25
26
#     @note: Add -DCMAKE_BUILD_TYPE=Debug       # if you want to build Debug
#     @note: Add -DCMAKE_PREFIX_PATH="Rocm Dir" # if you don't define Env var
#
27
28
#

Ashutosh Mishra's avatar
Ashutosh Mishra committed
29
30
31
32
33
34
# Specify name of project to build, install and package
set(PROJECT_NAME "rocm-bandwidth-test")
set(TEST_NAME "${PROJECT_NAME}")
project(${PROJECT_NAME})


35
# Build is not supported on Windows plaform
36
if(WIN32)
37
  message("Windows platfom is not supported")
38
  return()
39
40
41
endif()

# Flag to enable / disable verbose output.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SET(CMAKE_VERBOSE_MAKEFILE on)

# Compiler Preprocessor definitions.
add_definitions(-D__linux__)
add_definitions(-DUNIX_OS)
add_definitions(-DLINUX)
add_definitions(-D__AMD64__)
add_definitions(-D__x86_64__)
add_definitions(-DAMD_INTERNAL_BUILD)
add_definitions(-DLITTLEENDIAN_CPU=1)
add_definitions(-DHSA_LARGE_MODEL=)
add_definitions(-DHSA_DEPRECATED=)

# Enable debug trace
if(DEFINED ENV{CMAKE_DEBUG_TRACE})
57
  add_definitions(-DDEBUG_TRACE=1)
58
59
endif()

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Linux Compiler options
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fms-extensions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmerge-all-constants")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")

# CLANG options
if("$ENV{CXX}" STREQUAL "/usr/bin/clang++")
77
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1000000")
78
79
endif()

80
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack")
81
set(CMAKE_SKIP_BUILD_RPATH TRUE)
82

83
84
85
86
87
88
89
90
91
92
93
94
## Address Sanitize Flag
if ( ${ADDRESS_SANITIZER} )
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
else ()
    if (CMAKE_COMPILER_IS_GNUCC)
        set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no-undefined")
    else ()
        set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-undefined,error")
    endif ()
endif ()

95
96
97
98
99
# Check Env vars
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
  if(DEFINED ENV{CMAKE_BUILD_TYPE})
    set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
  endif()
100
101
endif()

102
103
104
# Extend Compiler flags based on build type
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
if("${CMAKE_BUILD_TYPE}" STREQUAL debug)
105
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
106
  set(CMAKE_BUILD_TYPE "debug")
107
else()
108
  set(CMAKE_BUILD_TYPE "release")
109
110
endif()

111
112
113
114
115
116
117
118
119
120
# Extend Compiler flags based on Processor architecture
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  set(NBIT 64)
  set(NBITSTR "64")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64  -msse -msse2")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
  set(NBIT 32)
  set(NBITSTR "")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
121

122
123
124
125
# Set project requirements
set(CORE_RUNTIME_NAME "hsa-runtime")
set(CORE_RUNTIME_TARGET "${CORE_RUNTIME_NAME}64")

126
127
128
129
130
131
132
# Add cmake_modules to default module path if it is not
# already set and include utils from cmake modules
if(NOT DEFINED CMAKE_MODULE_PATH)
  set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
endif()
include(utils)

133
134
135
136
# Using find_package(has-runtime64 to find required header and library files
# This scheme could fail when using older builds of ROCm. In such a case the
# build system relies on user defined locations to find header and library files
find_package(hsa-runtime64 PATHS /opt/rocm )
Ashutosh Mishra's avatar
Ashutosh Mishra committed
137
if(${hsa-runtime64_FOUND})
Ashutosh Mishra's avatar
Ashutosh Mishra committed
138
  message("hsa-runtime64 found @  ${hsa-runtime64_DIR} ")
Ashutosh Mishra's avatar
Ashutosh Mishra committed
139
else()
140
141
142
143
144
145
  message("find_package did NOT find hsa-runtime64, finding it the OLD Way")
  message("Looking for header files in ${ROCR_INC_DIR}")
  message("Looking for library files in ${ROCR_LIB_DIR}")

  # Search for ROCr header file in user defined locations
  find_path(ROCR_HDR hsa.h PATHS ${ROCR_INC_DIR} "/opt/rocm" PATH_SUFFIXES include/hsa REQUIRED)
Ashutosh Mishra's avatar
Ashutosh Mishra committed
146
  INCLUDE_DIRECTORIES(${ROCR_HDR})
147
148
149
  
  # Search for ROCr library file in user defined locations
  find_library(ROCR_LIB ${CORE_RUNTIME_TARGET} PATHS ${ROCR_LIB_DIR} "/opt/rocm" PATH_SUFFIXES lib lib64 REQUIRED)
Ashutosh Mishra's avatar
Ashutosh Mishra committed
150
151
endif()

152
153
154
155
156
#
# Set the package version for the test. It is critical that this
# value track what is used in the test source. The code from utils
# module will parse the string into major, minor and patch sub-fields
#
157
get_version()
158
159
160
161
162

# Bind the Major, Minor and Patch values
set(BUILD_VERSION_MAJOR ${VERSION_MAJOR})
set(BUILD_VERSION_MINOR ${VERSION_MINOR})

163
164
165
166
167
168
169
170
171
172
# Basic Tool Chain Information
message(" ")
message("----------------NBIT: ${NBIT}")
message("-----------BuildType: ${CMAKE_BUILD_TYPE}")
message("------------Compiler: ${CMAKE_CXX_COMPILER}")
message("----Compiler-Version: ${CMAKE_CXX_COMPILER_VERSION}")
message("-----CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("---CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(" ")

173
174
175
# Add sources that belong to the project
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} Src)

176
# Build and link the test program
177
add_executable(${TEST_NAME} ${Src})
Ashutosh Mishra's avatar
Ashutosh Mishra committed
178
179
180
if(${hsa-runtime64_FOUND})
   target_link_libraries(${TEST_NAME} PRIVATE hsa-runtime64::hsa-runtime64)
else()
181
   target_link_libraries(${TEST_NAME} PRIVATE ${ROCR_LIB})
Ashutosh Mishra's avatar
Ashutosh Mishra committed
182
endif()
Ashutosh Mishra's avatar
Ashutosh Mishra committed
183
target_link_libraries(${TEST_NAME} PRIVATE c stdc++ dl pthread rt)
184

185
186
# Update linker flags to include RPATH
# Add --enable-new-dtags to generate DT_RUNPATH
Ashutosh Mishra's avatar
Ashutosh Mishra committed
187
188
if(DEFINED ENV{ROCM_RPATH})
   set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags -Wl,--rpath,$ENV{ROCM_RPATH}")
189
190
endif()

191
192
193
194
195
# Add install directives for rocm_bandwidth_test
install(TARGETS ${TEST_NAME} RUNTIME DESTINATION bin)

# Add packaging directives for rocm_bandwidth_test
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
Ashutosh Mishra's avatar
Ashutosh Mishra committed
196
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
197
198
199
set(CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${BUILD_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${BUILD_VERSION_PATCH})
Ashutosh Mishra's avatar
Ashutosh Mishra committed
200
201
202
set(CPACK_PACKAGE_CONTACT "TODO <Add a valid email id>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Diagnostic utility tool to measure PCIe bandwidth on ROCm platforms")

Ashutosh Mishra's avatar
Ashutosh Mishra committed
203
204
# Make proper version for appending
# Default Value is 99999, setting it first
Ashutosh Mishra's avatar
Ashutosh Mishra committed
205
206
207
208
set(ROCM_VERSION_FOR_PACKAGE "99999")
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
  set(ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_LIBPATCH_VERSION})
endif()
209

210
211
212
213
214
#Set the License information
set( CPACK_RPM_PACKAGE_LICENSE "NCSA" )
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
install(FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/${CPACK_PACKAGE_NAME})

215
# Debian package specific variables
dinggy's avatar
dinggy committed
216
set(CPACK_DEBIAN_PACKAGE_DEPENDS "hsa-rocr-dev")
217
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/rocm_bandwidth_test")
Ashutosh Mishra's avatar
Ashutosh Mishra committed
218
219
220
221
222
if (DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
   set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
else()
   set(CPACK_DEBIAN_PACKAGE_RELEASE "local")
endif()
223

224
# RPM package specific variables
dinggy's avatar
dinggy committed
225
set(CPACK_RPM_PACKAGE_DEPENDS "hsa-rocr-dev")
226
227
228
if(DEFINED CPACK_PACKAGING_INSTALL_PREFIX)
  set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/bin")
endif()
Ashutosh Mishra's avatar
Ashutosh Mishra committed
229
230
231
232
233
if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE})
  set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE})
else()
  set(CPACK_RPM_PACKAGE_RELEASE "local")
endif()
234

Ashutosh Mishra's avatar
Ashutosh Mishra committed
235
# Set rpm distro
Ashutosh Mishra's avatar
Ashutosh Mishra committed
236
237
238
if(CPACK_RPM_PACKAGE_RELEASE)
  set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
endif()
239

Ashutosh Mishra's avatar
Ashutosh Mishra committed
240
# Prepare final version for the CAPACK use
Ashutosh Mishra's avatar
Ashutosh Mishra committed
241
242
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${ROCM_VERSION_FOR_PACKAGE}")

Ashutosh Mishra's avatar
Ashutosh Mishra committed
243
# Set the names now using CPACK utility
Ashutosh Mishra's avatar
Ashutosh Mishra committed
244
245
246
247
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")

include(CPack)