You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

secinput.h 5.6 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
  17. #define SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
  18. #include "securecutil.h"
  19. #define SECUREC_SCANF_EINVAL (-1)
  20. #define SECUREC_SCANF_ERROR_PARA (-2)
  21. /* for internal stream flag */
  22. #define SECUREC_MEM_STR_FLAG 0X01
  23. #define SECUREC_FILE_STREAM_FLAG 0X02
  24. #define SECUREC_FROM_STDIN_FLAG 0X04
  25. #define SECUREC_LOAD_FILE_TO_MEM_FLAG 0X08
  26. #define SECUREC_UNINITIALIZED_FILE_POS (-1)
  27. #define SECUREC_BOM_HEADER_SIZE 2
  28. #define SECUREC_BOM_HEADER_BE_1ST 0xFEU
  29. #define SECUREC_BOM_HEADER_BE_2ST 0xFFU
  30. #define SECUREC_BOM_HEADER_LE_1ST 0xFFU
  31. #define SECUREC_BOM_HEADER_LE_2ST 0xFEU
  32. #define SECUREC_UTF8_BOM_HEADER_SIZE 3
  33. #define SECUREC_UTF8_BOM_HEADER_1ST 0xEFU
  34. #define SECUREC_UTF8_BOM_HEADER_2ND 0xBBU
  35. #define SECUREC_UTF8_BOM_HEADER_3RD 0xBFU
  36. #define SECUREC_UTF8_LEAD_1ST 0xE0
  37. #define SECUREC_UTF8_LEAD_2ND 0x80
  38. typedef struct {
  39. unsigned int flag; /* mark the properties of input stream */
  40. int count; /* the size of buffered string in bytes */
  41. const char *cur; /* the pointer to next read position */
  42. char *base; /* the pointer to the header of buffered string */
  43. #if SECUREC_ENABLE_SCANF_FILE
  44. FILE *pf; /* the file pointer */
  45. long oriFilePos; /* the original position of file offset when fscanf is called */
  46. int fileRealRead;
  47. #if defined(SECUREC_NO_STD_UNGETC)
  48. unsigned int lastChar; /* the char code of last input */
  49. int fUnget; /* the boolean flag of pushing a char back to read stream */
  50. #endif
  51. #endif
  52. } SecFileStream;
  53. #define SECUREC_INIT_SEC_FILE_STREAM_COMMON(fileStream, streamFlag, curPtr, strCount) do { \
  54. (fileStream).flag = (streamFlag); \
  55. (fileStream).count = (strCount); \
  56. (fileStream).cur = (curPtr); \
  57. (fileStream).base = NULL; \
  58. } SECUREC_WHILE_ZERO
  59. #if SECUREC_ENABLE_SCANF_FILE
  60. #if defined(SECUREC_NO_STD_UNGETC)
  61. /* This initialization for eliminating redundant initialization.
  62. * Compared with the previous version initialization 0,
  63. * the current code causes the binary size to increase by some bytes
  64. */
  65. #define SECUREC_INIT_SEC_FILE_STREAM(fileStream, streamFlag, stream, filePos, curPtr, strCount) do { \
  66. SECUREC_INIT_SEC_FILE_STREAM_COMMON((fileStream), (streamFlag), (curPtr), (strCount)); \
  67. (fileStream).pf = (stream); \
  68. (fileStream).oriFilePos = (filePos); \
  69. (fileStream).fileRealRead = 0; \
  70. (fileStream).lastChar = 0; \
  71. (fileStream).fUnget = 0; \
  72. } SECUREC_WHILE_ZERO
  73. #else
  74. #define SECUREC_INIT_SEC_FILE_STREAM(fileStream, streamFlag, stream, filePos, curPtr, strCount) do { \
  75. SECUREC_INIT_SEC_FILE_STREAM_COMMON((fileStream), (streamFlag), (curPtr), (strCount)); \
  76. (fileStream).pf = (stream); \
  77. (fileStream).oriFilePos = (filePos); \
  78. (fileStream).fileRealRead = 0; \
  79. } SECUREC_WHILE_ZERO
  80. #endif
  81. #else /* No SECUREC_ENABLE_SCANF_FILE */
  82. #define SECUREC_INIT_SEC_FILE_STREAM(fileStream, streamFlag, stream, filePos, curPtr, strCount) do { \
  83. SECUREC_INIT_SEC_FILE_STREAM_COMMON((fileStream), (streamFlag), (curPtr), (strCount)); \
  84. } SECUREC_WHILE_ZERO
  85. #endif
  86. #ifdef __cplusplus
  87. extern "C" {
  88. #endif
  89. extern int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList);
  90. extern void SecClearDestBuf(const char *buffer, const char *format, va_list argList);
  91. #if SECUREC_IN_KERNEL == 0
  92. extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList);
  93. extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList);
  94. #endif
  95. /* 20150105 For software and hardware decoupling,such as UMG */
  96. #if defined(SECUREC_SYSAPI4VXWORKS)
  97. #ifdef feof
  98. #undef feof
  99. #endif
  100. extern int feof(FILE *stream);
  101. #endif
  102. #if defined(SECUREC_SYSAPI4VXWORKS) || defined(SECUREC_CTYPE_MACRO_ADAPT)
  103. #ifndef isspace
  104. #define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
  105. #endif
  106. #ifndef iswspace
  107. #define iswspace(c) (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n'))
  108. #endif
  109. #ifndef isascii
  110. #define isascii(c) (((unsigned char)(c)) <= 0x7f)
  111. #endif
  112. #ifndef isupper
  113. #define isupper(c) ((c) >= 'A' && (c) <= 'Z')
  114. #endif
  115. #ifndef islower
  116. #define islower(c) ((c) >= 'a' && (c) <= 'z')
  117. #endif
  118. #ifndef isalpha
  119. #define isalpha(c) (isupper(c) || (islower(c)))
  120. #endif
  121. #ifndef isdigit
  122. #define isdigit(c) ((c) >= '0' && (c) <= '9')
  123. #endif
  124. #ifndef isxupper
  125. #define isxupper(c) ((c) >= 'A' && (c) <= 'F')
  126. #endif
  127. #ifndef isxlower
  128. #define isxlower(c) ((c) >= 'a' && (c) <= 'f')
  129. #endif
  130. #ifndef isxdigit
  131. #define isxdigit(c) (isdigit(c) || isxupper(c) || isxlower(c))
  132. #endif
  133. #endif
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. /* Reserved file operation macro interface */
  138. #define SECUREC_LOCK_FILE(s)
  139. #define SECUREC_UNLOCK_FILE(s)
  140. #define SECUREC_LOCK_STDIN(i, s)
  141. #define SECUREC_UNLOCK_STDIN(i, s)
  142. #endif

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知.