summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: c97ddd5bd3f8655d4c6af079a216a006b5a9889c (plain)
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
# ==================================================================================================
# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
# project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
# width of 100 characters per line.
#
# Author(s):
#   Cedric Nugteren <www.cedricnugteren.nl>
#
# ==================================================================================================

# CMake project details
cmake_minimum_required(VERSION 2.8.10)
project("clblast" CXX)
set(clblast_VERSION_MAJOR 0)
set(clblast_VERSION_MINOR 2)
set(clblast_VERSION_PATCH 0)

# Options and their default values
option(SAMPLES "Enable compilation of the examples" OFF)
option(TUNERS "Enable compilation of the tuners" OFF)
option(TESTS "Enable compilation of the performance and correctness tests" OFF)

# ==================================================================================================

# RPATH settings
set(CMAKE_SKIP_BUILD_RPATH false) # Use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_BUILD_WITH_INSTALL_RPATH false) # When building, don't use the install RPATH already
set(CMAKE_INSTALL_RPATH "") # The RPATH to be used when installing
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH false) # Don't add the automatically determined parts

# ==================================================================================================

# Compiler-version check (requires at least CMake 2.8.10)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
    message(FATAL_ERROR "GCC version must be at least 4.7")
  endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
    message(FATAL_ERROR "Clang version must be at least 3.3")
  endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
    message(FATAL_ERROR "AppleClang version must be at least 5.0")
  endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0)
    message(FATAL_ERROR "ICC version must be at least 14.0")
  endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
    message(FATAL_ERROR "MS Visual Studio version must be at least 18.0")
  endif()
endif()

# C++ compiler settings
set(FLAGS "-O3 -std=c++11")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  set(FLAGS "${FLAGS} -Wall -Wno-comment -Wno-return-type -Wno-switch -Wno-missing-noreturn")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)
    set(FLAGS "${FLAGS} -Wno-attributes -Wno-unused-variable")
  endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  set(FLAGS "${FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded")
  set(FLAGS "${FLAGS} -Wno-missing-prototypes -Wno-float-equal -Wno-switch-enum -Wno-switch")
  set(FLAGS "${FLAGS} -Wno-exit-time-destructors -Wno-global-constructors -Wno-missing-noreturn")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")

# ==================================================================================================

# Package scripts location
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Requires OpenCL. It is found through the included "FindOpenCL.cmake" in CMAKE_MODULE_PATH.
find_package(OpenCL REQUIRED)

# Locates the CLTune library in case the tuners need to be compiled. "FindCLTune.cmake" is included.
if(TUNERS)
  find_package(CLTune)
  if(NOT CLTUNE_FOUND)
    message(STATUS "Could NOT find CLTune, disabling the compilation of the tuners")
    set(TUNERS OFF)
  endif()
endif()

# ==================================================================================================

# Includes directories: CLBlast and OpenCL
include_directories(${clblast_SOURCE_DIR}/include ${OPENCL_INCLUDE_DIRS})

# ==================================================================================================

# Sets the supported routines and the used kernels. New routines and kernels should be added here.
set(KERNELS copy pad transpose padtranspose xaxpy xgemv xgemm)
set(SAMPLE_PROGRAMS sgemm)
set(LEVEL1_ROUTINES xaxpy)
set(LEVEL2_ROUTINES xgemv)
set(LEVEL3_ROUTINES xgemm xsymm xhemm xsyrk xherk xsyr2k xher2k xtrmm)
set(ROUTINES ${LEVEL1_ROUTINES} ${LEVEL2_ROUTINES} ${LEVEL3_ROUTINES})

# ==================================================================================================

# Gathers all source-files
set(SOURCES src/clblast.cc src/database.cc src/routine.cc src/utilities.cc)
foreach(ROUTINE ${LEVEL1_ROUTINES})
  set(SOURCES ${SOURCES} src/routines/level1/${ROUTINE}.cc)
endforeach()
foreach(ROUTINE ${LEVEL2_ROUTINES})
  set(SOURCES ${SOURCES} src/routines/level2/${ROUTINE}.cc)
endforeach()
foreach(ROUTINE ${LEVEL3_ROUTINES})
  set(SOURCES ${SOURCES} src/routines/level3/${ROUTINE}.cc)
endforeach()

