Skip to content

Instantly share code, notes, and snippets.

@h4tr3d
Created May 22, 2024 02:58
Show Gist options
  • Save h4tr3d/8494613f7d4e50d082f33cdba316c95d to your computer and use it in GitHub Desktop.
Save h4tr3d/8494613f7d4e50d082f33cdba316c95d to your computer and use it in GitHub Desktop.
OpenCV2 and OpenCL capabilities dump
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>
void opencv_opencl_dump()
{
std::vector<cv::ocl::PlatformInfo> platform_info;
cv::ocl::getPlatfomsInfo(platform_info);
std::cout << "OpenCL infos: " << platform_info.size() << '\n';
for (auto &&item : platform_info) {
std::cout << " - Name: " << item.name() << '\n'
<< " - Device Number: " << item.deviceNumber() << '\n'
<< " - Vendor: " << item.vendor() << '\n'
<< " - Version: " << item.version() << '\n';
for (int devid = 0; devid < item.deviceNumber(); ++devid) {
cv::ocl::Device dev;
item.getDevice(dev, devid);
std::cout << " - Device Idx: " << devid << '\n'
<< " - Name: " << dev.name() << '\n'
<< " - Extensions: " << dev.extensions() << '\n'
<< " - Version: " << dev.version() << '\n'
<< " - Vendor Name: " << dev.vendorName() << '\n'
<< " - OpenCL C Version: " << dev.OpenCL_C_Version() << '\n'
<< " - OpenCL Version: " << dev.OpenCLVersion() << '\n'
<< " - Device Version Major: " << dev.deviceVersionMajor() << '\n'
<< " - Device Version Minor: " << dev.deviceVersionMinor() << '\n'
<< " - Drvier Version: " << dev.driverVersion() << '\n'
<< " - Avail: " << dev.available() << '\n'
<< " - Compiler Available: " << dev.compilerAvailable() << '\n'
<< " - Linker Available: " << dev.linkerAvailable() << '\n'
<< " - Address Bits: " << dev.addressBits() << '\n'
<< " - Endian Little: " << dev.endianLittle() << '\n'
<< " - Error Correction Supported: " << dev.errorCorrectionSupport() << '\n'
<< " - Image Support: " << dev.imageSupport() << '\n'
<< " - Image From Buffer Support: " << dev.imageFromBufferSupport() << '\n'
<< " - Image Pitch Alignment: " << dev.imagePitchAlignment() << '\n'
<< " - Image Base Address Alignment: " << dev.imageBaseAddressAlignment() << '\n'
<< " - Type: " << (unsigned int)dev.type() << '\n';
#define TYPE(x) ((dev.type() & (x)) == (x)) ? std::cout << " - " << #x << '\n' : std::cout
TYPE(cv::ocl::Device::TYPE_DEFAULT);
TYPE(cv::ocl::Device::TYPE_CPU);
TYPE(cv::ocl::Device::TYPE_GPU);
TYPE(cv::ocl::Device::TYPE_ACCELERATOR);
TYPE(cv::ocl::Device::TYPE_DGPU);
TYPE(cv::ocl::Device::TYPE_IGPU);
#undef TYPE
}
std::cout << " -----\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment