opencl-template/main.cpp

44 lines
1.0 KiB
C++
Raw Normal View History

2018-04-16 21:02:23 +02:00
#include <iostream>
#include <vector>
#include <CL/cl.h>
int main()
{
cl_int error;
cl_uint platformIdCount = 0;
clGetPlatformIDs (0, nullptr, &platformIdCount);
std::vector<cl_platform_id> platformIds (platformIdCount);
clGetPlatformIDs (platformIdCount, platformIds.data(), nullptr);
std::cout << "Platform count: " << platformIdCount << std::endl;
cl_uint deviceIdCount = 0;
clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, 0, nullptr,
&deviceIdCount);
std::cout << "Device in Platform 0 count: " << deviceIdCount << std::endl;
std::vector<cl_device_id> deviceIds (deviceIdCount);
clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, deviceIdCount,
deviceIds.data (), nullptr);
const cl_context_properties contextProperties [] =
{
CL_CONTEXT_PLATFORM,
reinterpret_cast<cl_context_properties> (platformIds [0]),
0, 0
};
cl_context context = clCreateContext (
contextProperties, deviceIdCount,
deviceIds.data (), nullptr,
nullptr, &error);
return 0;
}