10#ifndef INCLUDED_OPENCL_INC_OPENCL_DEVICE_SELECTION_H
11#define INCLUDED_OPENCL_INC_OPENCL_DEVICE_SELECTION_H
25#include <rtl/math.hxx>
100 clGetPlatformInfo(aPlatformId, aPlatformInfo,
temporary.size(),
temporary.data(),
nullptr);
114 cl_device_type aDeviceType;
115 clGetDeviceInfo(aDeviceId, CL_DEVICE_TYPE,
sizeof(aDeviceType), &aDeviceType,
nullptr);
116 if (aDeviceType & CL_DEVICE_TYPE_CPU)
118 if (aDeviceType & CL_DEVICE_TYPE_GPU)
120 if (aDeviceType & CL_DEVICE_TYPE_ACCELERATOR)
121 sType +=
"accelerator ";
122 if (aDeviceType & CL_DEVICE_TYPE_CUSTOM)
124 if (aDeviceType & CL_DEVICE_TYPE_DEFAULT)
134 clGetDeviceInfo(aDeviceId, aDeviceInfo,
sizeof(bCLBool), &bCLBool,
nullptr);
135 return bCLBool == CL_TRUE;
143 cl_uint numPlatforms;
144 std::vector<cl_platform_id> platforms;
145 std::vector<cl_device_id> devices;
152 clGetPlatformIDs(0,
nullptr, &numPlatforms);
153 if (numPlatforms != 0)
155 platforms.resize(numPlatforms);
156 clGetPlatformIDs(numPlatforms, platforms.data(),
nullptr);
160 for (
i = 0; i < static_cast<unsigned int>(numPlatforms);
i++)
163 cl_int
err = clGetDeviceIDs(platforms[
i], CL_DEVICE_TYPE_ALL, 0,
nullptr, &num);
164 if (
err != CL_SUCCESS)
178 devices.resize(numDevices);
181 rProfile->devices.resize(numDevices + 1);
184 for (
i = 0; i < static_cast<unsigned int>(numPlatforms);
i++)
195 cl_int
err = clGetDeviceIDs(platforms[
i], CL_DEVICE_TYPE_ALL, numDevices, devices.data(), &num);
196 if (
err != CL_SUCCESS)
205 for (j = 0; j < num; j++, next++)
207 cl_device_id aDeviceID = devices[j];
209 ds_device& rDevice = rProfile->devices[next];
239 if (pProfile ==
nullptr)
241 if (rStreamName.isEmpty())
244 std::unique_ptr<SvStream> pStream;
245 pStream.reset(
new SvFileStream(rStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
255 aXmlWriter.
content(pProfile->version);
258 for (
const ds_device& rDevice : pProfile->devices)
262 switch(rDevice.
eType)
266 aXmlWriter.
content(OString(
"native"));
271 aXmlWriter.
content(OString(
"opencl"));
287 if (rtl::math::approxEqual(rDevice.
fTime, DBL_MAX))
288 aXmlWriter.
content(OString(
"max"));
294 aXmlWriter.
content(rDevice.
bErrors ? OString(
"true") : OString(
"false"));
310 if (rStreamName.isEmpty())
313 std::unique_ptr<SvStream> pStream;
314 pStream.reset(
new SvFileStream(rStreamName, StreamMode::READ));
317 if (!aWalker.
open(pStream.get()))
320 if (aWalker.
name() ==
"profile")
325 if (aWalker.
name() ==
"version")
327 if (aWalker.
content() != pProfile->version)
330 else if (aWalker.
name() ==
"device")
342 if (aWalker.
name() ==
"type")
344 OString sContent = aWalker.
content();
345 if (sContent ==
"native")
347 else if (sContent ==
"opencl")
352 else if (aWalker.
name() ==
"name")
356 else if (aWalker.
name() ==
"driver")
360 else if (aWalker.
name() ==
"time")
362 if (aWalker.
content() ==
"max")
365 fTime = aWalker.
content().toDouble();
367 else if (aWalker.
name() ==
"errors")
369 bErrors = (aWalker.
content() ==
"true");
378 for (
ds_device& rDevice : pProfile->devices)
381 if (rDevice.
eType == eDeviceType)
388 rDevice.
fTime = fTime;
constexpr T & temporary(T &&x)
@ DS_SCORE_DESERIALIZER_ERROR
@ DS_SCORE_SERIALIZER_ERROR
@ DS_INVALID_PERF_EVALUATOR
@ DS_INVALID_PERF_EVALUATOR_TYPE
@ DS_PERF_EVALUATOR_ERROR
OString getDeviceInfoString(cl_device_id aDeviceId, cl_device_info aDeviceInfo)
OString getPlatformInfoString(cl_platform_id aPlatformId, cl_platform_info aPlatformInfo)
bool getDeviceInfoBool(cl_device_id aDeviceId, cl_device_info aDeviceInfo)
OString getDeviceType(cl_device_id aDeviceId)
ds_status writeProfile(const OUString &rStreamName, std::unique_ptr< ds_profile > const &pProfile)
ds_status readProfile(const OUString &rStreamName, std::unique_ptr< ds_profile > const &pProfile)
ds_status initDSProfile(std::unique_ptr< ds_profile > &rProfile, OString const &rVersion)
OString sDeviceExtensions
bool bDeviceCompilerAvailable
OString sPlatformExtensions
OString sDeviceOpenCLVersion
bool bDeviceLinkerAvailable
std::vector< ds_device > devices
ds_profile(OString inVersion)