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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. static const std::multimap<std::string, std::shared_ptr<OpInfo>> &GetAllOpsInfo() { return op_info_; }
  35. protected:
  36. static std::multimap<std::string, std::shared_ptr<OpInfo>> op_info_;
  37. private:
  38. static bool RegOpFromLocalInfo();
  39. static bool DecodeOpInfo(const nlohmann::json &obj, OpImplyType imply_type, const std::string &impl_path);
  40. static bool DecodeAttr(const nlohmann::json &obj, OpImplyType imply_type, const std::shared_ptr<OpInfo> &op_info);
  41. static bool DecodeDtypeFormat(const nlohmann::json &dtype_format, const std::shared_ptr<OpIOInfo> &op_io,
  42. size_t index);
  43. static void DecodeTBESpecificInfo(const nlohmann::json &obj, const std::shared_ptr<OpInfo> &op_info);
  44. static void DecodeAKGSpecificInfo(const nlohmann::json &obj, const std::shared_ptr<OpInfo> &op_info);
  45. static bool DecodeInputOutput(const nlohmann::json &obj, OpImplyType imply_type, OpIOType io_type,
  46. const std::shared_ptr<OpInfo> &op_info, const nlohmann::json &dtype_format);
  47. static bool GetRefInfo(const std::shared_ptr<OpInfo> &op_info);
  48. static bool CheckRepetition(const std::shared_ptr<OpInfo> &op_info);
  49. };
  50. } // namespace kernel
  51. } // namespace mindspore
  52. #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_OPLIB_OPLIB_H_