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.

state_ops.h 5.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * Copyright 2019-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 GE_OP_STATE_OPS_H_
  17. #define GE_OP_STATE_OPS_H_
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Creates a variable tensor.
  22. *@par Inputs:
  23. *x: A tensor, used to assign a value to the variable tensor internally. \n
  24. The caller does not need to pass the value of the variable tensor.
  25. *@par Attributes:
  26. *@li index: An integer. Index of the input tensor.
  27. *@li value: A tensor, used to pass and record the value of the variable tensor.
  28. *@li container: A string. The container of the variable tensor.
  29. *@li shared_name: A string. The shared name of the variable tensor.
  30. *@par Outputs:
  31. *y: The created variable tensor.
  32. *@par Third-party framework compatibility
  33. *Compatible with the TensorFlow operator Variable.
  34. */
  35. REG_OP(Variable)
  36. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  37. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  38. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  39. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  40. .ATTR(index, Int, 0)
  41. .ATTR(value, Tensor, Tensor())
  42. .ATTR(container, String, "")
  43. .ATTR(shared_name, String, "")
  44. .OP_END_FACTORY_REG(Variable)
  45. /**
  46. *@brief Returns a temporary variable tensor. After the use of TemporaryVariable, \n
  47. pass the reference to the variable tensor to the matching DestroyTemporaryVariable op for destruction.
  48. *@par Attributes:
  49. *@li shape: A required list of int32 or int64. The shape of the variable tensor.
  50. *@li dtype: Required. The type of elements in the variable tensor.
  51. *@li var_name: An optional string. The name of the variable to be created.
  52. *@par Outputs:
  53. *y: The created variable tensor.
  54. *@par Third-party framework compatibility
  55. *Compatible with the TensorFlow operator TemporaryVariable.
  56. */
  57. REG_OP(TemporaryVariable)
  58. .OUTPUT(y, TensorType::ALL())
  59. .REQUIRED_ATTR(shape, ListInt)
  60. .REQUIRED_ATTR(dtype, Int)
  61. .ATTR(var_name, String, "")
  62. .OP_END_FACTORY_REG(TemporaryVariable)
  63. /**
  64. *@brief Destroys the temporary variable and returns its final value. \n
  65. All other uses of the temporary variable must have been executed before this op.
  66. *@par Inputs:
  67. *x: A reference to the temporary variable tensor.
  68. *@par Attributes:
  69. *var_name: A required string. Name of the temporary variable. \n
  70. Must be the same as the "var_name" attribute of the reference to the temporary variable tensor.
  71. *@par Outputs:
  72. *y: Final value of the reference to the temporary variable tensor.
  73. *@par Third-party framework compatibility
  74. *Compatible with the TensorFlow operator DestroyTemporaryVariable.
  75. */
  76. REG_OP(DestroyTemporaryVariable)
  77. .INPUT(x, TensorType::ALL())
  78. .OUTPUT(y, TensorType::ALL())
  79. .ATTR(var_name, String, "")
  80. .OP_END_FACTORY_REG(DestroyTemporaryVariable)
  81. /**
  82. *@brief Checks whether a tensor has been initialized. Outputs boolean scalar indicating whether the tensor has been initialized.
  83. *@par Inputs:
  84. *x: A tensor.
  85. *@par Outputs:
  86. *y: A tensor, indicating whether "x" has been initialized.
  87. *@par Third-party framework compatibility
  88. *Compatible with the TensorFlow operator IsVariableInitialized.
  89. */
  90. REG_OP(IsVariableInitialized)
  91. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  92. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  93. .OUTPUT(y, TensorType({DT_BOOL}))
  94. .OP_END_FACTORY_REG(IsVariableInitialized)
  95. /**
  96. *@brief Checks whether a tensor has been initialized. Outputs boolean scalar indicating whether the tensor has been initialized.
  97. *@par Inputs:
  98. *x: A tensor.
  99. *@par Outputs:
  100. *y: A tensor, indicating whether "x" has been initialized, and the data type is boolean.
  101. *@par Third-party framework compatibility
  102. *Compatible with the TensorFlow operator VarIsInitializedOp.
  103. */
  104. REG_OP(VarIsInitializedOp)
  105. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  106. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  107. .OUTPUT(y, TensorType({DT_BOOL}))
  108. .OP_END_FACTORY_REG(VarIsInitializedOp)
  109. /**
  110. *@brief Increments 'ref' until it reaches 'limit'.
  111. *@par Inputs:
  112. *Inputs include: \n
  113. *ref: A mutable Tensor. Must be one of the following types: int32, int64.
  114. *@par Attributes:
  115. *limit: An int. If incrementing ref would bring it above limit, instead \n
  116. generates an 'OutOfRange' error.
  117. *@par Outputs:
  118. *y: A Tensor. Has the same type as ref.
  119. *@attention Constraints:\n
  120. *-The implementation for CountUpTo on Ascend uses AICPU, with bad performance.\n
  121. *@par Third-party framework compatibility
  122. *@li compatible with tensorflow CountUpTo operator.
  123. */
  124. REG_OP(CountUpTo)
  125. .INPUT(ref, TensorType({DT_INT32, DT_INT64}))
  126. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  127. .ATTR(limit, Int, 0)
  128. .OP_END_FACTORY_REG(CountUpTo)
  129. } // namespace ge
  130. #endif // GE_OP_STATE_OPS_H_

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