softmax.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_SOFTMAX_H_
  13. #define TENSORFLOW_LITE_MICRO_KERNELS_SOFTMAX_H_
  14. #include "tensorflow/lite/c/builtin_op_data.h"
  15. #include "tensorflow/lite/c/common.h"
  16. #include "tensorflow/lite/kernels/internal/types.h"
  17. namespace tflite {
  18. void* SoftmaxInit(TfLiteContext* context, const char* buffer, size_t length);
  19. // Common helper function to SoftmaxPrepare.
  20. TfLiteStatus CalculateSoftmaxParams(TfLiteContext* context,
  21. const TfLiteTensor* input,
  22. TfLiteTensor* output,
  23. const TfLiteSoftmaxParams* params,
  24. SoftmaxParams* op_data);
  25. TfLiteStatus SoftmaxPrepare(TfLiteContext* context, TfLiteNode* node);
  26. // This is the most generic TfLiteRegistration. The actual supported types may
  27. // still be target dependent. The only requirement is that every implementation
  28. // (reference or optimized) must define this function.
  29. TfLiteRegistration Register_SOFTMAX();
  30. #if defined(XTENSA) || defined(CMSIS_NN)
  31. // Returns a TfLiteRegistration struct for kernel variant that only supports
  32. // int8 input and int16 output.
  33. TfLiteRegistration Register_SOFTMAX_INT8_INT16();
  34. #else
  35. inline TfLiteRegistration Register_SOFTMAX_INT8_INT16() {
  36. return Register_SOFTMAX();
  37. }
  38. #endif
  39. #if defined(CMSIS_NN)
  40. // Returns a TfLiteRegistration struct for kernel variant that only supports
  41. // int8 input/output and uses the latency optimized implementations.
  42. TfLiteRegistration Register_SOFTMAX_INT8();
  43. // Returns a TfLiteRegistration struct for kernel variant that only supports
  44. // int16 input/output and uses the latency optimized implementations.
  45. TfLiteRegistration Register_SOFTMAX_INT16();
  46. #else
  47. inline TfLiteRegistration Register_SOFTMAX_INT8() { return Register_SOFTMAX(); }
  48. inline TfLiteRegistration Register_SOFTMAX_INT16() {
  49. return Register_SOFTMAX();
  50. }
  51. #endif
  52. } // namespace tflite
  53. #endif // TENSORFLOW_LITE_MICRO_KERNELS_SOFTMAX_H_