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