Commit 16adbda4 authored by Alexander Alekhin's avatar Alexander Alekhin

ocl: added OpenCL device selection via OPENCV_OPENCL_DEVICE environment variable

parent dd9ff587
...@@ -51,6 +51,8 @@ const char * impls[] = ...@@ -51,6 +51,8 @@ const char * impls[] =
#endif #endif
}; };
using namespace cv::ocl;
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
const char * keys = const char * keys =
...@@ -59,42 +61,49 @@ int main(int argc, char ** argv) ...@@ -59,42 +61,49 @@ int main(int argc, char ** argv)
"{ p | platform | -1 | set platform id }" "{ p | platform | -1 | set platform id }"
"{ d | device | 0 | set device id }"; "{ d | device | 0 | set device id }";
CommandLineParser cmd(argc, argv, keys); if (getenv("OPENCV_OPENCL_DEVICE") == NULL) // TODO Remove this after buildbot updates
if (cmd.get<bool>("help"))
{ {
cout << "Available options besides google test option:" << endl; CommandLineParser cmd(argc, argv, keys);
cmd.printParams(); if (cmd.get<bool>("help"))
return 0; {
} cout << "Available options besides google test option:" << endl;
cmd.printParams();
return 0;
}
string type = cmd.get<string>("type"); string type = cmd.get<string>("type");
int pid = cmd.get<int>("platform"); int pid = cmd.get<int>("platform");
int device = cmd.get<int>("device"); int device = cmd.get<int>("device");
int flag = type == "cpu" ? cv::ocl::CVCL_DEVICE_TYPE_CPU : int flag = type == "cpu" ? cv::ocl::CVCL_DEVICE_TYPE_CPU :
cv::ocl::CVCL_DEVICE_TYPE_GPU; cv::ocl::CVCL_DEVICE_TYPE_GPU;
cv::ocl::PlatformsInfo platformsInfo; cv::ocl::PlatformsInfo platformsInfo;
cv::ocl::getOpenCLPlatforms(platformsInfo); cv::ocl::getOpenCLPlatforms(platformsInfo);
if (pid >= (int)platformsInfo.size()) if (pid >= (int)platformsInfo.size())
{ {
std::cout << "platform is invalid\n"; std::cout << "platform is invalid\n";
return 1; return 1;
} }
cv::ocl::DevicesInfo devicesInfo; cv::ocl::DevicesInfo devicesInfo;
int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]); int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]);
if (device < 0 || device >= devnums) if (device < 0 || device >= devnums)
{ {
std::cout << "device/platform invalid\n"; std::cout << "device/platform invalid\n";
return 1; return 1;
}
cv::ocl::setDevice(devicesInfo[device]);
} }
cv::ocl::setDevice(devicesInfo[device]); const DeviceInfo& deviceInfo = cv::ocl::Context::getContext()->getDeviceInfo();
cout << "Device type:" << type << endl cout << "Device type: " << (deviceInfo.deviceType == CVCL_DEVICE_TYPE_CPU ?
<< "Platform name:" << devicesInfo[device]->platform->platformName << endl "CPU" :
<< "Device name:" << devicesInfo[device]->deviceName << endl; (deviceInfo.deviceType == CVCL_DEVICE_TYPE_GPU ? "GPU" : "unknown")) << endl
<< "Platform name: " << deviceInfo.platform->platformName << endl
<< "Device name: " << deviceInfo.deviceName << endl;
CV_PERF_TEST_MAIN_INTERNALS(ocl, impls) CV_PERF_TEST_MAIN_INTERNALS(ocl, impls)
} }
This diff is collapsed.
...@@ -83,45 +83,52 @@ int main(int argc, char **argv) ...@@ -83,45 +83,52 @@ int main(int argc, char **argv)
"{ p | platform | -1 | set platform id }" "{ p | platform | -1 | set platform id }"
"{ d | device | 0 | set device id }"; "{ d | device | 0 | set device id }";
CommandLineParser cmd(argc, argv, keys); if (getenv("OPENCV_OPENCL_DEVICE") == NULL) // TODO Remove this after buildbot updates
if (cmd.get<bool>("help"))
{ {
cout << "Available options besides google test option:" << endl; CommandLineParser cmd(argc, argv, keys);
cmd.printParams(); if (cmd.get<bool>("help"))
return 0; {
} cout << "Available options besides google test option:" << endl;
string type = cmd.get<string>("type"); cmd.printParams();
int pid = cmd.get<int>("platform"); return 0;
int device = cmd.get<int>("device"); }
string type = cmd.get<string>("type");
int pid = cmd.get<int>("platform");
int device = cmd.get<int>("device");
print_info(); print_info();
int flag = CVCL_DEVICE_TYPE_GPU; int flag = CVCL_DEVICE_TYPE_GPU;
if(type == "cpu") if(type == "cpu")
{ {
flag = CVCL_DEVICE_TYPE_CPU; flag = CVCL_DEVICE_TYPE_CPU;
} }
cv::ocl::PlatformsInfo platformsInfo; cv::ocl::PlatformsInfo platformsInfo;
cv::ocl::getOpenCLPlatforms(platformsInfo); cv::ocl::getOpenCLPlatforms(platformsInfo);
if (pid >= (int)platformsInfo.size()) if (pid >= (int)platformsInfo.size())
{ {
std::cout << "platform is invalid\n"; std::cout << "platform is invalid\n";
return 1; return 1;
} }
cv::ocl::DevicesInfo devicesInfo; cv::ocl::DevicesInfo devicesInfo;
int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]); int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]);
if (device < 0 || device >= devnums) if (device < 0 || device >= devnums)
{ {
std::cout << "device/platform invalid\n"; std::cout << "device/platform invalid\n";
return 1; return 1;
}
cv::ocl::setDevice(devicesInfo[device]);
} }
cv::ocl::setDevice(devicesInfo[device]); const DeviceInfo& deviceInfo = cv::ocl::Context::getContext()->getDeviceInfo();
cout << "Device type: " << type << endl cout << "Device type: " << (deviceInfo.deviceType == CVCL_DEVICE_TYPE_CPU ?
<< "Platform name: " << devicesInfo[device]->platform->platformName << endl "CPU" :
<< "Device name: " << devicesInfo[device]->deviceName << endl; (deviceInfo.deviceType == CVCL_DEVICE_TYPE_GPU ? "GPU" : "unknown")) << endl
<< "Platform name: " << deviceInfo.platform->platformName << endl
<< "Device name: " << deviceInfo.deviceName << endl;
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment