blob: 05964e78a79a9da609ae40ca24fa1f30139352bd [file] [log] [blame]
Francisco Jerezc6db1b32012-04-20 16:56:19 +02001//
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 Graunkef0cb66b2013-04-21 13:52:08 -070017// 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 Jerezc6db1b32012-04-20 16:56:19 +020021//
22
Francisco Jerez099d2812013-09-15 15:29:34 -070023#ifndef CLOVER_CORE_PROGRAM_HPP
24#define CLOVER_CORE_PROGRAM_HPP
Francisco Jerezc6db1b32012-04-20 16:56:19 +020025
26#include <map>
27
Francisco Jerezbff60c82013-10-06 13:51:01 -070028#include "core/object.hpp"
Francisco Jerezc6db1b32012-04-20 16:56:19 +020029#include "core/context.hpp"
30#include "core/module.hpp"
31
32namespace clover {
Francisco Jerez9c7cda22016-05-17 16:03:17 +020033 typedef std::vector<std::pair<std::string, std::string>> header_map;
34
Francisco Jerez35307f52013-09-17 23:20:11 -070035 class program : public ref_counter, public _cl_program {
Francisco Jerez7a9bbff2013-09-16 21:50:40 -070036 private:
37 typedef adaptor_range<
Francisco Jerezc4578d22014-02-18 15:07:11 +010038 evals, const std::vector<intrusive_ref<device>> &> device_range;
Francisco Jerez7a9bbff2013-09-16 21:50:40 -070039
Francisco Jerez35307f52013-09-17 23:20:11 -070040 public:
Francisco Jerezc4578d22014-02-18 15:07:11 +010041 program(clover::context &ctx,
Francisco Jerez35307f52013-09-17 23:20:11 -070042 const std::string &source);
Francisco Jerezc4578d22014-02-18 15:07:11 +010043 program(clover::context &ctx,
Francisco Jerez010918f2016-05-17 16:03:14 +020044 const ref_vector<device> &devs = {},
45 const std::vector<module> &binaries = {});
Francisco Jerez35307f52013-09-17 23:20:11 -070046
Francisco Jerez5226eac2013-09-16 21:44:36 -070047 program(const program &prog) = delete;
48 program &
49 operator=(const program &prog) = delete;
50
Francisco Jerez010918f2016-05-17 16:03:14 +020051 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 Jerez35307f52013-09-17 23:20:11 -070055
Francisco Jerez56626022014-01-14 21:55:29 +010056 const bool has_source;
Francisco Jerez35307f52013-09-17 23:20:11 -070057 const std::string &source() const;
Francisco Jerez35307f52013-09-17 23:20:11 -070058
Francisco Jerez7a9bbff2013-09-16 21:50:40 -070059 device_range devices() const;
60
Francisco Jerez19424902016-05-17 16:03:13 +020061 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 Martincc495052016-10-30 17:21:15 -070066 cl_program_binary_type binary_type() const;
Francisco Jerez19424902016-05-17 16:03:13 +020067
68 module binary;
69 std::string opts;
70 std::string log;
71 };
72
Francisco Jerez010918f2016-05-17 16:03:14 +020073 const build &build(const device &dev) const;
Francisco Jerez7a9bbff2013-09-16 21:50:40 -070074
EdBd8f817a2015-04-23 20:13:51 +020075 const std::vector<module::symbol> &symbols() const;
Francisco Jerez35307f52013-09-17 23:20:11 -070076
Francisco Jereze9a4e742014-08-16 16:25:34 +030077 unsigned kernel_ref_count() const;
78
Francisco Jerezc4578d22014-02-18 15:07:11 +010079 const intrusive_ref<clover::context> context;
Francisco Jerez35307f52013-09-17 23:20:11 -070080
Francisco Jereze9a4e742014-08-16 16:25:34 +030081 friend class kernel;
82
Francisco Jerez35307f52013-09-17 23:20:11 -070083 private:
Francisco Jerezc4578d22014-02-18 15:07:11 +010084 std::vector<intrusive_ref<device>> _devices;
Francisco Jerez19424902016-05-17 16:03:13 +020085 std::map<const device *, struct build> _builds;
Francisco Jerez35307f52013-09-17 23:20:11 -070086 std::string _source;
Francisco Jereze9a4e742014-08-16 16:25:34 +030087 ref_counter _kernel_ref_counter;
Francisco Jerez35307f52013-09-17 23:20:11 -070088 };
Francisco Jerezc6db1b32012-04-20 16:56:19 +020089}
90
Francisco Jerezc6db1b32012-04-20 16:56:19 +020091#endif