[clfft] 39/107: cleaning up the selection and printing of CL devices
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 30 18:06:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository clfft.
commit 533c3c3dea4d508b1485b5a106c9356908ee57e1
Author: bragadeesh <bragadeesh.natarajan at amd>
Date: Fri Mar 13 17:36:31 2015 -0500
cleaning up the selection and printing of CL devices
---
src/client/client.cpp | 35 +++++++++++++++++++++++------------
src/client/openCL.misc.cpp | 41 +++++++++++++++++------------------------
src/client/openCL.misc.h | 4 ++++
src/tests/cl_transform.h | 7 ++++---
src/tests/gtest_main.cpp | 35 ++++++++++++++++++++++-------------
src/tests/test_constants.cpp | 5 +++--
src/tests/test_constants.h | 7 ++++---
src/tests/unit_test.cpp | 5 +++--
8 files changed, 80 insertions(+), 59 deletions(-)
diff --git a/src/client/client.cpp b/src/client/client.cpp
index ef55afd..5eb3bfe 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -47,7 +47,7 @@ template < typename T >
int transform( size_t* lengths, const size_t *inStrides, const size_t *outStrides, size_t batch_size,
clfftLayout in_layout, clfftLayout out_layout,
clfftResultLocation place, clfftPrecision precision, clfftDirection dir,
- cl_device_type deviceType, cl_int deviceId, bool printInfo,
+ cl_device_type deviceType, cl_int deviceId, cl_int platformId, bool printInfo,
cl_uint command_queue_flags, cl_uint profile_count,
std::auto_ptr< clfftSetupData > setupData )
{
@@ -168,7 +168,7 @@ int transform( size_t* lengths, const size_t *inStrides, const size_t *outStride
// This call creates our openCL context and sets up our devices; expected to throw on error
size_of_input_buffers_in_bytes = fftBatchSize * sizeof( std::complex< T > );
- device_id = initializeCL( deviceType, deviceId, context, printInfo );
+ device_id = initializeCL( deviceType, deviceId, platformId, context, printInfo );
createOpenCLCommandQueue( context,
command_queue_flags, queue,
device_id,
@@ -214,7 +214,7 @@ int transform( size_t* lengths, const size_t *inStrides, const size_t *outStride
// This call creates our openCL context and sets up our devices; expected to throw on error
size_of_input_buffers_in_bytes = fftBatchSize * sizeof( T );
- device_id = initializeCL( deviceType, deviceId, context, printInfo );
+ device_id = initializeCL( deviceType, deviceId, platformId, context, printInfo );
createOpenCLCommandQueue( context,
command_queue_flags, queue,
device_id,
@@ -264,7 +264,7 @@ int transform( size_t* lengths, const size_t *inStrides, const size_t *outStride
// This call creates our openCL context and sets up our devices; expected to throw on error
size_of_input_buffers_in_bytes = fftBatchSize * sizeof( std::complex< T > );
- device_id = initializeCL( deviceType, deviceId, context, printInfo );
+ device_id = initializeCL( deviceType, deviceId, platformId, context, printInfo );
createOpenCLCommandQueue( context,
command_queue_flags, queue,
device_id,
@@ -298,7 +298,7 @@ int transform( size_t* lengths, const size_t *inStrides, const size_t *outStride
// This call creates our openCL context and sets up our devices; expected to throw on error
size_of_input_buffers_in_bytes = fftBatchSize * sizeof( T );
- device_id = initializeCL( deviceType, deviceId, context, printInfo );
+ device_id = initializeCL( deviceType, deviceId, platformId, context, printInfo );
createOpenCLCommandQueue( context,
command_queue_flags, queue,
device_id,
@@ -337,7 +337,7 @@ int transform( size_t* lengths, const size_t *inStrides, const size_t *outStride
// This call creates our openCL context and sets up our devices; expected to throw on error
size_of_input_buffers_in_bytes = fftBatchSize * sizeof( T );
- device_id = initializeCL( deviceType, deviceId, context, printInfo );
+ device_id = initializeCL( deviceType, deviceId, platformId, context, printInfo );
createOpenCLCommandQueue( context,
command_queue_flags, queue,
device_id,
@@ -753,7 +753,8 @@ int _tmain( int argc, _TCHAR* argv[] )
// OpenCL state
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
- cl_int deviceId = -1;
+ cl_int deviceId = 0;
+ cl_int platformId = 0;
// FFT state
@@ -783,11 +784,13 @@ int _tmain( int argc, _TCHAR* argv[] )
desc.add_options()
( "help,h", "produces this help message" )
( "version,v", "Print queryable version information from the clFFT library" )
- ( "clInfo,i", "Print queryable information of the OpenCL runtime" )
+ ( "clinfo,i", "Print queryable information of all the OpenCL runtimes and devices" )
+ ( "printChosen", "Print queryable information of the selected OpenCL runtime and device" )
( "gpu,g", "Force selection of OpenCL GPU devices only" )
( "cpu,c", "Force selection of OpenCL CPU devices only" )
( "all,a", "Force selection of all OpenCL devices (default)" )
- ( "device", po::value< cl_int >( &deviceId )->default_value( -1 ), "Force selection of a specific OpenCL device id as it is reported by clInfo" )
+ ( "platform", po::value< cl_int >( &platformId )->default_value( 0 ), "Select a specific OpenCL platform id as it is reported by clinfo" )
+ ( "device", po::value< cl_int >( &deviceId )->default_value( 0 ), "Select a specific OpenCL device id as it is reported by clinfo" )
( "outPlace,o", "Out of place FFT transform (default: in place)" )
( "double", "Double precision transform (default: single)" )
( "inv", "Backward transform (default: forward)" )
@@ -863,8 +866,16 @@ int _tmain( int argc, _TCHAR* argv[] )
deviceType = CL_DEVICE_TYPE_ALL;
}
+ if( vm.count( "clinfo" ) )
+ {
+ std::vector< cl_platform_id > platformInfos;
+ std::vector< std::vector< cl_device_id > > deviceInfos;
+ discoverCLPlatforms( deviceType, platformInfos, deviceInfos );
+ prettyPrintCLPlatforms(platformInfos, deviceInfos);
+ }
+
bool printInfo = false;
- if( vm.count( "clInfo" ) )
+ if( vm.count( "printChosen" ) )
{
printInfo = true;
}
@@ -972,9 +983,9 @@ int _tmain( int argc, _TCHAR* argv[] )
}
if( precision == CLFFT_SINGLE )
- transform<float>( lengths, iStrides, oStrides, batchSize, inLayout, outLayout, place, precision, dir, deviceType, deviceId, printInfo, command_queue_flags, profile_count, setupData );
+ transform<float>( lengths, iStrides, oStrides, batchSize, inLayout, outLayout, place, precision, dir, deviceType, deviceId, platformId, printInfo, command_queue_flags, profile_count, setupData );
else
- transform<double>( lengths, iStrides, oStrides, batchSize, inLayout, outLayout, place, precision, dir, deviceType, deviceId, printInfo, command_queue_flags, profile_count, setupData );
+ transform<double>( lengths, iStrides, oStrides, batchSize, inLayout, outLayout, place, precision, dir, deviceType, deviceId, platformId, printInfo, command_queue_flags, profile_count, setupData );
}
catch( std::exception& e )
{
diff --git a/src/client/openCL.misc.cpp b/src/client/openCL.misc.cpp
index aa1c7af..b369956 100644
--- a/src/client/openCL.misc.cpp
+++ b/src/client/openCL.misc.cpp
@@ -408,6 +408,7 @@ int discoverCLPlatforms( cl_device_type deviceType,
std::vector< cl_device_id > initializeCL( cl_device_type deviceType,
cl_int deviceId,
+ cl_int platformId,
cl_context& context,
bool printclInfo )
{
@@ -420,43 +421,35 @@ std::vector< cl_device_id > initializeCL( cl_device_type deviceType,
std::vector< cl_platform_id > platformInfos;
std::vector< std::vector< cl_device_id > > deviceInfos;
discoverCLPlatforms( deviceType, platformInfos, deviceInfos );
- if (printclInfo)
- {
- prettyPrintCLPlatforms(platformInfos, deviceInfos);
- }
- if (deviceId >= 0)
- {
- cl_int devNr = 0;
- // A specific deviceId is selected, so try to find it
- for (unsigned int i = 0; i < platformInfos.size(); ++i)
+ for (unsigned int i = 0; i < platformInfos.size(); ++i)
+ {
+ if(i == platformId)
{
for (unsigned int n = 0; n < deviceInfos[i].size(); ++n)
{
- if (deviceId == devNr)
+ if (n == deviceId)
{
platform = platformInfos[i];
devices[0] = deviceInfos[i][n];
- }
- devNr++;
- }
- }
- }
- else
- {
- // The default device (here: the last reported device) shall be selected
- for (unsigned int i = 0; i < platformInfos.size(); ++i)
- {
- for (unsigned int n = 0; n < deviceInfos[i].size(); ++n)
- {
- platform = platformInfos[i];
- devices[0] = deviceInfos[i][n];
+ if(printclInfo)
+ {
+ prettyPrintPlatformInfo(platform);
+ prettyPrintDeviceInfo(devices[0]);
+ }
+
+ break;
+ }
}
+
+ break;
}
}
+
+
// Do some error checking if we really selected a valid platform and a valid device
if (NULL == devices[0])
{
diff --git a/src/client/openCL.misc.h b/src/client/openCL.misc.h
index de4e6d0..07cc416 100644
--- a/src/client/openCL.misc.h
+++ b/src/client/openCL.misc.h
@@ -38,6 +38,9 @@ int discoverCLPlatforms( cl_device_type deviceType,
std::vector< cl_platform_id >& platforms,
std::vector< std::vector< cl_device_id > >& devices );
+void prettyPrintCLPlatforms(std::vector< cl_platform_id >& platforms,
+ std::vector< std::vector< cl_device_id > >& devices);
+
/*
* \brief OpenCL related initialization
* Create Context, Device list
@@ -46,6 +49,7 @@ int discoverCLPlatforms( cl_device_type deviceType,
*/
std::vector< cl_device_id > initializeCL( cl_device_type deviceType,
cl_int deviceId,
+ cl_int platformId,
cl_context& context,
bool printclInfo );
diff --git a/src/tests/cl_transform.h b/src/tests/cl_transform.h
index 71e62e4..776a318 100644
--- a/src/tests/cl_transform.h
+++ b/src/tests/cl_transform.h
@@ -263,8 +263,9 @@ public:
{
cl_context tempContext = NULL;
device_id = initializeCL(
- device_type,
- dev_id,
+ g_device_type,
+ g_device_id,
+ g_platform_id,
tempContext,
printInfo
);
@@ -646,7 +647,7 @@ public:
// we don't want to bog down the CPU with ginormous problem sizes
// so we chop the global memory way down to keep things manageable
- if( device_type == CL_DEVICE_TYPE_CPU )
+ if( g_device_type == CL_DEVICE_TYPE_CPU )
{
global_memory_size /= 8;
}
diff --git a/src/tests/gtest_main.cpp b/src/tests/gtest_main.cpp
index 6fc648f..8fb9548 100644
--- a/src/tests/gtest_main.cpp
+++ b/src/tests/gtest_main.cpp
@@ -57,9 +57,9 @@ void inline BSF (unsigned long * index, size_t & mask) {
bool suppress_output = false;
// Globals that user can set on the command line, that need to be passed down to unit tests
-cl_device_type device_type = CL_DEVICE_TYPE_GPU;
-cl_uint device_gpu_list = ~0x0;
-cl_int dev_id = -1;
+cl_device_type g_device_type = CL_DEVICE_TYPE_ALL;
+cl_int g_device_id = 0;
+cl_int g_platform_id = 0;
bool comparison_type = root_mean_square;
@@ -105,8 +105,10 @@ int main( int argc, char **argv )
( "noVersion", "Don't print version information from the clFFT library" )
( "noInfoCL", "Don't print information from the OpenCL runtime" )
( "cpu,c", "Run tests on a CPU device" )
- ( "gpu,g", "Run tests on a GPU device (default)" )
- ("device", po::value< cl_int >(&dev_id)->default_value(-1), "Run tests on a specific OpenCL device id as reported by clInfo")
+ ( "gpu,g", "Run tests on a GPU device" )
+ ( "all,a", "Run tests on any device type (default)" )
+ ( "platform", po::value< cl_int >( &g_platform_id )->default_value( 0 ), "Select a specific OpenCL platform id as it is reported by clinfo" )
+ ( "device", po::value< cl_int >( &g_device_id )->default_value( 0 ), "Select a specific OpenCL device id as it is reported by clinfo" )
( "pointwise,p", "Do a pointwise comparison to determine test correctness (default: use root mean square)" )
( "tolerance,t", po::value< float >( &tolerance )->default_value( 0.001f ), "tolerance level to use when determining test pass/fail" )
( "numRandom,r", po::value< size_t >( &number_of_random_tests )->default_value( 2000 ), "number of random tests to run" )
@@ -128,25 +130,32 @@ int main( int argc, char **argv )
std::cout << std::endl;
size_t mutex = ((vm.count( "gpu" ) > 0) ? 1 : 0)
- | ((vm.count( "cpu" ) > 0) ? 2 : 0);
+ | ((vm.count( "cpu" ) > 0) ? 2 : 0)
+ | ((vm.count( "all" ) > 0) ? 4 : 0);
if ((mutex & (mutex-1)) != 0) {
terr << _T("You have selected mutually-exclusive OpenCL device options:") << std::endl;
- if (vm.count ( "cpu" ) > 0) terr << _T(" cpu, c Run tests on a CPU device" ) << std::endl;
- if (vm.count ( "gpu" ) > 0) terr << _T(" gpu, g Run tests on a GPU device" ) << std::endl;
+ if (vm.count ( "gpu" ) > 0) terr << _T(" gpu,g Force selection of OpenCL GPU devices only" ) << std::endl;
+ if (vm.count ( "cpu" ) > 0) terr << _T(" cpu,c Force selection of OpenCL CPU devices only" ) << std::endl;
+ if (vm.count ( "all" ) > 0) terr << _T(" all,a Force selection of all OpenCL devices (default)" ) << std::endl;
return 1;
}
+ if( vm.count( "gpu" ) )
+ {
+ g_device_type = CL_DEVICE_TYPE_GPU;
+ }
+
if( vm.count( "cpu" ) )
{
- device_type = CL_DEVICE_TYPE_CPU;
+ g_device_type = CL_DEVICE_TYPE_CPU;
}
- if( vm.count( "gpu" ) )
+ if( vm.count( "all" ) )
{
- device_type = CL_DEVICE_TYPE_GPU;
- device_gpu_list = ~0;
+ g_device_type = CL_DEVICE_TYPE_ALL;
}
+
// Print version by default
if( !vm.count( "noVersion" ) )
{
@@ -171,7 +180,7 @@ int main( int argc, char **argv )
cl_context tempContext = NULL;
cl_command_queue tempQueue = NULL;
cl_event tempEvent = NULL;
- std::vector< cl_device_id > device_id = ::initializeCL(device_type, dev_id, tempContext, true);
+ ::initializeCL(g_device_type, g_device_id, g_platform_id, tempContext, true);
::cleanupCL( &tempContext, &tempQueue, 0, NULL, 0, NULL, &tempEvent );
}
diff --git a/src/tests/test_constants.cpp b/src/tests/test_constants.cpp
index cbaf790..17d04cd 100644
--- a/src/tests/test_constants.cpp
+++ b/src/tests/test_constants.cpp
@@ -87,8 +87,9 @@ size_t max_mem_available_on_cl_device(size_t device_index) {
std::vector< cl_device_id > device_id;
cl_context tempContext = NULL;
device_id = initializeCL(
- device_type,
- dev_id,
+ g_device_type,
+ (cl_int)device_index,
+ g_platform_id,
tempContext,
false
);
diff --git a/src/tests/test_constants.h b/src/tests/test_constants.h
index 95699f5..bf94606 100644
--- a/src/tests/test_constants.h
+++ b/src/tests/test_constants.h
@@ -61,9 +61,10 @@ const double magnitude_lower_limit = 1.0E-100;
extern float tolerance;
-extern cl_device_type device_type;
-extern cl_uint device_gpu_list;
-extern cl_int dev_id;
+extern cl_device_type g_device_type;
+//extern cl_uint device_gpu_list;
+extern cl_int g_device_id;
+extern cl_int g_platform_id;
extern size_t number_of_random_tests;
extern time_t random_test_parameter_seed;
diff --git a/src/tests/unit_test.cpp b/src/tests/unit_test.cpp
index 671faab..f25829f 100644
--- a/src/tests/unit_test.cpp
+++ b/src/tests/unit_test.cpp
@@ -19,6 +19,7 @@
#include <complex>
#include "clFFT.h"
#include "../client/openCL.misc.h"
+#include "test_constants.h"
class clfft_UnitTest : public ::testing::Test {
protected:
@@ -29,12 +30,12 @@ protected:
lengths[ 0 ] = 32;
lengths[ 1 ] = 32;
lengths[ 2 ] = 32;
- cl_int devId = -1;
+
commandQueueFlags = 0;
size_t memSizeBytes = lengths[ 0 ] * lengths[ 1 ] * lengths[ 2 ] * sizeof( std::complex< float > );
- device_id = initializeCL( CL_DEVICE_TYPE_CPU, devId, context, printInfo );
+ device_id = initializeCL( g_device_type, g_device_id, g_platform_id, context, printInfo );
createOpenCLCommandQueue( context,
commandQueueFlags,
queue,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clfft.git
More information about the debian-science-commits
mailing list