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