shl_utils.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2016-2022 T-Head Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* CSI-NN2 version 2.0.x */
  19. #ifndef INCLUDE_SHL_UTILS_H_
  20. #define INCLUDE_SHL_UTILS_H_
  21. #include <assert.h>
  22. #include <float.h>
  23. #include <math.h>
  24. #include <stdint.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #if (!defined SHL_BUILD_RTOS)
  29. #include <omp.h>
  30. #endif
  31. #include "csinn_data_structure.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. void shl_get_top5(float *buf, uint32_t size, float *prob, uint32_t *cls);
  36. void shl_show_top5(struct csinn_tensor *output, struct csinn_session *sess);
  37. uint64_t shl_get_timespec();
  38. void shl_print_time_interval(uint64_t start, uint64_t end, const char *msg);
  39. void shl_statistical_mean_std(float *data, int sz);
  40. void shl_quantize_multiplier(double double_multiplier, int32_t *quantized_multiplier,
  41. int32_t *shift);
  42. void shl_register_runtime_callback(int api, void *cb);
  43. void shl_register_op_callback(int api, void *cb);
  44. int shl_op_callback_map(struct csinn_params_base *base, int op, int dtype);
  45. void *shl_get_p0_cb(struct csinn_params_base *base);
  46. void *shl_get_init_cb(struct csinn_params_base *base);
  47. enum csinn_rmode_enum shl_get_run_mode(struct csinn_params_base *base);
  48. struct shl_cb_op_list {
  49. struct shl_cb_op_list *next;
  50. enum csinn_dtype_enum dtype;
  51. enum csinn_op_enum op_name;
  52. struct csinn_callback *cb;
  53. };
  54. struct shl_cb_op_list *shl_cb_list_end(struct shl_cb_op_list *list);
  55. struct csinn_callback *shl_cb_list_match(struct shl_cb_op_list *list, enum csinn_dtype_enum dtype,
  56. enum csinn_op_enum op_name);
  57. struct shl_bm_sections {
  58. int32_t graph_offset;
  59. int32_t graph_size;
  60. int32_t params_offset;
  61. int32_t params_size;
  62. int32_t info_offset;
  63. int32_t info_size;
  64. int32_t debug_offset;
  65. int32_t debug_size;
  66. };
  67. struct shl_binary_model_section_info {
  68. int32_t section_num;
  69. int32_t section_info_size;
  70. int32_t reserve[6];
  71. struct shl_bm_sections sections[127];
  72. };
  73. char *shl_bm_header_str();
  74. void shl_dump_bm_header(FILE *f);
  75. void shl_dump_bm_section_info(FILE *f, struct shl_binary_model_section_info *info);
  76. void shl_dump_bm_graph_info_section(FILE *f, struct csinn_session *sess);
  77. void shl_bm_session_load(struct csinn_session *dest, struct csinn_session *src);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif // INCLUDE_SHL_UTILS_H_