blob: 0c02039eba7695c1cceb6ad07d9eeac48334caac [file] [log] [blame]
Francisco Jerezc6db1b32012-04-20 16:56:19 +02001//
2// Copyright 2012 Francisco Jerez
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Kenneth Graunkef0cb66b2013-04-21 13:52:08 -070017// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20// OTHER DEALINGS IN THE SOFTWARE.
Francisco Jerezc6db1b32012-04-20 16:56:19 +020021//
22
Aaron Watry5e253fe2017-08-16 20:44:41 -050023#include <unistd.h>
Francisco Jerezc6db1b32012-04-20 16:56:19 +020024#include "core/device.hpp"
Francisco Jerezc4578d22014-02-18 15:07:11 +010025#include "core/platform.hpp"
Francisco Jerezc6db1b32012-04-20 16:56:19 +020026#include "pipe/p_screen.h"
27#include "pipe/p_state.h"
Aaron Watry95ae6c02017-08-09 22:02:30 -050028#include "util/u_debug.h"
Francisco Jerezc6db1b32012-04-20 16:56:19 +020029
30using namespace clover;
31
32namespace {
33 template<typename T>
34 std::vector<T>
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +010035 get_compute_param(pipe_screen *pipe, pipe_shader_ir ir_format,
36 pipe_compute_cap cap) {
37 int sz = pipe->get_compute_param(pipe, ir_format, cap, NULL);
Francisco Jerezc6db1b32012-04-20 16:56:19 +020038 std::vector<T> v(sz / sizeof(T));
39
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +010040 pipe->get_compute_param(pipe, ir_format, cap, &v.front());
Francisco Jerezc6db1b32012-04-20 16:56:19 +020041 return v;
42 }
43}
44
Francisco Jerezc9e009b2013-09-15 20:06:57 -070045device::device(clover::platform &platform, pipe_loader_device *ldev) :
Francisco Jerez1a8ad6c2013-04-06 14:35:00 +020046 platform(platform), ldev(ldev) {
Nicolai Hähnleae7283d2017-08-03 15:02:09 +020047 pipe = pipe_loader_create_screen(ldev);
Tom Stellardc5f0c982014-05-08 21:08:32 -040048 if (!pipe || !pipe->get_param(pipe, PIPE_CAP_COMPUTE)) {
49 if (pipe)
50 pipe->destroy(pipe);
Francisco Jerezc6db1b32012-04-20 16:56:19 +020051 throw error(CL_INVALID_DEVICE);
Tom Stellardc5f0c982014-05-08 21:08:32 -040052 }
Francisco Jerezc6db1b32012-04-20 16:56:19 +020053}
54
Francisco Jerezc9e009b2013-09-15 20:06:57 -070055device::~device() {
Francisco Jerezc6db1b32012-04-20 16:56:19 +020056 if (pipe)
57 pipe->destroy(pipe);
58 if (ldev)
59 pipe_loader_release(&ldev, 1);
60}
61
Francisco Jerez369419f2013-09-16 21:11:16 -070062bool
63device::operator==(const device &dev) const {
64 return this == &dev;
65}
66
Francisco Jerezc6db1b32012-04-20 16:56:19 +020067cl_device_type
Francisco Jerezc9e009b2013-09-15 20:06:57 -070068device::type() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +020069 switch (ldev->type) {
70 case PIPE_LOADER_DEVICE_SOFTWARE:
71 return CL_DEVICE_TYPE_CPU;
72 case PIPE_LOADER_DEVICE_PCI:
Emil Velikov26458422014-01-11 05:19:36 +000073 case PIPE_LOADER_DEVICE_PLATFORM:
Francisco Jerezc6db1b32012-04-20 16:56:19 +020074 return CL_DEVICE_TYPE_GPU;
75 default:
Francisco Jerez27c51b52014-10-08 17:29:14 +030076 unreachable("Unknown device type.");
Francisco Jerezc6db1b32012-04-20 16:56:19 +020077 }
78}
79
80cl_uint
Francisco Jerezc9e009b2013-09-15 20:06:57 -070081device::vendor_id() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +020082 switch (ldev->type) {
83 case PIPE_LOADER_DEVICE_SOFTWARE:
Emil Velikov26458422014-01-11 05:19:36 +000084 case PIPE_LOADER_DEVICE_PLATFORM:
Francisco Jerezc6db1b32012-04-20 16:56:19 +020085 return 0;
86 case PIPE_LOADER_DEVICE_PCI:
Francisco Jerez03e3bc42012-05-16 15:43:29 +020087 return ldev->u.pci.vendor_id;
Francisco Jerezc6db1b32012-04-20 16:56:19 +020088 default:
Francisco Jerez27c51b52014-10-08 17:29:14 +030089 unreachable("Unknown device type.");
Francisco Jerezc6db1b32012-04-20 16:56:19 +020090 }
91}
92
93size_t
Francisco Jerezc9e009b2013-09-15 20:06:57 -070094device::max_images_read() const {
Marek Olšákb73bec02015-07-05 14:34:13 +020095 return PIPE_MAX_SHADER_IMAGES;
Francisco Jerezc6db1b32012-04-20 16:56:19 +020096}
97
98size_t
Francisco Jerezc9e009b2013-09-15 20:06:57 -070099device::max_images_write() const {
Marek Olšákb73bec02015-07-05 14:34:13 +0200100 return PIPE_MAX_SHADER_IMAGES;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200101}
102
Serge Martin05fcc732016-10-01 18:51:11 +0200103size_t
104device::max_image_buffer_size() const {
105 return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE);
106}
107
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200108cl_uint
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700109device::max_image_levels_2d() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200110 return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
111}
112
113cl_uint
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700114device::max_image_levels_3d() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200115 return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_3D_LEVELS);
116}
117
Serge Martin05fcc732016-10-01 18:51:11 +0200118size_t
119device::max_image_array_number() const {
120 return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
121}
122
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200123cl_uint
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700124device::max_samplers() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200125 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
126 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
127}
128
129cl_ulong
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700130device::max_mem_global() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100131 return get_compute_param<uint64_t>(pipe, ir_format(),
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200132 PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE)[0];
133}
134
135cl_ulong
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700136device::max_mem_local() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100137 return get_compute_param<uint64_t>(pipe, ir_format(),
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200138 PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE)[0];
139}
140
141cl_ulong
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700142device::max_mem_input() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100143 return get_compute_param<uint64_t>(pipe, ir_format(),
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200144 PIPE_COMPUTE_CAP_MAX_INPUT_SIZE)[0];
145}
146
147cl_ulong
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700148device::max_const_buffer_size() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200149 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
Marek Olšák04f2c882014-07-24 20:32:08 +0200150 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE);
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200151}
152
153cl_uint
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700154device::max_const_buffers() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200155 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
156 PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
157}
158
Christoph Bumiller5c9bccc2012-05-12 19:32:46 +0200159size_t
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700160device::max_threads_per_block() const {
Christoph Bumiller5c9bccc2012-05-12 19:32:46 +0200161 return get_compute_param<uint64_t>(
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100162 pipe, ir_format(), PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK)[0];
Christoph Bumiller5c9bccc2012-05-12 19:32:46 +0200163}
164
Tom Stellard71682cf2012-09-17 14:29:49 +0000165cl_ulong
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700166device::max_mem_alloc_size() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100167 return get_compute_param<uint64_t>(pipe, ir_format(),
Tom Stellard71682cf2012-09-17 14:29:49 +0000168 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0];
169}
170
Tom Stellardca848e82014-04-18 16:28:41 +0200171cl_uint
172device::max_clock_frequency() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100173 return get_compute_param<uint32_t>(pipe, ir_format(),
Tom Stellardca848e82014-04-18 16:28:41 +0200174 PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)[0];
175}
176
Bruno Jiménez2a0dffa2014-05-30 17:31:12 +0200177cl_uint
178device::max_compute_units() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100179 return get_compute_param<uint32_t>(pipe, ir_format(),
Bruno Jiménez2a0dffa2014-05-30 17:31:12 +0200180 PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS)[0];
181}
182
Tom Stellard0ec85872014-07-23 20:37:08 -0400183bool
184device::image_support() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100185 return get_compute_param<uint32_t>(pipe, ir_format(),
Tom Stellard0ec85872014-07-23 20:37:08 -0400186 PIPE_COMPUTE_CAP_IMAGES_SUPPORTED)[0];
187}
188
Tom Stellardc97e9022014-07-02 15:42:43 -0400189bool
190device::has_doubles() const {
Nicolai Hähnlea020cb32017-01-27 10:35:13 +0100191 return pipe->get_param(pipe, PIPE_CAP_DOUBLES);
Tom Stellardc97e9022014-07-02 15:42:43 -0400192}
193
Aaron Watryd364ab42017-06-02 21:51:43 -0500194bool
Jan Veselyfdf0f1d2017-09-01 17:48:39 -0400195device::has_halves() const {
196 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
197 PIPE_SHADER_CAP_FP16);
198}
199
200bool
Jan Veselyf67ceef2017-09-20 16:06:10 -0400201device::has_int64_atomics() const {
202 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
203 PIPE_SHADER_CAP_INT64_ATOMICS);
204}
205
206bool
Aaron Watryd364ab42017-06-02 21:51:43 -0500207device::has_unified_memory() const {
208 return pipe->get_param(pipe, PIPE_CAP_UMA);
209}
210
Aaron Watry5e253fe2017-08-16 20:44:41 -0500211cl_uint
212device::mem_base_addr_align() const {
213 return sysconf(_SC_PAGESIZE);
214}
215
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200216std::vector<size_t>
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700217device::max_block_size() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100218 auto v = get_compute_param<uint64_t>(pipe, ir_format(),
219 PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
Francisco Jerezb70736f2012-05-12 19:33:33 +0200220 return { v.begin(), v.end() };
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200221}
222
Grigori Goronzyd15b32e2015-05-28 13:01:51 +0200223cl_uint
224device::subgroup_size() const {
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100225 return get_compute_param<uint32_t>(pipe, ir_format(),
226 PIPE_COMPUTE_CAP_SUBGROUP_SIZE)[0];
Grigori Goronzyd15b32e2015-05-28 13:01:51 +0200227}
228
Jan Vesely083746b2016-08-28 04:08:15 -0400229cl_uint
230device::address_bits() const {
231 return get_compute_param<uint32_t>(pipe, ir_format(),
232 PIPE_COMPUTE_CAP_ADDRESS_BITS)[0];
233}
234
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200235std::string
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700236device::device_name() const {
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200237 return pipe->get_name(pipe);
238}
239
240std::string
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700241device::vendor_name() const {
Giuseppe Bilotta7932b302015-03-22 07:21:02 +0100242 return pipe->get_device_vendor(pipe);
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200243}
244
Tom Stellard613323b2012-04-23 12:09:08 -0400245enum pipe_shader_ir
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700246device::ir_format() const {
Pierre Moreau67769c92018-02-10 16:56:11 +0100247 return PIPE_SHADER_IR_NATIVE;
Tom Stellard613323b2012-04-23 12:09:08 -0400248}
249
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200250std::string
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700251device::ir_target() const {
252 std::vector<char> target = get_compute_param<char>(
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100253 pipe, ir_format(), PIPE_COMPUTE_CAP_IR_TARGET);
Tom Stellard613323b2012-04-23 12:09:08 -0400254 return { target.data() };
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200255}
Tom Stellard8c9d3c62013-07-09 21:21:40 -0700256
257enum pipe_endian
Francisco Jerezc9e009b2013-09-15 20:06:57 -0700258device::endianness() const {
Tom Stellard8c9d3c62013-07-09 21:21:40 -0700259 return (enum pipe_endian)pipe->get_param(pipe, PIPE_CAP_ENDIANNESS);
260}
Aaron Watry293b3e02017-07-21 21:17:50 -0500261
262std::string
263device::device_version() const {
Aaron Watry95ae6c02017-08-09 22:02:30 -0500264 static const std::string device_version =
265 debug_get_option("CLOVER_DEVICE_VERSION_OVERRIDE", "1.1");
266 return device_version;
Aaron Watry293b3e02017-07-21 21:17:50 -0500267}
268
269std::string
270device::device_clc_version() const {
Aaron Watry95ae6c02017-08-09 22:02:30 -0500271 static const std::string device_clc_version =
272 debug_get_option("CLOVER_DEVICE_CLC_VERSION_OVERRIDE", "1.1");
273 return device_clc_version;
Aaron Watry293b3e02017-07-21 21:17:50 -0500274}
Pierre Moreau505ec3a2017-10-03 21:07:45 +0200275
276bool
277device::supports_ir(enum pipe_shader_ir ir) const {
278 return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
279 PIPE_SHADER_CAP_SUPPORTED_IRS) & (1 << ir);
280}
Pierre Moreaub0336202018-01-21 18:49:00 +0100281
282std::string
283device::supported_extensions() const {
284 return
285 "cl_khr_byte_addressable_store"
286 " cl_khr_global_int32_base_atomics"
287 " cl_khr_global_int32_extended_atomics"
288 " cl_khr_local_int32_base_atomics"
289 " cl_khr_local_int32_extended_atomics"
290 + std::string(has_int64_atomics() ? " cl_khr_int64_base_atomics" : "")
291 + std::string(has_int64_atomics() ? " cl_khr_int64_extended_atomics" : "")
292 + std::string(has_doubles() ? " cl_khr_fp64" : "")
293 + std::string(has_halves() ? " cl_khr_fp16" : "");
294}