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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 // SOFTWARE.
21 //
22 
23 #ifndef __CORE_DEVICE_HPP__
24 #define __CORE_DEVICE_HPP__
25 
26 #include <set>
27 #include <vector>
28 
29 #include "core/base.hpp"
30 #include "core/format.hpp"
31 #include "pipe-loader/pipe_loader.h"
32 
33 namespace clover {
34    typedef struct _cl_device_id device;
35    class root_resource;
36    class hard_event;
37 }
38 
39 struct _cl_device_id {
40 public:
41    _cl_device_id(pipe_loader_device *ldev);
42    _cl_device_id(_cl_device_id &&dev);
43    _cl_device_id(const _cl_device_id &dev) = delete;
44    ~_cl_device_id();
45 
46    cl_device_type type() const;
47    cl_uint vendor_id() const;
48    size_t max_images_read() const;
49    size_t max_images_write() const;
50    cl_uint max_image_levels_2d() const;
51    cl_uint max_image_levels_3d() const;
52    cl_uint max_samplers() const;
53    cl_ulong max_mem_global() const;
54    cl_ulong max_mem_local() const;
55    cl_ulong max_mem_input() const;
56    cl_ulong max_const_buffer_size() const;
57    cl_uint max_const_buffers() const;
58    size_t max_threads_per_block() const;
59 
60    std::vector<size_t> max_block_size() const;
61    std::string device_name() const;
62    std::string vendor_name() const;
63    enum pipe_shader_ir ir_format() const;
64    std::string ir_target() const;
65 
66    friend struct _cl_command_queue;
67    friend class clover::root_resource;
68    friend class clover::hard_event;
69    friend std::set<cl_image_format>
70    clover::supported_formats(cl_context, cl_mem_object_type);
71 
72 private:
73    pipe_screen *pipe;
74    pipe_loader_device *ldev;
75 };
76 
77 namespace clover {
78    ///
79    /// Container of all the compute devices that are available in the
80    /// system.
81    ///
82    class device_registry {
83    public:
84       typedef std::vector<device>::iterator iterator;
85 
86       device_registry();
87 
begin()88       iterator begin() {
89          return devs.begin();
90       }
91 
end()92       iterator end() {
93          return devs.end();
94       }
95 
front()96       device &front() {
97          return devs.front();
98       }
99 
back()100       device &back() {
101          return devs.back();
102       }
103 
104    protected:
105       std::vector<device> devs;
106    };
107 }
108 
109 #endif
110