我正在尝试在我的笔记本电脑上查询和输出 MAX Work ITEM SIZES。查询具有返回类型 size_t[]
,如 here 所示
但是我仍然无法输出它。如何输出 MAX WORK ITEM SIZES?我是否正确声明了变量?
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
int main(void)
{
vector<cl::Platform> platforms; // available platforms
vector<cl::Device> devices; // devices available to a platform
string outputString; // string for output
VECTOR_CLASS<::size_t> maxWorkItem[3]; // for MAX_WORK_ITEM_SIZES
unsigned int i, j; // counters
cl::Platform::get(&platforms);
// for each platform
for (i = 0; i < platforms.size(); i++)
{
vector<cl::Device> devices; // available devices
//get all devices available to the platform
platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
//for each device
for (j = 0; j < devices.size(); j++)
{
cl_device_type type;
devices[j].getInfo(CL_DEVICE_TYPE, &type);
if (type == CL_DEVICE_TYPE_CPU)
{
platforms[i].getInfo(CL_PLATFORM_NAME, &outputString);
cout << "\tName of Platform: " << outputString << std::endl;
cout << "\tType: " << "CPU" << endl;
//Help here
maxWorkItem[0] = devices[j].getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
cout << "\tMax Work Item Size: " << maxWorkItem[0] << endl;
cout << "--------------------------------------------------" << endl;
}
}
}
}
您可以通过两种方式执行此操作,具体取决于您使用的 Device::getInfo()
重载。请注意,MAX WORK ITEM SIZES 为您提供了可以在工作组的每个维度中指定的最大工作项数:
1.
// ...
vector<size_t> maxWorkItem;
unsigned int i, j, k;
//...
//Help here
maxWorkItem = devices[j].getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
for (k = 0 ; k < maxWorkItem.size(); ++k)
{
cout << "\tMax Work Item Size (dim " << k << "): " << maxWorkItem[k] << endl;
}
cout << "--------------------------------------------------" << endl;
//...
2.
// ...
size_t maxWorkItem[3];
unsigned int i, j, k;
//...
//Help here
devices[j].getInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES, &maxWorkItem);
for (k = 0 ; k < 3; ++k)
{
cout << "\tMax Work Item Size (dim " << k << "): " << maxWorkItem[k] << endl;
}
cout << "--------------------------------------------------" << endl;
//...
检查 OpenCL C++ bindings documentation获取更多信息。
我是一名优秀的程序员,十分优秀!