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/Spinlock.h"
16 #include "common/SynchronizedValue.h"
17
18 #include <functional>
19
20 namespace cl
21 {
22
23 class Device final : public _cl_device_id, public Object
24 {
25 public:
26 // Front end entry functions, only called from OpenCL entry points
27
28 cl_int getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const;
29
30 cl_int createSubDevices(const cl_device_partition_property *properties,
31 cl_uint numDevices,
32 cl_device_id *subDevices,
33 cl_uint *numDevicesRet);
34
35 public:
36 ~Device() override;
37
38 Platform &getPlatform() noexcept;
39 const Platform &getPlatform() const noexcept;
40 bool isRoot() const noexcept;
41 const rx::CLDeviceImpl::Info &getInfo() const;
42 cl_version getVersion() const;
43 bool isVersionOrNewer(cl_uint major, cl_uint minor) const;
44
45 template <typename T = rx::CLDeviceImpl>
46 T &getImpl() const;
47
48 bool supportsBuiltInKernel(const std::string &name) const;
49 bool supportsNativeImageDimensions(const cl_image_desc &desc) const;
50 bool supportsImageDimensions(const ImageDescriptor &desc) const;
51
52 static bool IsValidType(DeviceType type);
53
54 private:
55 Device(Platform &platform,
56 Device *parent,
57 DeviceType type,
58 const rx::CLDeviceImpl::CreateFunc &createFunc);
59
60 Platform &mPlatform;
61 const DevicePtr mParent;
62 const rx::CLDeviceImpl::Ptr mImpl;
63 const rx::CLDeviceImpl::Info mInfo;
64
65 angle::SynchronizedValue<CommandQueue *, angle::Spinlock> mDefaultCommandQueue = nullptr;
66
67 friend class CommandQueue;
68 friend class Platform;
69 };
70
getPlatform()71 inline Platform &Device::getPlatform() noexcept
72 {
73 return mPlatform;
74 }
75
getPlatform()76 inline const Platform &Device::getPlatform() const noexcept
77 {
78 return mPlatform;
79 }
80
isRoot()81 inline bool Device::isRoot() const noexcept
82 {
83 return mParent == nullptr;
84 }
85
getInfo()86 inline const rx::CLDeviceImpl::Info &Device::getInfo() const
87 {
88 return mInfo;
89 }
90
getVersion()91 inline cl_version Device::getVersion() const
92 {
93 return mInfo.version;
94 }
95
isVersionOrNewer(cl_uint major,cl_uint minor)96 inline bool Device::isVersionOrNewer(cl_uint major, cl_uint minor) const
97 {
98 return mInfo.version >= CL_MAKE_VERSION(major, minor, 0u);
99 }
100
101 template <typename T>
getImpl()102 inline T &Device::getImpl() const
103 {
104 return static_cast<T &>(*mImpl);
105 }
106
IsValidType(DeviceType type)107 inline bool Device::IsValidType(DeviceType type)
108 {
109 return type.get() <= CL_DEVICE_TYPE_CUSTOM || type == CL_DEVICE_TYPE_ALL;
110 }
111
112 } // namespace cl
113
114 #endif // LIBANGLE_CLDEVICE_H_
115