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