csinn_runtime.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_CSINN_RUNTIME_H_
  20. #define INCLUDE_CSINN_RUNTIME_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. #define VERSION_MAJOR 2
  36. #define VERSION_MINOR 0
  37. #define VERSION_PATCH 20
  38. #define VERSION_SHIFT 8
  39. int csinn_version(char *vstr);
  40. /* tensor */
  41. int csinn_tensor_size(struct csinn_tensor *tensor);
  42. int csinn_tensor_byte_size(struct csinn_tensor *tensor);
  43. struct csinn_tensor *csinn_alloc_tensor(struct csinn_session *session);
  44. void csinn_free_tensor(struct csinn_tensor *tensor);
  45. void csinn_realloc_quant_info(struct csinn_tensor *tensor, int quant_info_num);
  46. void csinn_tensor_copy(struct csinn_tensor *dest, struct csinn_tensor *src);
  47. int csinn_tensor_data_convert(struct csinn_tensor *dest, struct csinn_tensor *src);
  48. int csinn_tensor_layout_convert(struct csinn_tensor *dest, struct csinn_tensor *src);
  49. /* op parameters */
  50. void *csinn_alloc_params(int params_size, struct csinn_session *session);
  51. void csinn_free_params(void *params);
  52. /* session */
  53. struct csinn_session *csinn_alloc_session();
  54. void csinn_free_session(struct csinn_session *session);
  55. void csinn_session_init(struct csinn_session *session);
  56. void csinn_session_deinit(struct csinn_session *session);
  57. int csinn_session_setup(struct csinn_session *session);
  58. int csinn_session_run(struct csinn_session *session);
  59. int csinn_load_binary_model(struct csinn_session *session);
  60. struct csinn_session *__attribute__((weak)) csinn_import_binary_model(char *bm_addr);
  61. /* input/output */
  62. void csinn_set_input_number(int number, struct csinn_session *sess);
  63. void csinn_set_output_number(int number, struct csinn_session *sess);
  64. int csinn_get_input_number(struct csinn_session *sess);
  65. int csinn_get_output_number(struct csinn_session *sess);
  66. int csinn_set_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
  67. int csinn_set_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
  68. int csinn_get_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
  69. int csinn_get_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
  70. int csinn_update_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
  71. int csinn_update_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
  72. int csinn_set_tensor_entry(struct csinn_tensor *tensor, struct csinn_session *sess);
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif // INCLUDE_CSINN_RUNTIME_H_