gpt4 book ai didi

opencv - 如何从opencv中的上下文获取设备列表

转载 作者:行者123 更新时间:2023-12-02 17:50:11 25 4
gpt4 key购买 nike

我正在使用 opencv 和 opencl 开发一个项目。现在,内核和缓冲区使用 opencv 指定的函数运行。出于某些原因,我想使用 OpenCL 的 native 函数而不是更改次数最少的 opencv 函数。我有两个文件。在主文件中,我创建了上下文并将其传递给第二个文件的函数。在第二个文件中,我需要构建和执行内核。如果我要使用 OpenCV 的函数,我可以将执行内核与已传递给第二个文件的上下文一起使用。但是因为我打算使用 OpenCL 的原生内核​​,所以我需要对内核进行 bild,为此我需要设备列表。我的问题是,有什么方法可以从 opencv 创建的上下文中获取设备列表?或者如何在不从主文件传递信息的情况下获取设备列表?

这是主文件的片段:

  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)

这是第二个文件的代码片段:
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 功能的设备列表的帮助。

最佳答案

您可以使用 clGetContextInfo() CL_CONTEXT_DEVICES 的函数参数以获取与上下文关联的设备列表。获得设备列表后,您可以将其传递给 clBuildProgram()编译你的程序。

请参阅此处的文档:http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clGetContextInfo.html

关于opencv - 如何从opencv中的上下文获取设备列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24020596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com