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.

oplib.h 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_OPLIB_OPLIB_H_
  17. #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_OPLIB_OPLIB_H_
  18. #include <vector>
  19. #include <string>
  20. #include <memory>
  21. #include <map>
  22. #include <nlohmann/json.hpp>
  23. #include "utils/ms_utils.h"
  24. #include "backend/kernel_compiler/oplib/opinfo.h"
  25. namespace mindspore {
  26. namespace kernel {
  27. class OpLib {
  28. public:
  29. OpLib() = default;
  30. virtual ~OpLib() = default;
  31. static bool RegOp(const std::string &json_string, const std::string &impl_path);
  32. static void RegOpInfo(const std::shared_ptr<OpInfo> &opinfo) { op_info_.emplace(opinfo->op_name(), opinfo); }
  33. static std::shared_ptr<OpInfo> FindOp(const std::string &op_name, OpImplyType imply_type,
  34. bool is_dynamic_shape = false);
  35. static const std::multimap<std::string, std::shared_ptr<OpInfo>> &GetAllOpsInfo() { return op_info_; }
  36. protected:
  37. static std::multimap<std::string, std::shared_ptr<OpInfo>> op_info_;
  38. private:
  39. static bool RegOpFromLocalInfo();
  40. static bool DecodeOpInfo(const nlohmann::json &obj, OpImplyType imply_type, const std::string &impl_path);
  41. static bool DecodeAttr(const nlohmann::json &obj, OpImplyType imply_type, const std::shared_ptr<OpInfo> &op_info);
  42. static bool DecodeDtypeFormat(const nlohmann::json &dtype_format, const std::shared_ptr<OpIOInfo> &op_io,
  43. size_t index);
  44. static void DecodeTBESpecificInfo(const nlohmann::json &obj, const std::shared_ptr<OpInfo> &op_info);
  45. static void DecodeAKGSpecificInfo(const nlohmann::json &obj, const std::shared_ptr<OpInfo> &op_info);
  46. static bool DecodeInputOutput(const nlohmann::json &obj, OpImplyType imply_type, OpIOType io_type,
  47. const std::shared_ptr<OpInfo> &op_info, const nlohmann::json &dtype_format);
  48. static bool GetRefInfo(const std::shared_ptr<OpInfo> &op_info);
  49. static bool CheckRepetition(const std::shared_ptr<OpInfo> &op_info);
  50. };
  51. } // namespace kernel
  52. } // namespace mindspore
  53. #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_OPLIB_OPLIB_H_