[clblas] 45/75: Device selection for test-correctness and test-functional
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jan 24 23:30:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository clblas.
commit 22830771478415fc5236f077967b98872967733a
Author: Kent Knox <kent.knox at amd>
Date: Mon Apr 18 17:26:05 2016 -0500
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
---
src/tests/BlasBase.cpp | 89 +++++++------------------
src/tests/cmdline.c | 40 +++++++++--
src/tests/correctness/test-correctness.cpp | 102 +++++++++++++++--------------
src/tests/functional/test-functional.cpp | 100 ++++++++++++++--------------
src/tests/include/BlasBase.h | 8 ++-
src/tests/include/cmdline.h | 6 +-
6 files changed, 173 insertions(+), 172 deletions(-)
diff --git a/src/tests/BlasBase.cpp b/src/tests/BlasBase.cpp
index c012803..73a6f5e 100644
--- a/src/tests/BlasBase.cpp
+++ b/src/tests/BlasBase.cpp
@@ -40,10 +40,10 @@ BlasBase::BlasBase()
useNumCommandQueues_(false), numCommandQueues_(1),
useAlpha_(false), useBeta_(false), useSeed_(false),
useM_(false), useN_(false), useK_(false),
- M_(0), N_(0), K_(0),
+ M_(0), N_(0), K_(0), devOrd_(0), platOrd_(0),
useIncX_(false), useIncY_(false),
incX_(0), incY_(0),
- useImages_(false), devType_(CL_DEVICE_TYPE_GPU), imageA_(0), imageB_(0)
+ useImages_(false), devType_(CL_DEVICE_TYPE_DEFAULT), imageA_(0), imageB_(0)
{
memset(&alpha_, 0, sizeof(alpha_));
memset(&beta_, 0, sizeof(beta_));
@@ -57,7 +57,7 @@ BlasBase::~BlasBase()
/*
* Teardown() is disabled due to troubles with test interrupting
* with CTRL-C in windows. This occurs since after pressing of these keys
- * the OpenCL runtime is destroyed before calling global object destructors.
+ * the OpenCL runtime is destroyed before calling global object destructor's.
*/
#if 0
TearDown();
@@ -110,7 +110,6 @@ BlasBase::getDevice(cl_device_type type, const char* name,
char *str;
cl_platform_id *platforms, selPlatform = NULL;
cl_uint nrPlatforms;
- cl_device_info devInfo;
nrPlatforms = getPlatforms(&platforms, &err);
@@ -118,29 +117,9 @@ BlasBase::getDevice(cl_device_type type, const char* name,
*error = CL_SUCCESS;
}
- /*
- * If device name is not specified, then any AMD device is preferable.
- * It there are not AMD devices of such a type presented in the system,
- * then get a device of another vendor. If this is the additional device
- * which is being tried to get, it must be supported by the same platform
- * as the primary device does.
- */
-
- if (name == NULL) {
- name = "Advanced Micro Devices, Inc.";
- devInfo = CL_DEVICE_VENDOR;
- }
- else {
- devInfo = CL_DEVICE_NAME;
- type = CL_DEVICE_TYPE_ALL;
- }
-
- for (p = 0; p < nrPlatforms; p++) {
- cl_platform_id platform = platforms[p];
- err = clGetDeviceIDs(platform, type, 0, NULL, &nrDevices);
- if (err == CL_DEVICE_NOT_FOUND) {
- continue;
- }
+ if (platOrd_ < nrPlatforms) {
+ platform_ = platforms[platOrd_];
+ err = clGetDeviceIDs(platform_, type, 0, NULL, &nrDevices);
if (err != CL_SUCCESS) {
if (error != NULL) {
*error = err;
@@ -152,7 +131,7 @@ BlasBase::getDevice(cl_device_type type, const char* name,
}
devices = new cl_device_id[nrDevices];
- err = clGetDeviceIDs(platform, type, nrDevices, devices, NULL);
+ err = clGetDeviceIDs(platform_, type, nrDevices, devices, NULL);
if (err != CL_SUCCESS) {
if (error != NULL) {
*error = err;
@@ -161,40 +140,15 @@ BlasBase::getDevice(cl_device_type type, const char* name,
return NULL;
}
- for (i = 0; i < nrDevices; i++) {
- err = clGetDeviceInfo(devices[i], devInfo, 0, NULL, &sz);
- if (err != CL_SUCCESS) {
- continue;
- }
- str = new char[sz + 1];
- memset(str, 0, sz + 1);
- err = clGetDeviceInfo(devices[i], devInfo, sz, str, NULL);
- if (err != CL_SUCCESS) {
- delete[] str;
- continue;
- }
- if ((devInfo == CL_DEVICE_VENDOR) && (result == NULL) &&
- ((platform_ == NULL) || (platform == platform_))) {
-
- result = devices[i];
- selPlatform = platform;
- }
- printf("---- %s\n", str);
- if (strcmp(str, name) == 0) {
- //printf("---- %s\n", str);
- platform_ = platform;
- result = devices[i];
- delete[] str;
- break;
- }
- delete[] str;
+ if (devOrd_ < nrDevices) {
+ result = devices[devOrd_];
}
delete[] devices;
devices = NULL;
}
-
- if (platform_ == NULL) {
- platform_ = selPlatform;
+ else
+ {
+ platform_ = NULL;
}
delete[] platforms;
@@ -211,6 +165,7 @@ BlasBase::SetUp()
cl_device_id devices[2] = {NULL, NULL};
primaryDevice_ = getDevice(devType_, devName_, &err);
+
if ((err != CL_SUCCESS) || (primaryDevice_ == NULL)) {
ASSERT_EQ(CL_SUCCESS, clGetPlatformIDs(1, &platform_, NULL));
ASSERT_EQ(CL_SUCCESS,
@@ -243,7 +198,7 @@ BlasBase::SetUp()
printf("SetUp: Created context %p\n", context_);
#endif
printf("SetUp: about to create command queues\n");
- for (i = 0; i < MAX_COMMAND_QUEUES; i++) {
+ for (i = 0; i < numCommandQueues_; i++) {
cl_device_id dev;
dev = (i == addDevQueueIdx) ? additionalDevice_ : primaryDevice_;
@@ -260,10 +215,9 @@ BlasBase::TearDown()
{
cl_uint i;
- for (i = 0; i < MAX_COMMAND_QUEUES; i++) {
+ for (i = 0; i < numCommandQueues_; i++) {
clReleaseCommandQueue(commandQueues_[i]);
}
- numCommandQueues_ = 1;
if (context_ != NULL) {
clReleaseContext(context_);
@@ -282,20 +236,23 @@ BlasBase::initialized()
}
bool
-BlasBase::setDeviceType(cl_device_type* devType, const char* devName)
+BlasBase::setDeviceType(const TestParams& params)
{
- if (devType_ == *devType && devName_ == devName) {
+ // Early exit if no device state changed
+ if (devType_ == params.devType && devName_ == params.devName && platOrd_ == params.platOrd && devOrd_ == params.devOrd) {
return true;
}
- devType_ = *devType;
- devName_ = devName;
+ devType_ = params.devType;
+ devName_ = params.devName;
+ platOrd_ = params.platOrd;
+ devOrd_ = params.devOrd;
if (!initialized()) {
return true;
}
TearDown();
SetUp();
- *devType = devType_;
+
return initialized();
}
diff --git a/src/tests/cmdline.c b/src/tests/cmdline.c
index 259a9f2..c9519cc 100644
--- a/src/tests/cmdline.c
+++ b/src/tests/cmdline.c
@@ -24,7 +24,7 @@
static const char *testUsage =
"<M N K> [--seed s] [--alpha a] [--beta b] "
"[--alpha-real a] [--beta-real b] [--alpha-imag a] [--beta-imag b] "
- "[--use-images f] [--device dev] [--queues n]\n"
+ "[--use-images f] [--platform ordinal] [--device string] [--device-ord ordinal] [--queues n]\n"
"\n"
"seed - seed for the random number generator"
"\n"
@@ -42,8 +42,12 @@ static const char *testUsage =
"\n"
"use-images - allow the library to use images for computing"
"\n"
- "device - device to run the test on, 'cpu' or 'gpu'(default)"
+ "platform-ord - platform ordinal containing device of interest as reported by clinfo; (default 0)"
"\n"
+ "device-ord - device ordinal as device under test as reported by clinfo; (default 0)"
+ "\n"
+ "device-type - device type to filter device enumeration: 'default', 'all', 'gpu' or 'cpu'\n"
+ "\t\tWith 'default', platform-ord && device-ord should both be 0\n"
"queues - number of command queues to use"
"\n"
"Parameters defined through the command line are kept over the whole "
@@ -169,7 +173,7 @@ setMult(SetterArg *sarg)
}
static int
-setDevice(SetterArg *sarg)
+setDevice_type(SetterArg *sarg)
{
if (!strcmp(sarg->arg, "cpu")) {
sarg->params->devType = CL_DEVICE_TYPE_CPU;
@@ -181,12 +185,38 @@ setDevice(SetterArg *sarg)
sarg->params->devName = NULL;
return 0;
}
+ if (!strcmp(sarg->arg, "all")) {
+ sarg->params->devType = CL_DEVICE_TYPE_ALL;
+ sarg->params->devName = NULL;
+ return 0;
+ }
+ if (!strcmp(sarg->arg, "default")) {
+ sarg->params->devType = CL_DEVICE_TYPE_DEFAULT;
+ sarg->params->devName = NULL;
+ return 0;
+ }
sarg->params->devName = sarg->arg;
return 0;
}
static int
+setDevice(SetterArg *sarg)
+{
+ sarg->params->devOrd = atoi(sarg->arg);
+
+ return 0;
+}
+
+static int
+setPlatform(SetterArg *sarg)
+{
+ sarg->params->platOrd = atoi(sarg->arg);
+
+ return 0;
+}
+
+static int
setNumCommandQueues(SetterArg *sarg)
{
sarg->params->numCommandQueues = atoi(sarg->arg);
@@ -202,7 +232,9 @@ static const CmdLineOpt opts[] = {
{"alpha-imag", SET_ALPHA, setMult, MULT_ALPHA | MULT_IMAG_ONLY},
{"beta-real", SET_BETA, setMult, MULT_BETA | MULT_REAL_ONLY},
{"beta-imag", SET_BETA, setMult, MULT_BETA | MULT_IMAG_ONLY},
- {"device", SET_DEVICE_TYPE, setDevice, 0},
+ {"platform-ord", SET_PLATFORM_ORD, setPlatform, 0 },
+ {"device-type", SET_DEVICE_TYPE, setDevice_type, 0},
+ {"device-ord", SET_DEVICE_ORD, setDevice, 0 },
{"queues", SET_NUM_COMMAND_QUEUES, setNumCommandQueues, 0},
};
static const unsigned int nrOpts = sizeof(opts) / sizeof(CmdLineOpt);
diff --git a/src/tests/correctness/test-correctness.cpp b/src/tests/correctness/test-correctness.cpp
index 67ac971..3b80a03 100644
--- a/src/tests/correctness/test-correctness.cpp
+++ b/src/tests/correctness/test-correctness.cpp
@@ -3307,11 +3307,8 @@ INSTANTIATE_TEST_CASE_P(MultipleQueues, iAMAX, Combine(
int
main(int argc, char *argv[])
{
- ::clMath::BlasBase *base;
- TestParams params;
int ret;
-
- if( (argc > 1) && ( !strcmp(argv[1], "--test-help") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") ) )
+ if( (argc > 1) && ( !strcmp(argv[1], "--test-help") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ) )
{
printUsage("test-correctness");
::testing::InitGoogleTest(&argc, argv);
@@ -3331,58 +3328,63 @@ main(int argc, char *argv[])
}
::testing::InitGoogleTest(&argc, argv);
- ::std::cerr << "Initialize OpenCL and clblas..." << ::std::endl;
- base = ::clMath::BlasBase::getInstance();
+ TestParams params;
+ params.optFlags = NO_FLAGS;
+ params.devType = CL_DEVICE_TYPE_ALL;
+ params.devName = NULL;
+ params.devOrd = 0;
+ params.platOrd = 0;
+
+ if (argc != 1) {
+ if (parseBlasCmdLineArgs(argc, argv, ¶ms) != 0) {
+ printUsage(argv[0]);
+ return 1;
+ }
+ }
+
+ ::std::cout << "Initialize default OpenCL and clblas..." << ::std::endl;
+ ::clMath::BlasBase* base = ::clMath::BlasBase::getInstance( );
if (base == NULL) {
::std::cerr << "Fatal error, OpenCL or clblas initialization failed! "
- "Leaving the test." << ::std::endl;
+ "Leaving the test." << ::std::endl;
return -1;
}
base->setSeed(DEFAULT_SEED);
- if (argc != 1) {
- params.optFlags = NO_FLAGS;
- params.devType = CL_DEVICE_TYPE_GPU;
- params.devName = NULL;
- if (parseBlasCmdLineArgs(argc, argv, ¶ms) != 0) {
- printUsage(argv[0]);
- return 1;
- }
- if (params.optFlags & SET_SEED) {
- base->setSeed(params.seed);
- }
- if (params.optFlags & SET_ALPHA) {
- base->setAlpha(params.alpha);
- }
- if (params.optFlags & SET_BETA) {
- base->setBeta(params.beta);
- }
- if (params.optFlags & SET_M) {
- base->setM(params.M);
- }
- if (params.optFlags & SET_N) {
- base->setN(params.N);
- }
- if (params.optFlags & SET_K) {
- base->setK(params.K);
- }
- if (params.optFlags & SET_INCX) {
- base->setIncX(params.incx);
- }
- if (params.optFlags & SET_INCY) {
- base->setIncY(params.incy);
- }
- if (params.optFlags & SET_DEVICE_TYPE) {
- if (!base->setDeviceType(¶ms.devType, params.devName)) {
- ::std::cerr << "Fatal error, OpenCL or clblas "
- "initialization failed! Leaving the test." <<
- ::std::endl;
- return -1;
- }
- }
- if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
- base->setNumCommandQueues(params.numCommandQueues);
+ if (params.optFlags & SET_SEED) {
+ base->setSeed(params.seed);
+ }
+ if (params.optFlags & SET_ALPHA) {
+ base->setAlpha(params.alpha);
+ }
+ if (params.optFlags & SET_BETA) {
+ base->setBeta(params.beta);
+ }
+ if (params.optFlags & SET_M) {
+ base->setM(params.M);
+ }
+ if (params.optFlags & SET_N) {
+ base->setN(params.N);
+ }
+ if (params.optFlags & SET_K) {
+ base->setK(params.K);
+ }
+ if (params.optFlags & SET_INCX) {
+ base->setIncX(params.incx);
+ }
+ if (params.optFlags & SET_INCY) {
+ base->setIncY(params.incy);
+ }
+ if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
+ base->setNumCommandQueues(params.numCommandQueues);
+ }
+ if ((params.optFlags & SET_DEVICE_TYPE) || (params.optFlags & SET_PLATFORM_ORD) || (params.optFlags & SET_DEVICE_ORD)) {
+ if (!base->setDeviceType(params)) {
+ ::std::cerr << "Fatal error, OpenCL or clblas "
+ "initialization failed! Leaving the test." <<
+ ::std::endl;
+ return -1;
}
}
@@ -3407,7 +3409,7 @@ main(int argc, char *argv[])
}
/*
- * Explicitely tell the singleton to release all resources,
+ * Explicitly tell singleton to release all resources,
* before we return from main.
*/
base->release( );
diff --git a/src/tests/functional/test-functional.cpp b/src/tests/functional/test-functional.cpp
index c147b77..d5d0d4e 100644
--- a/src/tests/functional/test-functional.cpp
+++ b/src/tests/functional/test-functional.cpp
@@ -24,66 +24,69 @@
int
main(int argc, char *argv[])
{
- ::clMath::BlasBase *base;
- TestParams params;
int ret;
-
- if ((argc > 1) && !strcmp(argv[1], "--test-help")) {
+ if ((argc > 1) && (!strcmp(argv[1], "--test-help") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
printUsage("test-functional");
+ ::testing::InitGoogleTest(&argc, argv);
return 0;
}
+ TestParams params;
+ params.optFlags = NO_FLAGS;
+ params.devType = CL_DEVICE_TYPE_ALL;
+ params.devName = NULL;
+ params.devOrd = 0;
+ params.platOrd = 0;
+
+ if (argc != 1) {
+ if (parseBlasCmdLineArgs(argc, argv, ¶ms) != 0) {
+ printUsage(argv[0]);
+ return 1;
+ }
+ }
+
::testing::InitGoogleTest(&argc, argv);
- ::std::cerr << "Initialize OpenCL and clblas..." << ::std::endl;
- base = ::clMath::BlasBase::getInstance();
+ ::std::cout << "Initialize default OpenCL and clblas..." << ::std::endl;
+ ::clMath::BlasBase *base = ::clMath::BlasBase::getInstance();
if (base == NULL) {
::std::cerr << "Fatal error, OpenCL or clblas initialization failed! "
"Leaving the test." << ::std::endl;
return -1;
}
- if (argc != 1) {
- params.optFlags = NO_FLAGS;
- params.devType = CL_DEVICE_TYPE_GPU;
- params.devName = NULL;
- if (parseBlasCmdLineArgs(argc, argv, ¶ms) != 0) {
- printUsage(argv[0]);
- return 1;
- }
- if (params.optFlags & SET_SEED) {
- base->setSeed(params.seed);
- }
- if (params.optFlags & SET_ALPHA) {
- base->setAlpha(params.alpha);
- }
- if (params.optFlags & SET_BETA) {
- base->setBeta(params.beta);
- }
- if (params.optFlags & SET_M) {
- base->setM(params.M);
- }
- if (params.optFlags & SET_N) {
- base->setN(params.N);
- }
- if (params.optFlags & SET_K) {
- base->setK(params.K);
- }
- if (params.optFlags & SET_INCX) {
- base->setIncX(params.incx);
- }
- if (params.optFlags & SET_INCY) {
- base->setIncY(params.incy);
- }
- if (params.optFlags & SET_DEVICE_TYPE) {
- if (!base->setDeviceType(¶ms.devType, params.devName)) {
- ::std::cerr << "Fatal error, OpenCL or clblas "
- "initialization failed! Leaving the test." <<
- ::std::endl;
- return -1;
- }
- }
- if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
- base->setNumCommandQueues(params.numCommandQueues);
+ if (params.optFlags & SET_SEED) {
+ base->setSeed(params.seed);
+ }
+ if (params.optFlags & SET_ALPHA) {
+ base->setAlpha(params.alpha);
+ }
+ if (params.optFlags & SET_BETA) {
+ base->setBeta(params.beta);
+ }
+ if (params.optFlags & SET_M) {
+ base->setM(params.M);
+ }
+ if (params.optFlags & SET_N) {
+ base->setN(params.N);
+ }
+ if (params.optFlags & SET_K) {
+ base->setK(params.K);
+ }
+ if (params.optFlags & SET_INCX) {
+ base->setIncX(params.incx);
+ }
+ if (params.optFlags & SET_INCY) {
+ base->setIncY(params.incy);
+ }
+ if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
+ base->setNumCommandQueues(params.numCommandQueues);
+ }
+ if ((params.optFlags & SET_DEVICE_TYPE) || (params.optFlags & SET_PLATFORM_ORD) || (params.optFlags & SET_DEVICE_ORD)) {
+ if (!base->setDeviceType( params )) {
+ ::std::cerr << "Fatal error, OpenCL or clblas "
+ "initialization failed! Leaving the test." <<
+ ::std::endl;
+ return -1;
}
}
@@ -101,6 +104,7 @@ main(int argc, char *argv[])
}
*/
+ base->printEnvInfo();
ret = RUN_ALL_TESTS();
if (base->useImages()) {
diff --git a/src/tests/include/BlasBase.h b/src/tests/include/BlasBase.h
index bcde47f..9245439 100644
--- a/src/tests/include/BlasBase.h
+++ b/src/tests/include/BlasBase.h
@@ -61,6 +61,8 @@ private:
cl_device_id additionalDevice_;
cl_context context_;
cl_command_queue commandQueues_[MAX_COMMAND_QUEUES];
+ size_t devOrd_;
+ size_t platOrd_;
bool useNumCommandQueues_;
cl_uint numCommandQueues_;
@@ -85,7 +87,7 @@ private:
cl_ulong imageA_;
cl_ulong imageB_;
- BlasBase();
+ BlasBase( );
~BlasBase();
BlasBase(const BlasBase &); // intentionally undefined
BlasBase & operator=(const BlasBase &); // intentionally undefined
@@ -101,7 +103,7 @@ private:
int primAdd);
public:
- static BlasBase* getInstance();
+ static BlasBase* getInstance( );
cl_context context()
{
@@ -197,7 +199,7 @@ public:
useImages_ = (value != 0);
}
- bool setDeviceType(cl_device_type* devType, const char* devName);
+ bool setDeviceType(const TestParams& params );
cl_mem createEnqueueBuffer(const void *data, size_t matrSize, size_t off,
cl_mem_flags mode);
cl_mem readBuffer(void *ptr, size_t off, size_t size);
diff --git a/src/tests/include/cmdline.h b/src/tests/include/cmdline.h
index addb929..68ddfba 100644
--- a/src/tests/include/cmdline.h
+++ b/src/tests/include/cmdline.h
@@ -42,7 +42,9 @@ typedef enum SetoptFlags {
SET_DEVICE_TYPE = (1 << 7),
SET_INCX = (1 << 8),
SET_INCY = (1 << 9),
- SET_NUM_COMMAND_QUEUES = (1 << 10)
+ SET_NUM_COMMAND_QUEUES = (1 << 10),
+ SET_DEVICE_ORD = (1 << 11),
+ SET_PLATFORM_ORD = (1 << 12),
} SetoptFlags;
typedef struct TestParams {
@@ -83,6 +85,8 @@ typedef struct TestParams {
int useImages;
cl_device_type devType;
const char* devName;
+ size_t devOrd;
+ size_t platOrd;
cl_uint numCommandQueues;
SetoptFlags optFlags;
} TestParams;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clblas.git
More information about the debian-science-commits
mailing list