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.

memmove_s.c 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "securecutil.h"
  17. #ifdef SECUREC_NOT_CALL_LIBC_CORE_API
  18. /*
  19. * Implementing memory data movement
  20. */
  21. static void SecUtilMemmove(void *dst, const void *src, size_t count)
  22. {
  23. unsigned char *pDest = (unsigned char *)dst;
  24. const unsigned char *pSrc = (const unsigned char *)src;
  25. size_t maxCount = count;
  26. if (dst <= src || pDest >= (pSrc + maxCount)) {
  27. /*
  28. * Non-Overlapping Buffers
  29. * copy from lower addresses to higher addresses
  30. */
  31. while (maxCount--) {
  32. *pDest = *pSrc;
  33. ++pDest;
  34. ++pSrc;
  35. }
  36. } else {
  37. /*
  38. * Overlapping Buffers
  39. * copy from higher addresses to lower addresses
  40. */
  41. pDest = pDest + maxCount - 1;
  42. pSrc = pSrc + maxCount - 1;
  43. while (maxCount--) {
  44. *pDest = *pSrc;
  45. --pDest;
  46. --pSrc;
  47. }
  48. }
  49. }
  50. #endif
  51. /*
  52. * <FUNCTION DESCRIPTION>
  53. * The memmove_s function copies count bytes of characters from src to dest.
  54. * This function can be assigned correctly when memory overlaps.
  55. * <INPUT PARAMETERS>
  56. * dest Destination object.
  57. * destMax Size of the destination buffer.
  58. * src Source object.
  59. * count Number of characters to copy.
  60. *
  61. * <OUTPUT PARAMETERS>
  62. * dest buffer is uptdated.
  63. *
  64. * <RETURN VALUE>
  65. * EOK Success
  66. * EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
  67. * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
  68. * ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
  69. * ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0
  70. * and destMax <= SECUREC_MEM_MAX_LEN
  71. *
  72. * If an error occured, dest will be filled with 0 when dest and destMax valid.
  73. * If some regions of the source area and the destination overlap, memmove_s
  74. * ensures that the original source bytes in the overlapping region are copied
  75. * before being overwritten.
  76. */
  77. errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count)
  78. {
  79. if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
  80. SECUREC_ERROR_INVALID_RANGE("memmove_s");
  81. return ERANGE;
  82. }
  83. if (dest == NULL || src == NULL) {
  84. SECUREC_ERROR_INVALID_PARAMTER("memmove_s");
  85. if (dest != NULL) {
  86. (void)memset(dest, 0, destMax);
  87. return EINVAL_AND_RESET;
  88. }
  89. return EINVAL;
  90. }
  91. if (count > destMax) {
  92. (void)memset(dest, 0, destMax);
  93. SECUREC_ERROR_INVALID_RANGE("memmove_s");
  94. return ERANGE_AND_RESET;
  95. }
  96. if (dest == src) {
  97. return EOK;
  98. }
  99. if (count > 0) {
  100. #ifdef SECUREC_NOT_CALL_LIBC_CORE_API
  101. SecUtilMemmove(dest, src, count);
  102. #else
  103. /* use underlying memmove for performance consideration */
  104. (void)memmove(dest, src, count);
  105. #endif
  106. }
  107. return EOK;
  108. }
  109. #if SECUREC_IN_KERNEL
  110. EXPORT_SYMBOL(memmove_s);
  111. #endif

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