# Creates and links the library
add_library(clblast SHARED ${SOURCES})
target_link_libraries(clblast ${OPENCL_LIBRARIES})

# Installs the library
install(TARGETS clblast DESTINATION lib)
install(FILES include/clblast.h DESTINATION include)

# ==================================================================================================

# This section contains all the code related to the examples
if(SAMPLES)

  # Adds sample programs
  foreach(SAMPLE ${SAMPLE_PROGRAMS})
    add_executable(sample_${SAMPLE} samples/${SAMPLE}.cc)
    target_link_libraries(sample_${SAMPLE} clblast ${OPENCL_LIBRARIES})
    install(TARGETS sample_${SAMPLE} DESTINATION bin)
  endforeach()

endif()

# ==================================================================================================

# This section contains all the code related to the tuners. These tuners require the presence of
# the CLTune library (not included as part of the source).
if(TUNERS)

  # Includes CLTune
  include_directories(${CLTUNE_INCLUDE_DIRS})

  # Creates the common tuner objects (requires CMake 2.8.8)
  add_library(tuners_common OBJECT src/tuning/tuning.cc)

  # Adds tuning executables
  foreach(KERNEL ${KERNELS})
    add_executable(tuner_${KERNEL} $<TARGET_OBJECTS:tuners_common> src/tuning/${KERNEL}.cc)
    target_link_libraries(tuner_${KERNEL} clblast ${CLTUNE_LIBRARIES} ${OPENCL_LIBRARIES})
    install(TARGETS tuner_${KERNEL} DESTINATION bin)
  endforeach()

endif()

# ==================================================================================================

# Down from here is all test (performance and correctness) related. Note that these tests require
# the compilation of the clBLAS library to act as a reference.
if(TESTS)

  # Enables clBLAS to provide as reference for the tests (source-code is shipped with the project).
  # This subproject uses specific flags to reduce the amount of warnings.
  set(CMAKE_CXX_FLAGS_CLBLAST ${CMAKE_CXX_FLAGS})
  set(CMAKE_CXX_FLAGS "-O3")
  add_subdirectory(external/clBLAS/src)
  set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_CLBLAST})

  # Adds new include directories for the reference clBLAS
  include_directories(${clblast_SOURCE_DIR}/test ${clBLAS_SOURCE_DIR})

  # Creates the common correctness-tests objects (requires CMake 2.8.8)
  add_library(test_correctness_common OBJECT
              test/correctness/tester.cc test/correctness/testblas.cc)

  # Compiles the correctness-tests
  foreach(ROUTINE ${LEVEL1_ROUTINES})
    add_executable(test_${ROUTINE} $<TARGET_OBJECTS:test_correctness_common>
                   test/correctness/routines/level1/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${LEVEL2_ROUTINES})
    add_executable(test_${ROUTINE} $<TARGET_OBJECTS:test_correctness_common>
                   test/correctness/routines/level2/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${LEVEL3_ROUTINES})
    add_executable(test_${ROUTINE} $<TARGET_OBJECTS:test_correctness_common>
                   test/correctness/routines/level3/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${ROUTINES})
    target_link_libraries(test_${ROUTINE} clBLAS clblast ${OPENCL_LIBRARIES})
    install(TARGETS test_${ROUTINE} DESTINATION bin)
  endforeach()

  # Creates the common performance-tests objects (requires CMake 2.8.8)
  add_library(test_performance_common OBJECT test/performance/client.cc)

  # Compiles the performance-tests
  foreach(ROUTINE ${LEVEL1_ROUTINES})
    add_executable(client_${ROUTINE} $<TARGET_OBJECTS:test_performance_common>
                   test/performance/routines/level1/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${LEVEL2_ROUTINES})
    add_executable(client_${ROUTINE} $<TARGET_OBJECTS:test_performance_common>
                   test/performance/routines/level2/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${LEVEL3_ROUTINES})
    add_executable(client_${ROUTINE} $<TARGET_OBJECTS:test_performance_common>
                   test/performance/routines/level3/${ROUTINE}.cc)
  endforeach()
  foreach(ROUTINE ${ROUTINES})
    target_link_libraries(client_${ROUTINE} clBLAS clblast ${OPENCL_LIBRARIES})
    install(TARGETS client_${ROUTINE} DESTINATION bin)
  endforeach()

endif()
# ==================================================================================================