• 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_PROGRAM_HPP
24 #define CLOVER_CORE_PROGRAM_HPP
25 
26 #include <map>
27 
28 #include "core/object.hpp"
29 #include "core/context.hpp"
30 #include "core/module.hpp"
31 
32 namespace clover {
33    typedef std::vector<std::pair<std::string, std::string>> header_map;
34 
35    class program : public ref_counter, public _cl_program {
36    private:
37       typedef adaptor_range<
38          evals, const std::vector<intrusive_ref<device>> &> device_range;
39 
40    public:
41       program(clover::context &ctx,
42               const std::string &source);
43       program(clover::context &ctx,
44               const ref_vector<device> &devs = {},
45               const std::vector<module> &binaries = {});
46 
47       program(const program &prog) = delete;
48       program &
49       operator=(const program &prog) = delete;
50 
51       void compile(const ref_vector<device> &devs, const std::string &opts,
52                    const header_map &headers = {});
53       void link(const ref_vector<device> &devs, const std::string &opts,
54                 const ref_vector<program> &progs);
55 
56       const bool has_source;
57       const std::string &source() const;
58 
59       device_range devices() const;
60 
61       struct build {
buildclover::program::build62          build(const module &m = {}, const std::string &opts = {},
63                const std::string &log = {}) : binary(m), opts(opts), log(log) {}
64 
65          cl_build_status status() const;
66          cl_program_binary_type binary_type() const;
67 
68          module binary;
69          std::string opts;
70          std::string log;
71       };
72 
73       const build &build(const device &dev) const;
74 
75       const std::vector<module::symbol> &symbols() const;
76 
77       unsigned kernel_ref_count() const;
78 
79       const intrusive_ref<clover::context> context;
80 
81       friend class kernel;
82 
83    private:
84       std::vector<intrusive_ref<device>> _devices;
85       std::map<const device *, struct build> _builds;
86       std::string _source;
87       ref_counter _kernel_ref_counter;
88    };
89 }
90 
91 #endif
92