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.

convert_utils.h 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 MINDSPORE_CCSRC_UTILS_CONVERT_UTILS_H_
  17. #define MINDSPORE_CCSRC_UTILS_CONVERT_UTILS_H_
  18. #include <limits>
  19. #include <memory>
  20. #include <utility>
  21. #include <stack>
  22. #include <unordered_map>
  23. #include <unordered_set>
  24. #include "pybind11/pybind11.h"
  25. #include "utils/convert_utils_base.h"
  26. #include "utils/any.h"
  27. #include "utils/base_ref.h"
  28. #include "ir/base.h"
  29. #include "ir/anf.h"
  30. namespace py = pybind11;
  31. namespace mindspore {
  32. namespace tensor {
  33. class Tensor;
  34. using TensorPtr = std::shared_ptr<Tensor>;
  35. } // namespace tensor
  36. py::object AnyToPyData(const Any &value);
  37. py::object BaseRefToPyData(const BaseRef &value);
  38. bool BaseRefToBool(const BaseRef &in, bool *out);
  39. bool ValueToBool(const ValuePtr &in, bool *out);
  40. py::object ValuePtrToPyData(const ValuePtr &value);
  41. AbstractBasePtr PyListDtype2AbstractTensor(const py::object &shape_obj, const py::object &type_obj);
  42. bool IsGraphOutputValueNodeOrParameter(const AnfNodePtr &output, const py::tuple &args,
  43. const std::shared_ptr<py::object> &ret_val);
  44. // Isomorphism
  45. struct PairHasher {
  46. template <class T1, class T2>
  47. std::size_t operator()(const std::pair<T1, T2> &p) const {
  48. auto h1 = std::hash<T1>{}(p.first);
  49. auto h2 = std::hash<T2>{}(p.second);
  50. return h1 ^ h2;
  51. }
  52. };
  53. enum EquivState { kNotEquiv = 0, kEquiv = 1, kPending = 2 };
  54. using FuncGraphPairMapEquiv = std::unordered_map<std::pair<FuncGraphPtr, FuncGraphPtr>, EquivState, PairHasher>;
  55. using NodeMapEquiv = std::unordered_map<AnfNodePtr, AnfNodePtr>;
  56. bool Isomorphic(FuncGraphPtr g1, FuncGraphPtr g2, FuncGraphPairMapEquiv *equiv_func_graph, NodeMapEquiv *equiv_node);
  57. tensor::TensorPtr ScalarToTensor(const ScalarPtr &scalar);
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_UTILS_CONVERT_UTILS_H_