-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
241 lines (197 loc) · 8.5 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
PROJECT(GAUSSMIX)
ENABLE_LANGUAGE(C)
ENABLE_LANGUAGE(CXX)
ENABLE_LANGUAGE(Fortran)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gdwarf-2 -DDEBUG")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -gdwarf-2 -DDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
IF(USEMPI)
FIND_PACKAGE(MPI)
IF(MPI_CXX_FOUND)
SET(CMAKE_C_COMPILER ${MPI_COMPILER})
SET(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUseMPI ${MPI_CXX_COMPILE_FLAGS}")
INCLUDE_DIRECTORIES(${MPI_CXX_INCLUDE_PATH})
ENDIF(MPI_CXX_FOUND)
ELSE(NOT USEMPI)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF(OPENMP_FOUND)
ENDIF(USEMPI)
# Find OpenCL
#
# To set manually the paths, define these environment variables:
# OpenCL_INCPATH - Include path (e.g. OpenCL_INCPATH=/opt/cuda/4.0/cuda/include)
# OpenCL_LIBPATH - Library path (e.h. OpenCL_LIBPATH=/usr/lib64/nvidia)
#
# Once done this will define
# OPENCL_FOUND - system has OpenCL
# OPENCL_INCLUDE_DIRS - the OpenCL include directory
# OPENCL_LIBRARIES - link these to use OpenCL
# OPENCL_HAS_CPP_BINDINGS - system has also cl.hpp
FIND_PACKAGE(PackageHandleStandardArgs)
SET (OPENCL_VERSION_STRING "0.1.0")
SET (OPENCL_VERSION_MAJOR 0)
SET (OPENCL_VERSION_MINOR 1)
SET (OPENCL_VERSION_PATCH 0)
IF (APPLE)
# IF OpenCL_LIBPATH is given use it and don't use default path
IF (DEFINED ENV{OpenCL_LIBPATH})
FIND_LIBRARY(OPENCL_LIBRARIES OpenCL PATHS ENV OpenCL_LIBPATH NO_DEFAULT_PATH)
ELSE ()
FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX")
ENDIF ()
# IF OpenCL_INCPATH is given use it and find for CL/cl.h and OpenCL/cl.h do not try to find default paths
IF (DEFINED ENV{OpenCL_INCPATH})
FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h OpenCL/cl.h PATHS ENV OpenCL_INCPATH NO_DEFAULT_PATH)
FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp OpenCL/cl.hpp PATHS ${OPENCL_INCLUDE_DIRS} NO_DEFAULT_PATH)
ELSE ()
FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX")
FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX")
ENDIF ()
ELSE (APPLE)
IF (WIN32)
# Find OpenCL includes and libraries from environment variables provided by vendor
SET(OPENCL_INCLUDE_SEARCH_PATHS)
SET(OPENCL_LIBRARY_SEARCH_PATHS)
SET(OPENCL_LIBRARY_64_SEARCH_PATHS)
# Nvidia
IF (DEFINED ENV{CUDA_INC_PATH})
SET(OPENCL_INCLUDE_SEARCH_PATHS ${OPENCL_INCLUDE_SEARCH_PATHS} $ENV{CUDA_INC_PATH})
SET(OPENCL_LIBRARY_64_SEARCH_PATHS ${OPENCL_LIBRARY_64_SEARCH_PATHS} $ENV{CUDA_LIB_PATH}/../lib64)
SET(OPENCL_LIBRARY_SEARCH_PATHS ${OPENCL_LIBRARY_SEARCH_PATHS} $ENV{CUDA_LIB_PATH}/../lib)
ENDIF()
# Intel SDK
IF (DEFINED ENV{INTELOCSDKROOT})
SET(OPENCL_INCLUDE_SEARCH_PATHS ${OPENCL_INCLUDE_SEARCH_PATHS} $ENV{INTELOCSDKROOT}/include)
SET(OPENCL_LIBRARY_64_SEARCH_PATHS ${OPENCL_LIBRARY_64_SEARCH_PATHS} $ENV{INTELOCSDKROOT}/lib/x64)
SET(OPENCL_LIBRARY_SEARCH_PATHS ${OPENCL_LIBRARY_SEARCH_PATHS} $ENV{INTELOCSDKROOT}/lib/x86)
ENDIF()
# AMD SDK
IF (DEFINED ENV{AMDAPPSDKROOT})
SET(OPENCL_INCLUDE_SEARCH_PATHS ${OPENCL_INCLUDE_SEARCH_PATHS} $ENV{AMDAPPSDKROOT}/include)
SET(OPENCL_LIBRARY_64_SEARCH_PATHS ${OPENCL_LIBRARY_64_SEARCH_PATHS} $ENV{AMDAPPSDKROOT}/lib/x86_64)
SET(OPENCL_LIBRARY_SEARCH_PATHS ${OPENCL_LIBRARY_SEARCH_PATHS} $ENV{AMDAPPSDKROOT}/lib/x86)
ENDIF()
# Override search paths with OpenCL_INCPATH env variable
IF (DEFINED ENV{OpenCL_INCPATH})
SET(OPENCL_INCLUDE_SEARCH_PATHS $ENV{OpenCL_INCPATH})
ENDIF ()
# Override search paths with OpenCL_LIBPATH env variable
IF (DEFINED ENV{OpenCL_INCPATH})
SET(OPENCL_LIBRARY_SEARCH_PATHS $ENV{OpenCL_LIBPATH})
SET(OPENCL_LIBRARY_64_SEARCH_PATHS $ENV{OpenCL_LIBPATH})
ENDIF ()
FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${OPENCL_INCLUDE_SEARCH_PATHS})
FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${OPENCL_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(_OPENCL_32_LIBRARIES OpenCL.lib HINTS ${OPENCL_LIBRARY_SEARCH_PATHS} PATHS ${OPENCL_LIB_DIR} ENV PATH)
FIND_LIBRARY(_OPENCL_64_LIBRARIES OpenCL.lib HINTS ${OPENCL_LIBRARY_64_SEARCH_PATHS} PATHS ${OPENCL_LIB_DIR} ENV PATH)
# Check if 64bit or 32bit versions links fine
SET (_OPENCL_VERSION_SOURCE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/openclversion.c")
#SET (_OPENCL_VERSION_SOURCE "${CMAKE_BINARY_DIR}/test.c")
FILE (WRITE "${_OPENCL_VERSION_SOURCE}"
"
#if __APPLE__
#include <OpenCL/cl.h>
#else /* !__APPLE__ */
#include <CL/cl.h>
#endif /* __APPLE__ */
int main()
{
cl_int result;
cl_platform_id id;
result = clGetPlatformIDs(1, &id, NULL);
return result != CL_SUCCESS;
}
")
TRY_COMPILE(_OPENCL_64_COMPILE_SUCCESS ${CMAKE_BINARY_DIR} "${_OPENCL_VERSION_SOURCE}"
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${OPENCL_INCLUDE_DIRS}"
CMAKE_FLAGS
"-DLINK_LIBRARIES:STRING=${_OPENCL_64_LIBRARIES}"
)
IF(_OPENCL_64_COMPILE_SUCCESS)
message(STATUS "OpenCL 64bit lib found.")
SET(OPENCL_LIBRARIES ${_OPENCL_64_LIBRARIES})
ELSE()
TRY_COMPILE(_OPENCL_32_COMPILE_SUCCESS ${CMAKE_BINARY_DIR} "${_OPENCL_VERSION_SOURCE}"
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${OPENCL_INCLUDE_DIRS}"
CMAKE_FLAGS
"-DLINK_LIBRARIES:STRING=${_OPENCL_32_LIBRARIES}"
)
IF(_OPENCL_32_COMPILE_SUCCESS)
message(STATUS "OpenCL 32bit lib found.")
SET(OPENCL_LIBRARIES ${_OPENCL_32_LIBRARIES})
ELSE()
message(STATUS "Couldn't link opencl..")
ENDIF()
ENDIF()
ELSE (WIN32)
IF (CYGWIN)
SET (CMAKE_FIND_LIBRARY_SUFFIXES .lib)
SET (OCL_LIB_SUFFIX .lib)
ENDIF (CYGWIN)
# Unix style platforms
FIND_LIBRARY(OPENCL_LIBRARIES OpenCL${OCL_LIB_SUFFIX}
PATHS ENV LD_LIBRARY_PATH ENV OpenCL_LIBPATH
)
GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH)
GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
# The AMD SDK currently does not place its headers
# in /usr/include, therefore also search relative
# to the library
FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
ENDIF (WIN32)
ENDIF (APPLE)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)
IF(_OPENCL_CPP_INCLUDE_DIRS)
SET( OPENCL_HAS_CPP_BINDINGS TRUE )
LIST( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS} )
# This is often the same, so clean up
LIST( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS )
ENDIF(_OPENCL_CPP_INCLUDE_DIRS)
MARK_AS_ADVANCED(
OPENCL_INCLUDE_DIRS
)
#FILE(COPY ${CMAKE_SOURCE_DIR}/cmake/findopencl/FindOpenCL.cmake DESTINATION ${CMAKE_SOURCE_DIR}/cmake/Modules/)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/findopencl/FindOpenCL.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/FindOpenCL.cmake" COPYONLY)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
FIND_PACKAGE(OpenCL)
IF(OPENCL_FOUND)
INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENCL")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCL")
ENDIF()
FIND_PACKAGE(BLAS REQUIRED)
IF(BLAS_FOUND)
INCLUDE_DIRECTORIES(${BLAS_INCLUDE_DIR})
ENDIF()
FIND_PACKAGE(LAPACK REQUIRED)
IF(LAPACK_FOUND)
INCLUDE_DIRECTORIES(${LAPACK_INCLUDE_DIR})
ENDIF()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(LIBGAUSSMIX_SRC_FILES Adapt.cpp GaussMix.cpp KMeans.cpp Matrix.cpp)
ADD_LIBRARY(gaussmixShared SHARED ${LIBGAUSSMIX_SRC_FILES})
SET_TARGET_PROPERTIES(gaussmixShared PROPERTIES OUTPUT_NAME gaussmix)
ADD_LIBRARY(gaussmixStatic STATIC ${LIBGAUSSMIX_SRC_FILES})
SET_TARGET_PROPERTIES(gaussmixStatic PROPERTIES OUTPUT_NAME gaussmix)
ADD_EXECUTABLE(gaussmix_ex sample_main.cpp)
ADD_DEPENDENCIES(gaussmix_ex gaussmixStatic)
SET_TARGET_PROPERTIES(gaussmix_ex PROPERTIES OUTPUT_NAME gaussmix)
IF(OPENCL_FOUND)
TARGET_LINK_LIBRARIES(gaussmix_ex gaussmixStatic lapacke lapack blas ${OPENCL_LIBRARIES})
ELSE(NOT OPENCL_FOUND)
TARGET_LINK_LIBRARIES(gaussmix_ex gaussmixStatic lapacke lapack blas)
ENDIF(OPENCL_FOUND)
#IF(OPENCL_FOUND)
# FILE(COPY "${CMAKE_SOURCE_DIR}/oclEstep.cl" DESTINATION ${CMAKE_SOURCE_DIR}/build)
#ENDIF(OPENCL_FOUND)