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 3.9 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. */
  33. REG_OP(Variable)
  34. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  35. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  36. .OUTPUT(y, 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. .ATTR(index, Int, 0)
  39. .ATTR(value, Tensor, Tensor())
  40. .ATTR(container, String, "")
  41. .ATTR(shared_name, String, "")
  42. .OP_END_FACTORY_REG(Variable)
  43. /**
  44. *@brief Returns a temporary variable tensor. After the use of TemporaryVariable, \n
  45. pass the reference to the variable tensor to the matching DestroyTemporaryVariable op for destruction.
  46. *@par Attributes:
  47. *@li shape: A required list of int32 or int64. The shape of the variable tensor.
  48. *@li dtype: Required. The type of elements in the variable tensor.
  49. *@li var_name: An optional string. The name of the variable to be created.
  50. *@par Outputs:
  51. *y: The created variable tensor.
  52. */
  53. REG_OP(TemporaryVariable)
  54. .OUTPUT(y, TensorType::ALL())
  55. .ATTR(shape, ListInt, {})
  56. .ATTR(dtype, Int, 0)
  57. .ATTR(var_name, String, "")
  58. .OP_END_FACTORY_REG(TemporaryVariable)
  59. /**
  60. *@brief Destroys the temporary variable and returns its final value. \n
  61. All other uses of the temporary variable must have been executed before this op.
  62. *@par Inputs:
  63. *x: A reference to the temporary variable tensor.
  64. *@par Attributes:
  65. *var_name: A required string. Name of the temporary variable. \n
  66. Must be the same as the "var_name" attribute of the reference to the temporary variable tensor.
  67. *@par Outputs:
  68. *y: Final value of the reference to the temporary variable tensor.
  69. */
  70. REG_OP(DestroyTemporaryVariable)
  71. .INPUT(x, TensorType::ALL())
  72. .OUTPUT(y, TensorType::ALL())
  73. .ATTR(var_name, String, "")
  74. .OP_END_FACTORY_REG(DestroyTemporaryVariable)
  75. /**
  76. *@brief Checks whether a tensor has been initialized. Outputs boolean scalar indicating whether the tensor has been initialized.
  77. *@par Inputs:
  78. *x: A tensor.
  79. *@par Outputs:
  80. *y: A tensor, indicating whether "x" has been initialized.
  81. */
  82. REG_OP(IsVariableInitialized)
  83. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  84. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  85. .OUTPUT(y, TensorType({DT_BOOL}))
  86. .OP_END_FACTORY_REG(IsVariableInitialized)
  87. REG_OP(CountUpTo)
  88. .INPUT(ref, TensorType({DT_INT32, DT_INT64}))
  89. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  90. .ATTR(limit, Int, 0)
  91. .OP_END_FACTORY_REG(CountUpTo)
  92. } // namespace ge
  93. #endif // GE_OP_STATE_OPS_H_

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