• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
54     static bool IsValidType(DeviceType type);
55 
56   private:
57     Device(Platform &platform,
58            Device *parent,
59            DeviceType type,
60            const rx::CLDeviceImpl::CreateFunc &createFunc);
61 
62     Platform &mPlatform;
63     const DevicePtr mParent;
64     const rx::CLDeviceImpl::Ptr mImpl;
65     const rx::CLDeviceImpl::Info mInfo;
66 
67     angle::SynchronizedValue<CommandQueue *> mDefaultCommandQueue = nullptr;
68 
69     friend class CommandQueue;
70     friend class Platform;
71 };
72 
getPlatform()73 inline Platform &Device::getPlatform() noexcept
74 {
75     return mPlatform;
76 }
77 
getPlatform()78 inline const Platform &Device::getPlatform() const noexcept
79 {
80     return mPlatform;
81 }
82 
isRoot()83 inline bool Device::isRoot() const noexcept
84 {
85     return mParent == nullptr;
86 }
87 
getInfo()88 inline const rx::CLDeviceImpl::Info &Device::getInfo() const
89 {
90     return mInfo;
91 }
92 
getVersion()93 inline cl_version Device::getVersion() const
94 {
95     return mInfo.version;
96 }
97 
isVersionOrNewer(cl_uint major,cl_uint minor)98 inline bool Device::isVersionOrNewer(cl_uint major, cl_uint minor) const
99 {
100     return mInfo.version >= CL_MAKE_VERSION(major, minor, 0u);
101 }
102 
103 template <typename T>
getImpl()104 inline T &Device::getImpl() const
105 {
106     return static_cast<T &>(*mImpl);
107 }
108 
IsValidType(DeviceType type)109 inline bool Device::IsValidType(DeviceType type)
110 {
111     return type.get() <= CL_DEVICE_TYPE_CUSTOM || type == CL_DEVICE_TYPE_ALL;
112 }
113 
114 }  // namespace cl
115 
116 #endif  // LIBANGLE_CLDEVICE_H_
117