2 // Copyright 2012 Francisco Jerez
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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
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.
23 #include "core/device.hpp"
24 #include "core/platform.hpp"
25 #include "pipe/p_screen.h"
26 #include "pipe/p_state.h"
28 using namespace clover
;
33 get_compute_param(pipe_screen
*pipe
, pipe_shader_ir ir_format
,
34 pipe_compute_cap cap
) {
35 int sz
= pipe
->get_compute_param(pipe
, ir_format
, cap
, NULL
);
36 std::vector
<T
> v(sz
/ sizeof(T
));
38 pipe
->get_compute_param(pipe
, ir_format
, cap
, &v
.front());
43 device::device(clover::platform
&platform
, pipe_loader_device
*ldev
) :
44 platform(platform
), ldev(ldev
) {
45 pipe
= pipe_loader_create_screen(ldev
);
46 if (!pipe
|| !pipe
->get_param(pipe
, PIPE_CAP_COMPUTE
)) {
49 throw error(CL_INVALID_DEVICE
);
57 pipe_loader_release(&ldev
, 1);
61 device::operator==(const device
&dev
) const {
66 device::type() const {
68 case PIPE_LOADER_DEVICE_SOFTWARE
:
69 return CL_DEVICE_TYPE_CPU
;
70 case PIPE_LOADER_DEVICE_PCI
:
71 case PIPE_LOADER_DEVICE_PLATFORM
:
72 return CL_DEVICE_TYPE_GPU
;
74 unreachable("Unknown device type.");
79 device::vendor_id() const {
81 case PIPE_LOADER_DEVICE_SOFTWARE
:
82 case PIPE_LOADER_DEVICE_PLATFORM
:
84 case PIPE_LOADER_DEVICE_PCI
:
85 return ldev
->u
.pci
.vendor_id
;
87 unreachable("Unknown device type.");
92 device::max_images_read() const {
93 return PIPE_MAX_SHADER_IMAGES
;
97 device::max_images_write() const {
98 return PIPE_MAX_SHADER_IMAGES
;
102 device::max_image_buffer_size() const {
103 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE
);
107 device::max_image_levels_2d() const {
108 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
112 device::max_image_levels_3d() const {
113 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_3D_LEVELS
);
117 device::max_image_array_number() const {
118 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
);
122 device::max_samplers() const {
123 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
124 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
128 device::max_mem_global() const {
129 return get_compute_param
<uint64_t>(pipe
, ir_format(),
130 PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE
)[0];
134 device::max_mem_local() const {
135 return get_compute_param
<uint64_t>(pipe
, ir_format(),
136 PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE
)[0];
140 device::max_mem_input() const {
141 return get_compute_param
<uint64_t>(pipe
, ir_format(),
142 PIPE_COMPUTE_CAP_MAX_INPUT_SIZE
)[0];
146 device::max_const_buffer_size() const {
147 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
148 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
);
152 device::max_const_buffers() const {
153 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
154 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
);
158 device::max_threads_per_block() const {
159 return get_compute_param
<uint64_t>(
160 pipe
, ir_format(), PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
)[0];
164 device::max_mem_alloc_size() const {
165 return get_compute_param
<uint64_t>(pipe
, ir_format(),
166 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
)[0];
170 device::max_clock_frequency() const {
171 return get_compute_param
<uint32_t>(pipe
, ir_format(),
172 PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY
)[0];
176 device::max_compute_units() const {
177 return get_compute_param
<uint32_t>(pipe
, ir_format(),
178 PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS
)[0];
182 device::image_support() const {
183 return get_compute_param
<uint32_t>(pipe
, ir_format(),
184 PIPE_COMPUTE_CAP_IMAGES_SUPPORTED
)[0];
188 device::has_doubles() const {
189 return pipe
->get_param(pipe
, PIPE_CAP_DOUBLES
);
193 device::has_unified_memory() const {
194 return pipe
->get_param(pipe
, PIPE_CAP_UMA
);
198 device::max_block_size() const {
199 auto v
= get_compute_param
<uint64_t>(pipe
, ir_format(),
200 PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE
);
201 return { v
.begin(), v
.end() };
205 device::subgroup_size() const {
206 return get_compute_param
<uint32_t>(pipe
, ir_format(),
207 PIPE_COMPUTE_CAP_SUBGROUP_SIZE
)[0];
211 device::address_bits() const {
212 return get_compute_param
<uint32_t>(pipe
, ir_format(),
213 PIPE_COMPUTE_CAP_ADDRESS_BITS
)[0];
217 device::device_name() const {
218 return pipe
->get_name(pipe
);
222 device::vendor_name() const {
223 return pipe
->get_device_vendor(pipe
);
227 device::ir_format() const {
228 return (enum pipe_shader_ir
) pipe
->get_shader_param(
229 pipe
, PIPE_SHADER_COMPUTE
, PIPE_SHADER_CAP_PREFERRED_IR
);
233 device::ir_target() const {
234 std::vector
<char> target
= get_compute_param
<char>(
235 pipe
, ir_format(), PIPE_COMPUTE_CAP_IR_TARGET
);
236 return { target
.data() };
240 device::endianness() const {
241 return (enum pipe_endian
)pipe
->get_param(pipe
, PIPE_CAP_ENDIANNESS
);