Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 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 |
Kenneth Graunke | f0cb66b | 2013-04-21 13:52:08 -0700 | [diff] [blame] | 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. |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 21 | // |
| 22 | |
Francisco Jerez | 099d281 | 2013-09-15 15:29:34 -0700 | [diff] [blame] | 23 | #ifndef CLOVER_CORE_PROGRAM_HPP |
| 24 | #define CLOVER_CORE_PROGRAM_HPP |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 25 | |
| 26 | #include <map> |
| 27 | |
Francisco Jerez | bff60c8 | 2013-10-06 13:51:01 -0700 | [diff] [blame] | 28 | #include "core/object.hpp" |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 29 | #include "core/context.hpp" |
| 30 | #include "core/module.hpp" |
| 31 | |
| 32 | namespace clover { |
Francisco Jerez | 9c7cda2 | 2016-05-17 16:03:17 +0200 | [diff] [blame] | 33 | typedef std::vector<std::pair<std::string, std::string>> header_map; |
| 34 | |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 35 | class program : public ref_counter, public _cl_program { |
Francisco Jerez | 7a9bbff | 2013-09-16 21:50:40 -0700 | [diff] [blame] | 36 | private: |
| 37 | typedef adaptor_range< |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 38 | evals, const std::vector<intrusive_ref<device>> &> device_range; |
Francisco Jerez | 7a9bbff | 2013-09-16 21:50:40 -0700 | [diff] [blame] | 39 | |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 40 | public: |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 41 | program(clover::context &ctx, |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 42 | const std::string &source); |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 43 | program(clover::context &ctx, |
Francisco Jerez | 010918f | 2016-05-17 16:03:14 +0200 | [diff] [blame] | 44 | const ref_vector<device> &devs = {}, |
| 45 | const std::vector<module> &binaries = {}); |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 46 | |
Francisco Jerez | 5226eac | 2013-09-16 21:44:36 -0700 | [diff] [blame] | 47 | program(const program &prog) = delete; |
| 48 | program & |
| 49 | operator=(const program &prog) = delete; |
| 50 | |
Francisco Jerez | 010918f | 2016-05-17 16:03:14 +0200 | [diff] [blame] | 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); |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 55 | |
Francisco Jerez | 5662602 | 2014-01-14 21:55:29 +0100 | [diff] [blame] | 56 | const bool has_source; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 57 | const std::string &source() const; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 58 | |
Francisco Jerez | 7a9bbff | 2013-09-16 21:50:40 -0700 | [diff] [blame] | 59 | device_range devices() const; |
| 60 | |
Francisco Jerez | 1942490 | 2016-05-17 16:03:13 +0200 | [diff] [blame] | 61 | struct build { |
| 62 | 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; |
Serge Martin | cc49505 | 2016-10-30 17:21:15 -0700 | [diff] [blame] | 66 | cl_program_binary_type binary_type() const; |
Francisco Jerez | 1942490 | 2016-05-17 16:03:13 +0200 | [diff] [blame] | 67 | |
| 68 | module binary; |
| 69 | std::string opts; |
| 70 | std::string log; |
| 71 | }; |
| 72 | |
Francisco Jerez | 010918f | 2016-05-17 16:03:14 +0200 | [diff] [blame] | 73 | const build &build(const device &dev) const; |
Francisco Jerez | 7a9bbff | 2013-09-16 21:50:40 -0700 | [diff] [blame] | 74 | |
EdB | d8f817a | 2015-04-23 20:13:51 +0200 | [diff] [blame] | 75 | const std::vector<module::symbol> &symbols() const; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 76 | |
Francisco Jerez | e9a4e74 | 2014-08-16 16:25:34 +0300 | [diff] [blame] | 77 | unsigned kernel_ref_count() const; |
| 78 | |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 79 | const intrusive_ref<clover::context> context; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 80 | |
Francisco Jerez | e9a4e74 | 2014-08-16 16:25:34 +0300 | [diff] [blame] | 81 | friend class kernel; |
| 82 | |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 83 | private: |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 84 | std::vector<intrusive_ref<device>> _devices; |
Francisco Jerez | 1942490 | 2016-05-17 16:03:13 +0200 | [diff] [blame] | 85 | std::map<const device *, struct build> _builds; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 86 | std::string _source; |
Francisco Jerez | e9a4e74 | 2014-08-16 16:25:34 +0300 | [diff] [blame] | 87 | ref_counter _kernel_ref_counter; |
Francisco Jerez | 35307f5 | 2013-09-17 23:20:11 -0700 | [diff] [blame] | 88 | }; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 91 | #endif |