forked from ROCm/MIOpen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
282 lines (251 loc) · 9.12 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
################################################################################
#
# MIT License
#
# Copyright (c) 2017 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
cmake_minimum_required( VERSION 2.8.12 )
# 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 MSVC_IDE AND NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." )
endif()
# Default installation path
if(WIN32)
set(CMAKE_INSTALL_PREFIX "/opt/rocm/x86_64-w64-mingw32" CACHE PATH "")
else()
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "")
endif()
project ( MIOpen C CXX )
enable_testing()
find_package(ROCM REQUIRED PATHS /opt/rocm)
include(ROCMInstallTargets)
include(ROCMPackageConfigHelpers)
include(ROCMSetupVersion)
include(ROCMInstallSymlinks)
include(ROCMCreatePackage)
# Strip symbols for release
if(NOT WIN32 AND NOT APPLE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
endif()
rocm_setup_version(VERSION 1.2.0)
list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.3")
message(FATAL_ERROR "MIOpen requires at least gcc 5.3")
endif()
endif()
############################################################
# require C++11
add_compile_options(-std=gnu++14)
############################################################
# OPTION - MIOpen Backend
# - OpenCL
# - HCC
if(CMAKE_CXX_COMPILER MATCHES ".*hcc")
set(MIOPEN_DEFAULT_BACKEND "HIP")
else()
set(MIOPEN_DEFAULT_BACKEND "OpenCL")
endif()
if(WIN32 AND CMAKE_CROSSCOMPILING)
set(WINE_CMD "wine")
else()
set(WINE_CMD)
endif()
option(ENABLE_HIP_WORKAROUNDS Off)
if(ENABLE_HIP_WORKAROUNDS)
# Add these to CMAKE_PREFIX_PATH to workaround installation problems with hip and hcc
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip)
endif()
set( MIOPEN_BACKEND ${MIOPEN_DEFAULT_BACKEND} CACHE STRING
"Which of MIOpens's backends to use?" )
set_property( CACHE MIOPEN_BACKEND PROPERTY STRINGS
OpenCL HIP HIPOC )
# OpenCL 1.2
if( MIOPEN_BACKEND STREQUAL "OpenCL")
set(MIOPEN_BACKEND_OPENCL 1)
find_package( OpenCL REQUIRED )
endif()
# HIP
if( MIOPEN_BACKEND STREQUAL "HIP" OR MIOPEN_BACKEND STREQUAL "HIPOC")
set(MIOPEN_BACKEND_HIP 1)
find_program(HIP_OC_COMPILER clang-ocl
PATH_SUFFIXES bin
PATHS /opt/rocm
)
if(HIP_OC_COMPILER)
message(STATUS "hip compiler: ${HIP_OC_COMPILER}")
set(HIP_OC_COMPILER "${HIP_OC_COMPILER}")
else()
message(FATAL_ERROR "clang-ocl not found")
endif()
find_package(hip REQUIRED PATHS /opt/rocm)
link_libraries(stdc++)
# A hack to make this work without the device enumerator
link_libraries(-amdgpu-target=gfx803 -amdgpu-target=gfx900 -Wno-unused-command-line-argument)
endif()
message( STATUS "${MIOPEN_BACKEND} backend selected." )
# Online assembler
find_program(MIOPEN_AMDGCN_ASSEMBLER
NAMES clang
PATHS ${MIOPEN_AMDGCN_ASSEMBLER_PATH} /opt/rocm
PATH_SUFFIXES /opencl/bin/x86_64
NO_DEFAULT_PATH
)
message(STATUS "AMDGCN assembler: ${MIOPEN_AMDGCN_ASSEMBLER}")
# miopengemm
find_package(miopengemm PATHS /opt/rocm)
if(miopengemm_FOUND)
message(STATUS "Build with miopengemm")
set(MIOPEN_USE_MIOPENGEMM 1)
else()
message(STATUS "Build without miopengemm")
set(MIOPEN_USE_MIOPENGEMM 0)
endif()
find_package(OpenSSL REQUIRED)
set(BOOST_COMPONENTS filesystem system)
add_definitions(-DBOOST_ALL_NO_LIB=1)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
option( BUILD_SHARED_LIBS "Build as a shared library" ON )
option( BUILD_DEV "Build for development only" OFF)
set( MIOPEN_INSTALL_DIR miopen)
set( DATA_INSTALL_DIR ${MIOPEN_INSTALL_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/miopen )
if(BUILD_DEV)
set(MIOPEN_BUILD_DEV 1)
set(MIOPEN_DB_PATH "${CMAKE_SOURCE_DIR}/src/kernels")
set(MIOPEN_CACHE_DIR "" CACHE STRING "")
else()
set(MIOPEN_BUILD_DEV 0)
set(MIOPEN_DB_PATH "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/db" CACHE PATH "Default path to search for db")
set(MIOPEN_CACHE_DIR "~/.cache/miopen/" CACHE STRING "")
endif()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "openssl, rocm-opencl-dev, rocm-utils, hip_hcc, miopengemm")
set(CPACK_RPM_PACKAGE_REQUIRES "openssl, rocm-opencl-dev, rocm-utils, hip_hcc, miopengemm")
rocm_create_package(
NAME MIOpen-${MIOPEN_BACKEND}
DESCRIPTION "AMD's DNN Library"
MAINTAINER "Paul Fultz II <paul.fultz@amd.com>"
LDCONFIG
# DEPENDS rocm-opencl rocm-utils hip_hcc tinygemm
)
include(EnableCompilerWarnings)
if(CMAKE_CXX_COMPILER MATCHES ".*hcc")
set(CLANG_TIDY_CHECKS -modernize-use-override -readability-non-const-parameter)
endif()
include(ClangTidy)
enable_clang_tidy(
CHECKS
*
-cert-env33-c
-android-cloexec-fopen
# Yea we shouldn't be using rand()
-cert-msc30-c
-cert-msc50-cpp
-clang-analyzer-alpha.core.CastToStruct
-clang-analyzer-optin.performance.Padding
-clang-diagnostic-deprecated-declarations
-clang-diagnostic-extern-c-compat
-clang-diagnostic-unused-command-line-argument
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
-cppcoreguidelines-pro-bounds-constant-array-index
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-pro-type-member-init
-cppcoreguidelines-pro-type-reinterpret-cast
-cppcoreguidelines-pro-type-union-access
-cppcoreguidelines-pro-type-vararg
-cppcoreguidelines-special-member-functions
-google-explicit-constructor
-google-readability-braces-around-statements
-google-readability-todo
-google-runtime-int
-google-runtime-references
-hicpp-braces-around-statements
-hicpp-explicit-conversions
-hicpp-no-array-decay
# We really shouldn't use bitwise operators with signed integers, but
# opencl leaves us no choice
-hicpp-signed-bitwise
-hicpp-special-member-functions
-hicpp-use-equals-default
-hicpp-use-override
-llvm-header-guard
-llvm-include-order
-misc-macro-parentheses
-misc-misplaced-const
-misc-misplaced-widening-cast
-modernize-pass-by-value
-modernize-use-default-member-init
-modernize-use-equals-default
-modernize-use-transparent-functors
-performance-unnecessary-value-param
-readability-braces-around-statements
-readability-else-after-return
-readability-implicit-bool-cast
-readability-implicit-bool-conversion
-readability-misleading-indentation
-readability-named-parameter
${CLANG_TIDY_CHECKS}
ERRORS
*
-readability-inconsistent-declaration-parameter-name
HEADER_FILTER
"hpp$"
EXTRA_ARGS
-DMIOPEN_USE_CLANG_TIDY
ANALYZE_TEMPORARY_DTORS ON
)
include(CppCheck)
enable_cppcheck(
CHECKS
all
FORCE
SUPPRESS
ConfigurationNotChecked
unmatchedSuppression
constStatement
noExplicitConstructor
passedByValue
# preprocessorErrorDirective
unusedStructMember
# TODO: Try to reenable this without needing inline suppressions
leakReturnValNotUsed
*:*.cl
SOURCES
include/
src/
# test/
INCLUDE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src/include
DEFINE
MIOPEN_USE_MIOPENGEMM=1
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
add_subdirectory(addkernels)
add_subdirectory(doc)
add_subdirectory(src)
add_subdirectory(driver)
add_subdirectory(test)