Skip to content

Commit 2283077

Browse files
author
Kent Knox
committed
Device selection for test-correctness and test-functional
test-functional and test-correctness with derivatives have been enhanced to be able to specify the device under test through the command line. The ordinals can be queried with clinfo program Externally available, comes in AMD SDK --platform-ord is an unsigned value picking the platform --device-ord is an unsigned value picking the device --device has been renamed to --device-type
1 parent ac1854d commit 2283077

File tree

6 files changed

+173
-172
lines changed

6 files changed

+173
-172
lines changed

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

src/tests/cmdline.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
static const char *testUsage =
2525
"<M N K> [--seed s] [--alpha a] [--beta b] "
2626
"[--alpha-real a] [--beta-real b] [--alpha-imag a] [--beta-imag b] "
27-
"[--use-images f] [--device dev] [--queues n]\n"
27+
"[--use-images f] [--platform ordinal] [--device string] [--device-ord ordinal] [--queues n]\n"
2828
"\n"
2929
"seed - seed for the random number generator"
3030
"\n"
@@ -42,8 +42,12 @@ static const char *testUsage =
4242
"\n"
4343
"use-images - allow the library to use images for computing"
4444
"\n"
45-
"device - device to run the test on, 'cpu' or 'gpu'(default)"
45+
"platform-ord - platform ordinal containing device of interest as reported by clinfo; (default 0)"
4646
"\n"
47+
"device-ord - device ordinal as device under test as reported by clinfo; (default 0)"
48+
"\n"
49+
"device-type - device type to filter device enumeration: 'default', 'all', 'gpu' or 'cpu'\n"
50+
"\t\tWith 'default', platform-ord && device-ord should both be 0\n"
4751
"queues - number of command queues to use"
4852
"\n"
4953
"Parameters defined through the command line are kept over the whole "
@@ -169,7 +173,7 @@ setMult(SetterArg *sarg)
169173
}
170174

171175
static int
172-
setDevice(SetterArg *sarg)
176+
setDevice_type(SetterArg *sarg)
173177
{
174178
if (!strcmp(sarg->arg, "cpu")) {
175179
sarg->params->devType = CL_DEVICE_TYPE_CPU;
@@ -181,11 +185,37 @@ setDevice(SetterArg *sarg)
181185
sarg->params->devName = NULL;
182186
return 0;
183187
}
188+
if (!strcmp(sarg->arg, "all")) {
189+
sarg->params->devType = CL_DEVICE_TYPE_ALL;
190+
sarg->params->devName = NULL;
191+
return 0;
192+
}
193+
if (!strcmp(sarg->arg, "default")) {
194+
sarg->params->devType = CL_DEVICE_TYPE_DEFAULT;
195+
sarg->params->devName = NULL;
196+
return 0;
197+
}
184198
sarg->params->devName = sarg->arg;
185199

186200
return 0;
187201
}
188202

