25{
26 onError = errFunc;
27 onStatus = statusFunc;
28 std::vector<cl::Platform> platforms;
29 cl::Platform::get(&platforms);
30
31 if (platforms.size() == 0)
32 {
33 onError("No Platform found supporting OpenCL!");
34 return;
35 }
36
37 platform = platforms[0];
38 onStatus("Using OpenCL Platform : " + platform.getInfo<CL_PLATFORM_NAME>() );
39 std::vector<cl::Device> devices;
40 platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
41
42 if (devices.size() == 0)
43 {
44 onError("No Device found supporting OpenCL!");
45 return;
46 }
47
48 bool tmp = false;
49
50 for (auto &d : devices)
51 {
52 tmp = (d.getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_GPU);
53
54 if (tmp)
55 {
56 device = d;
57 onStatus("Using GPU Device : " + device.getInfo<CL_DEVICE_NAME>());
58 break;
59 }
60 }
61
62 if (!tmp)
63 {
64 device = devices[0];
65 onStatus("Using CPU Device : " + device.getInfo<CL_DEVICE_NAME>());
66 }
67
68 context = cl::Context({device});
69 queue = cl::CommandQueue(context, device);
70}