From 217b2282b86b020841641c220db8eb2a42029707 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 25 Dec 2013 18:41:24 +0400 Subject: [PATCH] fixes --- modules/core/include/opencv2/core/utility.hpp | 2 +- modules/core/src/ocl.cpp | 85 ++++++++----------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 2d7d3130e..191d696df 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -85,7 +85,7 @@ template class AutoBuffer public: typedef _Tp value_type; - //! the default contructor + //! the default constructor AutoBuffer(); //! constructor taking the real buffer size AutoBuffer(size_t _size); diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 92c9ffb6c..4f5258196 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -1919,30 +1919,30 @@ inline cl_int getStringInfo(Functor f, ObjectType obj, cl_uint name, std::string param.clear(); if (required > 0) { - std::vector buf(required + 1, char(0)); - err = f(obj, name, required, &buf[0], NULL); + AutoBuffer buf(required + 1); + char* ptr = (char*)buf; // cleanup is not needed + err = f(obj, name, required, ptr, NULL); if (err != CL_SUCCESS) return err; - param = &buf[0]; + param = ptr; } return CL_SUCCESS; }; static void split(const std::string &s, char delim, std::vector &elems) { - std::stringstream ss(s); + elems.clear(); + if (s.size() == 0) + return; + std::istringstream ss(s); std::string item; - while (std::getline(ss, item, delim)) { + while (!ss.eof()) + { + std::getline(ss, item, delim); elems.push_back(item); } } -static std::vector split(const std::string &s, char delim) { - std::vector elems; - split(s, delim, elems); - return elems; -} - // Layout: :: // Sample: AMD:GPU: // Sample: AMD:GPU:Tahiti @@ -1950,40 +1950,23 @@ static std::vector split(const std::string &s, char delim) { static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr, std::string& platform, std::vector& deviceTypes, std::string& deviceNameOrID) { - std::string deviceTypesStr; - size_t p0 = configurationStr.find(':'); - if (p0 != std::string::npos) + std::vector parts; + split(configurationStr, ':', parts); + 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; - return false; - } - else - { - // assume platform + device types + device name/id - platform = configurationStr.substr(0, p0); - deviceTypesStr = configurationStr.substr(p0 + 1, p1 - (p0 + 1)); - deviceNameOrID = configurationStr.substr(p1 + 1, configurationStr.length() - (p1 + 1)); - } - } - else - { - // assume platform + device types - platform = configurationStr.substr(0, p0); - deviceTypesStr = configurationStr.substr(p0 + 1, configurationStr.length() - (p0 + 1)); - } + std::cerr << "ERROR: Invalid configuration string for OpenCL device" << std::endl; + return false; } - else + if (parts.size() > 2) + deviceNameOrID = parts[2]; + if (parts.size() > 1) { - // assume only platform - platform = configurationStr; + split(parts[1], '|', deviceTypes); + } + if (parts.size() > 0) + { + platform = parts[0]; } - deviceTypes = split(deviceTypesStr, '|'); return true; } @@ -2024,15 +2007,19 @@ static cl_device_id selectOpenCLDevice() } } + cl_int status = CL_SUCCESS; std::vector platforms; - cl_uint numPlatforms = 0; - cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); - CV_Assert(status == CL_SUCCESS); - if (numPlatforms == 0) - return NULL; - platforms.resize((size_t)numPlatforms); - status = clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms); - CV_Assert(status == CL_SUCCESS); + { + cl_uint numPlatforms = 0; + status = clGetPlatformIDs(0, NULL, &numPlatforms); + CV_Assert(status == CL_SUCCESS); + if (numPlatforms == 0) + return NULL; + platforms.resize((size_t)numPlatforms); + status = clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms); + CV_Assert(status == CL_SUCCESS); + platforms.resize(numPlatforms); + } int selectedPlatform = -1; if (platform.length() > 0)