203+
static int
204+
setDevice(SetterArg *sarg)
205+
{
206+
sarg->params->devOrd = atoi(sarg->arg);
207+
208+
return 0;
209+
}
210+
211+
static int
212+
setPlatform(SetterArg *sarg)
213+
{
214+
sarg->params->platOrd = atoi(sarg->arg);
215+
216+
return 0;
217+
}
218+
189219
static int
190220
setNumCommandQueues(SetterArg *sarg)
191221
{
@@ -202,7 +232,9 @@ static const CmdLineOpt opts[] = {
202232
{"alpha-imag", SET_ALPHA, setMult, MULT_ALPHA | MULT_IMAG_ONLY},
203233
{"beta-real", SET_BETA, setMult, MULT_BETA | MULT_REAL_ONLY},
204234
{"beta-imag", SET_BETA, setMult, MULT_BETA | MULT_IMAG_ONLY},
205-
{"device", SET_DEVICE_TYPE, setDevice, 0},
235+
{"platform-ord", SET_PLATFORM_ORD, setPlatform, 0 },
236+
{"device-type", SET_DEVICE_TYPE, setDevice_type, 0},
237+
{"device-ord", SET_DEVICE_ORD, setDevice, 0 },
206238
{"queues", SET_NUM_COMMAND_QUEUES, setNumCommandQueues, 0},
207239
};
208240
static const unsigned int nrOpts = sizeof(opts) / sizeof(CmdLineOpt);

src/tests/correctness/test-correctness.cpp

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,11 +3307,8 @@ INSTANTIATE_TEST_CASE_P(MultipleQueues, iAMAX, Combine(
33073307
int
33083308
main(int argc, char *argv[])
33093309
{
3310-
::clMath::BlasBase *base;
3311-
TestParams params;
33123310
int ret;
3313-
3314-
if( (argc > 1) && ( !strcmp(argv[1], "--test-help") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") ) )
3311+
if( (argc > 1) && ( !strcmp(argv[1], "--test-help") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ) )
33153312
{
33163313
printUsage("test-correctness");
33173314
::testing::InitGoogleTest(&argc, argv);
@@ -3331,58 +3328,63 @@ main(int argc, char *argv[])
33313328
}
33323329

33333330
::testing::InitGoogleTest(&argc, argv);
3334-
::std::cerr << "Initialize OpenCL and clblas..." << ::std::endl;
3335-
base = ::clMath::BlasBase::getInstance();
3331+
TestParams params;
3332+
params.optFlags = NO_FLAGS;
3333+
params.devType = CL_DEVICE_TYPE_ALL;
3334+
params.devName = NULL;
3335+
params.devOrd = 0;
3336+
params.platOrd = 0;
3337+
3338+
if (argc != 1) {
3339+
if (parseBlasCmdLineArgs(argc, argv, &params) != 0) {
3340+
printUsage(argv[0]);
3341+
return 1;
3342+
}
3343+
}
3344+
3345+
::std::cout << "Initialize default OpenCL and clblas..." << ::std::endl;
3346+
::clMath::BlasBase* base = ::clMath::BlasBase::getInstance( );
33363347
if (base == NULL) {
33373348
::std::cerr << "Fatal error, OpenCL or clblas initialization failed! "
3338-
"Leaving the test." << ::std::endl;
3349+
"Leaving the test." << ::std::endl;
33393350
return -1;
33403351
}
33413352

33423353
base->setSeed(DEFAULT_SEED);
33433354

3344-
if (argc != 1) {
3345-
params.optFlags = NO_FLAGS;
3346-
params.devType = CL_DEVICE_TYPE_GPU;
3347-
params.devName = NULL;
3348-
if (parseBlasCmdLineArgs(argc, argv, &params) != 0) {
3349-
printUsage(argv[0]);
3350-
return 1;
3351-
}
3352-
if (params.optFlags & SET_SEED) {
3353-
base->setSeed(params.seed);
3354-
}
3355-
if (params.optFlags & SET_ALPHA) {
3356-
base->setAlpha(params.alpha);
3357-
}
3358-
if (params.optFlags & SET_BETA) {
3359-
base->setBeta(params.beta);
3360-
}
3361-
if (params.optFlags & SET_M) {
3362-
base->setM(params.M);
3363-
}
3364-
if (params.optFlags & SET_N) {
3365-
base->setN(params.N);
3366-
}
3367-
if (params.optFlags & SET_K) {
3368-
base->setK(params.K);
3369-
}
3370-
if (params.optFlags & SET_INCX) {
3371-
base->setIncX(params.incx);
3372-
}
3373-
if (params.optFlags & SET_INCY) {
3374-
base->setIncY(params.incy);
3375-
}
3376-
if (params.optFlags & SET_DEVICE_TYPE) {
3377-
if (!base->setDeviceType(&params.devType, params.devName)) {
3378-
::std::cerr << "Fatal error, OpenCL or clblas "
3379-
"initialization failed! Leaving the test." <<
3380-
::std::endl;
3381-
return -1;
3382-
}
3383-
}
3384-
if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
3385-
base->setNumCommandQueues(params.numCommandQueues);
3355+
if (params.optFlags & SET_SEED) {
3356+
base->setSeed(params.seed);
3357+
}
3358+
if (params.optFlags & SET_ALPHA) {
3359+
base->setAlpha(params.alpha);
3360+
}
3361+
if (params.optFlags & SET_BETA) {
3362+
base->setBeta(params.beta);
3363+
}
3364+
if (params.optFlags & SET_M) {
3365+
base->setM(params.M);
3366+
}
3367+
if (params.optFlags & SET_N) {
3368+
base->setN(params.N);
3369+
}
3370+
if (params.optFlags & SET_K) {
3371+
base->setK(params.K);
3372+
}
3373+
if (params.optFlags & SET_INCX) {
3374+
base->setIncX(params.incx);
3375+
}
3376+
if (params.optFlags & SET_INCY) {
3377+
base->setIncY(params.incy);
3378+
}
3379+
if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
3380+
base->setNumCommandQueues(params.numCommandQueues);
3381+
}
3382+
if ((params.optFlags & SET_DEVICE_TYPE) || (params.optFlags & SET_PLATFORM_ORD) || (params.optFlags & SET_DEVICE_ORD)) {
3383+
if (!base->setDeviceType(params)) {
3384+
::std::cerr << "Fatal error, OpenCL or clblas "
3385+
"initialization failed! Leaving the test." <<
3386+
::std::endl;
3387+
return -1;
33863388
}
33873389
}
33883390

@@ -3407,7 +3409,7 @@ main(int argc, char *argv[])
34073409
}
34083410

34093411
/*
3410-
* Explicitely tell the singleton to release all resources,
3412+
* Explicitly tell singleton to release all resources,
34113413
* before we return from main.
34123414
*/
34133415
base->release( );

0 commit comments

Comments
 (0)