Reputation: 103
I am new to OpenCL and I have a problem with displaying the <CL_DEVICE_MAX_WORK_ITEM_SIZES>
as a whole number/value. Instead I get a memory address.
Initially, I tried to declare a string and integer output variable to display the maximum work item size. But eventually I found out that the work item size returns a size_t
data type instead. So I created a vector to store the size_t variable but it outputs a memory address instead.
And also, my display shows the Device Number in the reverse order (shows Device #1 then Device #0 - this is used to select a device for the later part of my program)
Any help would be appreciated. Thank you.
int main()
{
std::vector<cl::Platform> platforms; // available platforms
std::vector<cl::Device> devices; // devices available to a platform
std::string outputString; // string for output
std::vector<::size_t> maxWorkItems[3];
unsigned int i, j; // counters
std::string choice; // user input choice
cl::Platform::get(&platforms);
std::cout << "Do you want to use a CPU or GPU device: ";
std::cin >> choice;
if (choice == "CPU" || choice == "cpu")
{
// for each platform
for (i = 0; i < platforms.size(); i++)
{
// get all CPU devices available to the platform
platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
for (j = 0; j < devices.size(); j++)
{
cl_device_type type;
devices[j].getInfo(CL_DEVICE_TYPE, &type);
if (type == CL_DEVICE_TYPE_CPU) {
std::cout << "\tDevice #" << j << std::endl;
//outputs the device type
std::cout << "\tType: " << "CPU" << std::endl;
// get and output device name
outputString = devices[j].getInfo<CL_DEVICE_NAME>();
std::cout << "\tName: " << outputString << std::endl;
// get and output device vendor
outputString = devices[j].getInfo<CL_DEVICE_VENDOR>();
std::cout << "\tVendor: " << outputString << std::endl;
//get and output compute units
std::cout << "\tNumber of compute units: " << devices[j].getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>() << std::endl;
//get and output workgroup size
std::cout << "\tMaximum work group size: " << devices[j].getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>() << std::endl;
//get and output workitem size
maxWorkItems[0] = devices[j].getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
std::cout << "\tMaximum work item size: " << maxWorkItems << std::endl;
//get and output local memory size
std::cout << "\tLocal memory size: " << devices[j].getInfo<CL_DEVICE_LOCAL_MEM_SIZE>() << std::endl;
std::cout << std::endl;
}
}
}
}
Below is the undesired output of my code:
The max work item size is in hexadecimal format, and the device numbers are in reverse order.
Upvotes: 3
Views: 1632
Reputation: 23438
The CL_DEVICE_MAX_WORK_ITEM_SIZE
property is of array type, specifically, size_t[]
. You shouldn't be expecting a scalar value, but an array of CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
elements. With the OpenCL C++ wrapper, you're on the right track with the vector
, but you've now declared an array of 3 vectors:
std::vector<::size_t> maxWorkItems[3];
You in fact just want the one vector that will hold all the returned values:
std::vector<::size_t> maxWorkItems;
The property query becomes:
maxWorkItems = devices[j].getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
Then you should be able to query the max work items in each dimension using maxWorkItems[0]
, maxWorkItems[1]
, etc.
Upvotes: 3