blob: 92c090f70d77df2b1f085c56627bf29091013886 [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_MODULE_HPP
24#define CLOVER_CORE_MODULE_HPP
Francisco Jerezc6db1b32012-04-20 16:56:19 +020025
EdBd8f817a2015-04-23 20:13:51 +020026#include <vector>
27#include <string>
Francisco Jerezc6db1b32012-04-20 16:56:19 +020028
Serge Martin9aea6e32020-05-09 23:13:48 +020029#include "CL/cl.h"
30
Francisco Jerezc6db1b32012-04-20 16:56:19 +020031namespace clover {
32 struct module {
Francisco Jerezc6db1b32012-04-20 16:56:19 +020033 typedef uint32_t resource_id;
34 typedef uint32_t size_t;
35
36 struct section {
37 enum type {
Serge Martincc495052016-10-30 17:21:15 -070038 text_intermediate,
39 text_library,
40 text_executable,
Francisco Jerezc6db1b32012-04-20 16:56:19 +020041 data_constant,
42 data_global,
43 data_local,
44 data_private
45 };
46
Tom Stellardd7241902012-04-24 12:36:34 -040047 section(resource_id id, enum type type, size_t size,
EdBd8f817a2015-04-23 20:13:51 +020048 const std::vector<char> &data) :
Tom Stellardd7241902012-04-24 12:36:34 -040049 id(id), type(type), size(size), data(data) { }
Serge Martincc495052016-10-30 17:21:15 -070050 section() : id(0), type(text_intermediate), size(0), data() { }
Tom Stellardd7241902012-04-24 12:36:34 -040051
Francisco Jerezc6db1b32012-04-20 16:56:19 +020052 resource_id id;
53 type type;
54 size_t size;
EdBd8f817a2015-04-23 20:13:51 +020055 std::vector<char> data;
Francisco Jerezc6db1b32012-04-20 16:56:19 +020056 };
57
Serge Martin9aea6e32020-05-09 23:13:48 +020058 struct arg_info {
59 arg_info(const std::string &arg_name, const std::string &type_name,
60 const cl_kernel_arg_type_qualifier type_qualifier,
61 const cl_kernel_arg_address_qualifier address_qualifier,
62 const cl_kernel_arg_access_qualifier access_qualifier) :
63 arg_name(arg_name), type_name(type_name),
64 type_qualifier(type_qualifier),
65 address_qualifier(address_qualifier),
66 access_qualifier(access_qualifier) { };
67 arg_info() : arg_name(""), type_name(""), type_qualifier(0),
68 address_qualifier(0), access_qualifier(0) { };
69
70 std::string arg_name;
71 std::string type_name;
72 cl_kernel_arg_type_qualifier type_qualifier;
73 cl_kernel_arg_address_qualifier address_qualifier;
74 cl_kernel_arg_access_qualifier access_qualifier;
75 };
76
Francisco Jerezc6db1b32012-04-20 16:56:19 +020077 struct argument {
78 enum type {
79 scalar,
80 constant,
81 global,
82 local,
83 image2d_rd,
84 image2d_wr,
85 image3d_rd,
86 image3d_wr,
87 sampler
88 };
89
Francisco Jerez2265b402013-07-21 00:49:54 +020090 enum ext_type {
91 zero_ext,
92 sign_ext
93 };
94
Francisco Jerez06139c52014-10-08 17:32:18 +030095 enum semantic {
96 general,
97 grid_dimension,
Zoltan Gilian9ef5b7a2015-07-27 11:34:07 +020098 grid_offset,
99 image_size,
Karol Herbstadbfff62020-09-02 20:36:41 +0200100 image_format,
101 constant_buffer
Francisco Jerez06139c52014-10-08 17:32:18 +0300102 };
103
Francisco Jerez2265b402013-07-21 00:49:54 +0200104 argument(enum type type, size_t size,
105 size_t target_size, size_t target_align,
Francisco Jerez06139c52014-10-08 17:32:18 +0300106 enum ext_type ext_type,
107 enum semantic semantic = general) :
Francisco Jerez2265b402013-07-21 00:49:54 +0200108 type(type), size(size),
109 target_size(target_size), target_align(target_align),
Francisco Jerez06139c52014-10-08 17:32:18 +0300110 ext_type(ext_type), semantic(semantic) { }
Francisco Jerez2265b402013-07-21 00:49:54 +0200111
112 argument(enum type type, size_t size) :
113 type(type), size(size),
114 target_size(size), target_align(1),
Francisco Jerez06139c52014-10-08 17:32:18 +0300115 ext_type(zero_ext), semantic(general) { }
Francisco Jerez2265b402013-07-21 00:49:54 +0200116
117 argument() : type(scalar), size(0),
118 target_size(0), target_align(1),
Francisco Jerez06139c52014-10-08 17:32:18 +0300119 ext_type(zero_ext), semantic(general) { }
Tom Stellardd7241902012-04-24 12:36:34 -0400120
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200121 type type;
122 size_t size;
Francisco Jerez2265b402013-07-21 00:49:54 +0200123 size_t target_size;
124 size_t target_align;
125 ext_type ext_type;
Francisco Jerez06139c52014-10-08 17:32:18 +0300126 semantic semantic;
Serge Martin9aea6e32020-05-09 23:13:48 +0200127 arg_info info;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200128 };
129
130 struct symbol {
Serge Martinaadd1342020-08-23 08:50:54 +0200131 symbol(const std::string &name, const std::string &attributes,
Serge Martinc04d5e72020-09-27 15:45:33 +0200132 const std::vector<::size_t> &reqd_work_group_size,
Serge Martinaadd1342020-08-23 08:50:54 +0200133 resource_id section, size_t offset,
134 const std::vector<argument> &args) :
135 name(name), attributes(attributes),
Serge Martinc04d5e72020-09-27 15:45:33 +0200136 reqd_work_group_size(reqd_work_group_size),
Serge Martinaadd1342020-08-23 08:50:54 +0200137 section(section),
138 offset(offset), args(args) { }
Serge Martinc04d5e72020-09-27 15:45:33 +0200139 symbol() : name(), attributes(), reqd_work_group_size({0, 0, 0}),
140 section(0), offset(0), args() { }
Tom Stellardd7241902012-04-24 12:36:34 -0400141
EdB2d112ed2015-04-24 12:59:56 +0200142 std::string name;
Serge Martinaadd1342020-08-23 08:50:54 +0200143 std::string attributes;
Serge Martinc04d5e72020-09-27 15:45:33 +0200144 std::vector<::size_t> reqd_work_group_size;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200145 resource_id section;
146 size_t offset;
EdBd8f817a2015-04-23 20:13:51 +0200147 std::vector<argument> args;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200148 };
149
EdBd8f817a2015-04-23 20:13:51 +0200150 void serialize(std::ostream &os) const;
151 static module deserialize(std::istream &is);
Francisco Jerez4a39e502014-06-14 21:03:02 +0200152 size_t size() const;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200153
EdBd8f817a2015-04-23 20:13:51 +0200154 std::vector<symbol> syms;
155 std::vector<section> secs;
Francisco Jerezc6db1b32012-04-20 16:56:19 +0200156 };
157}
158
159#endif