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.4 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_KERNEL_OPLIB_OPLIB_H_
  17. #define MINDSPORE_CCSRC_KERNEL_OPLIB_OPLIB_H_
  18. #include <vector>
  19. #include <string>
  20. #include <memory>
  21. #include <nlohmann/json.hpp>
  22. #include "kernel/oplib/opinfo.h"
  23. namespace mindspore {
  24. namespace kernel {
  25. class OpLib {
  26. public:
  27. OpLib() = default;
  28. virtual ~OpLib() = default;
  29. bool RegOp(const std::string &json_string, const std::string &impl_path);
  30. static void RegOpInfo(std::shared_ptr<OpInfo> opinfo) {
  31. op_info_.emplace_back(opinfo);
  32. return;
  33. }
  34. static std::shared_ptr<OpInfo> FindOp(const std::string &op_name, OpImplyType imply_type);
  35. static const std::vector<std::shared_ptr<OpInfo>> &GetAllOpsInfo() { return op_info_; }
  36. protected:
  37. static std::vector<std::shared_ptr<OpInfo>> op_info_;
  38. private:
  39. static bool DecodeOpInfo(const nlohmann::json &obj, const OpImplyType imply_type, const std::string &impl_path);
  40. static bool DecodeAttr(const nlohmann::json &obj, const OpImplyType imply_type,
  41. 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 bool DecodeInputOutput(const nlohmann::json &obj, const OpImplyType imply_type, const 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_KERNEL_OPLIB_OPLIB_H_