1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CLDevice.h: Defines the cl::Device class, which provides information about OpenCL device
7 // configurations.
8
9 #ifndef LIBANGLE_CLDEVICE_H_
10 #define LIBANGLE_CLDEVICE_H_
11
12 #include "libANGLE/CLObject.h"
13 #include "libANGLE/renderer/CLDeviceImpl.h"
14
15 #include "common/SynchronizedValue.h"
16
17 #include <functional>
18
19 namespace cl
20 {
21
22 class Device final : public _cl_device_id, public Object
23 {
24 public:
25 // Front end entry functions, only called from OpenCL entry points
26
27 angle::Result getInfo(DeviceInfo name,
28 size_t valueSize,
29 void *value,
30 size_t *valueSizeRet) const;
31
32 angle::Result createSubDevices(const cl_device_partition_property *properties,
33 cl_uint numDevices,
34 cl_device_id *subDevices,
35 cl_uint *numDevicesRet);
36
37 public:
38 ~Device() override;
39
40 Platform &getPlatform() noexcept;
41 const Platform &getPlatform() const noexcept;
42 bool isRoot() const noexcept;
43 const rx::CLDeviceImpl::Info &getInfo() const;
44 cl_version getVersion() const;
45 bool isVersionOrNewer(cl_uint major, cl_uint minor) const;
46
47 template <typename T = rx::CLDeviceImpl>
48 T &getImpl() const;
49
50 bool supportsBuiltInKernel(const std::string &name) const;
51 bool supportsNativeImageDimensions(const cl_image_desc &desc) const;
52 bool supportsImageDimensions(const ImageDescriptor &desc) const;
53 bool hasDeviceEnqueueCaps() const;
54 bool supportsNonUniformWorkGroups() const;
55
56 static bool IsValidType(DeviceType type);
57
58 private:
59 Device(Platform &platform,
60 Device *parent,
61 DeviceType type,
62 const rx::CLDeviceImpl::CreateFunc &createFunc);
63
64 Platform &mPlatform;
65 const DevicePtr mParent;
66 const rx::CLDeviceImpl::Ptr mImpl;
67 const rx::CLDeviceImpl::Info mInfo;
68
69 angle::SynchronizedValue<CommandQueue *> mDefaultCommandQueue = nullptr;
70
71 friend class CommandQueue;
72 friend class Platform;
73 };
74
getPlatform()75 inline Platform &Device::getPlatform() noexcept
76 {
77 return mPlatform;
78 }
79
getPlatform()80 inline const Platform &Device::getPlatform() const noexcept
81 {
82 return mPlatform;
83 }
84
isRoot()85 inline bool Device::isRoot() const noexcept
86 {
87 return mParent == nullptr;
88 }
89
getInfo()90 inline const rx::CLDeviceImpl::Info &Device::getInfo() const
91 {
92 return mInfo;
93 }
94
getVersion()95 inline cl_version Device::getVersion() const
96 {
97 return mInfo.version;
98 }
99
isVersionOrNewer(cl_uint major,cl_uint minor)100 inline bool Device::isVersionOrNewer(cl_uint major, cl_uint minor) const
101 {
102 return mInfo.version >= CL_MAKE_VERSION(major, minor, 0u);
103 }
104
105 template <typename T>
getImpl()106 inline T &Device::getImpl() const
107 {
108 return static_cast<T &>(*mImpl);
109 }
110
IsValidType(DeviceType type)111 inline bool Device::IsValidType(DeviceType type)
112 {
113 return type.get() <= CL_DEVICE_TYPE_CUSTOM || type == CL_DEVICE_TYPE_ALL;
114 }
115
116 } // namespace cl
117
118 #endif // LIBANGLE_CLDEVICE_H_
119