【发布时间】:2014-06-04 13:13:10
【问题描述】:
我正在使用 opencv 和 opencl 开发一个项目。现在,内核和缓冲区使用 opencv 指定的函数运行。由于某些原因,我想使用 OpenCL 的本机函数而不是更改次数最少的 opencv 函数。我有两个文件。在主文件中,我创建了上下文并将其传递给第二个文件的函数。在第二个文件中,我需要构建和执行内核。如果我要使用 OpenCV 的函数,我可以将执行内核与已传递给第二个文件的上下文一起使用。但是因为我打算使用 OpenCL 的原生内核,所以我需要对内核进行 bild,为此我需要设备列表。我的问题是,有什么方法可以从 opencv 创建的上下文中获取设备列表?或者如何在不传递主文件信息的情况下获取设备列表?
这里是主文件的sn-p:
vector<ocl::Info> oclinfo;
int devnums = ocl::getDevice(oclinfo);
if( devnums < 1 )
{
std::cout << "no device found\n";
return -1;
}
ocl::setBinpath("./");
cv::ocl::Context* clCxt = ocl::Context::getContext();
ScanKernel( Mat& img,string kernelsrc,string kernelName,cv::ocl::Context* clCxt)
这里是第二个文件的代码sn-p:
const char * source = kernelsrc.c_str();
size_t sourceSize[] = { strlen(source) };
cpProgram = clCreateProgramWithSource((cl_context)clCxt->oclContext(), 1, &source, sourceSize, &ciErr1);
if (ciErr1 != CL_SUCCESS) {
printf("Error in clCreateProgramWithSource, Line %u in file %s %d !!!\n\n", __LINE__, __FILE__,ciErr1);
}
else
{ printf("*** Got createprogramwithsource\n");
**ciErr1 = clBuildProgram(cpProgram, NULL, NULL, NULL, NULL, NULL);**
if (ciErr1 != CL_SUCCESS) {
printf("Error in building, Line %u in file %s error NO: %d!!!\n\n", __LINE__, __FILE__,ciErr1);
}
我在获取 clBuildProgram 功能的设备列表方面需要帮助。
【问题讨论】:
-
你在哪个操作系统上工作?