add.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_LITE_MICRO_KERNELS_ADD_H_
  13. #define TENSORFLOW_LITE_MICRO_KERNELS_ADD_H_
  14. #include <cstdint>
  15. #include "tensorflow/lite/c/builtin_op_data.h"
  16. #include "tensorflow/lite/c/common.h"
  17. namespace tflite {
  18. extern const int kAddInputTensor1;
  19. extern const int kAddInputTensor2;
  20. extern const int kAddOutputTensor;
  21. struct OpDataAdd {
  22. bool requires_broadcast;
  23. // These fields are used in both the general 8-bit -> 8bit quantized path,
  24. // and the special 16-bit -> 16bit quantized path
  25. int input1_shift;
  26. int input2_shift;
  27. int32_t output_activation_min;
  28. int32_t output_activation_max;
  29. // These fields are used only in the general 8-bit -> 8bit quantized path
  30. int32_t input1_multiplier;
  31. int32_t input2_multiplier;
  32. int32_t output_multiplier;
  33. int output_shift;
  34. int left_shift;
  35. int32_t input1_offset;
  36. int32_t input2_offset;
  37. int32_t output_offset;
  38. // Used only for float evals:
  39. float output_activation_min_f32;
  40. float output_activation_max_f32;
  41. };
  42. TfLiteStatus CalculateOpDataAdd(TfLiteContext* context, TfLiteAddParams* params,
  43. const TfLiteTensor* input1,
  44. const TfLiteTensor* input2,
  45. TfLiteTensor* output, OpDataAdd* data);
  46. TfLiteStatus AddPrepare(TfLiteContext* context, TfLiteNode* node);
  47. // Generic must define registration function.
  48. TfLiteRegistration Register_ADD();
  49. #if defined(CMSIS_NN)
  50. TfLiteRegistration Register_ADD_INT8();
  51. TfLiteRegistration Register_ADD_INT16();
  52. #else
  53. // Fallback registration
  54. inline TfLiteRegistration Register_ADD_INT8() { return Register_ADD(); }
  55. inline TfLiteRegistration Register_ADD_INT16() { return Register_ADD(); }
  56. #endif
  57. } // namespace tflite
  58. #endif // TENSORFLOW_LITE_MICRO_KERNELS_ADD_H_