diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.cc index 699036acdaf..7f7796fa9c4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.cc @@ -13,32 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.h" -#include #include +#include "backend/kernel_compiler/cpu/eigen/eigen_common_utils.h" #include "utils/ms_utils.h" +#include "Eigen/Eigenvalues" namespace mindspore { namespace kernel { - namespace { constexpr size_t kInputsNum = 1; constexpr size_t kOutputsNum = 2; - } // namespace -using Eigen::Dynamic; -using Eigen::EigenSolver; -using Eigen::Lower; -using Eigen::Map; -using Eigen::MatrixBase; -using Eigen::RowMajor; -using Eigen::Upper; - -template -using MatrixSquare = Eigen::Matrix; - -template -using ComplexMatrixSquare = Eigen::Matrix, Dynamic, Dynamic, RowMajor>; template void EigCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { @@ -53,35 +40,27 @@ void EigCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { } template -void EigCpuKernelMod::InitInputOutputSize(const CNodePtr &kernel_node) { - NativeCpuKernelMod::InitInputOutputSize(kernel_node); - (void)workspace_size_list_.template emplace_back(m_ * m_ * sizeof(T)); -} - -template -bool SolveGenericRealScalaMatrix(const Map> &A, Map> *output, +void SolveGenericRealScalaMatrix(const Map> &A, Map> *output, Map> *outputv, bool compute_eigen_vectors) { Eigen::EigenSolver> solver(A); output->noalias() = solver.eigenvalues(); if (compute_eigen_vectors) { outputv->noalias() = solver.eigenvectors(); } - return true; } template -bool SolveComplexMatrix(const Map> &A, Map> *output, Map> *outputv, +void SolveComplexMatrix(const Map> &A, Map> *output, Map> *outputv, bool compute_eigen_vectors) { Eigen::ComplexEigenSolver> solver(A); output->noalias() = solver.eigenvalues(); if (compute_eigen_vectors) { outputv->noalias() = solver.eigenvectors(); } - return true; } template -bool EigCpuKernelMod::Launch(const std::vector &inputs, const std::vector &workspace, +bool EigCpuKernelMod::Launch(const std::vector &inputs, const std::vector &, const std::vector &outputs) { CHECK_KERNEL_INPUTS_NUM(inputs.size(), kInputsNum, kernel_name_); CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), kOutputsNum, kernel_name_); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.h index 626d067929e..eb69092cb77 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eig_cpu_kernel.h @@ -42,9 +42,6 @@ class EigCpuKernelMod : public NativeCpuKernelMod { bool Launch(const std::vector &inputs, const std::vector &workspace, const std::vector &outputs) override; - protected: - void InitInputOutputSize(const CNodePtr &kernel_node); - private: size_t m_{1}; bool compute_eigen_vectors{false}; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigen_common_utils.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigen_common_utils.h index 729c265ba77..bf3a9c2604b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigen_common_utils.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigen_common_utils.h @@ -31,6 +31,10 @@ using Eigen::UnitUpper; using Eigen::Upper; template using Matrix = Eigen::Matrix; +template +using MatrixSquare = Eigen::Matrix; +template +using ComplexMatrixSquare = Eigen::Matrix, Dynamic, Dynamic, RowMajor>; } // namespace kernel } // namespace mindspore #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EIGEN_EIGEN_COMMON_UTILS_H_ diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.cc index 2d2adce9554..2583bbcacca 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.cc @@ -13,32 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.h" -#include #include +#include "backend/kernel_compiler/cpu/eigen/eigen_common_utils.h" +#include "Eigen/Eigenvalues" #include "utils/ms_utils.h" namespace mindspore { namespace kernel { - namespace { constexpr size_t kInputsNum = 1; constexpr size_t kOutputsNum = 2; - } // namespace -using Eigen::Dynamic; -using Eigen::EigenSolver; -using Eigen::Lower; -using Eigen::Map; -using Eigen::MatrixBase; -using Eigen::RowMajor; -using Eigen::Upper; - -template -using MatrixSquare = Eigen::Matrix; - -template -using ComplexMatrixSquare = Eigen::Matrix, Dynamic, Dynamic, RowMajor>; template void EighCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { @@ -57,35 +44,27 @@ void EighCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { } template -void EighCpuKernelMod::InitInputOutputSize(const CNodePtr &kernel_node) { - NativeCpuKernelMod::InitInputOutputSize(kernel_node); - (void)workspace_size_list_.template emplace_back(m_ * m_ * sizeof(T)); -} - -template -bool SolveSelfAdjointMatrix(const Map> &A, Map> *output, Map> *outputv, +void SolveSelfAdjointMatrix(const Map> &A, Map> *output, Map> *outputv, bool compute_eigen_vectors) { Eigen::SelfAdjointEigenSolver> solver(A); output->noalias() = solver.eigenvalues(); if (compute_eigen_vectors) { outputv->noalias() = solver.eigenvectors(); } - return true; } template -bool SolveComplexMatrix(const Map> &A, Map> *output, Map> *outputv, +void SolveComplexMatrix(const Map> &A, Map> *output, Map> *outputv, bool compute_eigen_vectors) { Eigen::ComplexEigenSolver> solver(A); output->noalias() = solver.eigenvalues(); if (compute_eigen_vectors) { outputv->noalias() = solver.eigenvectors(); } - return true; } template -bool EighCpuKernelMod::Launch(const std::vector &inputs, const std::vector &workspace, +bool EighCpuKernelMod::Launch(const std::vector &inputs, const std::vector &, const std::vector &outputs) { CHECK_KERNEL_INPUTS_NUM(inputs.size(), kInputsNum, kernel_name_); CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), kOutputsNum, kernel_name_); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.h index 8dd2e8372c7..d1c693158e0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eigen/eigh_cpu_kernel.h @@ -41,9 +41,6 @@ class EighCpuKernelMod : public NativeCpuKernelMod { bool Launch(const std::vector &inputs, const std::vector &workspace, const std::vector &outputs) override; - protected: - void InitInputOutputSize(const CNodePtr &kernel_node); - private: size_t m_{1}; bool compute_eigen_vectors_{false};