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.

akgkernelbuild.h 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_AKG_AKGKERNELBUILD_H_
  17. #define MINDSPORE_CCSRC_KERNEL_AKG_AKGKERNELBUILD_H_
  18. #include <unordered_map>
  19. #include <string>
  20. #include <vector>
  21. #include <memory>
  22. #include <map>
  23. #include <utility>
  24. #include "kernel/kernel.h"
  25. #include "ir/dtype.h"
  26. #include <nlohmann/json.hpp>
  27. #include "kernel/common_utils.h"
  28. #include "kernel/oplib/oplib.h"
  29. namespace mindspore {
  30. namespace kernel {
  31. class AkgKernelBuild {
  32. public:
  33. AkgKernelBuild() = default;
  34. ~AkgKernelBuild() = default;
  35. KernelPackPtr BuildByJson(const AnfNodePtr &anf_node, std::vector<size_t> *const input_size,
  36. std::vector<size_t> *const output_size);
  37. private:
  38. bool CreateInputDescJson(const AnfNodePtr &anf_node, nlohmann::json *const inputs_json);
  39. bool CreateOutputDescJson(const AnfNodePtr &anf_node, nlohmann::json *const outputs_json);
  40. bool CreateAttrDescJson(const AnfNodePtr &anf_node, const std::string &op_name,
  41. const std::shared_ptr<OpInfo> &op_info, nlohmann::json *const attrs_json);
  42. bool GenerateSingleKernelJson(const AnfNodePtr &anf_node, const std::string &op_name,
  43. nlohmann::json *const node_json);
  44. KernelPackPtr OpBuild(const std::string &node_json, const AnfNodePtr &anf_node);
  45. int GetOpCntInc();
  46. std::string GetProcessor(const AnfNodePtr &anf_node);
  47. static int op_cnt_;
  48. // lock for variable fusionOpCnt in singleton mode
  49. static std::mutex op_cnt_mtx_;
  50. std::string json_name_;
  51. std::string json_info_;
  52. };
  53. } // namespace kernel
  54. } // namespace mindspore
  55. #endif // MINDSPORE_CCSRC_KERNEL_AKG_AKGKERNELBUILD_H_