• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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.
21 //
22 
23 #ifndef CLOVER_CORE_DEVICE_HPP
24 #define CLOVER_CORE_DEVICE_HPP
25 
26 #include <set>
27 #include <vector>
28 
29 #include "core/object.hpp"
30 #include "core/format.hpp"
31 #include "core/binary.hpp"
32 #include "util/lazy.hpp"
33 #include "pipe-loader/pipe_loader.h"
34 
35 struct nir_shader;
36 struct disk_cache;
37 
38 namespace clover {
39    class platform;
40    class root_resource;
41    class hard_event;
42 
43    class device : public ref_counter, public _cl_device_id {
44    public:
45       device(clover::platform &platform, pipe_loader_device *ldev);
46       ~device();
47 
48       device(const device &dev) = delete;
49       device &
50       operator=(const device &dev) = delete;
51 
52       bool
53       operator==(const device &dev) const;
54 
55       cl_device_type type() const;
56       cl_uint vendor_id() const;
57       size_t max_images_read() const;
58       size_t max_images_write() const;
59       size_t max_image_buffer_size() const;
60       // Use for 1D and 2D images.
61       cl_uint max_image_size() const;
62       // Use for 3D images.
63       cl_uint max_image_size_3d() const;
64       size_t max_image_array_number() const;
65       cl_uint max_samplers() const;
66       cl_ulong max_mem_global() const;
67       cl_ulong max_mem_local() const;
68       cl_ulong max_mem_input() const;
69       cl_ulong max_const_buffer_size() const;
70       cl_uint max_const_buffers() const;
71       size_t max_threads_per_block() const;
72       cl_ulong max_mem_alloc_size() const;
73       cl_uint max_clock_frequency() const;
74       cl_uint max_compute_units() const;
75       cl_uint max_printf_buffer_size() const;
76       bool image_support() const;
77       bool has_doubles() const;
78       bool has_halves() const;
79       bool has_int64_atomics() const;
80       bool has_unified_memory() const;
81       size_t mem_base_addr_align() const;
82       cl_device_svm_capabilities svm_support() const;
83       bool allows_user_pointers() const;
84 
85       std::vector<size_t> max_block_size() const;
86       cl_uint subgroup_size() const;
87       cl_uint address_bits() const;
88       std::string device_name() const;
89       std::string vendor_name() const;
90       std::string device_version_as_string() const;
91       std::string device_clc_version_as_string() const;
92       enum pipe_shader_ir ir_format() const;
93       std::string ir_target() const;
94       enum pipe_endian endianness() const;
95       bool supports_ir(enum pipe_shader_ir ir) const;
96       std::string supported_extensions_as_string() const;
97       cl_version device_version() const;
98       cl_version device_clc_version(bool api = false) const;
99       std::vector<cl_name_version> opencl_c_all_versions() const;
100       std::vector<cl_name_version> supported_extensions() const;
101       std::vector<cl_name_version> supported_il_versions() const;
102 
103       std::vector<cl_name_version> opencl_c_features() const;
104 
105       friend class command_queue;
106       friend class root_resource;
107       friend class hard_event;
108       friend std::set<cl_image_format>
109       supported_formats(const context &, cl_mem_object_type, cl_mem_flags flags);
110       const void *get_compiler_options(enum pipe_shader_ir ir) const;
111 
112       clover::platform &platform;
113 
114       inline bool
has_system_svm() const115       has_system_svm() const {
116          return svm_support() & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM;
117       }
118 
119       lazy<std::shared_ptr<nir_shader>> clc_nir;
120       disk_cache *clc_cache;
121       cl_version version;
122       cl_version clc_version;
123    private:
124       pipe_screen *pipe;
125       pipe_loader_device *ldev;
126    };
127 }
128 
129 #endif
130