Skip to content

Commit f682e98

Browse files
author
Kent Knox
committed
Merge pull request #258 from kknox/unit-test-improvements
Unit test improvements
2 parents f7c076b + 2283077 commit f682e98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+734
-889
lines changed

src/CMakeLists.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# ########################################################################
22
# Copyright 2013 Advanced Micro Devices, Inc.
3-
#
3+
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
66
# You may obtain a copy of the License at
7-
#
7+
#
88
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
9+
#
1010
# Unless required by applicable law or agreed to in writing, software
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,33 +41,33 @@ set( OPENCL_OFFLINE_BUILD_TAHITI_KERNEL OFF)
4141
#use dynamic generated kernels
4242
# MESSAGE(STATUS "Build dynamic Hawaii kernels.")
4343
# MESSAGE(STATUS "Check OPENCL_OFFLINE_BUILD_HAWAII_KERNEL to build kernls at compile-time. This will eliminates clBuildProgram() overhead and better kernel performance with certain driver.")
44-
add_definitions(-DCLBLAS_HAWAII_DYNAMIC_KERNEL)
44+
add_definitions(-DCLBLAS_HAWAII_DYNAMIC_KERNEL)
4545
#else()
4646
# MESSAGE(STATUS "Build static Hawaii kernels.")
4747
# MESSAGE(STATUS "Uncheck OPENCL_OFFLINE_BUILD_HAWAII_KERNEL to build kernls at run-time")
48-
# MESSAGE(STATUS "Please ensure the presence of Hawaii device in the system. With certain driver/compiler flags, this might result in compile-time error.")
48+
# MESSAGE(STATUS "Please ensure the presence of Hawaii device in the system. With certain driver/compiler flags, this might result in compile-time error.")
4949
#endif( )
5050

5151
#if( NOT OPENCL_OFFLINE_BUILD_BONAIRE_KERNEL )
5252
#use dynamic generated kernels
5353
# MESSAGE(STATUS "Build dynamic Bonaire kernels.")
5454
# MESSAGE(STATUS "Check OPENCL_OFFLINE_BUILD_BONAIRE_KERNEL to build kernls at compile-time. This will eliminates clBuildProgram() overhead and better kernel performance with certain driver.")
55-
add_definitions(-DCLBLAS_BONAIRE_DYNAMIC_KERNEL)
55+
add_definitions(-DCLBLAS_BONAIRE_DYNAMIC_KERNEL)
5656
#else()
5757
# MESSAGE(STATUS "Build static Bonaire kernels.")
5858
# MESSAGE(STATUS "Uncheck OPENCL_OFFLINE_BUILD_BONAIRE_KERNEL to build kernls at run-time")
59-
# MESSAGE(STATUS "Please ensure the presence of Bonaire device in the system. With certain driver/compiler flags, this might result in compile-time error.")
59+
# MESSAGE(STATUS "Please ensure the presence of Bonaire device in the system. With certain driver/compiler flags, this might result in compile-time error.")
6060
#endif( )
6161

6262
#if( NOT OPENCL_OFFLINE_BUILD_TAHITI_KERNEL )
6363
#use dynamic generated kernels
6464
# MESSAGE(STATUS "Build dynamic Tahiti kernels.")
6565
# MESSAGE(STATUS "Check OPENCL_OFFLINE_BUILD_TAHITI_KERNEL to build kernls at compile-time. This will eliminates clBuildProgram() overhead and better kernel performance with certain driver.")
66-
add_definitions(-DCLBLAS_TAHITI_DYNAMIC_KERNEL)
66+
add_definitions(-DCLBLAS_TAHITI_DYNAMIC_KERNEL)
6767
#else( )
6868
# MESSAGE(STATUS "Build static Tahiti kernels.")
6969
# MESSAGE(STATUS "Uncheck OPENCL_OFFLINE_BUILD_TAHITI_KERNEL to build kernls at run-time")
70-
# MESSAGE(STATUS "Please ensure the presence of Tahiti device in the system. With certain driver/compiler flags, this might result in compile-time error.")
70+
# MESSAGE(STATUS "Please ensure the presence of Tahiti device in the system. With certain driver/compiler flags, this might result in compile-time error.")
7171
#endif( )
7272

