This commit is contained in:
Alexander Alekhin 2013-12-25 18:41:24 +04:00
parent e49065b1dc
commit 217b2282b8
2 changed files with 37 additions and 50 deletions

View File

@ -85,7 +85,7 @@ template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8> class AutoBuffer
public: public:
typedef _Tp value_type; typedef _Tp value_type;
//! the default contructor //! the default constructor
AutoBuffer(); AutoBuffer();
//! constructor taking the real buffer size //! constructor taking the real buffer size
AutoBuffer(size_t _size); AutoBuffer(size_t _size);

View File

@ -1919,30 +1919,30 @@ inline cl_int getStringInfo(Functor f, ObjectType obj, cl_uint name, std::string
param.clear(); param.clear();
if (required > 0) if (required > 0)
{ {
std::vector<char> buf(required + 1, char(0)); AutoBuffer<char> buf(required + 1);
err = f(obj, name, required, &buf[0], NULL); char* ptr = (char*)buf; // cleanup is not needed
err = f(obj, name, required, ptr, NULL);
if (err != CL_SUCCESS) if (err != CL_SUCCESS)
return err; return err;
param = &buf[0]; param = ptr;
} }
return CL_SUCCESS; return CL_SUCCESS;
}; };
static void split(const std::string &s, char delim, std::vector<std::string> &elems) { static void split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s); elems.clear();
if (s.size() == 0)
return;
std::istringstream ss(s);
std::string item; std::string item;
while (std::getline(ss, item, delim)) { while (!ss.eof())
{
std::getline(ss, item, delim);
elems.push_back(item); elems.push_back(item);
} }
} }
static std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
// Layout: <Platform>:<CPU|GPU|ACCELERATOR|nothing=GPU/CPU>:<deviceName> // Layout: <Platform>:<CPU|GPU|ACCELERATOR|nothing=GPU/CPU>:<deviceName>
// Sample: AMD:GPU: // Sample: AMD:GPU:
// Sample: AMD:GPU:Tahiti // Sample: AMD:GPU:Tahiti
@ -1950,40 +1950,23 @@ static std::vector<std::string> split(const std::string &s, char delim) {
static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr, static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr,
std::string& platform, std::vector<std::string>& deviceTypes, std::string& deviceNameOrID) std::string& platform, std::vector<std::string>& deviceTypes, std::string& deviceNameOrID)
{ {
std::string deviceTypesStr; std::vector<std::string> parts;
size_t p0 = configurationStr.find(':'); split(configurationStr, ':', parts);
if (p0 != std::string::npos) if (parts.size() > 3)
{
size_t p1 = configurationStr.find(':', p0 + 1);
if (p1 != std::string::npos)
{
size_t p2 = configurationStr.find(':', p1 + 1);
if (p2 != std::string::npos)
{ {
std::cerr << "ERROR: Invalid configuration string for OpenCL device" << std::endl; std::cerr << "ERROR: Invalid configuration string for OpenCL device" << std::endl;
return false; return false;
} }
else if (parts.size() > 2)
deviceNameOrID = parts[2];
if (parts.size() > 1)
{ {
// assume platform + device types + device name/id split(parts[1], '|', deviceTypes);
platform = configurationStr.substr(0, p0);
deviceTypesStr = configurationStr.substr(p0 + 1, p1 - (p0 + 1));
deviceNameOrID = configurationStr.substr(p1 + 1, configurationStr.length() - (p1 + 1));
} }
} if (parts.size() > 0)
else
{ {
// assume platform + device types platform = parts[0];
platform = configurationStr.substr(0, p0);
deviceTypesStr = configurationStr.substr(p0 + 1, configurationStr.length() - (p0 + 1));
} }
}
else
{
// assume only platform
platform = configurationStr;
}
deviceTypes = split(deviceTypesStr, '|');
return true; return true;
} }
@ -2024,15 +2007,19 @@ static cl_device_id selectOpenCLDevice()
} }
} }
cl_int status = CL_SUCCESS;
std::vector<cl_platform_id> platforms; std::vector<cl_platform_id> platforms;
{
cl_uint numPlatforms = 0; cl_uint numPlatforms = 0;
cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); status = clGetPlatformIDs(0, NULL, &numPlatforms);
CV_Assert(status == CL_SUCCESS); CV_Assert(status == CL_SUCCESS);
if (numPlatforms == 0) if (numPlatforms == 0)
return NULL; return NULL;
platforms.resize((size_t)numPlatforms); platforms.resize((size_t)numPlatforms);
status = clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms); status = clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms);
CV_Assert(status == CL_SUCCESS); CV_Assert(status == CL_SUCCESS);
platforms.resize(numPlatforms);
}
int selectedPlatform = -1; int selectedPlatform = -1;
if (platform.length() > 0) if (platform.length() > 0)