blob: 06aaac88f45da9d24ab53e936c228a826ce10ed0 [file] [log] [blame]
Michalis Spyrou11d49182020-03-26 10:31:32 +00001/*
Georgios Pinitasc6f95102021-03-30 10:03:01 +01002 * Copyright (c) 2020-2021 Arm Limited.
Michalis Spyrou11d49182020-03-26 10:31:32 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_CLDEVICE_H
25#define ARM_COMPUTE_CLDEVICE_H
26
27#include "arm_compute/core/CL/CLHelpers.h"
28#include "arm_compute/core/CL/CLTypes.h"
29#include "arm_compute/core/GPUTarget.h"
30#include "arm_compute/core/IDevice.h"
31
32#include <set>
Georgios Pinitasc6f95102021-03-30 10:03:01 +010033#include <sstream>
Michalis Spyrou11d49182020-03-26 10:31:32 +000034#include <string>
35
36namespace arm_compute
37{
38/** OpenCL device type class
39 *
40 * Initializes and stores all the information about a cl device,
41 * working mainly as a cache mechanism.
42 * */
43class CLDevice : public IDevice
44{
45public:
46 /** Default Constructor */
47 CLDevice()
48 : _device(cl::Device()), _options()
49 {
50 }
51
52 /** Constructor
53 *
54 * @param[in] cl_device OpenCL device
55 */
56 CLDevice(const cl::Device &cl_device)
57 : _device(), _options()
58 {
59 _device = cl_device;
60
61 // Get device target
62 std::string device_name = _device.getInfo<CL_DEVICE_NAME>();
63 _options.gpu_target = get_target_from_name(device_name);
64
65 // Fill extensions
66 std::string extensions = _device.getInfo<CL_DEVICE_EXTENSIONS>();
67
68 std::istringstream iss(extensions);
69 for(std::string s; iss >> s;)
70 {
71 _options.extensions.insert(s);
72 }
73
74 // SW workaround for G76
75 if(_options.gpu_target == GPUTarget::G76)
76 {
77 _options.extensions.insert("cl_arm_integer_dot_product_int8");
78 }
79
80 // Get device version
81 _options.version = get_cl_version(_device);
82
83 // Get compute units
84 _options.compute_units = _device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
85
86 // Get device version
87 _options.device_version = _device.getInfo<CL_DEVICE_VERSION>();
88 }
89
90 /** Returns the GPU target of the cl device
91 *
92 * @return The GPU target
93 */
94 const GPUTarget &target() const
95 {
96 return _options.gpu_target;
97 }
98
99 /** Returns the number of compute units available
100 *
101 * @return Number of compute units
102 */
103 size_t compute_units() const
104 {
105 return _options.compute_units;
106 }
107
108 /** Returns the underlying cl device object
109 *
110 * @return A cl device
111 */
112 const cl::Device &cl_device() const
113 {
114 return _device;
115 }
116
117 /** Returns the device's CL version
118 *
119 * @return CLVersion of the device
120 */
121 CLVersion version() const
122 {
123 return _options.version;
124 }
125
126 /** Returns the device version as a string
127 *
128 * @return CLVersion of the device
129 */
130 std::string device_version() const
131 {
132 return _options.device_version;
133 }
134
135 // Inherrited methods
136 DeviceType type() const override
137 {
138 return DeviceType::CL;
139 }
140
141 bool supported(const std::string &extension) const override
142 {
143 return _options.extensions.count(extension) != 0;
144 }
145
146private:
147 cl::Device _device; /**< OpenCL device. */
148 struct CLDeviceOptions _options; /**< OpenCL device options */
149};
150
151} // namespace arm_compute
152
153#endif /* ARM_COMPUTE_CLDEVICE_H */