Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include "ckw/KernelWriter.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 26 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 27 | #include "ckw/Error.h" |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 28 | #include "ckw/TensorInfo.h" |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 29 | #include "ckw/TensorOperand.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 31 | #include "src/Prototype.h" |
| 32 | |
| 33 | #include <sstream> |
| 34 | |
| 35 | namespace ckw |
| 36 | { |
| 37 | |
| 38 | namespace |
| 39 | { |
| 40 | |
| 41 | inline prototype::TensorInfo create_impl_tensor_info(const TensorInfo &info) |
| 42 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | return prototype::TensorInfo{info.shape(), info.data_type(), info.data_layout(), info.id()}; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | |
| 48 | // ================================================================================================= |
| 49 | // Constructors and destructor |
| 50 | // ================================================================================================= |
| 51 | |
| 52 | KernelWriter::KernelWriter(Kernel &kernel) |
| 53 | : _kernel(&kernel), |
| 54 | _impl_attr(std::make_unique<prototype::GpuKernelWriterAttribute>()), |
| 55 | _impl(prototype::GpuKernelWriterFactory::create(_impl_attr.get(), kernel.impl())) |
| 56 | { |
| 57 | _impl->set_IdSpace(1); |
| 58 | } |
| 59 | |
| 60 | KernelWriter::~KernelWriter() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | // ================================================================================================= |
| 65 | // Scope management |
| 66 | // ================================================================================================= |
| 67 | |
| 68 | int32_t KernelWriter::id_space() const |
| 69 | { |
| 70 | return _id_space; |
| 71 | } |
| 72 | |
| 73 | KernelWriter &KernelWriter::id_space(int32_t id_space) |
| 74 | { |
| 75 | CKW_ASSERT(id_space <= _max_id_space); |
| 76 | |
| 77 | _id_space = id_space; |
| 78 | return *this; |
| 79 | } |
| 80 | |
| 81 | int32_t KernelWriter::next_id_space() |
| 82 | { |
| 83 | id_space(++_max_id_space); |
| 84 | return _id_space; |
| 85 | } |
| 86 | |
| 87 | // ================================================================================================= |
| 88 | // Tensor and tile declaration |
| 89 | // ================================================================================================= |
| 90 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 91 | TensorOperand & |
| 92 | KernelWriter::declare_tensor_argument(const std::string &name, const TensorInfo &info, TensorStorageType storage_type) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 93 | { |
| 94 | const auto var_name = generate_variable_name(name); |
| 95 | |
| 96 | _impl->declare_argument(var_name, create_impl_tensor_info(info)); |
| 97 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 98 | auto &operand = _kernel->register_operand(std::make_unique<TensorOperand>(var_name, info, storage_type)); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 99 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 100 | return operand; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 103 | TileOperand &KernelWriter::declare_tile_argument(const std::string &name, int32_t value) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 104 | { |
| 105 | const auto var_name = generate_variable_name(name); |
| 106 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 107 | auto &operand = _kernel->register_operand(std::make_unique<TileOperand>(var_name, value)); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 108 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 109 | return operand; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 112 | std::string KernelWriter::generate_variable_name(const std::string &name) const |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 113 | { |
| 114 | std::stringstream var_name; |
| 115 | |
| 116 | var_name << "_" << _id_space << "_" << name; |
| 117 | |
| 118 | return var_name.str(); |
| 119 | } |
| 120 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 121 | TileOperand &KernelWriter::declare_tile_operand(std::unique_ptr<TileOperand> operand_ptr) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 122 | { |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 123 | auto &operand = _kernel->register_operand(std::move(operand_ptr)); |
| 124 | const auto &name = operand.name(); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 125 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 126 | if (!operand.is_constant()) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 127 | { |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 128 | const auto &info = operand.tile_info(); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 129 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 130 | _impl->declare_tile(name, prototype::TileInfo(info.data_type(), info.width(), info.height())); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 131 | } |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 132 | else |
| 133 | { |
| 134 | _impl->declare_const_tile(name, operand.value(), operand.data_type()); |
| 135 | } |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 136 | |
| 137 | return operand; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // ================================================================================================= |
| 141 | // Load and store |
| 142 | // ================================================================================================= |
| 143 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 144 | void KernelWriter::op_load(TileOperand &tile, |
| 145 | const TensorOperand &tensor, |
| 146 | const TensorTileSampler &sampler, |
| 147 | const TileOperand &dilation_y) |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 148 | { |
| 149 | prototype::TensorOperand impl_tensor( |
| 150 | tensor.name(), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 151 | prototype::GpuSampler{sampler.format(), prototype::to_gpu_tensor_storage(tensor.storage_type()), |
| 152 | sampler.address_mode_x(), sampler.address_mode_y(), sampler.address_mode_z()}); |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 153 | |
| 154 | auto impl_x = sampler.x().create_impl_operand(_impl.get()); |
| 155 | auto impl_y = sampler.y().create_impl_operand(_impl.get()); |
| 156 | auto impl_z = sampler.z().create_impl_operand(_impl.get()); |
| 157 | auto impl_b = sampler.b().create_impl_operand(_impl.get()); |
| 158 | |
| 159 | auto impl_dilation_y = dilation_y.create_impl_operand(_impl.get()); |
| 160 | |
| 161 | auto impl_dst = tile.create_impl_operand(_impl.get()); |
| 162 | |
| 163 | _impl->op_load_immediate(impl_tensor, impl_dst, impl_x, impl_y, impl_z, impl_b, impl_dilation_y); |
| 164 | } |
| 165 | |
| 166 | void KernelWriter::op_load_indirect(TileOperand &tile, const TensorOperand &tensor, const TensorTileSampler &sampler) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 167 | { |
Viet-Hoa Do | e1880f0 | 2023-06-28 10:25:35 +0100 | [diff] [blame] | 168 | prototype::TensorOperand impl_tensor( |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 169 | tensor.name(), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 170 | prototype::GpuSampler{sampler.format(), prototype::to_gpu_tensor_storage(tensor.storage_type()), |
| 171 | sampler.address_mode_x(), sampler.address_mode_y(), sampler.address_mode_z()}); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 172 | |
| 173 | auto impl_x = sampler.x().create_impl_operand(_impl.get()); |
| 174 | auto impl_y = sampler.y().create_impl_operand(_impl.get()); |
| 175 | auto impl_z = sampler.z().create_impl_operand(_impl.get()); |
| 176 | auto impl_b = sampler.b().create_impl_operand(_impl.get()); |
| 177 | |
| 178 | auto impl_dst = tile.create_impl_operand(_impl.get()); |
| 179 | |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 180 | _impl->op_load_indirect(impl_tensor, impl_dst, impl_x, impl_y, impl_z, impl_b); |
| 181 | } |
| 182 | |
| 183 | void KernelWriter::util_get_indirect_buffer(TileOperand &tile, |
| 184 | const TensorOperand &tensor, |
| 185 | const TensorTileSampler &sampler, |
| 186 | const TileOperand &x, |
| 187 | const TileOperand &y, |
| 188 | const TileOperand &x_off, |
| 189 | const TileOperand &y_off) |
| 190 | { |
| 191 | prototype::TensorOperand impl_tensor( |
| 192 | tensor.name(), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 193 | prototype::GpuSampler{sampler.format(), prototype::to_gpu_tensor_storage(tensor.storage_type()), |
| 194 | sampler.address_mode_x(), sampler.address_mode_y(), sampler.address_mode_z()}); |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 195 | |
| 196 | auto impl_x = x.create_impl_operand(_impl.get()); |
| 197 | auto impl_y = y.create_impl_operand(_impl.get()); |
| 198 | auto impl_x_off = x_off.create_impl_operand(_impl.get()); |
| 199 | auto impl_y_off = y_off.create_impl_operand(_impl.get()); |
| 200 | |
| 201 | auto impl_dst = tile.create_impl_operand(_impl.get()); |
| 202 | |
| 203 | _impl->util_get_indirect_buffer(impl_dst, impl_tensor, impl_x, impl_y, impl_x_off, impl_y_off); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void KernelWriter::op_store(TensorOperand &tensor, const TileOperand &tile, const TensorTileSampler &sampler) |
| 207 | { |
Viet-Hoa Do | e1880f0 | 2023-06-28 10:25:35 +0100 | [diff] [blame] | 208 | prototype::TensorOperand impl_tensor( |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 209 | tensor.name(), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 210 | prototype::GpuSampler{sampler.format(), prototype::to_gpu_tensor_storage(tensor.storage_type()), |
| 211 | sampler.address_mode_x(), sampler.address_mode_y(), sampler.address_mode_z()}); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 212 | auto impl_src = tile.create_impl_operand(_impl.get()); |
| 213 | auto impl_x = sampler.x().create_impl_operand(_impl.get()); |
| 214 | auto impl_y = sampler.y().create_impl_operand(_impl.get()); |
| 215 | auto impl_z = sampler.z().create_impl_operand(_impl.get()); |
| 216 | auto impl_b = sampler.b().create_impl_operand(_impl.get()); |
| 217 | |
| 218 | _impl->op_store_immediate(impl_tensor, impl_src, impl_x, impl_y, impl_z, impl_b); |
| 219 | } |
| 220 | |
| 221 | // ================================================================================================= |
| 222 | // Data processing |
| 223 | // ================================================================================================= |
| 224 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 225 | void KernelWriter::op_assign(const TileOperand &dst, const TileOperand &src) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 226 | { |
| 227 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 228 | auto impl_src = src.create_impl_operand(_impl.get()); |
| 229 | |
| 230 | _impl->op_assign(impl_dst, impl_src); |
| 231 | } |
| 232 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 233 | void KernelWriter::op_cast_expression(const TileOperand &dst, const TileOperand &src, const ConvertPolicy policy) |
| 234 | { |
| 235 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 236 | auto impl_src = src.create_impl_operand(_impl.get()); |
| 237 | |
| 238 | _impl->op_cast_expression(impl_dst, impl_src, policy); |
| 239 | } |
| 240 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 241 | void KernelWriter::op_binary_expression(const TileOperand &dst, |
| 242 | const TileOperand &lhs, |
| 243 | BinaryOp op, |
| 244 | const TileOperand &rhs) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 245 | { |
| 246 | auto impl_lhs = lhs.create_impl_operand(_impl.get()); |
| 247 | auto impl_rhs = rhs.create_impl_operand(_impl.get()); |
| 248 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 249 | |
| 250 | _impl->op_binary_expression(impl_dst, impl_lhs, op, impl_rhs); |
| 251 | } |
| 252 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 253 | void KernelWriter::op_unary_expression(const TileOperand &dst, UnaryOp op, const TileOperand &src) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 254 | { |
| 255 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 256 | auto impl_src = src.create_impl_operand(_impl.get()); |
| 257 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 258 | _impl->op_unary_expression(impl_dst, op, impl_src); |
| 259 | } |
| 260 | |
| 261 | void KernelWriter::op_unary_elementwise_function(const TileOperand &dst, UnaryFunction opcode, const TileOperand &src) |
| 262 | { |
| 263 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 264 | auto impl_src = src.create_impl_operand(_impl.get()); |
| 265 | |
| 266 | _impl->op_unary_elementwise_function(impl_dst, opcode, impl_src); |
| 267 | } |
| 268 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 269 | void KernelWriter::op_binary_elementwise_function(const TileOperand &dst, |
| 270 | BinaryFunction opcode, |
| 271 | const TileOperand &first, |
| 272 | const TileOperand &second) |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 273 | { |
| 274 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 275 | auto impl_first = first.create_impl_operand(_impl.get()); |
| 276 | auto impl_second = second.create_impl_operand(_impl.get()); |
| 277 | |
| 278 | _impl->op_binary_elementwise_function(impl_dst, opcode, impl_first, impl_second); |
| 279 | } |
| 280 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 281 | void KernelWriter::op_ternary_elementwise_function(const TileOperand &dst, |
| 282 | TernaryFunction opcode, |
| 283 | const TileOperand &first, |
| 284 | const TileOperand &second, |
| 285 | const TileOperand &third) |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 286 | { |
| 287 | auto impl_dst = dst.create_impl_operand(_impl.get()); |
| 288 | auto impl_first = first.create_impl_operand(_impl.get()); |
| 289 | auto impl_second = second.create_impl_operand(_impl.get()); |
| 290 | auto impl_third = third.create_impl_operand(_impl.get()); |
| 291 | |
| 292 | _impl->op_ternary_elementwise_function(impl_dst, opcode, impl_first, impl_second, impl_third); |
| 293 | } |
| 294 | |
| 295 | void KernelWriter::op_if(const TileOperand &lhs, BinaryOp op, const TileOperand &rhs, const std::function<void()> &body) |
| 296 | { |
| 297 | auto impl_lhs = lhs.create_impl_operand(_impl.get()); |
| 298 | auto impl_rhs = rhs.create_impl_operand(_impl.get()); |
| 299 | |
| 300 | _impl->op_if_header(impl_lhs, op, impl_rhs); |
| 301 | _impl->compound_statement_begin(); |
| 302 | body(); |
| 303 | _impl->compound_statement_end(); |
| 304 | } |
| 305 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 306 | void KernelWriter::op_else_if(const TileOperand &lhs, |
| 307 | BinaryOp op, |
| 308 | const TileOperand &rhs, |
| 309 | const std::function<void()> &body) |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 310 | { |
| 311 | auto impl_lhs = lhs.create_impl_operand(_impl.get()); |
| 312 | auto impl_rhs = rhs.create_impl_operand(_impl.get()); |
| 313 | |
| 314 | _impl->op_else_if_header(impl_lhs, op, impl_rhs); |
| 315 | _impl->compound_statement_begin(); |
| 316 | body(); |
| 317 | _impl->compound_statement_end(); |
| 318 | } |
| 319 | |
| 320 | void KernelWriter::op_else(const std::function<void()> &body) |
| 321 | { |
| 322 | _impl->op_else_header(); |
| 323 | _impl->compound_statement_begin(); |
| 324 | body(); |
| 325 | _impl->compound_statement_end(); |
| 326 | } |
| 327 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 328 | void KernelWriter::op_for_loop(const TileOperand &var_name, |
| 329 | BinaryOp cond_op, |
| 330 | const TileOperand &cond_value_name, |
| 331 | const TileOperand &update_var_name, |
| 332 | AssignmentOp update_op, |
| 333 | const TileOperand &update_value_name, |
| 334 | const std::function<void()> &body) |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 335 | { |
| 336 | auto impl_var_name = var_name.create_impl_operand(_impl.get()); |
| 337 | auto impl_cond_value_name = cond_value_name.create_impl_operand(_impl.get()); |
Nikolaj Jensen | fab6c21 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 338 | auto impl_update_var_name = update_var_name.create_impl_operand(_impl.get()); |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 339 | auto impl_update_value_name = update_value_name.create_impl_operand(_impl.get()); |
| 340 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 341 | _impl->op_for_loop_header(impl_var_name, cond_op, impl_cond_value_name, impl_update_var_name, update_op, |
| 342 | impl_update_value_name); |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 343 | _impl->compound_statement_begin(); |
| 344 | body(); |
| 345 | _impl->compound_statement_end(); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // ================================================================================================= |
| 349 | // Misc |
| 350 | // ================================================================================================= |
| 351 | |
Gunes Bayir | 91cb733 | 2023-07-25 17:00:33 +0100 | [diff] [blame] | 352 | void KernelWriter::op_get_global_id(const TileOperand &dst, int32_t dim) |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 353 | { |
| 354 | _impl->op_get_global_id(prototype::Operand(dst.name()), dim); |
| 355 | } |
| 356 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 357 | void KernelWriter::op_return() |
| 358 | { |
| 359 | _impl->op_return(); |
| 360 | } |
| 361 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 362 | // ================================================================================================= |
| 363 | // Code generation |
| 364 | // ================================================================================================= |
| 365 | |
| 366 | std::string KernelWriter::generate_code() |
| 367 | { |
| 368 | return prototype::generate_code(*_kernel->impl(), _kernel->name()); |
| 369 | } |
| 370 | |
| 371 | } // namespace ckw |