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.

spectral_ops.h 6.1 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Copyright 2019 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. /*!
  17. * \file spectral_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_SPECTRAL_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_SPECTRAL_OPS_H_
  22. #include "graph/operator.h"
  23. #include "graph/operator_reg.h"
  24. namespace ge {
  25. /**
  26. *@brief Computes the inverse 1-dimensional discrete Fourier transform over the
  27. inner-most dimension of `x`. \n
  28. *@par Inputs:
  29. *x: A Tensor. Must be the following types: complex64, complex128. \n
  30. *@par Outputs:
  31. *y: A complex tensor of the same rank as `x`. \n
  32. *@par Third-party framework compatibility
  33. * Compatible with TensorFlow IFFT operator.
  34. */
  35. REG_OP(IFFT)
  36. .INPUT(x, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  37. .OUTPUT(y, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  38. .OP_END_FACTORY_REG(IFFT)
  39. /**
  40. *@brief Real-valued fast Fourier transform . \n
  41. *@par Inputs:
  42. *@li input: A float32 tensor.
  43. *@li fft_length: An int32 tensor of shape [1]. The FFT length . \n
  44. *@par Outputs:
  45. *y: A complex64 tensor of the same rank as `input`. The inner-most
  46. dimension of `input` is replaced with the `fft_length / 2 + 1` unique
  47. frequency components of its 1D Fourier transform . \n
  48. *@par Third-party framework compatibility
  49. * Compatible with TensorFlow RFFT operator.
  50. */
  51. REG_OP(RFFT)
  52. .INPUT(input, TensorType({DT_FLOAT}))
  53. .INPUT(fft_length, TensorType({DT_INT32}))
  54. .OUTPUT(y, TensorType({DT_COMPLEX64}))
  55. .OP_END_FACTORY_REG(RFFT)
  56. /**
  57. *@brief Inverse real-valued fast Fourier transform. \n
  58. *@par Inputs:
  59. *@li x: A complex64 tensor.
  60. *@li fft_length: An int32 tensor of shape [1]. The FFT length. \n
  61. *@par Outputs:
  62. * y: A float32 tensor of the same rank as `input`. The inner-most
  63. dimension of `input` is replaced with the `fft_length` samples of its inverse
  64. 1D Fourier transform. \n
  65. *@par Third-party framework compatibility
  66. * Compatible with TensorFlow IRFFT operator.
  67. */
  68. REG_OP(IRFFT)
  69. .INPUT(x, TensorType({DT_COMPLEX64}))
  70. .INPUT(fft_length, TensorType({DT_INT32}))
  71. .OUTPUT(y, TensorType({DT_FLOAT}))
  72. .OP_END_FACTORY_REG(IRFFT)
  73. /**
  74. *@brief 2D fast Fourier transform. \n
  75. *@par Inputs:
  76. *x: A complex64 tensor.
  77. *@par Outputs:
  78. *y: A complex64 tensor of the same shape as `input`. The inner-most 2
  79. dimensions of `input` are replaced with their 2D Fourier transform. \n
  80. *@par Third-party framework compatibility
  81. * Compatible with TensorFlow FFT2D operator.
  82. */
  83. REG_OP(FFT2D)
  84. .INPUT(x, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
  85. .OUTPUT(y, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
  86. .OP_END_FACTORY_REG(FFT2D)
  87. /**
  88. *@brief Calculate the one-dimensional discrete Fourier transform on the
  89. innermost dimension of the input. \n
  90. *@par Inputs:
  91. *x: A Tensor. Must be the following types: complex64, complex128. \n
  92. *@par Outputs:
  93. *y: A complex tensor with the same shape as input. The innermost dimension
  94. of the input is replaced by its 1-dimensional Fourier transform. \n
  95. *@par Third-party framework compatibility
  96. * Compatible with TensorFlow FFT operator.
  97. */
  98. REG_OP(FFT)
  99. .INPUT(x, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  100. .OUTPUT(y, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  101. .OP_END_FACTORY_REG(FFT)
  102. /**
  103. *@brief Calculate the inverse 1-dimensional discrete Fourier transform on the
  104. innermost dimension of the input. \n
  105. *@par Inputs:
  106. *x: A Tensor. Must be the following types: complex64, complex128. \n
  107. *@par Outputs:
  108. *y: A complex tensor with the same shape as input. The innermost dimension
  109. of the input is replaced by its inverse two-dimensional Fourier transform. \n
  110. *@par Third-party framework compatibility
  111. * Compatible with TensorFlow IFFT2D operator.
  112. */
  113. REG_OP(IFFT2D)
  114. .INPUT(x, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  115. .OUTPUT(y, TensorType({DT_COMPLEX64,DT_COMPLEX128}))
  116. .OP_END_FACTORY_REG(IFFT2D)
  117. /**
  118. * @brief Computes the Fourier transform of short overlapping windows of the input. \n
  119. * @par Inputs:
  120. * @li x: A 1-D or 2-D tensor.
  121. * @li window: An optional tensor. The optional window function. Default: None (treated as window of all 1 s) \n
  122. * @par Attributes:
  123. * @li n_fft: A required int. Size of Fourier transform
  124. * @li hop_length: An optional int. The distance between neighboring sliding window frames.
  125. * Default: None (treated as equal to floor(n_fft/4))
  126. * @li win_length: An optional int. The size of window frame and STFT filter.
  127. * Default: None (treated as equal to n_fft)
  128. * @li normalized: An optional bool. Controls whether to return the normalized STFT results Default: False
  129. * @li onesided: An optional bool. Controls whether to return half of results to avoid redundancy for real inputs.
  130. * Default: True for real input and window, False otherwise.
  131. * @li return_complex: An optional bool. Whether to return a complex tensor, or a real tensor
  132. * with an extra last dimension for the real and imaginary components. \n
  133. * @par Outputs:
  134. * y: A tensor containing the STFT result with shape described above. \n
  135. * @par Third-party framework compatibility
  136. * Compatible with pytorch STFT operator.
  137. */
  138. REG_OP(STFT)
  139. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  140. .OPTIONAL_INPUT(window, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  141. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  142. .ATTR(hop_length, Int, 0)
  143. .ATTR(win_length, Int, 0)
  144. .ATTR(normalized, Bool, false)
  145. .ATTR(onesided, Bool, true)
  146. .ATTR(return_complex, Bool, true)
  147. .REQUIRED_ATTR(n_fft, Int)
  148. .OP_END_FACTORY_REG(STFT)
  149. } // namespace ge
  150. #endif // OPS_BUILT_IN_OP_PROTO_INC_SPECTRAL_OPS_H_

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