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.

snprintf_s.c 4.5 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "securec.h"
  17. #if SECUREC_ENABLE_SNPRINTF
  18. /*
  19. * <FUNCTION DESCRIPTION>
  20. * The snprintf_s function is equivalent to the snprintf function
  21. * except for the parameter destMax/count and the explicit runtime-constraints violation
  22. * The snprintf_s function formats and stores count or fewer characters in
  23. * strDest and appends a terminating null. Each argument (if any) is converted
  24. * and output according to the corresponding format specification in format.
  25. * The formatting is consistent with the printf family of functions; If copying
  26. * occurs between strings that overlap, the behavior is undefined.
  27. *
  28. * <INPUT PARAMETERS>
  29. * strDest Storage location for the output.
  30. * destMax The size of the storage location for output. Size
  31. * in bytes for snprintf_s or size in words for snwprintf_s.
  32. * count Maximum number of character to store.
  33. * format Format-control string.
  34. * ... Optional arguments.
  35. *
  36. * <OUTPUT PARAMETERS>
  37. * strDest is updated
  38. *
  39. * <RETURN VALUE>
  40. * return the number of characters written, not including the terminating null
  41. * return -1 if an error occurs.
  42. * return -1 if count < destMax and the output string has been truncated
  43. *
  44. * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
  45. *
  46. */
  47. int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...)
  48. {
  49. int ret; /* If initialization causes e838 */
  50. va_list argList;
  51. va_start(argList, format);
  52. ret = vsnprintf_s(strDest, destMax, count, format, argList);
  53. va_end(argList);
  54. (void)argList; /* to clear e438 last value assigned not used , the compiler will optimize this code */
  55. return ret;
  56. }
  57. #if SECUREC_IN_KERNEL
  58. EXPORT_SYMBOL(snprintf_s);
  59. #endif
  60. #endif
  61. #if SECUREC_SNPRINTF_TRUNCATED
  62. /*
  63. * <FUNCTION DESCRIPTION>
  64. * The snprintf_truncated_s function is equivalent to the snprintf function
  65. * except for the parameter destMax/count and the explicit runtime-constraints violation
  66. * The snprintf_truncated_s function formats and stores count or fewer characters in
  67. * strDest and appends a terminating null. Each argument (if any) is converted
  68. * and output according to the corresponding format specification in format.
  69. * The formatting is consistent with the printf family of functions; If copying
  70. * occurs between strings that overlap, the behavior is undefined.
  71. *
  72. * <INPUT PARAMETERS>
  73. * strDest Storage location for the output.
  74. * destMax The size of the storage location for output. Size
  75. * in bytes for snprintf_truncated_s or size in words for snwprintf_s.
  76. * format Format-control string.
  77. * ... Optional arguments.
  78. *
  79. * <OUTPUT PARAMETERS>
  80. * strDest is updated
  81. *
  82. * <RETURN VALUE>
  83. * return the number of characters written, not including the terminating null
  84. * return -1 if an error occurs.
  85. * return destMax-1 if output string has been truncated
  86. *
  87. * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
  88. *
  89. */
  90. int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...)
  91. {
  92. int ret; /* If initialization causes e838 */
  93. va_list argList;
  94. va_start(argList, format);
  95. ret = vsnprintf_truncated_s(strDest, destMax, format, argList);
  96. va_end(argList);
  97. (void)argList; /* to clear e438 last value assigned not used , the compiler will optimize this code */
  98. return ret;
  99. }
  100. #if SECUREC_IN_KERNEL
  101. EXPORT_SYMBOL(snprintf_truncated_s);
  102. #endif
  103. #endif

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