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.

ops_stub.h 5.7 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 MAIN_OPS_STUB_H
  17. #define MAIN_OPS_STUB_H
  18. #include "external/graph/operator_reg.h"
  19. // for ir
  20. namespace ge {
  21. // Data
  22. REG_OP(Data)
  23. .INPUT(data, TensorType::ALL())
  24. .OUTPUT(out, TensorType::ALL())
  25. .ATTR(index, Int, 0)
  26. .OP_END_FACTORY_REG(Data)
  27. // Softmax
  28. REG_OP(Softmax)
  29. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  30. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  31. .ATTR(axis, Int, 0) // which mean compute which dims
  32. .ATTR(algo, Int, 1) // 1 means using "subtract max from every point to avoid overflow",
  33. /// 0 means using "ubtract max from every point to avoid overflow"
  34. /// 2 means using "perform the Log softmax operation to avoid overflow"
  35. /// now is only support 1
  36. .ATTR(alpha, Float, 1)
  37. .ATTR(beta, Float, 0)
  38. .OP_END_FACTORY_REG(Softmax)
  39. // Flatten
  40. REG_OP(Flatten)
  41. .INPUT(x, TensorType::ALL())
  42. .OUTPUT(y, TensorType::ALL())
  43. .OP_END_FACTORY_REG(Flatten)
  44. REG_OP(Square)
  45. .INPUT(x, TensorType({DT_FLOAT}))
  46. .OUTPUT(y, TensorType({DT_FLOAT}))
  47. .ATTR(alpha, Float, 1.0)
  48. .ATTR(beta, Float, 0.0)
  49. .OP_END_FACTORY_REG(Square)
  50. REG_OP(ReadVariable)
  51. .INPUT(x, TensorType::ALL())
  52. .OUTPUT(y, TensorType::ALL())
  53. .OP_END_FACTORY_REG(ReadVariable)
  54. REG_OP(Activation)
  55. .INPUT(x, TensorType::ALL())
  56. .OUTPUT(y, TensorType::ALL())
  57. /// 0:sigmod, 1:relu, 2:tanh, 3:clipped ReLU, 4:Elu,
  58. /// 5:leaky relu, 6:abs, 7:relu1, 8:softsign, 9:softplus
  59. .ATTR(mode, Int, 1)
  60. .ATTR(coef, Float, 0)
  61. .ATTR(alpha, Float, 1.0)
  62. .ATTR(beta, Float, 0)
  63. .OP_END_FACTORY_REG(Activation)
  64. REG_OP(Add)
  65. .INPUT(x1, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16})) // "First operand."
  66. .INPUT(x2, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16})) // "Second operand."
  67. // "Result, has same element type as two inputs"
  68. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16}))
  69. .ATTR(mode, Int, 0) // mode=0, infer mode=1, train
  70. .ATTR(alpha, Float, 1.0)
  71. .ATTR(beta, Float, 0.0)
  72. .ATTR(is_input_const, ListBool, {false, false})
  73. .ATTR(T, Int, 0)
  74. .OP_END_FACTORY_REG(Add)
  75. REG_OP(Variable)
  76. .INPUT(x, TensorType::ALL())
  77. .OUTPUT(y, TensorType::ALL())
  78. .ATTR(index, Int, 0)
  79. .ATTR(value, Tensor, Tensor())
  80. .OP_END_FACTORY_REG(Variable)
  81. REG_OP(Summary)
  82. .INPUT(x, TensorType::ALL())
  83. .OP_END_FACTORY_REG(Summary)
  84. REG_OP(Const)
  85. .OUTPUT(y, TensorType::ALL()) // TensorType({DT_FLOAT, DT_INT8, DT_INT32, DT_BOOL})
  86. .ATTR(value, Tensor, Tensor()) // This is the value of the const op
  87. .ATTR(dtype, Int, 0)
  88. .OP_END_FACTORY_REG(Const)
  89. REG_OP(HcomBroadcast)
  90. .DYNAMIC_INPUT(x, TensorType::ALL())
  91. .DYNAMIC_OUTPUT(y, TensorType::ALL())
  92. .REQUIRED_ATTR(root_rank, Int)
  93. .REQUIRED_ATTR(group, String)
  94. .ATTR(alpha, Float, 1.0)
  95. .ATTR(beta, Float, 0.0)
  96. .OP_END_FACTORY_REG(HcomBroadcast)
  97. REG_OP(Assign)
  98. .INPUT(resource, TensorType::ALL())
  99. .INPUT(value, TensorType::ALL())
  100. .OUTPUT(y, TensorType::ALL())
  101. .OP_END_FACTORY_REG(Assign) REG_OP(Sqrt)
  102. .INPUT(x, TensorType{(DT_FLOAT.DT_FLOAT16)})
  103. .OUTPUT(y, TensorType{(DT_FLOAT, DT_FLOAT16)})
  104. .ATTR(T, Int, 1)
  105. .ATTR(alpha, Float, 1.0)
  106. .ATTR(beta, Float, 0.0)
  107. .OP_END_FACTORY_REG(Sqrt)
  108. REG_OP(Save)
  109. .DYNAMIC_INPUT(tensors, TensorType
  110. : ALL())
  111. .OP_END_FACTORY_REG(Save)
  112. REG_OP(PReLU)
  113. .INPUT(x, TensorType({DT_FLOAT}))
  114. .OUTPUT(y, TensorType({DT_FLOAT}))
  115. .ATTR(channel_shared, Bool, false)
  116. .ATTR(nan_opt, Int, 0)
  117. .ATTR(alpha, Float, 1.0)
  118. .ATTR(beta, Float, 0.0)
  119. .OP_END_FACTORY_REG(PReLU) REG_OP(Acosh)
  120. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  121. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  122. .OP_END_FACTORY_REG(Acosh)
  123. REG_OP(GuaranteeConst)
  124. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  125. DT_UINT64, DT_BOOL, DT_DOUBLE}))
  126. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  127. DT_UINT64, DT_BOOL, DT_DOUBLE}))
  128. .OP_END_FACTORY_REG(GuaranteeConst)
  129. REG_OP(MatMulV2)
  130. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  131. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  132. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  133. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  134. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  135. .ATTR(transpose_x1, Bool, false)
  136. .ATTR(transpose_x2, Bool, false)
  137. .ATTR(offset_x, Int, 0)
  138. .OP_END_FACTORY_REG(MatMulV2)
  139. IMPLEMT_INFERFUNC(GuaranteeConst, GuaranteeConstInfer) {
  140. TensorDesc tensorDesc = op.GetInputDesc("x");
  141. (void)op.UpdateOutputDesc("y", tensorDesc);
  142. return GRAPH_SUCCESS;
  143. }
  144. INFER_FUNC_REG(GuaranteeConst, GuaranteeConstInfer);
  145. } // namespace ge
  146. #endif // MAIN_OPS_STUB_H

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