Build a kernel registration for an op that copies its one input to an output
| 1083 | // Build a kernel registration for an op that copies its one input |
| 1084 | // to an output |
| 1085 | TfLiteRegistration AddOpRegistration() { |
| 1086 | TfLiteRegistration reg = {nullptr, nullptr, nullptr, nullptr}; |
| 1087 | |
| 1088 | reg.custom_name = "my_add"; |
| 1089 | reg.builtin_code = tflite::BuiltinOperator_CUSTOM; |
| 1090 | |
| 1091 | reg.prepare = [](TfLiteContext* context, TfLiteNode* node) { |
| 1092 | // Set output size to input size |
| 1093 | TfLiteTensor* input1 = &context->tensors[node->inputs->data[0]]; |
| 1094 | TfLiteTensor* input2 = &context->tensors[node->inputs->data[1]]; |
| 1095 | TfLiteTensor* output = &context->tensors[node->outputs->data[0]]; |
| 1096 | |
| 1097 | TF_LITE_ENSURE_EQ(context, input1->dims->size, input2->dims->size); |
| 1098 | for (int i = 0; i < input1->dims->size; ++i) { |
| 1099 | TF_LITE_ENSURE_EQ(context, input1->dims->data[i], input2->dims->data[i]); |
| 1100 | } |
| 1101 | |
| 1102 | TF_LITE_ENSURE_STATUS(context->ResizeTensor( |
| 1103 | context, output, TfLiteIntArrayCopy(input1->dims))); |
| 1104 | return kTfLiteOk; |
| 1105 | }; |
| 1106 | |
| 1107 | reg.invoke = [](TfLiteContext* context, TfLiteNode* node) { |
| 1108 | // Copy input data to output data. |
| 1109 | TfLiteTensor* a0 = &context->tensors[node->inputs->data[0]]; |
| 1110 | TfLiteTensor* a1 = &context->tensors[node->inputs->data[1]]; |
| 1111 | TfLiteTensor* out = &context->tensors[node->outputs->data[0]]; |
| 1112 | int num = a0->dims->data[0]; |
| 1113 | for (int i = 0; i < num; i++) { |
| 1114 | out->data.f[i] = a0->data.f[i] + a1->data.f[i]; |
| 1115 | } |
| 1116 | return kTfLiteOk; |
| 1117 | }; |
| 1118 | return reg; |
| 1119 | } |
| 1120 | |
| 1121 | class TestDelegate : public ::testing::Test { |
| 1122 | protected: |
no test coverage detected