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