7373

@@ -135,8 +135,8 @@ if(NOT CMAKE_BUILD_TYPE)
135135
FORCE)
136136
endif()
137137

138-
# These variables are meant to contain string which should be appended to the installation paths
139-
# of library and executable binaries, respectively. They are meant to be user configurable/overridable.
138+
# These variables are meant to contain string which should be appended to the installation paths
139+
# of library and executable binaries, respectively. They are meant to be user configurable/overridable.
140140
set( SUFFIX_LIB_DEFAULT "" )
141141
set( SUFFIX_BIN_DEFAULT "" )
142142

@@ -170,7 +170,7 @@ if( MSVC_IDE )
170170
endif( )
171171

172172
# add the math library for Linux
173-
if( UNIX )
173+
if( UNIX )
174174
set(MATH_LIBRARY "m")
175175
endif()
176176

@@ -220,7 +220,7 @@ if( BUILD_TEST )
220220
else()
221221
message(WARNING "Cannot find acml.h")
222222
endif()
223-
223+
224224
if( UNIX )
225225
find_library(ACML_LIBRARIES acml_mp
226226
HINTS
@@ -238,7 +238,7 @@ if( BUILD_TEST )
238238
)
239239
mark_as_advanced(_acml_mv_library)
240240
endif( )
241-
241+
242242
if(WIN32)
243243
find_library(ACML_LIBRARIES libacml_mp_dll
244244
HINTS
@@ -248,7 +248,7 @@ if( BUILD_TEST )
248248
$ENV{ACML_ROOT}/${ACML_SUBDIR}/lib
249249
)
250250
endif( )
251-
251+
252252
if( NOT ACML_LIBRARIES )
253253
message(WARNING "Cannot find libacml")
254254
endif( )
@@ -272,8 +272,8 @@ find_package( OpenCL )
272272
set( Boost_USE_MULTITHREADED ON )
273273
set( Boost_USE_STATIC_LIBS ON )
274274
set( Boost_DETAILED_FAILURE_MSG ON )
275-
set( Boost_DEBUG ON )
276-
set( Boost_ADDITIONAL_VERSIONS "1.44.0" "1.44" "1.47.0" "1.47" )
275+
# set( Boost_DEBUG ON )
276+
set( Boost_ADDITIONAL_VERSIONS "1.44.0" "1.44" "1.47.0" "1.47" "1.60.0" "1.60" )
277277

