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_compute_cap cap
) {
34 int sz
= pipe
->get_compute_param(pipe
, cap
, NULL
);
35 std::vector
<T
> v(sz
/ sizeof(T
));
37 pipe
->get_compute_param(pipe
, cap
, &v
.front());
42 device::device(clover::platform
&platform
, pipe_loader_device
*ldev
) :
43 platform(platform
), ldev(ldev
) {
44 pipe
= pipe_loader_create_screen(ldev
, PIPE_SEARCH_DIR
);
45 if (!pipe
|| !pipe
->get_param(pipe
, PIPE_CAP_COMPUTE
))
46 throw error(CL_INVALID_DEVICE
);
53 pipe_loader_release(&ldev
, 1);
57 device::operator==(const device
&dev
) const {
62 device::type() const {
64 case PIPE_LOADER_DEVICE_SOFTWARE
:
65 return CL_DEVICE_TYPE_CPU
;
66 case PIPE_LOADER_DEVICE_PCI
:
67 case PIPE_LOADER_DEVICE_PLATFORM
:
68 return CL_DEVICE_TYPE_GPU
;
76 device::vendor_id() const {
78 case PIPE_LOADER_DEVICE_SOFTWARE
:
79 case PIPE_LOADER_DEVICE_PLATFORM
:
81 case PIPE_LOADER_DEVICE_PCI
:
82 return ldev
->u
.pci
.vendor_id
;
90 device::max_images_read() const {
91 return PIPE_MAX_SHADER_RESOURCES
;
95 device::max_images_write() const {
96 return PIPE_MAX_SHADER_RESOURCES
;
100 device::max_image_levels_2d() const {
101 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
105 device::max_image_levels_3d() const {
106 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_3D_LEVELS
);
110 device::max_samplers() const {
111 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
112 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
116 device::max_mem_global() const {
117 return get_compute_param
<uint64_t>(pipe
,
118 PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE
)[0];
122 device::max_mem_local() const {
123 return get_compute_param
<uint64_t>(pipe
,
124 PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE
)[0];
128 device::max_mem_input() const {
129 return get_compute_param
<uint64_t>(pipe
,
130 PIPE_COMPUTE_CAP_MAX_INPUT_SIZE
)[0];
134 device::max_const_buffer_size() const {
135 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
136 PIPE_SHADER_CAP_MAX_CONSTS
) * 16;
140 device::max_const_buffers() const {
141 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
142 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
);
146 device::max_threads_per_block() const {
147 return get_compute_param
<uint64_t>(
148 pipe
, PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
)[0];
152 device::max_mem_alloc_size() const {
153 return get_compute_param
<uint64_t>(pipe
,
154 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
)[0];
158 device::max_block_size() const {
159 auto v
= get_compute_param
<uint64_t>(pipe
, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE
);
160 return { v
.begin(), v
.end() };
164 device::device_name() const {
165 return pipe
->get_name(pipe
);
169 device::vendor_name() const {
170 return pipe
->get_vendor(pipe
);
174 device::ir_format() const {
175 return (enum pipe_shader_ir
) pipe
->get_shader_param(
176 pipe
, PIPE_SHADER_COMPUTE
, PIPE_SHADER_CAP_PREFERRED_IR
);
180 device::ir_target() const {
181 std::vector
<char> target
= get_compute_param
<char>(
182 pipe
, PIPE_COMPUTE_CAP_IR_TARGET
);
183 return { target
.data() };
187 device::endianness() const {
188 return (enum pipe_endian
)pipe
->get_param(pipe
, PIPE_CAP_ENDIANNESS
);