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 "pipe/p_screen.h"
25 #include "pipe/p_state.h"
27 using namespace clover
;
32 get_compute_param(pipe_screen
*pipe
, pipe_compute_cap cap
) {
33 int sz
= pipe
->get_compute_param(pipe
, cap
, NULL
);
34 std::vector
<T
> v(sz
/ sizeof(T
));
36 pipe
->get_compute_param(pipe
, cap
, &v
.front());
41 _cl_device_id::_cl_device_id(clover::platform
&platform
,
42 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
);
49 _cl_device_id::_cl_device_id(_cl_device_id
&&dev
) :
50 platform(dev
.platform
), pipe(dev
.pipe
), ldev(dev
.ldev
) {
55 _cl_device_id::~_cl_device_id() {
59 pipe_loader_release(&ldev
, 1);
63 _cl_device_id::operator=(_cl_device_id dev
) {
64 assert(&platform
== &dev
.platform
);
66 std::swap(pipe
, dev
.pipe
);
67 std::swap(ldev
, dev
.ldev
);
73 _cl_device_id::type() const {
75 case PIPE_LOADER_DEVICE_SOFTWARE
:
76 return CL_DEVICE_TYPE_CPU
;
77 case PIPE_LOADER_DEVICE_PCI
:
78 return CL_DEVICE_TYPE_GPU
;
86 _cl_device_id::vendor_id() const {
88 case PIPE_LOADER_DEVICE_SOFTWARE
:
90 case PIPE_LOADER_DEVICE_PCI
:
91 return ldev
->u
.pci
.vendor_id
;
99 _cl_device_id::max_images_read() const {
100 return PIPE_MAX_SHADER_RESOURCES
;
104 _cl_device_id::max_images_write() const {
105 return PIPE_MAX_SHADER_RESOURCES
;
109 _cl_device_id::max_image_levels_2d() const {
110 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
114 _cl_device_id::max_image_levels_3d() const {
115 return pipe
->get_param(pipe
, PIPE_CAP_MAX_TEXTURE_3D_LEVELS
);
119 _cl_device_id::max_samplers() const {
120 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
121 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
125 _cl_device_id::max_mem_global() const {
126 return get_compute_param
<uint64_t>(pipe
,
127 PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE
)[0];
131 _cl_device_id::max_mem_local() const {
132 return get_compute_param
<uint64_t>(pipe
,
133 PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE
)[0];
137 _cl_device_id::max_mem_input() const {
138 return get_compute_param
<uint64_t>(pipe
,
139 PIPE_COMPUTE_CAP_MAX_INPUT_SIZE
)[0];
143 _cl_device_id::max_const_buffer_size() const {
144 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
145 PIPE_SHADER_CAP_MAX_CONSTS
) * 16;
149 _cl_device_id::max_const_buffers() const {
150 return pipe
->get_shader_param(pipe
, PIPE_SHADER_COMPUTE
,
151 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
);
155 _cl_device_id::max_threads_per_block() const {
156 return get_compute_param
<uint64_t>(
157 pipe
, PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
)[0];
161 _cl_device_id::max_mem_alloc_size() const {
162 return get_compute_param
<uint64_t>(pipe
,
163 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
)[0];
167 _cl_device_id::max_block_size() const {
168 auto v
= get_compute_param
<uint64_t>(pipe
, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE
);
169 return { v
.begin(), v
.end() };
173 _cl_device_id::device_name() const {
174 return pipe
->get_name(pipe
);
178 _cl_device_id::vendor_name() const {
179 return pipe
->get_vendor(pipe
);
183 _cl_device_id::ir_format() const {
184 return (enum pipe_shader_ir
) pipe
->get_shader_param(pipe
,
186 PIPE_SHADER_CAP_PREFERRED_IR
);
190 _cl_device_id::ir_target() const {
191 std::vector
<char> target
= get_compute_param
<char>(pipe
,
192 PIPE_COMPUTE_CAP_IR_TARGET
);
193 return { target
.data() };