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_MODULE_HPP 24 #define CLOVER_CORE_MODULE_HPP 25 26 #include <vector> 27 #include <string> 28 29 #include "CL/cl.h" 30 31 namespace clover { 32 struct module { 33 typedef uint32_t resource_id; 34 typedef uint32_t size_t; 35 36 struct section { 37 enum type { 38 text_intermediate, 39 text_library, 40 text_executable, 41 data_constant, 42 data_global, 43 data_local, 44 data_private 45 }; 46 sectionclover::module::section47 section(resource_id id, enum type type, size_t size, 48 const std::vector<char> &data) : 49 id(id), type(type), size(size), data(data) { } sectionclover::module::section50 section() : id(0), type(text_intermediate), size(0), data() { } 51 52 resource_id id; 53 type type; 54 size_t size; 55 std::vector<char> data; 56 }; 57 58 struct arg_info { arg_infoclover::module::arg_info59 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) { }; arg_infoclover::module::arg_info67 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 77 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 90 enum ext_type { 91 zero_ext, 92 sign_ext 93 }; 94 95 enum semantic { 96 general, 97 grid_dimension, 98 grid_offset, 99 image_size, 100 image_format, 101 constant_buffer 102 }; 103 argumentclover::module::argument104 argument(enum type type, size_t size, 105 size_t target_size, size_t target_align, 106 enum ext_type ext_type, 107 enum semantic semantic = general) : 108 type(type), size(size), 109 target_size(target_size), target_align(target_align), 110 ext_type(ext_type), semantic(semantic) { } 111 argumentclover::module::argument112 argument(enum type type, size_t size) : 113 type(type), size(size), 114 target_size(size), target_align(1), 115 ext_type(zero_ext), semantic(general) { } 116 argumentclover::module::argument117 argument() : type(scalar), size(0), 118 target_size(0), target_align(1), 119 ext_type(zero_ext), semantic(general) { } 120 121 type type; 122 size_t size; 123 size_t target_size; 124 size_t target_align; 125 ext_type ext_type; 126 semantic semantic; 127 arg_info info; 128 }; 129 130 struct symbol { symbolclover::module::symbol131 symbol(const std::string &name, const std::string &attributes, 132 const std::vector<::size_t> &reqd_work_group_size, 133 resource_id section, size_t offset, 134 const std::vector<argument> &args) : 135 name(name), attributes(attributes), 136 reqd_work_group_size(reqd_work_group_size), 137 section(section), 138 offset(offset), args(args) { } symbolclover::module::symbol139 symbol() : name(), attributes(), reqd_work_group_size({0, 0, 0}), 140 section(0), offset(0), args() { } 141 142 std::string name; 143 std::string attributes; 144 std::vector<::size_t> reqd_work_group_size; 145 resource_id section; 146 size_t offset; 147 std::vector<argument> args; 148 }; 149 150 void serialize(std::ostream &os) const; 151 static module deserialize(std::istream &is); 152 size_t size() const; 153 154 std::vector<symbol> syms; 155 std::vector<section> secs; 156 }; 157 } 158 159 #endif 160