278278
find_package( Boost 1.33.0 COMPONENTS program_options )
279279
message(STATUS "Boost_PROGRAM_OPTIONS_LIBRARY: ${Boost_PROGRAM_OPTIONS_LIBRARY}")
@@ -315,7 +315,7 @@ elseif( MSVC )
315315
# CMake sets huge stack frames for windows, for whatever reason. We go with compiler default.
316316
string( REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" )
317317
string( REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" )
318-
string( REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}" )
318+
string( REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}" )
319319
endif( )
320320

321321
if (WIN32)
@@ -328,13 +328,13 @@ add_definitions( -DCL_USE_DEPRECATED_OPENCL_1_1_APIS )
328328
configure_file( "${PROJECT_SOURCE_DIR}/clBLAS.version.h.in" "${PROJECT_BINARY_DIR}/include/clBLAS.version.h" )
329329

330330
# configure a header file to pass the CMake version settings to the source, and package the header files in the output archive
331-
install( FILES
332-
"clBLAS.h"
331+
install( FILES
332+
"clBLAS.h"
333333
"clAmdBlas.h"
334334
"clAmdBlas.version.h"
335335
"clBLAS-complex.h"
336336
"${PROJECT_BINARY_DIR}/include/clBLAS.version.h"
337-
DESTINATION
337+
DESTINATION
338338
"./include" )
339339

340340

@@ -359,7 +359,7 @@ if( BUILD_SAMPLE AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/samples" )
359359
add_subdirectory( samples )
360360
endif( )
361361

362-
# The build server is not supposed to build or package any of the tests; build server script will define this on the command line with
362+
# The build server is not supposed to build or package any of the tests; build server script will define this on the command line with
363363
# cmake -G "Visual Studio 10 Win64" -D BUILDSERVER:BOOL=ON ../..
364364
if( BUILD_TEST )
365365
if( IS_DIRECTORY "${PROJECT_SOURCE_DIR}/tests" )
@@ -394,7 +394,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/clBLASConfigVersion.cmake
394394
DESTINATION ${destdir})
395395

396396

397-
# The following code is setting variables to control the behavior of CPack to generate our
397+
# The following code is setting variables to control the behavior of CPack to generate our
398398
if( WIN32 )
399399
set( CPACK_SOURCE_GENERATOR "ZIP" )
400400
set( CPACK_GENERATOR "ZIP" )

src/tests/BlasBase.cpp

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ BlasBase::BlasBase()
4040
useNumCommandQueues_(false), numCommandQueues_(1),
4141
useAlpha_(false), useBeta_(false), useSeed_(false),
4242
useM_(false), useN_(false), useK_(false),
43-
M_(0), N_(0), K_(0),
43+
M_(0), N_(0), K_(0), devOrd_(0), platOrd_(0),
4444
useIncX_(false), useIncY_(false),
4545
incX_(0), incY_(0),
46-
useImages_(false), devType_(CL_DEVICE_TYPE_GPU), imageA_(0), imageB_(0)
46+
useImages_(false), devType_(CL_DEVICE_TYPE_DEFAULT), imageA_(0), imageB_(0)
4747
{
4848
memset(&alpha_, 0, sizeof(alpha_));
4949
memset(&beta_, 0, sizeof(beta_));
@@ -57,7 +57,7 @@ BlasBase::~BlasBase()
5757
/*
5858
* Teardown() is disabled due to troubles with test interrupting
5959
* with CTRL-C in windows. This occurs since after pressing of these keys
60-
* the OpenCL runtime is destroyed before calling global object destructors.
60+
* the OpenCL runtime is destroyed before calling global object destructor's.
6161
*/
6262
#if 0
6363
TearDown();
@@ -110,37 +110,16 @@ BlasBase::getDevice(cl_device_type type, const char* name,
110110
char *str;
111111
cl_platform_id *platforms, selPlatform = NULL;
112112
cl_uint nrPlatforms;
113-
cl_device_info devInfo;
114113

115114
nrPlatforms = getPlatforms(&platforms, &err);
116115

117116
if (error != NULL) {
118117
*error = CL_SUCCESS;
119118
}
120119

121-
/*
122-
* If device name is not specified, then any AMD device is preferable.
123-
* It there are not AMD devices of such a type presented in the system,
124-
* then get a device of another vendor. If this is the additional device
125-
* which is being tried to get, it must be supported by the same platform
126-
* as the primary device does.
127-
*/
128-
129-
if (name == NULL) {
130-
name = "Advanced Micro Devices, Inc.";
131-
devInfo = CL_DEVICE_VENDOR;
132-
}
133-
else {
134-
devInfo = CL_DEVICE_NAME;
135-
type = CL_DEVICE_TYPE_ALL;
136-
}
137-
138-
for (p = 0; p < nrPlatforms; p++) {
139-
cl_platform_id platform = platforms[p];
140-
err = clGetDeviceIDs(platform, type, 0, NULL, &nrDevices);
141-
if (err == CL_DEVICE_NOT_FOUND) {
142-
continue;
143-
}
120+
if (platOrd_ < nrPlatforms) {
121+
platform_ = platforms[platOrd_];
122+
err = clGetDeviceIDs(platform_, type, 0, NULL, &nrDevices);
144123
if (err != CL_SUCCESS) {
145124
if (error != NULL) {
146125
*error = err;
@@ -152,7 +131,7 @@ BlasBase::getDevice(cl_device_type type, const char* name,
152131
}
153132

154133
devices = new cl_device_id[nrDevices];
155-
err = clGetDeviceIDs(platform, type, nrDevices, devices, NULL);
134+
err = clGetDeviceIDs(platform_, type, nrDevices, devices, NULL);
156135
if (err != CL_SUCCESS) {
157136
if (error != NULL) {
158137
*error = err;
@@ -161,40 +140,15 @@ BlasBase::getDevice(cl_device_type type, const char* name,
161140
return NULL;
162141
}
163142

164-
for (i = 0; i < nrDevices; i++) {
165-
err = clGetDeviceInfo(devices[i], devInfo, 0, NULL, &sz);
166-
if (err != CL_SUCCESS) {
167-
continue;
168-
}
169-
str = new char[sz + 1];
170-
memset(str, 0, sz + 1);
171-
err = clGetDeviceInfo(devices[i], devInfo, sz, str, NULL);
172-
if (err != CL_SUCCESS) {
173-
delete[] str;
174-
continue;
175-
}
176-
if ((devInfo == CL_DEVICE_VENDOR) && (result == NULL) &&
177-
((platform_ == NULL) || (platform == platform_))) {
178-
179-
result = devices[i];
180-
selPlatform = platform;
181-
}
182-
printf("---- %s\n", str);
183-
if (strcmp(str, name) == 0) {
184-
//printf("---- %s\n", str);
185-
platform_ = platform;
186-
result = devices[i];
187-
delete[] str;
188-
break;
189-
}
190-
delete[] str;
143+
if (devOrd_ < nrDevices) {
144+
result = devices[devOrd_];
191145
}
192146
delete[] devices;
193147
devices = NULL;
194148
}
195-
196-
if (platform_ == NULL) {
197-
platform_ = selPlatform;
149+
else
150+
{
151+
platform_ = NULL;
198152
}
199153

200154
delete[] platforms;
@@ -211,6 +165,7 @@ BlasBase::SetUp()
211165
cl_device_id devices[2] = {NULL, NULL};
212166

213167
primaryDevice_ = getDevice(devType_, devName_, &err);
168+
214169
if ((err != CL_SUCCESS) || (primaryDevice_ == NULL)) {
215170
ASSERT_EQ(CL_SUCCESS, clGetPlatformIDs(1, &platform_, NULL));
216171
ASSERT_EQ(CL_SUCCESS,
@@ -243,7 +198,7 @@ BlasBase::SetUp()
243198
printf("SetUp: Created context %p\n", context_);
244199
#endif
245200
printf("SetUp: about to create command queues\n");
246-
for (i = 0; i < MAX_COMMAND_QUEUES; i++) {
201+
for (i = 0; i < numCommandQueues_; i++) {
247202
cl_device_id dev;
248203

249204
dev = (i == addDevQueueIdx) ? additionalDevice_ : primaryDevice_;
@@ -260,10 +215,9 @@ BlasBase::TearDown()
260215
{
261216
cl_uint i;
262217

263-
for (i = 0; i < MAX_COMMAND_QUEUES; i++) {
218+
for (i = 0; i < numCommandQueues_; i++) {
264219
clReleaseCommandQueue(commandQueues_[i]);
265220
}
266-
numCommandQueues_ = 1;
267221

268222
if (context_ != NULL) {
269223
clReleaseContext(context_);
@@ -282,20 +236,23 @@ BlasBase::initialized()
282236
}
283237

284238
bool
285-
BlasBase::setDeviceType(cl_device_type* devType, const char* devName)
239+
BlasBase::setDeviceType(const TestParams& params)
286240
{
287-
if (devType_ == *devType && devName_ == devName) {
241+
// Early exit if no device state changed
242+
if (devType_ == params.devType && devName_ == params.devName && platOrd_ == params.platOrd && devOrd_ == params.devOrd) {
288243
return true;
289244
}
290245

291-
devType_ = *devType;
292-
devName_ = devName;
246+
devType_ = params.devType;
247+
devName_ = params.devName;
248+
platOrd_ = params.platOrd;
249+
devOrd_ = params.devOrd;
293250
if (!initialized()) {
294251
return true;
295252
}
296253
TearDown();
297254
SetUp();
298-
*devType = devType_;
255+
299256
return initialized();
300257
}
301258

0 commit comments

Comments
 (0)