summaryrefslogtreecommitdiff
path: root/external/clBLAS/src/tests/CMakeLists.txt
blob: e0ebedef76b0502a756aa8e4a063fe3c9134f146 (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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# ########################################################################
# Copyright 2013 Advanced Micro Devices, Inc.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ########################################################################

set(SRC_COMMON
    cmdline.c
    common.cpp
    clBLAS-wrapper.cpp
    BlasBase.cpp
)

set(SRC_COMMON_TIMER
    timer.c
)

# group of sources with reference implementation stuff
set (SRC_COMMON_REFIMPL
    blas.c
    blas-cblas.c
    blas-wrapper.cpp
)

set(SRC_CORR
    correctness/blas-lapack.c
    correctness/BlasBase-corr.cpp
    correctness/corr-gemm.cpp
    correctness/corr-trmm.cpp
    correctness/corr-trsm.cpp
    correctness/corr-gemv.cpp
    correctness/corr-symv.cpp
    correctness/corr-spmv.cpp
    correctness/corr-syr2k.cpp
    correctness/corr-syrk.cpp
    correctness/corr-trmv.cpp
    correctness/corr-tpmv.cpp
    correctness/corr-trsv.cpp
	correctness/corr-symm.cpp
	correctness/corr-gemm2.cpp
	correctness/corr-ger.cpp
	correctness/corr-gerc.cpp
    correctness/corr-her.cpp
	correctness/corr-her2.cpp
	correctness/corr-syr.cpp
    correctness/corr-spr.cpp
	correctness/corr-syr2.cpp
	correctness/corr-hemv.cpp
	correctness/corr-hpmv.cpp
	correctness/corr-hemm.cpp
	correctness/corr-herk.cpp
    correctness/corr-tpsv.cpp
    correctness/corr-hpr.cpp
	correctness/corr-hpr2.cpp
	correctness/corr-spr2.cpp
	correctness/corr-gbmv.cpp
    correctness/corr-hbmv.cpp
	correctness/corr-tbmv.cpp
    correctness/corr-tbsv.cpp
    correctness/corr-sbmv.cpp
    correctness/corr-her2k.cpp
    correctness/corr-scal.cpp
	correctness/corr-swap.cpp
	correctness/corr-copy.cpp
    correctness/corr-axpy.cpp
	correctness/corr-dot.cpp
    correctness/corr-dotc.cpp
    correctness/corr-rotg.cpp
    correctness/corr-rotm.cpp
	correctness/corr-rot.cpp
    correctness/corr-rotmg.cpp
    correctness/corr-nrm2.cpp
    correctness/corr-asum.cpp
    correctness/corr-iamax.cpp
    correctness/test-correctness.cpp
    correctness/tcase-filter.cpp
)

set(SRC_PERF
    performance/PerformanceRecorder.cpp
    performance/PerformanceTest.cpp
    performance/TrxmPerformanceTest.cpp
    performance/BlasBase-perf.cpp
    performance/perf-gemm.cpp
    performance/perf-gemm2.cpp
    performance/perf-gemv.cpp
    performance/perf-syr2k.cpp
    performance/perf-syrk.cpp
    performance/perf-symv.cpp
    performance/perf-spmv.cpp
    performance/perf-trmm.cpp
    performance/perf-trsm.cpp
    performance/perf-trmv.cpp
    performance/perf-tpmv.cpp
    performance/perf-trsv.cpp
    performance/perf-symm.cpp
    performance/perf-ger.cpp
    performance/perf-gerc.cpp
    performance/perf-syr.cpp
    performance/perf-spr.cpp
	performance/perf-her.cpp
	performance/perf-her2.cpp
    performance/perf-syr2.cpp
	performance/perf-hemm.cpp
    performance/perf-hemv.cpp
    performance/perf-hpmv.cpp
    performance/perf-herk.cpp
	performance/perf-tpsv.cpp
    performance/perf-hpr.cpp
	performance/perf-hpr2.cpp
    performance/perf-spr2.cpp
    performance/perf-sbmv.cpp
    performance/perf-gbmv.cpp
    performance/perf-hbmv.cpp
    performance/perf-tbmv.cpp
    performance/perf-tbsv.cpp
    performance/perf-her2k.cpp
    performance/perf-scal.cpp
    performance/perf-swap.cpp
	performance/perf-copy.cpp
    performance/perf-axpy.cpp
	performance/perf-dot.cpp
    performance/perf-dotc.cpp
    performance/perf-rotg.cpp
    performance/perf-rotm.cpp
	performance/perf-rot.cpp
    performance/perf-rotmg.cpp
    performance/perf-nrm2.cpp
    performance/perf-asum.cpp
    performance/perf-iamax.cpp
	performance/test-performance.cpp
)

set(SRC_FUNC
   functional/func-error.cpp
   functional/func-event.cpp
   functional/func-thread.cpp
   functional/func-queue.cpp
   #functional/func-images.cpp
   functional/test-functional.cpp
   functional/BlasBase-func.cpp
)

set(TESTS_HEADERS
    ${clBLAS_SOURCE_DIR}/clBLAS.h
    ${clBLAS_SOURCE_DIR}/clBLAS-complex.h
	${clBLAS_SOURCE_DIR}/include/cltypes.h
	${clBLAS_SOURCE_DIR}/include/defbool.h
    include/blas-internal.h
    include/blas-cblas.h
    include/blas-wrapper.h
    include/clBLAS-wrapper.h
    include/cmdline.h
    include/BlasBase.h
    include/common.h
    include/BlasBase.h
    include/gemm.h
    include/trmm.h
    include/tpmv.h
    include/trsm.h
    include/gemv.h
    include/symv.h
    include/spmv.h
    include/syr2k.h
    include/syrk.h
    include/trmv.h
    include/trsv.h
	include/symm.h
	include/ger.h
    include/gerc.h
    include/syr.h
    include/spr.h
    include/her.h
	include/her2.h
    include/syr2.h
	include/hemv.h
	include/hpmv.h
	include/hemm.h
	include/herk.h
    include/tpsv.h
    include/hpr.h
	include/hpr2.h
    include/spr2.h
    include/gbmv.h
    include/hbmv.h
    include/tbmv.h
    include/tbsv.h
	include/copy.h
    include/sbmv.h
    include/dot.h
    include/dotc.h
    include/her2k.h
    include/scal.h
	include/swap.h
    include/axpy.h
    include/rotg.h
    include/rotm.h
	include/rot.h
    include/asum.h
    include/rotmg.h
    include/nrm2.h
    include/iamax.h
	include/blas-math.h
    include/blas-random.h
    include/matrix.h
    include/timer.h
)

set(CORR_HEADERS
    correctness/blas-lapack.h
    correctness/trsm-delta.h
    correctness/tcase-filter.h
    correctness/delta.h
	correctness/trsv-delta.h
)

set(PERF_HEADERS
    performance/PerformanceTest.h
    performance/PerformanceRecorder.h
)

set(FUNC_HEADERS
   functional/func.h
)

# Setup Visual Studio file tabs
source_group(correctness FILES ${SRC_CORR} ${CORR_HEADERS})
source_group(performance FILES ${SRC_PERF} ${PERF_HEADERS})
source_group(functional  FILES ${SRC_FUNC} ${FUNC_HEADERS})

# FIXME: it's a temporary solution to workaround segfault in clGetProgramInfo()
# at paramVal = CL_PROGRAM_BINARIES and several devices in the context
add_definitions( -DTEST_WITH_SINGLE_DEVICE )

# vs11 needs std::tuples compiled with 10 parameters by default
# NOTE: this assumes that googletest is compiled with the same preprocessor macro; they must match
if( MSVC11 )
	add_definitions( "/D_VARIADIC_MAX=10" )
endif()

# Having problems on build server, compiling gtest headers with -pedantic; disabling detection of long long
# http://code.google.com/p/googletest/issues/detail?id=334
if( CMAKE_COMPILER_IS_GNUCXX )
	add_definitions( -Wno-long-long )
endif( )

if( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
	message( STATUS "Detected PGI Fortran compiler." )

	# By default, -Mipa=fast is used, and this does not mix well with the cl compiler
	string( REPLACE "-Mipa=fast" "" CMAKE_Fortran_FLAGS_RELEASE ${CMAKE_Fortran_FLAGS_RELEASE} )
	
	# In windows, dynamically link to the C runtime, and tell fortran linker to not include default main subroutine
	if( WIN32 )
		set( CMAKE_EXE_LINKER_FLAGS "-Bdynamic -Mnostartup ${CMAKE_EXE_LINKER_FLAGS}" )
	endif( )
endif( )

# Library with functions for time measurement. In Windows they are included automatically
if(UNIX)
    if(NOT APPLE)
        set(TIME_LIBRARY "rt")
    endif()
    set(THREAD_LIBRARY "pthread")
endif()

# This logic supports the build server, if it compiles the runtime seperately from the test programs
# It stitches together a path to a previously built static library, based on our 'make install' logic
# Search for 64bit libs if FIND_LIBRARY_USE_LIB64_PATHS is set to true in the global environment, 32bit libs else
get_property( LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS )
set( runtime.library "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX_LIB}" )

if( WIN32 )
	set( runtime.library "${runtime.library}/import/clBLAS${CMAKE_STATIC_LIBRARY_SUFFIX}" )
else( )
	set( runtime.library "${runtime.library}/${CMAKE_SHARED_LIBRARY_PREFIX}clBLAS${CMAKE_SHARED_LIBRARY_SUFFIX}" )
endif( )

if( GTEST_FOUND )
    if( CORR_TEST_WITH_ACML AND ACML_FOUND )
		include_directories(${OPENCL_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
			${clBLAS_SOURCE_DIR} ${ACML_INCLUDE_DIRS}
			${clBLAS_SOURCE_DIR}/tests/include  ${clBLAS_SOURCE_DIR}/include)

		add_definitions(-DCORR_TEST_WITH_ACML)
	    
	    add_executable(test-correctness ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
									    ${CORR_HEADERS} ${TESTS_HEADERS})
        set_target_properties( test-correctness PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

	    add_executable(test-medium ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
							      ${CORR_HEADERS} ${TESTS_HEADERS})
	    set_target_properties(test-medium PROPERTIES COMPILE_DEFINITIONS MEDIUM_TESTS)
        set_target_properties( test-medium PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

	    add_executable(test-short ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
							      ${CORR_HEADERS} ${TESTS_HEADERS})
	    set_target_properties(test-short PROPERTIES COMPILE_DEFINITIONS SHORT_TESTS)
        set_target_properties( test-short PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

	    # The build server builds the library with gcc 4.1.2 to support Red Hat 5.5, but the test programs must be built with 
	    # gcc > 4.3.2 to support ACML.  
	    # If the runtime is being built by the project, use it, otherwise link to a runtime library specified in the install prefix
	    if( BUILD_RUNTIME )
		    target_link_libraries(test-correctness ${ACML_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
		    target_link_libraries(test-medium ${ACML_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
		    target_link_libraries(test-short ${ACML_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
	    else( )
		    target_link_libraries(test-correctness
			    ${ACML_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library})
		    target_link_libraries(test-medium
			    ${ACML_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library})
		    target_link_libraries(test-short
			    ${ACML_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library})
	    endif( )
	else( )
		#Link against the netlib reference library
		include_directories(${OPENCL_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
			${clBLAS_SOURCE_DIR} ${clBLAS_SOURCE_DIR}/tests/include ${clBLAS_SOURCE_DIR}/include})

		add_executable(test-correctness ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
						${CORR_HEADERS} ${TESTS_HEADERS})
        set_target_properties( test-correctness PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

		add_executable(test-medium ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
					  ${CORR_HEADERS} ${TESTS_HEADERS})
		set_target_properties( test-medium PROPERTIES COMPILE_DEFINITIONS MEDIUM_TESTS )
        set_target_properties( test-medium PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

		add_executable(test-short ${SRC_CORR} ${SRC_COMMON} ${SRC_COMMON_REFIMPL}
					  ${CORR_HEADERS} ${TESTS_HEADERS})
		set_target_properties( test-short PROPERTIES COMPILE_DEFINITIONS SHORT_TESTS )
        set_target_properties( test-short PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )

		if( NOT CORR_TEST_WITH_ACML AND NOT WIN32 AND NOT APPLE)
			set_target_properties( test-correctness PROPERTIES LINKER_LANGUAGE Fortran )
			set_target_properties( test-medium PROPERTIES LINKER_LANGUAGE Fortran )
			set_target_properties( test-short PROPERTIES LINKER_LANGUAGE Fortran )
		endif( )
		
	    if( BUILD_RUNTIME )
			if( NETLIB_FOUND )
				target_link_libraries(test-correctness ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
				target_link_libraries(test-medium ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
				target_link_libraries(test-short ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
			else( )
				target_link_libraries(test-correctness ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
				target_link_libraries(test-medium ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
				target_link_libraries(test-short ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
			endif( )
		else( )
			if( NETLIB_FOUND )
				target_link_libraries(test-correctness ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
				target_link_libraries(test-medium ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
				target_link_libraries(test-short ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
			else( )
				target_link_libraries(test-correctness ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
				target_link_libraries(test-medium ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
				target_link_libraries(test-short ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
			endif( )
		endif( )
    endif( )
    
    set_property( TARGET test-correctness PROPERTY FOLDER "Test")
    set_property( TARGET test-medium PROPERTY FOLDER "Test")
    set_property( TARGET test-short PROPERTY FOLDER "Test")

    # CPack configuration; include the executable into the package
    install( TARGETS test-correctness test-medium test-short
            RUNTIME DESTINATION bin${SUFFIX_BIN}
            LIBRARY DESTINATION lib${SUFFIX_LIB}
            ARCHIVE DESTINATION lib${SUFFIX_LIB}/import
            )
    
    get_target_property( testLocation test-correctness LOCATION )

    configure_file(
        "${CMAKE_CURRENT_SOURCE_DIR}/copyTestDependencies.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/copyTestDependencies.cmake"
        @ONLY
    )

    # Register script at run at install time to analyze the executable and copy dependencies into package
    install( SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/copyTestDependencies.cmake")
 
	if( ACML_FOUND )
		include_directories(${OPENCL_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
			${clBLAS_SOURCE_DIR} ${clBLAS_SOURCE_DIR}/tests/include  ${clBLAS_SOURCE_DIR}/include)

		add_definitions(-DPERF_TEST_WITH_ACML)
		include_directories(${ACML_INCLUDE_DIRS})
		add_executable(test-performance ${SRC_PERF} ${SRC_COMMON}
			${SRC_COMMON_TIMER} ${PERF_HEADERS} ${TESTS_HEADERS}
			${SRC_COMMON_REFIMPL})
		target_link_libraries(test-performance ${ACML_LIBRARIES})
        set_target_properties( test-performance PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )


		if( BUILD_RUNTIME )
			target_link_libraries(test-performance ${GTEST_LIBRARIES} ${TIME_LIBRARY} clBLAS)
		else()
			target_link_libraries( test-performance ${GTEST_LIBRARIES} ${TIME_LIBRARY} ${OPENCL_LIBRARIES} ${runtime.library} )
		endif()

        set_property( TARGET test-performance PROPERTY FOLDER "Test")

        # CPack configuration; include the executable into the package
        install( TARGETS test-performance
                RUNTIME DESTINATION bin${SUFFIX_BIN}
                LIBRARY DESTINATION lib${SUFFIX_LIB}
                ARCHIVE DESTINATION lib${SUFFIX_LIB}/import
                )
	endif()

	include_directories(${OPENCL_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
		${clBLAS_SOURCE_DIR} ${clBLAS_SOURCE_DIR}/tests/include ${clBLAS_SOURCE_DIR}/include )

	add_executable(test-functional ${SRC_FUNC} ${SRC_COMMON} ${SRC_COMMON_TIMER}
								  ${FUNC_HEADERS} ${TESTS_HEADERS})
								  
    set_target_properties( test-functional PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" )
	if( BUILD_RUNTIME )
		target_link_libraries(test-functional ${GTEST_LIBRARIES} ${TIME_LIBRARY} ${THREAD_LIBRARY} clBLAS )
	else()
		target_link_libraries(test-functional ${GTEST_LIBRARIES} ${TIME_LIBRARY} ${THREAD_LIBRARY} ${OPENCL_LIBRARIES} ${runtime.library} )
	endif()

    set_property( TARGET test-functional PROPERTY FOLDER "Test")

    # CPack configuration; include the executable into the package
    install( TARGETS test-functional
            RUNTIME DESTINATION bin${SUFFIX_BIN}
            LIBRARY DESTINATION lib${SUFFIX_LIB}
            ARCHIVE DESTINATION lib${SUFFIX_LIB}/import
            )
endif()