Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 1 | // |
| 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 Graunke | f0cb66b | 2013-04-21 13:52:08 -0700 | [diff] [blame] | 17 | // 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 Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 21 | // |
| 22 | |
Serge Martin | dad042b | 2020-05-03 13:56:15 +0200 | [diff] [blame] | 23 | #include <algorithm> |
Aaron Watry | 5e253fe | 2017-08-16 20:44:41 -0500 | [diff] [blame] | 24 | #include <unistd.h> |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 25 | #include "core/device.hpp" |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 26 | #include "core/platform.hpp" |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 27 | #include "pipe/p_screen.h" |
| 28 | #include "pipe/p_state.h" |
Eric Anholt | 0c31fe9 | 2019-04-29 15:38:24 -0700 | [diff] [blame] | 29 | #include "util/bitscan.h" |
Aaron Watry | 95ae6c0 | 2017-08-09 22:02:30 -0500 | [diff] [blame] | 30 | #include "util/u_debug.h" |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 31 | #include "spirv/invocation.hpp" |
| 32 | #include "nir/invocation.hpp" |
| 33 | #include <fstream> |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 34 | |
| 35 | using namespace clover; |
| 36 | |
| 37 | namespace { |
| 38 | template<typename T> |
| 39 | std::vector<T> |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 40 | get_compute_param(pipe_screen *pipe, pipe_shader_ir ir_format, |
| 41 | pipe_compute_cap cap) { |
| 42 | int sz = pipe->get_compute_param(pipe, ir_format, cap, NULL); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 43 | std::vector<T> v(sz / sizeof(T)); |
| 44 | |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 45 | pipe->get_compute_param(pipe, ir_format, cap, &v.front()); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 46 | return v; |
| 47 | } |
| 48 | } |
| 49 | |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 50 | device::device(clover::platform &platform, pipe_loader_device *ldev) : |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 51 | platform(platform), clc_cache(NULL), ldev(ldev) { |
Nicolai Hähnle | ae7283d | 2017-08-03 15:02:09 +0200 | [diff] [blame] | 52 | pipe = pipe_loader_create_screen(ldev); |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 53 | if (pipe && pipe->get_param(pipe, PIPE_CAP_COMPUTE)) { |
| 54 | if (supports_ir(PIPE_SHADER_IR_NATIVE)) |
| 55 | return; |
| 56 | #ifdef HAVE_CLOVER_SPIRV |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 57 | if (supports_ir(PIPE_SHADER_IR_NIR_SERIALIZED)) { |
Dave Airlie | 43390a5 | 2020-10-07 09:01:43 +1000 | [diff] [blame] | 58 | nir::check_for_libclc(*this); |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 59 | clc_cache = nir::create_clc_disk_cache(); |
Dave Airlie | 43390a5 | 2020-10-07 09:01:43 +1000 | [diff] [blame] | 60 | clc_nir = lazy<std::shared_ptr<nir_shader>>([&] () { std::string log; return std::shared_ptr<nir_shader>(nir::load_libclc_nir(*this, log), ralloc_free); }); |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 61 | return; |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 62 | } |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 63 | #endif |
Tom Stellard | c5f0c98 | 2014-05-08 21:08:32 -0400 | [diff] [blame] | 64 | } |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 65 | if (pipe) |
| 66 | pipe->destroy(pipe); |
| 67 | throw error(CL_INVALID_DEVICE); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 70 | device::~device() { |
Dave Airlie | f33b417 | 2019-04-10 10:24:46 +1000 | [diff] [blame] | 71 | if (clc_cache) |
| 72 | disk_cache_destroy(clc_cache); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 73 | if (pipe) |
| 74 | pipe->destroy(pipe); |
| 75 | if (ldev) |
| 76 | pipe_loader_release(&ldev, 1); |
| 77 | } |
| 78 | |
Francisco Jerez | 369419f | 2013-09-16 21:11:16 -0700 | [diff] [blame] | 79 | bool |
| 80 | device::operator==(const device &dev) const { |
| 81 | return this == &dev; |
| 82 | } |
| 83 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 84 | cl_device_type |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 85 | device::type() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 86 | switch (ldev->type) { |
| 87 | case PIPE_LOADER_DEVICE_SOFTWARE: |
| 88 | return CL_DEVICE_TYPE_CPU; |
| 89 | case PIPE_LOADER_DEVICE_PCI: |
Emil Velikov | 2645842 | 2014-01-11 05:19:36 +0000 | [diff] [blame] | 90 | case PIPE_LOADER_DEVICE_PLATFORM: |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 91 | return CL_DEVICE_TYPE_GPU; |
| 92 | default: |
Francisco Jerez | 27c51b5 | 2014-10-08 17:29:14 +0300 | [diff] [blame] | 93 | unreachable("Unknown device type."); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | cl_uint |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 98 | device::vendor_id() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 99 | switch (ldev->type) { |
| 100 | case PIPE_LOADER_DEVICE_SOFTWARE: |
Emil Velikov | 2645842 | 2014-01-11 05:19:36 +0000 | [diff] [blame] | 101 | case PIPE_LOADER_DEVICE_PLATFORM: |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 102 | return 0; |
| 103 | case PIPE_LOADER_DEVICE_PCI: |
Francisco Jerez | 03e3bc4 | 2012-05-16 15:43:29 +0200 | [diff] [blame] | 104 | return ldev->u.pci.vendor_id; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 105 | default: |
Francisco Jerez | 27c51b5 | 2014-10-08 17:29:14 +0300 | [diff] [blame] | 106 | unreachable("Unknown device type."); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | size_t |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 111 | device::max_images_read() const { |
Karol Herbst | f6c46e8 | 2020-10-15 16:31:10 +0200 | [diff] [blame] | 112 | return PIPE_MAX_SHADER_SAMPLER_VIEWS; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | size_t |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 116 | device::max_images_write() const { |
Marek Olšák | b73bec0 | 2015-07-05 14:34:13 +0200 | [diff] [blame] | 117 | return PIPE_MAX_SHADER_IMAGES; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Serge Martin | 05fcc73 | 2016-10-01 18:51:11 +0200 | [diff] [blame] | 120 | size_t |
| 121 | device::max_image_buffer_size() const { |
| 122 | return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE); |
| 123 | } |
| 124 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 125 | cl_uint |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 126 | device::max_image_levels_2d() const { |
Eric Anholt | 0c31fe9 | 2019-04-29 15:38:24 -0700 | [diff] [blame] | 127 | return util_last_bit(pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_2D_SIZE)); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | cl_uint |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 131 | device::max_image_levels_3d() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 132 | return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_3D_LEVELS); |
| 133 | } |
| 134 | |
Serge Martin | 05fcc73 | 2016-10-01 18:51:11 +0200 | [diff] [blame] | 135 | size_t |
| 136 | device::max_image_array_number() const { |
| 137 | return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS); |
| 138 | } |
| 139 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 140 | cl_uint |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 141 | device::max_samplers() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 142 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
| 143 | PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS); |
| 144 | } |
| 145 | |
| 146 | cl_ulong |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 147 | device::max_mem_global() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 148 | return get_compute_param<uint64_t>(pipe, ir_format(), |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 149 | PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE)[0]; |
| 150 | } |
| 151 | |
| 152 | cl_ulong |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 153 | device::max_mem_local() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 154 | return get_compute_param<uint64_t>(pipe, ir_format(), |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 155 | PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE)[0]; |
| 156 | } |
| 157 | |
| 158 | cl_ulong |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 159 | device::max_mem_input() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 160 | return get_compute_param<uint64_t>(pipe, ir_format(), |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 161 | PIPE_COMPUTE_CAP_MAX_INPUT_SIZE)[0]; |
| 162 | } |
| 163 | |
| 164 | cl_ulong |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 165 | device::max_const_buffer_size() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 166 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
Marek Olšák | 04f2c88 | 2014-07-24 20:32:08 +0200 | [diff] [blame] | 167 | PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | cl_uint |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 171 | device::max_const_buffers() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 172 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
| 173 | PIPE_SHADER_CAP_MAX_CONST_BUFFERS); |
| 174 | } |
| 175 | |
Christoph Bumiller | 5c9bccc | 2012-05-12 19:32:46 +0200 | [diff] [blame] | 176 | size_t |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 177 | device::max_threads_per_block() const { |
Christoph Bumiller | 5c9bccc | 2012-05-12 19:32:46 +0200 | [diff] [blame] | 178 | return get_compute_param<uint64_t>( |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 179 | pipe, ir_format(), PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK)[0]; |
Christoph Bumiller | 5c9bccc | 2012-05-12 19:32:46 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Tom Stellard | 71682cf | 2012-09-17 14:29:49 +0000 | [diff] [blame] | 182 | cl_ulong |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 183 | device::max_mem_alloc_size() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 184 | return get_compute_param<uint64_t>(pipe, ir_format(), |
Tom Stellard | 71682cf | 2012-09-17 14:29:49 +0000 | [diff] [blame] | 185 | PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0]; |
| 186 | } |
| 187 | |
Tom Stellard | ca848e8 | 2014-04-18 16:28:41 +0200 | [diff] [blame] | 188 | cl_uint |
| 189 | device::max_clock_frequency() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 190 | return get_compute_param<uint32_t>(pipe, ir_format(), |
Tom Stellard | ca848e8 | 2014-04-18 16:28:41 +0200 | [diff] [blame] | 191 | PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)[0]; |
| 192 | } |
| 193 | |
Bruno Jiménez | 2a0dffa | 2014-05-30 17:31:12 +0200 | [diff] [blame] | 194 | cl_uint |
| 195 | device::max_compute_units() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 196 | return get_compute_param<uint32_t>(pipe, ir_format(), |
Bruno Jiménez | 2a0dffa | 2014-05-30 17:31:12 +0200 | [diff] [blame] | 197 | PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS)[0]; |
| 198 | } |
| 199 | |
Tom Stellard | 0ec8587 | 2014-07-23 20:37:08 -0400 | [diff] [blame] | 200 | bool |
| 201 | device::image_support() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 202 | return get_compute_param<uint32_t>(pipe, ir_format(), |
Tom Stellard | 0ec8587 | 2014-07-23 20:37:08 -0400 | [diff] [blame] | 203 | PIPE_COMPUTE_CAP_IMAGES_SUPPORTED)[0]; |
| 204 | } |
| 205 | |
Tom Stellard | c97e902 | 2014-07-02 15:42:43 -0400 | [diff] [blame] | 206 | bool |
| 207 | device::has_doubles() const { |
Nicolai Hähnle | a020cb3 | 2017-01-27 10:35:13 +0100 | [diff] [blame] | 208 | return pipe->get_param(pipe, PIPE_CAP_DOUBLES); |
Tom Stellard | c97e902 | 2014-07-02 15:42:43 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Aaron Watry | d364ab4 | 2017-06-02 21:51:43 -0500 | [diff] [blame] | 211 | bool |
Jan Vesely | fdf0f1d | 2017-09-01 17:48:39 -0400 | [diff] [blame] | 212 | device::has_halves() const { |
| 213 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
| 214 | PIPE_SHADER_CAP_FP16); |
| 215 | } |
| 216 | |
| 217 | bool |
Jan Vesely | f67ceef | 2017-09-20 16:06:10 -0400 | [diff] [blame] | 218 | device::has_int64_atomics() const { |
| 219 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
| 220 | PIPE_SHADER_CAP_INT64_ATOMICS); |
| 221 | } |
| 222 | |
| 223 | bool |
Aaron Watry | d364ab4 | 2017-06-02 21:51:43 -0500 | [diff] [blame] | 224 | device::has_unified_memory() const { |
| 225 | return pipe->get_param(pipe, PIPE_CAP_UMA); |
| 226 | } |
| 227 | |
Serge Martin | dad042b | 2020-05-03 13:56:15 +0200 | [diff] [blame] | 228 | size_t |
Aaron Watry | 5e253fe | 2017-08-16 20:44:41 -0500 | [diff] [blame] | 229 | device::mem_base_addr_align() const { |
Serge Martin | dad042b | 2020-05-03 13:56:15 +0200 | [diff] [blame] | 230 | return std::max((size_t)sysconf(_SC_PAGESIZE), sizeof(cl_long) * 16); |
Aaron Watry | 5e253fe | 2017-08-16 20:44:41 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Karol Herbst | 035e882 | 2018-05-21 12:19:42 +0200 | [diff] [blame] | 233 | cl_device_svm_capabilities |
| 234 | device::svm_support() const { |
| 235 | // Without CAP_RESOURCE_FROM_USER_MEMORY SVM and CL_MEM_USE_HOST_PTR |
| 236 | // interactions won't work according to spec as clover manages a GPU side |
| 237 | // copy of the host data. |
| 238 | // |
| 239 | // The biggest problem are memory buffers created with CL_MEM_USE_HOST_PTR, |
| 240 | // but the application and/or the kernel updates the memory via SVM and not |
| 241 | // the cl_mem buffer. |
| 242 | // We can't even do proper tracking on what memory might have been accessed |
| 243 | // as the host ptr to the buffer could be within a SVM region, where through |
| 244 | // the CL API there is no reliable way of knowing if a certain cl_mem buffer |
| 245 | // was accessed by a kernel or not and the runtime can't reliably know from |
| 246 | // which side the GPU buffer content needs to be updated. |
| 247 | // |
| 248 | // Another unsolvable scenario is a cl_mem object passed by cl_mem reference |
| 249 | // and SVM pointer into the same kernel at the same time. |
Karol Herbst | c0f7f83 | 2020-05-05 15:09:50 +0200 | [diff] [blame] | 250 | if (allows_user_pointers() && pipe->get_param(pipe, PIPE_CAP_SYSTEM_SVM)) |
Karol Herbst | a218658 | 2019-05-22 22:34:09 +0200 | [diff] [blame] | 251 | // we can emulate all lower levels if we support fine grain system |
| 252 | return CL_DEVICE_SVM_FINE_GRAIN_SYSTEM | |
| 253 | CL_DEVICE_SVM_COARSE_GRAIN_BUFFER | |
| 254 | CL_DEVICE_SVM_FINE_GRAIN_BUFFER; |
Karol Herbst | 035e882 | 2018-05-21 12:19:42 +0200 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
Karol Herbst | c0f7f83 | 2020-05-05 15:09:50 +0200 | [diff] [blame] | 258 | bool |
| 259 | device::allows_user_pointers() const { |
| 260 | return pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY) || |
| 261 | pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY); |
| 262 | } |
| 263 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 264 | std::vector<size_t> |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 265 | device::max_block_size() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 266 | auto v = get_compute_param<uint64_t>(pipe, ir_format(), |
| 267 | PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE); |
Francisco Jerez | b70736f | 2012-05-12 19:33:33 +0200 | [diff] [blame] | 268 | return { v.begin(), v.end() }; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Grigori Goronzy | d15b32e | 2015-05-28 13:01:51 +0200 | [diff] [blame] | 271 | cl_uint |
| 272 | device::subgroup_size() const { |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 273 | return get_compute_param<uint32_t>(pipe, ir_format(), |
| 274 | PIPE_COMPUTE_CAP_SUBGROUP_SIZE)[0]; |
Grigori Goronzy | d15b32e | 2015-05-28 13:01:51 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Jan Vesely | 083746b | 2016-08-28 04:08:15 -0400 | [diff] [blame] | 277 | cl_uint |
| 278 | device::address_bits() const { |
| 279 | return get_compute_param<uint32_t>(pipe, ir_format(), |
| 280 | PIPE_COMPUTE_CAP_ADDRESS_BITS)[0]; |
| 281 | } |
| 282 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 283 | std::string |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 284 | device::device_name() const { |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 285 | return pipe->get_name(pipe); |
| 286 | } |
| 287 | |
| 288 | std::string |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 289 | device::vendor_name() const { |
Giuseppe Bilotta | 7932b30 | 2015-03-22 07:21:02 +0100 | [diff] [blame] | 290 | return pipe->get_device_vendor(pipe); |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Tom Stellard | 613323b | 2012-04-23 12:09:08 -0400 | [diff] [blame] | 293 | enum pipe_shader_ir |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 294 | device::ir_format() const { |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 295 | if (supports_ir(PIPE_SHADER_IR_NATIVE)) |
| 296 | return PIPE_SHADER_IR_NATIVE; |
| 297 | |
| 298 | assert(supports_ir(PIPE_SHADER_IR_NIR_SERIALIZED)); |
| 299 | return PIPE_SHADER_IR_NIR_SERIALIZED; |
Tom Stellard | 613323b | 2012-04-23 12:09:08 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 302 | std::string |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 303 | device::ir_target() const { |
| 304 | std::vector<char> target = get_compute_param<char>( |
Bas Nieuwenhuizen | 1a5c8c2 | 2016-03-25 02:06:50 +0100 | [diff] [blame] | 305 | pipe, ir_format(), PIPE_COMPUTE_CAP_IR_TARGET); |
Tom Stellard | 613323b | 2012-04-23 12:09:08 -0400 | [diff] [blame] | 306 | return { target.data() }; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 307 | } |
Tom Stellard | 8c9d3c6 | 2013-07-09 21:21:40 -0700 | [diff] [blame] | 308 | |
| 309 | enum pipe_endian |
Francisco Jerez | c9e009b | 2013-09-15 20:06:57 -0700 | [diff] [blame] | 310 | device::endianness() const { |
Tom Stellard | 8c9d3c6 | 2013-07-09 21:21:40 -0700 | [diff] [blame] | 311 | return (enum pipe_endian)pipe->get_param(pipe, PIPE_CAP_ENDIANNESS); |
| 312 | } |
Aaron Watry | 293b3e0 | 2017-07-21 21:17:50 -0500 | [diff] [blame] | 313 | |
| 314 | std::string |
| 315 | device::device_version() const { |
Aaron Watry | 95ae6c0 | 2017-08-09 22:02:30 -0500 | [diff] [blame] | 316 | static const std::string device_version = |
| 317 | debug_get_option("CLOVER_DEVICE_VERSION_OVERRIDE", "1.1"); |
| 318 | return device_version; |
Aaron Watry | 293b3e0 | 2017-07-21 21:17:50 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | std::string |
| 322 | device::device_clc_version() const { |
Aaron Watry | 95ae6c0 | 2017-08-09 22:02:30 -0500 | [diff] [blame] | 323 | static const std::string device_clc_version = |
| 324 | debug_get_option("CLOVER_DEVICE_CLC_VERSION_OVERRIDE", "1.1"); |
| 325 | return device_clc_version; |
Aaron Watry | 293b3e0 | 2017-07-21 21:17:50 -0500 | [diff] [blame] | 326 | } |
Pierre Moreau | 505ec3a | 2017-10-03 21:07:45 +0200 | [diff] [blame] | 327 | |
| 328 | bool |
| 329 | device::supports_ir(enum pipe_shader_ir ir) const { |
| 330 | return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE, |
| 331 | PIPE_SHADER_CAP_SUPPORTED_IRS) & (1 << ir); |
| 332 | } |
Pierre Moreau | b033620 | 2018-01-21 18:49:00 +0100 | [diff] [blame] | 333 | |
| 334 | std::string |
| 335 | device::supported_extensions() const { |
| 336 | return |
| 337 | "cl_khr_byte_addressable_store" |
| 338 | " cl_khr_global_int32_base_atomics" |
| 339 | " cl_khr_global_int32_extended_atomics" |
| 340 | " cl_khr_local_int32_base_atomics" |
| 341 | " cl_khr_local_int32_extended_atomics" |
| 342 | + std::string(has_int64_atomics() ? " cl_khr_int64_base_atomics" : "") |
| 343 | + std::string(has_int64_atomics() ? " cl_khr_int64_extended_atomics" : "") |
| 344 | + std::string(has_doubles() ? " cl_khr_fp64" : "") |
Karol Herbst | 471fd41 | 2019-05-24 15:47:28 +0200 | [diff] [blame] | 345 | + std::string(has_halves() ? " cl_khr_fp16" : "") |
| 346 | + std::string(svm_support() ? " cl_arm_shared_virtual_memory" : ""); |
Pierre Moreau | b033620 | 2018-01-21 18:49:00 +0100 | [diff] [blame] | 347 | } |
Karol Herbst | deb04ad | 2019-08-06 20:35:48 +0200 | [diff] [blame] | 348 | |
| 349 | const void * |
| 350 | device::get_compiler_options(enum pipe_shader_ir ir) const { |
| 351 | return pipe->get_compiler_options(pipe, ir, PIPE_SHADER_COMPUTE); |
| 352 | } |