Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2 | // Copyright (c) 2022-2023, ARM Limited. |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | // THIS FILE IS GENERATED. DO NOT EDIT! |
| 17 | // See scripts/operator_api/generate_api.py |
| 18 | |
| 19 | #include "operators.h" |
| 20 | #include "model_runner_impl.h" |
| 21 | #include "ops/op_factory.h" |
| 22 | |
| 23 | #define TOSA_RETURN_ON_ERROR(status) \ |
| 24 | do \ |
| 25 | { \ |
| 26 | if (status != 0) \ |
| 27 | { \ |
| 28 | return tosa_status_error; \ |
| 29 | } \ |
| 30 | } while (false) |
| 31 | |
| 32 | #define TOSA_RETURN_ON_GRAPH_STATUS_ERROR(status) \ |
| 33 | do \ |
| 34 | { \ |
| 35 | if (status != GraphStatus::TOSA_VALID) \ |
| 36 | { \ |
| 37 | auto ustatus = static_cast<std::underlying_type_t<GraphStatus>>(status); \ |
| 38 | return static_cast<tosa_status_t>(ustatus); \ |
| 39 | } \ |
| 40 | } while (false) |
| 41 | |
| 42 | namespace |
| 43 | { |
| 44 | |
| 45 | tosa::DType translate_client_datatype(tosa_datatype_t type) |
| 46 | { |
| 47 | switch (type) |
| 48 | { |
| 49 | case tosa_datatype_fp16_t: |
| 50 | return tosa::DType::DType_FP16; |
| 51 | case tosa_datatype_fp32_t: |
| 52 | return tosa::DType::DType_FP32; |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 53 | case tosa_datatype_bool_t: |
| 54 | return tosa::DType::DType_BOOL; |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 55 | default: |
| 56 | return tosa::DType::DType_UNKNOWN; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | tosa::TosaSerializationTensor* translate_client_tensor(tosa_tensor_t& tensor, const std::string& name) |
| 61 | { |
| 62 | std::vector<int32_t> shape(tensor.shape, tensor.shape + tensor.num_dims); |
| 63 | return new tosa::TosaSerializationTensor(name, shape, translate_client_datatype(tensor.data_type), {}); |
| 64 | } |
| 65 | |
| 66 | tosa::ResizeMode translate_client_tosa_mode(tosa_mode_t mode) |
| 67 | { |
| 68 | switch (mode) |
| 69 | { |
| 70 | case tosa_mode_nearest: |
| 71 | return tosa::ResizeMode_NEAREST; |
| 72 | case tosa_mode_max: |
| 73 | case tosa_mode_bilinear: |
| 74 | return tosa::ResizeMode_BILINEAR; |
| 75 | default: |
| 76 | return tosa::ResizeMode_UNKNOWN; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | } // namespace |
| 81 | |
| 82 | extern "C" |
| 83 | { |
| 84 | |
| 85 | tosa_status_t tosa_run_argmax(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 86 | { |
| 87 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 88 | const int32_t axis = client_axis; |
| 89 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 90 | |
| 91 | // Create tensors |
| 92 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 93 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 94 | |
| 95 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 96 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_ARGMAX, tosa::Attribute::Attribute_AxisAttribute, |
| 97 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 98 | |
| 99 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 100 | tosa::TosaSerializationBasicBlock block("argmax", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 101 | { output->GetName() }); |
| 102 | |
| 103 | // Setup model |
| 104 | TosaReference::ModelRunnerImpl runner; |
| 105 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 106 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 107 | |
| 108 | // Execute |
| 109 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 110 | |
| 111 | // Extract outputs |
| 112 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 113 | |
| 114 | return tosa_status_valid; |
| 115 | } |
| 116 | |
| 117 | tosa_status_t tosa_run_avg_pool2d(tosa_tensor_t client_input, |
| 118 | const int32_t client_kernel[2], |
| 119 | const int32_t client_stride[2], |
| 120 | const int32_t client_pad[4], |
| 121 | const int32_t client_input_zp, |
| 122 | const int32_t client_output_zp, |
| 123 | tosa_tensor_t client_output) |
| 124 | { |
| 125 | // Create operator attributes |
| 126 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[4]); |
| 127 | const std::vector<int32_t> kernel(&client_kernel[0], &client_kernel[2]); |
| 128 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[2]); |
| 129 | const int32_t input_zp = client_input_zp; |
| 130 | const int32_t output_zp = client_output_zp; |
| 131 | const tosa::DType accum_dtype = tosa::DType::DType_FP32; |
| 132 | TosaPoolAttribute attr(pad, kernel, stride, input_zp, output_zp, accum_dtype); |
| 133 | |
| 134 | // Create tensors |
| 135 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 136 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 137 | |
| 138 | // Create operator |
| 139 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_AVG_POOL2D, tosa::Attribute::Attribute_PoolAttribute, |
| 140 | &attr, { input->GetName() }, { output->GetName() }); |
| 141 | |
| 142 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 143 | tosa::TosaSerializationBasicBlock block("avg_pool2d", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 144 | { output->GetName() }); |
| 145 | |
| 146 | // Setup model |
| 147 | TosaReference::ModelRunnerImpl runner; |
| 148 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 149 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 150 | |
| 151 | // Execute |
| 152 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 153 | |
| 154 | // Extract outputs |
| 155 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 156 | |
| 157 | return tosa_status_valid; |
| 158 | } |
| 159 | |
| 160 | tosa_status_t tosa_run_conv2d(tosa_tensor_t client_input, |
| 161 | tosa_tensor_t client_weight, |
| 162 | tosa_tensor_t client_bias, |
| 163 | const int32_t client_pad[4], |
| 164 | const int32_t client_stride[2], |
| 165 | const int32_t client_dilation[2], |
| 166 | const int32_t client_input_zp, |
| 167 | const int32_t client_weight_zp, |
| 168 | tosa_tensor_t client_output) |
| 169 | { |
| 170 | // Create operator attributes |
| 171 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[4]); |
| 172 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[2]); |
| 173 | const std::vector<int32_t> dilation(&client_dilation[0], &client_dilation[2]); |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 174 | const int32_t input_zp = client_input_zp; |
| 175 | const int32_t weight_zp = client_weight_zp; |
| 176 | TosaConvAttribute attr(pad, stride, dilation, input_zp, weight_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 177 | |
| 178 | // Create tensors |
| 179 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 180 | tosa::TosaSerializationTensor* weight = translate_client_tensor(client_weight, "weight"); |
| 181 | tosa::TosaSerializationTensor* bias = translate_client_tensor(client_bias, "bias"); |
| 182 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 183 | |
| 184 | // Create operator |
| 185 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CONV2D, tosa::Attribute::Attribute_ConvAttribute, |
| 186 | &attr, { input->GetName(), weight->GetName(), bias->GetName() }, |
| 187 | { output->GetName() }); |
| 188 | |
| 189 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 190 | tosa::TosaSerializationBasicBlock block("conv2d", "main", { op }, { input, weight, bias, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 191 | { input->GetName(), weight->GetName(), bias->GetName() }, |
| 192 | { output->GetName() }); |
| 193 | |
| 194 | // Setup model |
| 195 | TosaReference::ModelRunnerImpl runner; |
| 196 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 197 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 198 | TOSA_RETURN_ON_ERROR(runner.setInput(weight->GetName(), client_weight.data, client_weight.size)); |
| 199 | TOSA_RETURN_ON_ERROR(runner.setInput(bias->GetName(), client_bias.data, client_bias.size)); |
| 200 | |
| 201 | // Execute |
| 202 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 203 | |
| 204 | // Extract outputs |
| 205 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 206 | |
| 207 | return tosa_status_valid; |
| 208 | } |
| 209 | |
| 210 | tosa_status_t tosa_run_conv3d(tosa_tensor_t client_input, |
| 211 | tosa_tensor_t client_weight, |
| 212 | tosa_tensor_t client_bias, |
| 213 | const int32_t client_pad[6], |
| 214 | const int32_t client_stride[3], |
| 215 | const int32_t client_dilation[3], |
| 216 | const int32_t client_input_zp, |
| 217 | const int32_t client_weight_zp, |
| 218 | tosa_tensor_t client_output) |
| 219 | { |
| 220 | // Create operator attributes |
| 221 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[6]); |
| 222 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[3]); |
| 223 | const std::vector<int32_t> dilation(&client_dilation[0], &client_dilation[3]); |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 224 | const int32_t input_zp = client_input_zp; |
| 225 | const int32_t weight_zp = client_weight_zp; |
| 226 | TosaConvAttribute attr(pad, stride, dilation, input_zp, weight_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 227 | |
| 228 | // Create tensors |
| 229 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 230 | tosa::TosaSerializationTensor* weight = translate_client_tensor(client_weight, "weight"); |
| 231 | tosa::TosaSerializationTensor* bias = translate_client_tensor(client_bias, "bias"); |
| 232 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 233 | |
| 234 | // Create operator |
| 235 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CONV3D, tosa::Attribute::Attribute_ConvAttribute, |
| 236 | &attr, { input->GetName(), weight->GetName(), bias->GetName() }, |
| 237 | { output->GetName() }); |
| 238 | |
| 239 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 240 | tosa::TosaSerializationBasicBlock block("conv3d", "main", { op }, { input, weight, bias, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 241 | { input->GetName(), weight->GetName(), bias->GetName() }, |
| 242 | { output->GetName() }); |
| 243 | |
| 244 | // Setup model |
| 245 | TosaReference::ModelRunnerImpl runner; |
| 246 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 247 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 248 | TOSA_RETURN_ON_ERROR(runner.setInput(weight->GetName(), client_weight.data, client_weight.size)); |
| 249 | TOSA_RETURN_ON_ERROR(runner.setInput(bias->GetName(), client_bias.data, client_bias.size)); |
| 250 | |
| 251 | // Execute |
| 252 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 253 | |
| 254 | // Extract outputs |
| 255 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 256 | |
| 257 | return tosa_status_valid; |
| 258 | } |
| 259 | |
| 260 | tosa_status_t tosa_run_depthwise_conv2d(tosa_tensor_t client_input, |
| 261 | tosa_tensor_t client_weight, |
| 262 | tosa_tensor_t client_bias, |
| 263 | const int32_t client_pad[4], |
| 264 | const int32_t client_stride[2], |
| 265 | const int32_t client_dilation[2], |
| 266 | const int32_t client_input_zp, |
| 267 | const int32_t client_weight_zp, |
| 268 | tosa_tensor_t client_output) |
| 269 | { |
| 270 | // Create operator attributes |
| 271 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[4]); |
| 272 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[2]); |
| 273 | const std::vector<int32_t> dilation(&client_dilation[0], &client_dilation[2]); |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 274 | const int32_t input_zp = client_input_zp; |
| 275 | const int32_t weight_zp = client_weight_zp; |
| 276 | TosaConvAttribute attr(pad, stride, dilation, input_zp, weight_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 277 | |
| 278 | // Create tensors |
| 279 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 280 | tosa::TosaSerializationTensor* weight = translate_client_tensor(client_weight, "weight"); |
| 281 | tosa::TosaSerializationTensor* bias = translate_client_tensor(client_bias, "bias"); |
| 282 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 283 | |
| 284 | // Create operator |
| 285 | auto op = new tosa::TosaSerializationOperator( |
| 286 | tosa::Op::Op_DEPTHWISE_CONV2D, tosa::Attribute::Attribute_ConvAttribute, &attr, |
| 287 | { input->GetName(), weight->GetName(), bias->GetName() }, { output->GetName() }); |
| 288 | |
| 289 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 290 | tosa::TosaSerializationBasicBlock block("depthwise_conv2d", "main", { op }, { input, weight, bias, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 291 | { input->GetName(), weight->GetName(), bias->GetName() }, |
| 292 | { output->GetName() }); |
| 293 | |
| 294 | // Setup model |
| 295 | TosaReference::ModelRunnerImpl runner; |
| 296 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 297 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 298 | TOSA_RETURN_ON_ERROR(runner.setInput(weight->GetName(), client_weight.data, client_weight.size)); |
| 299 | TOSA_RETURN_ON_ERROR(runner.setInput(bias->GetName(), client_bias.data, client_bias.size)); |
| 300 | |
| 301 | // Execute |
| 302 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 303 | |
| 304 | // Extract outputs |
| 305 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 306 | |
| 307 | return tosa_status_valid; |
| 308 | } |
| 309 | |
| 310 | tosa_status_t tosa_run_fully_connected(tosa_tensor_t client_input, |
| 311 | const int32_t client_input_zp, |
| 312 | const int32_t client_weight_zp, |
| 313 | tosa_tensor_t client_output) |
| 314 | { |
| 315 | // Create operator attributes |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 316 | const int32_t input_zp = client_input_zp; |
| 317 | const int32_t weight_zp = client_weight_zp; |
| 318 | TosaFullyConnectedAttribute attr(input_zp, weight_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 319 | |
| 320 | // Create tensors |
| 321 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 322 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 323 | |
| 324 | // Create operator |
| 325 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_FULLY_CONNECTED, |
| 326 | tosa::Attribute::Attribute_FullyConnectedAttribute, &attr, |
| 327 | { input->GetName() }, { output->GetName() }); |
| 328 | |
| 329 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 330 | tosa::TosaSerializationBasicBlock block("fully_connected", "main", { op }, { input, output }, |
| 331 | { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 332 | |
| 333 | // Setup model |
| 334 | TosaReference::ModelRunnerImpl runner; |
| 335 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 336 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 337 | |
| 338 | // Execute |
| 339 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 340 | |
| 341 | // Extract outputs |
| 342 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 343 | |
| 344 | return tosa_status_valid; |
| 345 | } |
| 346 | |
| 347 | tosa_status_t tosa_run_matmul(tosa_tensor_t client_a, |
| 348 | tosa_tensor_t client_b, |
| 349 | const int32_t client_a_zp, |
| 350 | const int32_t client_b_zp, |
| 351 | tosa_tensor_t client_output) |
| 352 | { |
| 353 | // Create operator attributes |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 354 | const int32_t a_zp = client_a_zp; |
| 355 | const int32_t b_zp = client_b_zp; |
| 356 | TosaMatMulAttribute attr(a_zp, b_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 357 | |
| 358 | // Create tensors |
| 359 | tosa::TosaSerializationTensor* a = translate_client_tensor(client_a, "a"); |
| 360 | tosa::TosaSerializationTensor* b = translate_client_tensor(client_b, "b"); |
| 361 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 362 | |
| 363 | // Create operator |
| 364 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_MATMUL, tosa::Attribute::Attribute_MatMulAttribute, |
| 365 | &attr, { a->GetName(), b->GetName() }, { output->GetName() }); |
| 366 | |
| 367 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 368 | tosa::TosaSerializationBasicBlock block("matmul", "main", { op }, { a, b, output }, |
| 369 | { a->GetName(), b->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 370 | |
| 371 | // Setup model |
| 372 | TosaReference::ModelRunnerImpl runner; |
| 373 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 374 | TOSA_RETURN_ON_ERROR(runner.setInput(a->GetName(), client_a.data, client_a.size)); |
| 375 | TOSA_RETURN_ON_ERROR(runner.setInput(b->GetName(), client_b.data, client_b.size)); |
| 376 | |
| 377 | // Execute |
| 378 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 379 | |
| 380 | // Extract outputs |
| 381 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 382 | |
| 383 | return tosa_status_valid; |
| 384 | } |
| 385 | |
| 386 | tosa_status_t tosa_run_max_pool2d(tosa_tensor_t client_input, |
| 387 | const int32_t client_kernel[2], |
| 388 | const int32_t client_stride[2], |
| 389 | const int32_t client_pad[4], |
| 390 | const int32_t client_input_zp, |
| 391 | const int32_t client_output_zp, |
| 392 | tosa_tensor_t client_output) |
| 393 | { |
| 394 | // Create operator attributes |
| 395 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[4]); |
| 396 | const std::vector<int32_t> kernel(&client_kernel[0], &client_kernel[2]); |
| 397 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[2]); |
| 398 | const int32_t input_zp = client_input_zp; |
| 399 | const int32_t output_zp = client_output_zp; |
| 400 | const tosa::DType accum_dtype = tosa::DType::DType_FP32; |
| 401 | TosaPoolAttribute attr(pad, kernel, stride, input_zp, output_zp, accum_dtype); |
| 402 | |
| 403 | // Create tensors |
| 404 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 405 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 406 | |
| 407 | // Create operator |
| 408 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_MAX_POOL2D, tosa::Attribute::Attribute_PoolAttribute, |
| 409 | &attr, { input->GetName() }, { output->GetName() }); |
| 410 | |
| 411 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 412 | tosa::TosaSerializationBasicBlock block("max_pool2d", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 413 | { output->GetName() }); |
| 414 | |
| 415 | // Setup model |
| 416 | TosaReference::ModelRunnerImpl runner; |
| 417 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 418 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 419 | |
| 420 | // Execute |
| 421 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 422 | |
| 423 | // Extract outputs |
| 424 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 425 | |
| 426 | return tosa_status_valid; |
| 427 | } |
| 428 | |
| 429 | tosa_status_t tosa_run_transpose_conv2d(tosa_tensor_t client_input, |
| 430 | tosa_tensor_t client_weight, |
| 431 | tosa_tensor_t client_bias, |
| 432 | const int32_t client_out_pad[4], |
| 433 | const int32_t client_stride[2], |
| 434 | const int32_t client_out_shape[4], |
| 435 | const int32_t client_input_zp, |
| 436 | const int32_t client_weight_zp, |
| 437 | const int32_t client_pad_len, |
| 438 | const int32_t client_pad[], |
| 439 | const int32_t client_dilation_len, |
| 440 | const int32_t client_dilation[], |
| 441 | tosa_tensor_t client_output) |
| 442 | { |
| 443 | // Create operator attributes |
| 444 | const std::vector<int32_t> pad(&client_pad[0], &client_pad[0] + client_pad_len); |
| 445 | const std::vector<int32_t> stride(&client_stride[0], &client_stride[2]); |
| 446 | const std::vector<int32_t> dilation(&client_dilation[0], &client_dilation[0] + client_dilation_len); |
James Ward | d34b3fc | 2023-01-18 14:51:25 +0000 | [diff] [blame] | 447 | const int32_t input_zp = client_input_zp; |
| 448 | const int32_t weight_zp = client_weight_zp; |
| 449 | TosaConvAttribute attr(pad, stride, dilation, input_zp, weight_zp); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 450 | |
| 451 | // Create tensors |
| 452 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 453 | tosa::TosaSerializationTensor* weight = translate_client_tensor(client_weight, "weight"); |
| 454 | tosa::TosaSerializationTensor* bias = translate_client_tensor(client_bias, "bias"); |
| 455 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 456 | |
| 457 | // Create operator |
| 458 | auto op = new tosa::TosaSerializationOperator( |
| 459 | tosa::Op::Op_TRANSPOSE_CONV2D, tosa::Attribute::Attribute_ConvAttribute, &attr, |
| 460 | { input->GetName(), weight->GetName(), bias->GetName() }, { output->GetName() }); |
| 461 | |
| 462 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 463 | tosa::TosaSerializationBasicBlock block("transpose_conv2d", "main", { op }, { input, weight, bias, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 464 | { input->GetName(), weight->GetName(), bias->GetName() }, |
| 465 | { output->GetName() }); |
| 466 | |
| 467 | // Setup model |
| 468 | TosaReference::ModelRunnerImpl runner; |
| 469 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 470 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 471 | TOSA_RETURN_ON_ERROR(runner.setInput(weight->GetName(), client_weight.data, client_weight.size)); |
| 472 | TOSA_RETURN_ON_ERROR(runner.setInput(bias->GetName(), client_bias.data, client_bias.size)); |
| 473 | |
| 474 | // Execute |
| 475 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 476 | |
| 477 | // Extract outputs |
| 478 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 479 | |
| 480 | return tosa_status_valid; |
| 481 | } |
| 482 | |
| 483 | tosa_status_t tosa_run_clamp(tosa_tensor_t client_input, |
| 484 | const int32_t client_min_int, |
| 485 | const int32_t client_max_int, |
| 486 | const float client_min_fp, |
| 487 | const float client_max_fp, |
| 488 | tosa_tensor_t client_output) |
| 489 | { |
| 490 | // Create operator attributes |
| 491 | const int32_t min_int = client_min_int; |
| 492 | const int32_t max_int = client_max_int; |
| 493 | const float min_fp = client_min_fp; |
| 494 | const float max_fp = client_max_fp; |
| 495 | TosaClampAttribute attr(min_int, max_int, min_fp, max_fp); |
| 496 | |
| 497 | // Create tensors |
| 498 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 499 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 500 | |
| 501 | // Create operator |
| 502 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CLAMP, tosa::Attribute::Attribute_ClampAttribute, |
| 503 | &attr, { input->GetName() }, { output->GetName() }); |
| 504 | |
| 505 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 506 | tosa::TosaSerializationBasicBlock block("clamp", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 507 | { output->GetName() }); |
| 508 | |
| 509 | // Setup model |
| 510 | TosaReference::ModelRunnerImpl runner; |
| 511 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 512 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 513 | |
| 514 | // Execute |
| 515 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 516 | |
| 517 | // Extract outputs |
| 518 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 519 | |
| 520 | return tosa_status_valid; |
| 521 | } |
| 522 | |
| 523 | tosa_status_t tosa_run_sigmoid(tosa_tensor_t client_input, tosa_tensor_t client_output) |
| 524 | { |
| 525 | // Create operator attributes |
| 526 | TosaNoneAttribute attr; |
| 527 | |
| 528 | // Create tensors |
| 529 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 530 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 531 | |
| 532 | // Create operator |
| 533 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_SIGMOID, tosa::Attribute::Attribute_NONE, &attr, |
| 534 | { input->GetName() }, { output->GetName() }); |
| 535 | |
| 536 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 537 | tosa::TosaSerializationBasicBlock block("sigmoid", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 538 | { output->GetName() }); |
| 539 | |
| 540 | // Setup model |
| 541 | TosaReference::ModelRunnerImpl runner; |
| 542 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 543 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 544 | |
| 545 | // Execute |
| 546 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 547 | |
| 548 | // Extract outputs |
| 549 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 550 | |
| 551 | return tosa_status_valid; |
| 552 | } |
| 553 | |
| 554 | tosa_status_t tosa_run_tanh(tosa_tensor_t client_input, tosa_tensor_t client_output) |
| 555 | { |
| 556 | // Create operator attributes |
| 557 | TosaNoneAttribute attr; |
| 558 | |
| 559 | // Create tensors |
| 560 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 561 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 562 | |
| 563 | // Create operator |
| 564 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_TANH, tosa::Attribute::Attribute_NONE, &attr, |
| 565 | { input->GetName() }, { output->GetName() }); |
| 566 | |
| 567 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 568 | tosa::TosaSerializationBasicBlock block("tanh", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 569 | { output->GetName() }); |
| 570 | |
| 571 | // Setup model |
| 572 | TosaReference::ModelRunnerImpl runner; |
| 573 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 574 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 575 | |
| 576 | // Execute |
| 577 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 578 | |
| 579 | // Extract outputs |
| 580 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 581 | |
| 582 | return tosa_status_valid; |
| 583 | } |
| 584 | |
| 585 | tosa_status_t tosa_run_add(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 586 | { |
| 587 | // Create operator attributes |
| 588 | TosaNoneAttribute attr; |
| 589 | |
| 590 | // Create tensors |
| 591 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 592 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 593 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 594 | |
| 595 | // Create operator |
| 596 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_ADD, tosa::Attribute::Attribute_NONE, &attr, |
| 597 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 598 | |
| 599 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 600 | tosa::TosaSerializationBasicBlock block("add", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 601 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 602 | |
| 603 | // Setup model |
| 604 | TosaReference::ModelRunnerImpl runner; |
| 605 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 606 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 607 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 608 | |
| 609 | // Execute |
| 610 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 611 | |
| 612 | // Extract outputs |
| 613 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 614 | |
| 615 | return tosa_status_valid; |
| 616 | } |
| 617 | |
| 618 | tosa_status_t tosa_run_arithmetic_right_shift(tosa_tensor_t client_input1, |
| 619 | tosa_tensor_t client_input2, |
| 620 | const bool client_round, |
| 621 | tosa_tensor_t client_output) |
| 622 | { |
| 623 | // Create operator attributes |
| 624 | const bool round = client_round; |
| 625 | TosaArithmeticRightShiftAttribute attr(round); |
| 626 | |
| 627 | // Create tensors |
| 628 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 629 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 630 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 631 | |
| 632 | // Create operator |
| 633 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_ARITHMETIC_RIGHT_SHIFT, |
| 634 | tosa::Attribute::Attribute_ArithmeticRightShiftAttribute, &attr, |
| 635 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 636 | |
| 637 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 638 | tosa::TosaSerializationBasicBlock block("arithmetic_right_shift", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 639 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 640 | |
| 641 | // Setup model |
| 642 | TosaReference::ModelRunnerImpl runner; |
| 643 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 644 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 645 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 646 | |
| 647 | // Execute |
| 648 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 649 | |
| 650 | // Extract outputs |
| 651 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 652 | |
| 653 | return tosa_status_valid; |
| 654 | } |
| 655 | |
| 656 | tosa_status_t |
| 657 | tosa_run_bitwise_and(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 658 | { |
| 659 | // Create operator attributes |
| 660 | TosaNoneAttribute attr; |
| 661 | |
| 662 | // Create tensors |
| 663 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 664 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 665 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 666 | |
| 667 | // Create operator |
| 668 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_BITWISE_AND, tosa::Attribute::Attribute_NONE, &attr, |
| 669 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 670 | |
| 671 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 672 | tosa::TosaSerializationBasicBlock block("bitwise_and", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 673 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 674 | |
| 675 | // Setup model |
| 676 | TosaReference::ModelRunnerImpl runner; |
| 677 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 678 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 679 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 680 | |
| 681 | // Execute |
| 682 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 683 | |
| 684 | // Extract outputs |
| 685 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 686 | |
| 687 | return tosa_status_valid; |
| 688 | } |
| 689 | |
| 690 | tosa_status_t |
| 691 | tosa_run_bitwise_or(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 692 | { |
| 693 | // Create operator attributes |
| 694 | TosaNoneAttribute attr; |
| 695 | |
| 696 | // Create tensors |
| 697 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 698 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 699 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 700 | |
| 701 | // Create operator |
| 702 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_BITWISE_OR, tosa::Attribute::Attribute_NONE, &attr, |
| 703 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 704 | |
| 705 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 706 | tosa::TosaSerializationBasicBlock block("bitwise_or", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 707 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 708 | |
| 709 | // Setup model |
| 710 | TosaReference::ModelRunnerImpl runner; |
| 711 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 712 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 713 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 714 | |
| 715 | // Execute |
| 716 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 717 | |
| 718 | // Extract outputs |
| 719 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 720 | |
| 721 | return tosa_status_valid; |
| 722 | } |
| 723 | |
| 724 | tosa_status_t |
| 725 | tosa_run_bitwise_xor(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 726 | { |
| 727 | // Create operator attributes |
| 728 | TosaNoneAttribute attr; |
| 729 | |
| 730 | // Create tensors |
| 731 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 732 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 733 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 734 | |
| 735 | // Create operator |
| 736 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_BITWISE_XOR, tosa::Attribute::Attribute_NONE, &attr, |
| 737 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 738 | |
| 739 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 740 | tosa::TosaSerializationBasicBlock block("bitwise_xor", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 741 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 742 | |
| 743 | // Setup model |
| 744 | TosaReference::ModelRunnerImpl runner; |
| 745 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 746 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 747 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 748 | |
| 749 | // Execute |
| 750 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 751 | |
| 752 | // Extract outputs |
| 753 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 754 | |
| 755 | return tosa_status_valid; |
| 756 | } |
| 757 | |
| 758 | tosa_status_t tosa_run_intdiv(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 759 | { |
| 760 | // Create operator attributes |
| 761 | TosaNoneAttribute attr; |
| 762 | |
| 763 | // Create tensors |
| 764 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 765 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 766 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 767 | |
| 768 | // Create operator |
| 769 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_INTDIV, tosa::Attribute::Attribute_NONE, &attr, |
| 770 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 771 | |
| 772 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 773 | tosa::TosaSerializationBasicBlock block("intdiv", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 774 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 775 | |
| 776 | // Setup model |
| 777 | TosaReference::ModelRunnerImpl runner; |
| 778 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 779 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 780 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 781 | |
| 782 | // Execute |
| 783 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 784 | |
| 785 | // Extract outputs |
| 786 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 787 | |
| 788 | return tosa_status_valid; |
| 789 | } |
| 790 | |
| 791 | tosa_status_t |
| 792 | tosa_run_logical_and(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 793 | { |
| 794 | // Create operator attributes |
| 795 | TosaNoneAttribute attr; |
| 796 | |
| 797 | // Create tensors |
| 798 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 799 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 800 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 801 | |
| 802 | // Create operator |
| 803 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_AND, tosa::Attribute::Attribute_NONE, &attr, |
| 804 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 805 | |
| 806 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 807 | tosa::TosaSerializationBasicBlock block("logical_and", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 808 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 809 | |
| 810 | // Setup model |
| 811 | TosaReference::ModelRunnerImpl runner; |
| 812 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 813 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 814 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 815 | |
| 816 | // Execute |
| 817 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 818 | |
| 819 | // Extract outputs |
| 820 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 821 | |
| 822 | return tosa_status_valid; |
| 823 | } |
| 824 | |
| 825 | tosa_status_t tosa_run_logical_left_shift(tosa_tensor_t client_input1, |
| 826 | tosa_tensor_t client_input2, |
| 827 | tosa_tensor_t client_output) |
| 828 | { |
| 829 | // Create operator attributes |
| 830 | TosaNoneAttribute attr; |
| 831 | |
| 832 | // Create tensors |
| 833 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 834 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 835 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 836 | |
| 837 | // Create operator |
| 838 | auto op = |
| 839 | new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_LEFT_SHIFT, tosa::Attribute::Attribute_NONE, &attr, |
| 840 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 841 | |
| 842 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 843 | tosa::TosaSerializationBasicBlock block("logical_left_shift", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 844 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 845 | |
| 846 | // Setup model |
| 847 | TosaReference::ModelRunnerImpl runner; |
| 848 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 849 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 850 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 851 | |
| 852 | // Execute |
| 853 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 854 | |
| 855 | // Extract outputs |
| 856 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 857 | |
| 858 | return tosa_status_valid; |
| 859 | } |
| 860 | |
| 861 | tosa_status_t tosa_run_logical_right_shift(tosa_tensor_t client_input1, |
| 862 | tosa_tensor_t client_input2, |
| 863 | tosa_tensor_t client_output) |
| 864 | { |
| 865 | // Create operator attributes |
| 866 | TosaNoneAttribute attr; |
| 867 | |
| 868 | // Create tensors |
| 869 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 870 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 871 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 872 | |
| 873 | // Create operator |
| 874 | auto op = |
| 875 | new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_RIGHT_SHIFT, tosa::Attribute::Attribute_NONE, |
| 876 | &attr, { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 877 | |
| 878 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 879 | tosa::TosaSerializationBasicBlock block("logical_right_shift", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 880 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 881 | |
| 882 | // Setup model |
| 883 | TosaReference::ModelRunnerImpl runner; |
| 884 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 885 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 886 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 887 | |
| 888 | // Execute |
| 889 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 890 | |
| 891 | // Extract outputs |
| 892 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 893 | |
| 894 | return tosa_status_valid; |
| 895 | } |
| 896 | |
| 897 | tosa_status_t |
| 898 | tosa_run_logical_or(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 899 | { |
| 900 | // Create operator attributes |
| 901 | TosaNoneAttribute attr; |
| 902 | |
| 903 | // Create tensors |
| 904 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 905 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 906 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 907 | |
| 908 | // Create operator |
| 909 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_OR, tosa::Attribute::Attribute_NONE, &attr, |
| 910 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 911 | |
| 912 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 913 | tosa::TosaSerializationBasicBlock block("logical_or", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 914 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 915 | |
| 916 | // Setup model |
| 917 | TosaReference::ModelRunnerImpl runner; |
| 918 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 919 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 920 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 921 | |
| 922 | // Execute |
| 923 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 924 | |
| 925 | // Extract outputs |
| 926 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 927 | |
| 928 | return tosa_status_valid; |
| 929 | } |
| 930 | |
| 931 | tosa_status_t |
| 932 | tosa_run_logical_xor(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 933 | { |
| 934 | // Create operator attributes |
| 935 | TosaNoneAttribute attr; |
| 936 | |
| 937 | // Create tensors |
| 938 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 939 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 940 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 941 | |
| 942 | // Create operator |
| 943 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_XOR, tosa::Attribute::Attribute_NONE, &attr, |
| 944 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 945 | |
| 946 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 947 | tosa::TosaSerializationBasicBlock block("logical_xor", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 948 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 949 | |
| 950 | // Setup model |
| 951 | TosaReference::ModelRunnerImpl runner; |
| 952 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 953 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 954 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 955 | |
| 956 | // Execute |
| 957 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 958 | |
| 959 | // Extract outputs |
| 960 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 961 | |
| 962 | return tosa_status_valid; |
| 963 | } |
| 964 | |
| 965 | tosa_status_t |
| 966 | tosa_run_maximum(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 967 | { |
| 968 | // Create operator attributes |
| 969 | TosaNoneAttribute attr; |
| 970 | |
| 971 | // Create tensors |
| 972 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 973 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 974 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 975 | |
| 976 | // Create operator |
| 977 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_MAXIMUM, tosa::Attribute::Attribute_NONE, &attr, |
| 978 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 979 | |
| 980 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 981 | tosa::TosaSerializationBasicBlock block("maximum", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 982 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 983 | |
| 984 | // Setup model |
| 985 | TosaReference::ModelRunnerImpl runner; |
| 986 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 987 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 988 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 989 | |
| 990 | // Execute |
| 991 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 992 | |
| 993 | // Extract outputs |
| 994 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 995 | |
| 996 | return tosa_status_valid; |
| 997 | } |
| 998 | |
| 999 | tosa_status_t |
| 1000 | tosa_run_minimum(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1001 | { |
| 1002 | // Create operator attributes |
| 1003 | TosaNoneAttribute attr; |
| 1004 | |
| 1005 | // Create tensors |
| 1006 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1007 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1008 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1009 | |
| 1010 | // Create operator |
| 1011 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_MINIMUM, tosa::Attribute::Attribute_NONE, &attr, |
| 1012 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1013 | |
| 1014 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1015 | tosa::TosaSerializationBasicBlock block("minimum", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1016 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1017 | |
| 1018 | // Setup model |
| 1019 | TosaReference::ModelRunnerImpl runner; |
| 1020 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1021 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1022 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1023 | |
| 1024 | // Execute |
| 1025 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1026 | |
| 1027 | // Extract outputs |
| 1028 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1029 | |
| 1030 | return tosa_status_valid; |
| 1031 | } |
| 1032 | |
| 1033 | tosa_status_t tosa_run_mul(tosa_tensor_t client_input1, |
| 1034 | tosa_tensor_t client_input2, |
| 1035 | const uint8_t client_shift, |
| 1036 | tosa_tensor_t client_output) |
| 1037 | { |
| 1038 | // Create operator attributes |
| 1039 | const int32_t shift = client_shift; |
| 1040 | TosaMulAttribute attr(shift); |
| 1041 | |
| 1042 | // Create tensors |
| 1043 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1044 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1045 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1046 | |
| 1047 | // Create operator |
| 1048 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_MUL, tosa::Attribute::Attribute_MulAttribute, &attr, |
| 1049 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1050 | |
| 1051 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1052 | tosa::TosaSerializationBasicBlock block("mul", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1053 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1054 | |
| 1055 | // Setup model |
| 1056 | TosaReference::ModelRunnerImpl runner; |
| 1057 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1058 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1059 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1060 | |
| 1061 | // Execute |
| 1062 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1063 | |
| 1064 | // Extract outputs |
| 1065 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1066 | |
| 1067 | return tosa_status_valid; |
| 1068 | } |
| 1069 | |
| 1070 | tosa_status_t tosa_run_pow(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1071 | { |
| 1072 | // Create operator attributes |
| 1073 | TosaNoneAttribute attr; |
| 1074 | |
| 1075 | // Create tensors |
| 1076 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1077 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1078 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1079 | |
| 1080 | // Create operator |
| 1081 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_POW, tosa::Attribute::Attribute_NONE, &attr, |
| 1082 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1083 | |
| 1084 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1085 | tosa::TosaSerializationBasicBlock block("pow", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1086 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1087 | |
| 1088 | // Setup model |
| 1089 | TosaReference::ModelRunnerImpl runner; |
| 1090 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1091 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1092 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1093 | |
| 1094 | // Execute |
| 1095 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1096 | |
| 1097 | // Extract outputs |
| 1098 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1099 | |
| 1100 | return tosa_status_valid; |
| 1101 | } |
| 1102 | |
| 1103 | tosa_status_t tosa_run_sub(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1104 | { |
| 1105 | // Create operator attributes |
| 1106 | TosaNoneAttribute attr; |
| 1107 | |
| 1108 | // Create tensors |
| 1109 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1110 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1111 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1112 | |
| 1113 | // Create operator |
| 1114 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_SUB, tosa::Attribute::Attribute_NONE, &attr, |
| 1115 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1116 | |
| 1117 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1118 | tosa::TosaSerializationBasicBlock block("sub", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1119 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1120 | |
| 1121 | // Setup model |
| 1122 | TosaReference::ModelRunnerImpl runner; |
| 1123 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1124 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1125 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1126 | |
| 1127 | // Execute |
| 1128 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1129 | |
| 1130 | // Extract outputs |
| 1131 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1132 | |
| 1133 | return tosa_status_valid; |
| 1134 | } |
| 1135 | |
| 1136 | tosa_status_t tosa_run_table(tosa_tensor_t client_input, |
| 1137 | const int32_t client_table_len, |
| 1138 | const int16_t client_table[], |
| 1139 | tosa_tensor_t client_output) |
| 1140 | { |
| 1141 | // Create operator attributes |
| 1142 | const std::vector<int16_t> table(&client_table[0], &client_table[0] + client_table_len); |
| 1143 | TosaTableAttribute attr(table); |
| 1144 | |
| 1145 | // Create tensors |
| 1146 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1147 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1148 | |
| 1149 | // Create operator |
| 1150 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_TABLE, tosa::Attribute::Attribute_TableAttribute, |
| 1151 | &attr, { input->GetName() }, { output->GetName() }); |
| 1152 | |
| 1153 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1154 | tosa::TosaSerializationBasicBlock block("table", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1155 | { output->GetName() }); |
| 1156 | |
| 1157 | // Setup model |
| 1158 | TosaReference::ModelRunnerImpl runner; |
| 1159 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1160 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1161 | |
| 1162 | // Execute |
| 1163 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1164 | |
| 1165 | // Extract outputs |
| 1166 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1167 | |
| 1168 | return tosa_status_valid; |
| 1169 | } |
| 1170 | |
| 1171 | tosa_status_t tosa_run_abs(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1172 | { |
| 1173 | // Create operator attributes |
| 1174 | TosaNoneAttribute attr; |
| 1175 | |
| 1176 | // Create tensors |
| 1177 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1178 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1179 | |
| 1180 | // Create operator |
| 1181 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_ABS, tosa::Attribute::Attribute_NONE, &attr, |
| 1182 | { input1->GetName() }, { output->GetName() }); |
| 1183 | |
| 1184 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1185 | tosa::TosaSerializationBasicBlock block("abs", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1186 | { output->GetName() }); |
| 1187 | |
| 1188 | // Setup model |
| 1189 | TosaReference::ModelRunnerImpl runner; |
| 1190 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1191 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1192 | |
| 1193 | // Execute |
| 1194 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1195 | |
| 1196 | // Extract outputs |
| 1197 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1198 | |
| 1199 | return tosa_status_valid; |
| 1200 | } |
| 1201 | |
| 1202 | tosa_status_t tosa_run_bitwise_not(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1203 | { |
| 1204 | // Create operator attributes |
| 1205 | TosaNoneAttribute attr; |
| 1206 | |
| 1207 | // Create tensors |
| 1208 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1209 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1210 | |
| 1211 | // Create operator |
| 1212 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_BITWISE_NOT, tosa::Attribute::Attribute_NONE, &attr, |
| 1213 | { input1->GetName() }, { output->GetName() }); |
| 1214 | |
| 1215 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1216 | tosa::TosaSerializationBasicBlock block("bitwise_not", "main", { op }, { input1, output }, |
| 1217 | { input1->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1218 | |
| 1219 | // Setup model |
| 1220 | TosaReference::ModelRunnerImpl runner; |
| 1221 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1222 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1223 | |
| 1224 | // Execute |
| 1225 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1226 | |
| 1227 | // Extract outputs |
| 1228 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1229 | |
| 1230 | return tosa_status_valid; |
| 1231 | } |
| 1232 | |
| 1233 | tosa_status_t tosa_run_ceil(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1234 | { |
| 1235 | // Create operator attributes |
| 1236 | TosaNoneAttribute attr; |
| 1237 | |
| 1238 | // Create tensors |
| 1239 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1240 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1241 | |
| 1242 | // Create operator |
| 1243 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CEIL, tosa::Attribute::Attribute_NONE, &attr, |
| 1244 | { input1->GetName() }, { output->GetName() }); |
| 1245 | |
| 1246 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1247 | tosa::TosaSerializationBasicBlock block("ceil", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1248 | { output->GetName() }); |
| 1249 | |
| 1250 | // Setup model |
| 1251 | TosaReference::ModelRunnerImpl runner; |
| 1252 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1253 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1254 | |
| 1255 | // Execute |
| 1256 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1257 | |
| 1258 | // Extract outputs |
| 1259 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1260 | |
| 1261 | return tosa_status_valid; |
| 1262 | } |
| 1263 | |
| 1264 | tosa_status_t tosa_run_clz(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1265 | { |
| 1266 | // Create operator attributes |
| 1267 | TosaNoneAttribute attr; |
| 1268 | |
| 1269 | // Create tensors |
| 1270 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1271 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1272 | |
| 1273 | // Create operator |
| 1274 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CLZ, tosa::Attribute::Attribute_NONE, &attr, |
| 1275 | { input1->GetName() }, { output->GetName() }); |
| 1276 | |
| 1277 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1278 | tosa::TosaSerializationBasicBlock block("clz", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1279 | { output->GetName() }); |
| 1280 | |
| 1281 | // Setup model |
| 1282 | TosaReference::ModelRunnerImpl runner; |
| 1283 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1284 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1285 | |
| 1286 | // Execute |
| 1287 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1288 | |
| 1289 | // Extract outputs |
| 1290 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1291 | |
| 1292 | return tosa_status_valid; |
| 1293 | } |
| 1294 | |
| 1295 | tosa_status_t tosa_run_exp(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1296 | { |
| 1297 | // Create operator attributes |
| 1298 | TosaNoneAttribute attr; |
| 1299 | |
| 1300 | // Create tensors |
| 1301 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1302 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1303 | |
| 1304 | // Create operator |
| 1305 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_EXP, tosa::Attribute::Attribute_NONE, &attr, |
| 1306 | { input1->GetName() }, { output->GetName() }); |
| 1307 | |
| 1308 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1309 | tosa::TosaSerializationBasicBlock block("exp", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1310 | { output->GetName() }); |
| 1311 | |
| 1312 | // Setup model |
| 1313 | TosaReference::ModelRunnerImpl runner; |
| 1314 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1315 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1316 | |
| 1317 | // Execute |
| 1318 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1319 | |
| 1320 | // Extract outputs |
| 1321 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1322 | |
| 1323 | return tosa_status_valid; |
| 1324 | } |
| 1325 | |
| 1326 | tosa_status_t tosa_run_floor(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1327 | { |
| 1328 | // Create operator attributes |
| 1329 | TosaNoneAttribute attr; |
| 1330 | |
| 1331 | // Create tensors |
| 1332 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1333 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1334 | |
| 1335 | // Create operator |
| 1336 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_FLOOR, tosa::Attribute::Attribute_NONE, &attr, |
| 1337 | { input1->GetName() }, { output->GetName() }); |
| 1338 | |
| 1339 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1340 | tosa::TosaSerializationBasicBlock block("floor", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1341 | { output->GetName() }); |
| 1342 | |
| 1343 | // Setup model |
| 1344 | TosaReference::ModelRunnerImpl runner; |
| 1345 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1346 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1347 | |
| 1348 | // Execute |
| 1349 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1350 | |
| 1351 | // Extract outputs |
| 1352 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1353 | |
| 1354 | return tosa_status_valid; |
| 1355 | } |
| 1356 | |
| 1357 | tosa_status_t tosa_run_log(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1358 | { |
| 1359 | // Create operator attributes |
| 1360 | TosaNoneAttribute attr; |
| 1361 | |
| 1362 | // Create tensors |
| 1363 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1364 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1365 | |
| 1366 | // Create operator |
| 1367 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_LOG, tosa::Attribute::Attribute_NONE, &attr, |
| 1368 | { input1->GetName() }, { output->GetName() }); |
| 1369 | |
| 1370 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1371 | tosa::TosaSerializationBasicBlock block("log", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1372 | { output->GetName() }); |
| 1373 | |
| 1374 | // Setup model |
| 1375 | TosaReference::ModelRunnerImpl runner; |
| 1376 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1377 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1378 | |
| 1379 | // Execute |
| 1380 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1381 | |
| 1382 | // Extract outputs |
| 1383 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1384 | |
| 1385 | return tosa_status_valid; |
| 1386 | } |
| 1387 | |
| 1388 | tosa_status_t tosa_run_logical_not(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1389 | { |
| 1390 | // Create operator attributes |
| 1391 | TosaNoneAttribute attr; |
| 1392 | |
| 1393 | // Create tensors |
| 1394 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1395 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1396 | |
| 1397 | // Create operator |
| 1398 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_LOGICAL_NOT, tosa::Attribute::Attribute_NONE, &attr, |
| 1399 | { input1->GetName() }, { output->GetName() }); |
| 1400 | |
| 1401 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1402 | tosa::TosaSerializationBasicBlock block("logical_not", "main", { op }, { input1, output }, |
| 1403 | { input1->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1404 | |
| 1405 | // Setup model |
| 1406 | TosaReference::ModelRunnerImpl runner; |
| 1407 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1408 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1409 | |
| 1410 | // Execute |
| 1411 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1412 | |
| 1413 | // Extract outputs |
| 1414 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1415 | |
| 1416 | return tosa_status_valid; |
| 1417 | } |
| 1418 | |
| 1419 | tosa_status_t tosa_run_negate(tosa_tensor_t client_input1, |
| 1420 | const int32_t client_input1_zp, |
| 1421 | const int32_t client_output_zp, |
| 1422 | tosa_tensor_t client_output) |
| 1423 | { |
| 1424 | // Create operator attributes |
| 1425 | const int32_t input1_zp = client_input1_zp; |
| 1426 | const int32_t output_zp = client_output_zp; |
| 1427 | TosaNegateAttribute attr(input1_zp, output_zp); |
| 1428 | |
| 1429 | // Create tensors |
| 1430 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1431 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1432 | |
| 1433 | // Create operator |
| 1434 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_NEGATE, tosa::Attribute::Attribute_NegateAttribute, |
| 1435 | &attr, { input1->GetName() }, { output->GetName() }); |
| 1436 | |
| 1437 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1438 | tosa::TosaSerializationBasicBlock block("negate", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1439 | { output->GetName() }); |
| 1440 | |
| 1441 | // Setup model |
| 1442 | TosaReference::ModelRunnerImpl runner; |
| 1443 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1444 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1445 | |
| 1446 | // Execute |
| 1447 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1448 | |
| 1449 | // Extract outputs |
| 1450 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1451 | |
| 1452 | return tosa_status_valid; |
| 1453 | } |
| 1454 | |
| 1455 | tosa_status_t tosa_run_reciprocal(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1456 | { |
| 1457 | // Create operator attributes |
| 1458 | TosaNoneAttribute attr; |
| 1459 | |
| 1460 | // Create tensors |
| 1461 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1462 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1463 | |
| 1464 | // Create operator |
| 1465 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_RECIPROCAL, tosa::Attribute::Attribute_NONE, &attr, |
| 1466 | { input1->GetName() }, { output->GetName() }); |
| 1467 | |
| 1468 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1469 | tosa::TosaSerializationBasicBlock block("reciprocal", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1470 | { output->GetName() }); |
| 1471 | |
| 1472 | // Setup model |
| 1473 | TosaReference::ModelRunnerImpl runner; |
| 1474 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1475 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1476 | |
| 1477 | // Execute |
| 1478 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1479 | |
| 1480 | // Extract outputs |
| 1481 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1482 | |
| 1483 | return tosa_status_valid; |
| 1484 | } |
| 1485 | |
| 1486 | tosa_status_t tosa_run_rsqrt(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 1487 | { |
| 1488 | // Create operator attributes |
| 1489 | TosaNoneAttribute attr; |
| 1490 | |
| 1491 | // Create tensors |
| 1492 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1493 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1494 | |
| 1495 | // Create operator |
| 1496 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_RSQRT, tosa::Attribute::Attribute_NONE, &attr, |
| 1497 | { input1->GetName() }, { output->GetName() }); |
| 1498 | |
| 1499 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1500 | tosa::TosaSerializationBasicBlock block("rsqrt", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1501 | { output->GetName() }); |
| 1502 | |
| 1503 | // Setup model |
| 1504 | TosaReference::ModelRunnerImpl runner; |
| 1505 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1506 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1507 | |
| 1508 | // Execute |
| 1509 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1510 | |
| 1511 | // Extract outputs |
| 1512 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1513 | |
| 1514 | return tosa_status_valid; |
| 1515 | } |
| 1516 | |
| 1517 | tosa_status_t tosa_run_select(tosa_tensor_t client_input1, |
| 1518 | tosa_tensor_t client_input2, |
| 1519 | tosa_tensor_t client_input3, |
| 1520 | tosa_tensor_t client_output) |
| 1521 | { |
| 1522 | // Create operator attributes |
| 1523 | TosaNoneAttribute attr; |
| 1524 | |
| 1525 | // Create tensors |
| 1526 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1527 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1528 | tosa::TosaSerializationTensor* input3 = translate_client_tensor(client_input3, "input3"); |
| 1529 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1530 | |
| 1531 | // Create operator |
| 1532 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_SELECT, tosa::Attribute::Attribute_NONE, &attr, |
| 1533 | { input1->GetName(), input2->GetName(), input3->GetName() }, |
| 1534 | { output->GetName() }); |
| 1535 | |
| 1536 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1537 | tosa::TosaSerializationBasicBlock block("select", "main", { op }, { input1, input2, input3, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1538 | { input1->GetName(), input2->GetName(), input3->GetName() }, |
| 1539 | { output->GetName() }); |
| 1540 | |
| 1541 | // Setup model |
| 1542 | TosaReference::ModelRunnerImpl runner; |
| 1543 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1544 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1545 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1546 | TOSA_RETURN_ON_ERROR(runner.setInput(input3->GetName(), client_input3.data, client_input3.size)); |
| 1547 | |
| 1548 | // Execute |
| 1549 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1550 | |
| 1551 | // Extract outputs |
| 1552 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1553 | |
| 1554 | return tosa_status_valid; |
| 1555 | } |
| 1556 | |
| 1557 | tosa_status_t tosa_run_equal(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1558 | { |
| 1559 | // Create operator attributes |
| 1560 | TosaNoneAttribute attr; |
| 1561 | |
| 1562 | // Create tensors |
| 1563 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1564 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1565 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1566 | |
| 1567 | // Create operator |
| 1568 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_EQUAL, tosa::Attribute::Attribute_NONE, &attr, |
| 1569 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1570 | |
| 1571 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1572 | tosa::TosaSerializationBasicBlock block("equal", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1573 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1574 | |
| 1575 | // Setup model |
| 1576 | TosaReference::ModelRunnerImpl runner; |
| 1577 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1578 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1579 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1580 | |
| 1581 | // Execute |
| 1582 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1583 | |
| 1584 | // Extract outputs |
| 1585 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1586 | |
| 1587 | return tosa_status_valid; |
| 1588 | } |
| 1589 | |
| 1590 | tosa_status_t |
| 1591 | tosa_run_greater(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1592 | { |
| 1593 | // Create operator attributes |
| 1594 | TosaNoneAttribute attr; |
| 1595 | |
| 1596 | // Create tensors |
| 1597 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1598 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1599 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1600 | |
| 1601 | // Create operator |
| 1602 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_GREATER, tosa::Attribute::Attribute_NONE, &attr, |
| 1603 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1604 | |
| 1605 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1606 | tosa::TosaSerializationBasicBlock block("greater", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1607 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1608 | |
| 1609 | // Setup model |
| 1610 | TosaReference::ModelRunnerImpl runner; |
| 1611 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1612 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1613 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1614 | |
| 1615 | // Execute |
| 1616 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1617 | |
| 1618 | // Extract outputs |
| 1619 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1620 | |
| 1621 | return tosa_status_valid; |
| 1622 | } |
| 1623 | |
| 1624 | tosa_status_t |
| 1625 | tosa_run_greater_equal(tosa_tensor_t client_input1, tosa_tensor_t client_input2, tosa_tensor_t client_output) |
| 1626 | { |
| 1627 | // Create operator attributes |
| 1628 | TosaNoneAttribute attr; |
| 1629 | |
| 1630 | // Create tensors |
| 1631 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1632 | tosa::TosaSerializationTensor* input2 = translate_client_tensor(client_input2, "input2"); |
| 1633 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1634 | |
| 1635 | // Create operator |
| 1636 | auto op = |
| 1637 | new tosa::TosaSerializationOperator(tosa::Op::Op_GREATER_EQUAL, tosa::Attribute::Attribute_NONE, &attr, |
| 1638 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1639 | |
| 1640 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1641 | tosa::TosaSerializationBasicBlock block("greater_equal", "main", { op }, { input1, input2, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1642 | { input1->GetName(), input2->GetName() }, { output->GetName() }); |
| 1643 | |
| 1644 | // Setup model |
| 1645 | TosaReference::ModelRunnerImpl runner; |
| 1646 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1647 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1648 | TOSA_RETURN_ON_ERROR(runner.setInput(input2->GetName(), client_input2.data, client_input2.size)); |
| 1649 | |
| 1650 | // Execute |
| 1651 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1652 | |
| 1653 | // Extract outputs |
| 1654 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1655 | |
| 1656 | return tosa_status_valid; |
| 1657 | } |
| 1658 | |
| 1659 | tosa_status_t |
| 1660 | tosa_run_reduce_all(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1661 | { |
| 1662 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1663 | const int32_t axis = client_axis; |
| 1664 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1665 | |
| 1666 | // Create tensors |
| 1667 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1668 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1669 | |
| 1670 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1671 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_ALL, tosa::Attribute::Attribute_AxisAttribute, |
| 1672 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1675 | tosa::TosaSerializationBasicBlock block("reduce_all", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1676 | { output->GetName() }); |
| 1677 | |
| 1678 | // Setup model |
| 1679 | TosaReference::ModelRunnerImpl runner; |
| 1680 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1681 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1682 | |
| 1683 | // Execute |
| 1684 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1685 | |
| 1686 | // Extract outputs |
| 1687 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1688 | |
| 1689 | return tosa_status_valid; |
| 1690 | } |
| 1691 | |
| 1692 | tosa_status_t |
| 1693 | tosa_run_reduce_any(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1694 | { |
| 1695 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1696 | const int32_t axis = client_axis; |
| 1697 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1698 | |
| 1699 | // Create tensors |
| 1700 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1701 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1702 | |
| 1703 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1704 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_ANY, tosa::Attribute::Attribute_AxisAttribute, |
| 1705 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1706 | |
| 1707 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1708 | tosa::TosaSerializationBasicBlock block("reduce_any", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1709 | { output->GetName() }); |
| 1710 | |
| 1711 | // Setup model |
| 1712 | TosaReference::ModelRunnerImpl runner; |
| 1713 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1714 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1715 | |
| 1716 | // Execute |
| 1717 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1718 | |
| 1719 | // Extract outputs |
| 1720 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1721 | |
| 1722 | return tosa_status_valid; |
| 1723 | } |
| 1724 | |
| 1725 | tosa_status_t |
| 1726 | tosa_run_reduce_max(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1727 | { |
| 1728 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1729 | const int32_t axis = client_axis; |
| 1730 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1731 | |
| 1732 | // Create tensors |
| 1733 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1734 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1735 | |
| 1736 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1737 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_MAX, tosa::Attribute::Attribute_AxisAttribute, |
| 1738 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1739 | |
| 1740 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1741 | tosa::TosaSerializationBasicBlock block("reduce_max", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1742 | { output->GetName() }); |
| 1743 | |
| 1744 | // Setup model |
| 1745 | TosaReference::ModelRunnerImpl runner; |
| 1746 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1747 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1748 | |
| 1749 | // Execute |
| 1750 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1751 | |
| 1752 | // Extract outputs |
| 1753 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1754 | |
| 1755 | return tosa_status_valid; |
| 1756 | } |
| 1757 | |
| 1758 | tosa_status_t |
| 1759 | tosa_run_reduce_min(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1760 | { |
| 1761 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1762 | const int32_t axis = client_axis; |
| 1763 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1764 | |
| 1765 | // Create tensors |
| 1766 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1767 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1768 | |
| 1769 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1770 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_MIN, tosa::Attribute::Attribute_AxisAttribute, |
| 1771 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1772 | |
| 1773 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1774 | tosa::TosaSerializationBasicBlock block("reduce_min", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1775 | { output->GetName() }); |
| 1776 | |
| 1777 | // Setup model |
| 1778 | TosaReference::ModelRunnerImpl runner; |
| 1779 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1780 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1781 | |
| 1782 | // Execute |
| 1783 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1784 | |
| 1785 | // Extract outputs |
| 1786 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1787 | |
| 1788 | return tosa_status_valid; |
| 1789 | } |
| 1790 | |
| 1791 | tosa_status_t |
| 1792 | tosa_run_reduce_product(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1793 | { |
| 1794 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1795 | const int32_t axis = client_axis; |
| 1796 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1797 | |
| 1798 | // Create tensors |
| 1799 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1800 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1801 | |
| 1802 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1803 | auto op = |
| 1804 | new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_PRODUCT, tosa::Attribute::Attribute_AxisAttribute, |
| 1805 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1806 | |
| 1807 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1808 | tosa::TosaSerializationBasicBlock block("reduce_product", "main", { op }, { input, output }, |
| 1809 | { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1810 | |
| 1811 | // Setup model |
| 1812 | TosaReference::ModelRunnerImpl runner; |
| 1813 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1814 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1815 | |
| 1816 | // Execute |
| 1817 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1818 | |
| 1819 | // Extract outputs |
| 1820 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1821 | |
| 1822 | return tosa_status_valid; |
| 1823 | } |
| 1824 | |
| 1825 | tosa_status_t |
| 1826 | tosa_run_reduce_sum(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1827 | { |
| 1828 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1829 | const int32_t axis = client_axis; |
| 1830 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1831 | |
| 1832 | // Create tensors |
| 1833 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1834 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1835 | |
| 1836 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1837 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REDUCE_SUM, tosa::Attribute::Attribute_AxisAttribute, |
| 1838 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1839 | |
| 1840 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1841 | tosa::TosaSerializationBasicBlock block("reduce_sum", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1842 | { output->GetName() }); |
| 1843 | |
| 1844 | // Setup model |
| 1845 | TosaReference::ModelRunnerImpl runner; |
| 1846 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1847 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1848 | |
| 1849 | // Execute |
| 1850 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1851 | |
| 1852 | // Extract outputs |
| 1853 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1854 | |
| 1855 | return tosa_status_valid; |
| 1856 | } |
| 1857 | |
| 1858 | tosa_status_t tosa_run_concat(tosa_tensor_t client_input1, const int32_t client_axis, tosa_tensor_t client_output) |
| 1859 | { |
| 1860 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1861 | const int32_t axis = client_axis; |
| 1862 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1863 | |
| 1864 | // Create tensors |
| 1865 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1866 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1867 | |
| 1868 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1869 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CONCAT, tosa::Attribute::Attribute_AxisAttribute, |
| 1870 | &attr, { input1->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1871 | |
| 1872 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1873 | tosa::TosaSerializationBasicBlock block("concat", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1874 | { output->GetName() }); |
| 1875 | |
| 1876 | // Setup model |
| 1877 | TosaReference::ModelRunnerImpl runner; |
| 1878 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1879 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1880 | |
| 1881 | // Execute |
| 1882 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1883 | |
| 1884 | // Extract outputs |
| 1885 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1886 | |
| 1887 | return tosa_status_valid; |
| 1888 | } |
| 1889 | |
| 1890 | tosa_status_t tosa_run_pad(tosa_tensor_t client_input1, |
| 1891 | const int32_t client_padding_len, |
| 1892 | const int32_t client_padding[], |
| 1893 | const int32_t client_pad_const_int, |
| 1894 | const float client_pad_const_fp, |
| 1895 | tosa_tensor_t client_output) |
| 1896 | { |
| 1897 | // Create operator attributes |
| 1898 | const std::vector<int32_t> padding(&client_padding[0], &client_padding[0] + client_padding_len); |
| 1899 | const int32_t pad_const_int = client_pad_const_int; |
| 1900 | const float pad_const_fp = client_pad_const_fp; |
| 1901 | TosaPadAttribute attr(padding, pad_const_int, pad_const_fp); |
| 1902 | |
| 1903 | // Create tensors |
| 1904 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1905 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1906 | |
| 1907 | // Create operator |
| 1908 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_PAD, tosa::Attribute::Attribute_PadAttribute, &attr, |
| 1909 | { input1->GetName() }, { output->GetName() }); |
| 1910 | |
| 1911 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1912 | tosa::TosaSerializationBasicBlock block("pad", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1913 | { output->GetName() }); |
| 1914 | |
| 1915 | // Setup model |
| 1916 | TosaReference::ModelRunnerImpl runner; |
| 1917 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1918 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1919 | |
| 1920 | // Execute |
| 1921 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1922 | |
| 1923 | // Extract outputs |
| 1924 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1925 | |
| 1926 | return tosa_status_valid; |
| 1927 | } |
| 1928 | |
| 1929 | tosa_status_t tosa_run_reshape(tosa_tensor_t client_input1, |
| 1930 | const int32_t client_new_shape_len, |
| 1931 | const int32_t client_new_shape[], |
| 1932 | tosa_tensor_t client_output) |
| 1933 | { |
| 1934 | // Create operator attributes |
| 1935 | const std::vector<int32_t> new_shape(&client_new_shape[0], &client_new_shape[0] + client_new_shape_len); |
| 1936 | TosaReshapeAttribute attr(new_shape); |
| 1937 | |
| 1938 | // Create tensors |
| 1939 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 1940 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1941 | |
| 1942 | // Create operator |
| 1943 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_RESHAPE, tosa::Attribute::Attribute_ReshapeAttribute, |
| 1944 | &attr, { input1->GetName() }, { output->GetName() }); |
| 1945 | |
| 1946 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1947 | tosa::TosaSerializationBasicBlock block("reshape", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1948 | { output->GetName() }); |
| 1949 | |
| 1950 | // Setup model |
| 1951 | TosaReference::ModelRunnerImpl runner; |
| 1952 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1953 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 1954 | |
| 1955 | // Execute |
| 1956 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1957 | |
| 1958 | // Extract outputs |
| 1959 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1960 | |
| 1961 | return tosa_status_valid; |
| 1962 | } |
| 1963 | |
| 1964 | tosa_status_t tosa_run_reverse(tosa_tensor_t client_input, const int32_t client_axis, tosa_tensor_t client_output) |
| 1965 | { |
| 1966 | // Create operator attributes |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1967 | const int32_t axis = client_axis; |
| 1968 | TosaAxisAttribute attr(axis); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1969 | |
| 1970 | // Create tensors |
| 1971 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 1972 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 1973 | |
| 1974 | // Create operator |
Grant Watson | 6168047 | 2023-05-31 14:56:13 +0100 | [diff] [blame^] | 1975 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_REVERSE, tosa::Attribute::Attribute_AxisAttribute, |
| 1976 | &attr, { input->GetName() }, { output->GetName() }); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1977 | |
| 1978 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 1979 | tosa::TosaSerializationBasicBlock block("reverse", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 1980 | { output->GetName() }); |
| 1981 | |
| 1982 | // Setup model |
| 1983 | TosaReference::ModelRunnerImpl runner; |
| 1984 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 1985 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 1986 | |
| 1987 | // Execute |
| 1988 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 1989 | |
| 1990 | // Extract outputs |
| 1991 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 1992 | |
| 1993 | return tosa_status_valid; |
| 1994 | } |
| 1995 | |
| 1996 | tosa_status_t tosa_run_slice(tosa_tensor_t client_input1, |
| 1997 | const int32_t client_start_len, |
| 1998 | const int32_t client_start[], |
| 1999 | const int32_t client_size_len, |
| 2000 | const int32_t client_size[], |
| 2001 | tosa_tensor_t client_output) |
| 2002 | { |
| 2003 | // Create operator attributes |
| 2004 | const std::vector<int32_t> start(&client_start[0], &client_start[0] + client_start_len); |
| 2005 | const std::vector<int32_t> size(&client_size[0], &client_size[0] + client_size_len); |
| 2006 | TosaSliceAttribute attr(start, size); |
| 2007 | |
| 2008 | // Create tensors |
| 2009 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 2010 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2011 | |
| 2012 | // Create operator |
| 2013 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_SLICE, tosa::Attribute::Attribute_SliceAttribute, |
| 2014 | &attr, { input1->GetName() }, { output->GetName() }); |
| 2015 | |
| 2016 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2017 | tosa::TosaSerializationBasicBlock block("slice", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2018 | { output->GetName() }); |
| 2019 | |
| 2020 | // Setup model |
| 2021 | TosaReference::ModelRunnerImpl runner; |
| 2022 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2023 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 2024 | |
| 2025 | // Execute |
| 2026 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2027 | |
| 2028 | // Extract outputs |
| 2029 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2030 | |
| 2031 | return tosa_status_valid; |
| 2032 | } |
| 2033 | |
| 2034 | tosa_status_t tosa_run_tile(tosa_tensor_t client_input1, |
| 2035 | const int32_t client_multiplies_len, |
| 2036 | const int32_t client_multiplies[], |
| 2037 | const int32_t client_multiples_len, |
| 2038 | const int32_t client_multiples[], |
| 2039 | tosa_tensor_t client_output) |
| 2040 | { |
| 2041 | // Create operator attributes |
| 2042 | const std::vector<int32_t> multiples(&client_multiples[0], &client_multiples[0] + client_multiples_len); |
| 2043 | TosaTileAttribute attr(multiples); |
| 2044 | |
| 2045 | // Create tensors |
| 2046 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 2047 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2048 | |
| 2049 | // Create operator |
| 2050 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_TILE, tosa::Attribute::Attribute_TileAttribute, |
| 2051 | &attr, { input1->GetName() }, { output->GetName() }); |
| 2052 | |
| 2053 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2054 | tosa::TosaSerializationBasicBlock block("tile", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2055 | { output->GetName() }); |
| 2056 | |
| 2057 | // Setup model |
| 2058 | TosaReference::ModelRunnerImpl runner; |
| 2059 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2060 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 2061 | |
| 2062 | // Execute |
| 2063 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2064 | |
| 2065 | // Extract outputs |
| 2066 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2067 | |
| 2068 | return tosa_status_valid; |
| 2069 | } |
| 2070 | |
| 2071 | tosa_status_t tosa_run_transpose(tosa_tensor_t client_input1, |
| 2072 | const int32_t client_perms_len, |
| 2073 | const int32_t client_perms[], |
| 2074 | tosa_tensor_t client_output) |
| 2075 | { |
| 2076 | // Create operator attributes |
| 2077 | const std::vector<int32_t> perms(&client_perms[0], &client_perms[0] + client_perms_len); |
| 2078 | TosaTransposeAttribute attr(perms); |
| 2079 | |
| 2080 | // Create tensors |
| 2081 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 2082 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2083 | |
| 2084 | // Create operator |
| 2085 | auto op = |
| 2086 | new tosa::TosaSerializationOperator(tosa::Op::Op_TRANSPOSE, tosa::Attribute::Attribute_TransposeAttribute, |
| 2087 | &attr, { input1->GetName() }, { output->GetName() }); |
| 2088 | |
| 2089 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2090 | tosa::TosaSerializationBasicBlock block("transpose", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2091 | { output->GetName() }); |
| 2092 | |
| 2093 | // Setup model |
| 2094 | TosaReference::ModelRunnerImpl runner; |
| 2095 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2096 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 2097 | |
| 2098 | // Execute |
| 2099 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2100 | |
| 2101 | // Extract outputs |
| 2102 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2103 | |
| 2104 | return tosa_status_valid; |
| 2105 | } |
| 2106 | |
| 2107 | tosa_status_t |
| 2108 | tosa_run_gather(tosa_tensor_t client_values, tosa_tensor_t client_indices, tosa_tensor_t client_output) |
| 2109 | { |
| 2110 | // Create operator attributes |
| 2111 | TosaNoneAttribute attr; |
| 2112 | |
| 2113 | // Create tensors |
| 2114 | tosa::TosaSerializationTensor* values = translate_client_tensor(client_values, "values"); |
| 2115 | tosa::TosaSerializationTensor* indices = translate_client_tensor(client_indices, "indices"); |
| 2116 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2117 | |
| 2118 | // Create operator |
| 2119 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_GATHER, tosa::Attribute::Attribute_NONE, &attr, |
| 2120 | { values->GetName(), indices->GetName() }, { output->GetName() }); |
| 2121 | |
| 2122 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2123 | tosa::TosaSerializationBasicBlock block("gather", "main", { op }, { values, indices, output }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2124 | { values->GetName(), indices->GetName() }, { output->GetName() }); |
| 2125 | |
| 2126 | // Setup model |
| 2127 | TosaReference::ModelRunnerImpl runner; |
| 2128 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2129 | TOSA_RETURN_ON_ERROR(runner.setInput(values->GetName(), client_values.data, client_values.size)); |
| 2130 | TOSA_RETURN_ON_ERROR(runner.setInput(indices->GetName(), client_indices.data, client_indices.size)); |
| 2131 | |
| 2132 | // Execute |
| 2133 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2134 | |
| 2135 | // Extract outputs |
| 2136 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2137 | |
| 2138 | return tosa_status_valid; |
| 2139 | } |
| 2140 | |
| 2141 | tosa_status_t tosa_run_scatter(tosa_tensor_t client_values_in, |
| 2142 | tosa_tensor_t client_indices, |
| 2143 | tosa_tensor_t client_input, |
| 2144 | tosa_tensor_t client_values_out) |
| 2145 | { |
| 2146 | // Create operator attributes |
| 2147 | TosaNoneAttribute attr; |
| 2148 | |
| 2149 | // Create tensors |
| 2150 | tosa::TosaSerializationTensor* values_in = translate_client_tensor(client_values_in, "values_in"); |
| 2151 | tosa::TosaSerializationTensor* indices = translate_client_tensor(client_indices, "indices"); |
| 2152 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 2153 | tosa::TosaSerializationTensor* values_out = translate_client_tensor(client_values_out, "values_out"); |
| 2154 | |
| 2155 | // Create operator |
| 2156 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_SCATTER, tosa::Attribute::Attribute_NONE, &attr, |
| 2157 | { values_in->GetName(), indices->GetName(), input->GetName() }, |
| 2158 | { values_out->GetName() }); |
| 2159 | |
| 2160 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2161 | tosa::TosaSerializationBasicBlock block("scatter", "main", { op }, { values_in, indices, input, values_out }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2162 | { values_in->GetName(), indices->GetName(), input->GetName() }, |
| 2163 | { values_out->GetName() }); |
| 2164 | |
| 2165 | // Setup model |
| 2166 | TosaReference::ModelRunnerImpl runner; |
| 2167 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2168 | TOSA_RETURN_ON_ERROR(runner.setInput(values_in->GetName(), client_values_in.data, client_values_in.size)); |
| 2169 | TOSA_RETURN_ON_ERROR(runner.setInput(indices->GetName(), client_indices.data, client_indices.size)); |
| 2170 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 2171 | |
| 2172 | // Execute |
| 2173 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2174 | |
| 2175 | // Extract outputs |
| 2176 | TOSA_RETURN_ON_ERROR(runner.getOutput(values_out->GetName(), client_values_out.data, client_values_out.size)); |
| 2177 | |
| 2178 | return tosa_status_valid; |
| 2179 | } |
| 2180 | |
| 2181 | tosa_status_t tosa_run_resize(tosa_tensor_t client_input, |
| 2182 | const int16_t client_scale[4], |
| 2183 | const int16_t client_offset[2], |
| 2184 | const int16_t client_border[2], |
| 2185 | const tosa_mode_t client_mode, |
| 2186 | tosa_tensor_t client_output) |
| 2187 | { |
| 2188 | // Create operator attributes |
| 2189 | const std::vector<int16_t> scale(&client_scale[0], &client_scale[4]); |
| 2190 | const std::vector<int16_t> offset(&client_offset[0], &client_offset[2]); |
| 2191 | const std::vector<int16_t> border(&client_border[0], &client_border[2]); |
| 2192 | const ResizeMode mode = translate_client_tosa_mode(client_mode); |
| 2193 | TosaResizeAttribute attr(scale, offset, border, mode); |
| 2194 | |
| 2195 | // Create tensors |
| 2196 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 2197 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2198 | |
| 2199 | // Create operator |
| 2200 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_RESIZE, tosa::Attribute::Attribute_ResizeAttribute, |
| 2201 | &attr, { input->GetName() }, { output->GetName() }); |
| 2202 | |
| 2203 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2204 | tosa::TosaSerializationBasicBlock block("resize", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2205 | { output->GetName() }); |
| 2206 | |
| 2207 | // Setup model |
| 2208 | TosaReference::ModelRunnerImpl runner; |
| 2209 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2210 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 2211 | |
| 2212 | // Execute |
| 2213 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2214 | |
| 2215 | // Extract outputs |
| 2216 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2217 | |
| 2218 | return tosa_status_valid; |
| 2219 | } |
| 2220 | |
| 2221 | tosa_status_t tosa_run_cast(tosa_tensor_t client_input, tosa_tensor_t client_output) |
| 2222 | { |
| 2223 | // Create operator attributes |
| 2224 | TosaNoneAttribute attr; |
| 2225 | |
| 2226 | // Create tensors |
| 2227 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 2228 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2229 | |
| 2230 | // Create operator |
| 2231 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_CAST, tosa::Attribute::Attribute_NONE, &attr, |
| 2232 | { input->GetName() }, { output->GetName() }); |
| 2233 | |
| 2234 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2235 | tosa::TosaSerializationBasicBlock block("cast", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2236 | { output->GetName() }); |
| 2237 | |
| 2238 | // Setup model |
| 2239 | TosaReference::ModelRunnerImpl runner; |
| 2240 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2241 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 2242 | |
| 2243 | // Execute |
| 2244 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2245 | |
| 2246 | // Extract outputs |
| 2247 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2248 | |
| 2249 | return tosa_status_valid; |
| 2250 | } |
| 2251 | |
| 2252 | tosa_status_t tosa_run_rescale(tosa_tensor_t client_input, |
| 2253 | tosa_tensor_t client_output, |
| 2254 | const int32_t client_input_zp, |
| 2255 | const int32_t client_output_zp, |
| 2256 | const int32_t client_multiplier_len, |
| 2257 | const int32_t client_multiplier[], |
| 2258 | const int32_t client_shift_len, |
| 2259 | const uint8_t client_shift[], |
| 2260 | const bool client_scale32, |
| 2261 | const bool client_double_round, |
| 2262 | const bool client_per_channel) |
| 2263 | { |
| 2264 | // Create operator attributes |
| 2265 | const int32_t input_zp = client_input_zp; |
| 2266 | const int32_t output_zp = client_output_zp; |
| 2267 | const std::vector<int32_t> multiplier(&client_multiplier[0], &client_multiplier[0] + client_multiplier_len); |
| 2268 | const std::vector<int32_t> shift(&client_shift[0], &client_shift[0] + client_shift_len); |
| 2269 | const bool scale32 = client_scale32; |
| 2270 | const bool double_round = client_double_round; |
| 2271 | const bool per_channel = client_per_channel; |
| 2272 | TosaRescaleAttribute attr(input_zp, output_zp, multiplier, shift, scale32, double_round, per_channel); |
| 2273 | |
| 2274 | // Create tensors |
| 2275 | tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input"); |
| 2276 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2277 | |
| 2278 | // Create operator |
| 2279 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_RESCALE, tosa::Attribute::Attribute_RescaleAttribute, |
| 2280 | &attr, { input->GetName() }, { output->GetName() }); |
| 2281 | |
| 2282 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2283 | tosa::TosaSerializationBasicBlock block("rescale", "main", { op }, { input, output }, { input->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2284 | { output->GetName() }); |
| 2285 | |
| 2286 | // Setup model |
| 2287 | TosaReference::ModelRunnerImpl runner; |
| 2288 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2289 | TOSA_RETURN_ON_ERROR(runner.setInput(input->GetName(), client_input.data, client_input.size)); |
| 2290 | |
| 2291 | // Execute |
| 2292 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2293 | |
| 2294 | // Extract outputs |
| 2295 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2296 | |
| 2297 | return tosa_status_valid; |
| 2298 | } |
| 2299 | |
| 2300 | tosa_status_t tosa_run_identity(tosa_tensor_t client_input1, tosa_tensor_t client_output) |
| 2301 | { |
| 2302 | // Create operator attributes |
| 2303 | TosaNoneAttribute attr; |
| 2304 | |
| 2305 | // Create tensors |
| 2306 | tosa::TosaSerializationTensor* input1 = translate_client_tensor(client_input1, "input1"); |
| 2307 | tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output"); |
| 2308 | |
| 2309 | // Create operator |
| 2310 | auto op = new tosa::TosaSerializationOperator(tosa::Op::Op_IDENTITY, tosa::Attribute::Attribute_NONE, &attr, |
| 2311 | { input1->GetName() }, { output->GetName() }); |
| 2312 | |
| 2313 | // Create a tosa single-op basic block |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 2314 | tosa::TosaSerializationBasicBlock block("identity", "main", { op }, { input1, output }, { input1->GetName() }, |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 2315 | { output->GetName() }); |
| 2316 | |
| 2317 | // Setup model |
| 2318 | TosaReference::ModelRunnerImpl runner; |
| 2319 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.initialize(block)); |
| 2320 | TOSA_RETURN_ON_ERROR(runner.setInput(input1->GetName(), client_input1.data, client_input1.size)); |
| 2321 | |
| 2322 | // Execute |
| 2323 | TOSA_RETURN_ON_GRAPH_STATUS_ERROR(runner.run()); |
| 2324 | |
| 2325 | // Extract outputs |
| 2326 | TOSA_RETURN_ON_ERROR(runner.getOutput(output->GetName(), client_output.data, client_output.size)); |
| 2327 | |
| 2328 | return tosa_status_valid; |
| 2329 | } |
| 2330 | |
| 2331 | } // extern "C" |