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.

vsnprintf_s.c 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include "secureprintoutput.h"
  17. #if SECUREC_ENABLE_VSNPRINTF
  18. /*
  19. * <FUNCTION DESCRIPTION>
  20. * The vsnprintf_s function is equivalent to the vsnprintf function
  21. * except for the parameter destMax/count and the explicit runtime-constraints violation
  22. * The vsnprintf_s function takes a pointer to an argument list, then formats
  23. * and writes up to count characters of the given data to the memory pointed
  24. * to by strDest and appends a terminating null.
  25. *
  26. * <INPUT PARAMETERS>
  27. * strDest Storage location for the output.
  28. * destMax The size of the strDest for output.
  29. * count Maximum number of character to write(not including
  30. * the terminating NULL)
  31. * format Format-control string.
  32. * argList pointer to list of arguments.
  33. *
  34. * <OUTPUT PARAMETERS>
  35. * strDest is updated
  36. *
  37. * <RETURN VALUE>
  38. * return the number of characters written, not including the terminating null
  39. * return -1 if an error occurs.
  40. * return -1 if count < destMax and the output string has been truncated
  41. *
  42. * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
  43. */
  44. int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, va_list argList)
  45. {
  46. int retVal;
  47. if (format == NULL || strDest == NULL || destMax == 0 || destMax > SECUREC_STRING_MAX_LEN ||
  48. (count > (SECUREC_STRING_MAX_LEN - 1) && count != (size_t)(-1))) {
  49. if (strDest != NULL && destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN) {
  50. strDest[0] = '\0';
  51. }
  52. SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
  53. return -1;
  54. }
  55. if (destMax > count) {
  56. retVal = SecVsnprintfImpl(strDest, count + 1, format, argList);
  57. if (retVal == SECUREC_PRINTF_TRUNCATE) { /* lsd add to keep dest buffer not destroyed 2014.2.18 */
  58. /* the string has been truncated, return -1 */
  59. return -1; /* to skip error handler, return strlen(strDest) or -1 */
  60. }
  61. } else {
  62. retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
  63. #ifdef SECUREC_COMPATIBLE_WIN_FORMAT
  64. if (retVal == SECUREC_PRINTF_TRUNCATE && count == (size_t)(-1)) {
  65. return -1;
  66. }
  67. #endif
  68. }
  69. if (retVal < 0) {
  70. strDest[0] = '\0'; /* empty the dest strDest */
  71. if (retVal == SECUREC_PRINTF_TRUNCATE) {
  72. /* Buffer too small */
  73. SECUREC_ERROR_INVALID_RANGE("vsnprintf_s");
  74. }
  75. SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
  76. return -1;
  77. }
  78. return retVal;
  79. }
  80. #if SECUREC_IN_KERNEL
  81. EXPORT_SYMBOL(vsnprintf_s);
  82. #endif
  83. #endif
  84. #if SECUREC_SNPRINTF_TRUNCATED
  85. /*
  86. * <FUNCTION DESCRIPTION>
  87. * The vsnprintf_truncated_s function is equivalent to the vsnprintf function
  88. * except for the parameter destMax/count and the explicit runtime-constraints violation
  89. * The vsnprintf_truncated_s function takes a pointer to an argument list, then formats
  90. * and writes up to count characters of the given data to the memory pointed
  91. * to by strDest and appends a terminating null.
  92. *
  93. * <INPUT PARAMETERS>
  94. * strDest Storage location for the output.
  95. * destMax The size of the strDest for output.
  96. * the terminating NULL)
  97. * format Format-control string.
  98. * argList pointer to list of arguments.
  99. *
  100. * <OUTPUT PARAMETERS>
  101. * strDest is updated
  102. *
  103. * <RETURN VALUE>
  104. * return the number of characters written, not including the terminating null
  105. * return -1 if an error occurs.
  106. * return destMax-1 if output string has been truncated
  107. *
  108. * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
  109. */
  110. int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_list argList)
  111. {
  112. int retVal;
  113. if (format == NULL || strDest == NULL || destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
  114. if (strDest != NULL && destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN) {
  115. strDest[0] = '\0';
  116. }
  117. SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
  118. return -1;
  119. }
  120. retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
  121. if (retVal < 0) {
  122. if (retVal == SECUREC_PRINTF_TRUNCATE) {
  123. return (int)(destMax - 1); /* to skip error handler, return strlen(strDest) */
  124. }
  125. strDest[0] = '\0'; /* empty the dest strDest */
  126. SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
  127. return -1;
  128. }
  129. return retVal;
  130. }
  131. #if SECUREC_IN_KERNEL
  132. EXPORT_SYMBOL(vsnprintf_truncated_s);
  133. #endif
  134. #endif

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