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.

common_utils.h 3.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_COMMON_UTILS_H_
  17. #define MINDSPORE_CCSRC_KERNEL_COMMON_UTILS_H_
  18. #include <dirent.h>
  19. #include <memory>
  20. #include <unordered_map>
  21. #include <map>
  22. #include <string>
  23. #include <vector>
  24. #include "kernel/kernel.h"
  25. #include "kernel/oplib/opinfo.h"
  26. #include "kernel/kernel_build_info.h"
  27. namespace mindspore {
  28. namespace kernel {
  29. constexpr auto kCceKernelMeta = "./kernel_meta/";
  30. constexpr auto kGpuKernelMeta = "./cuda_meta";
  31. constexpr auto kProcessorAiCore = "aicore";
  32. constexpr auto kProcessorAiCpu = "aicpu";
  33. constexpr auto kProcessorCuda = "cuda";
  34. constexpr auto kJsonSuffix = ".json";
  35. constexpr auto kInfoSuffix = ".info";
  36. constexpr unsigned int AUTODIFF_COMPILE_OVERTIME = 600;
  37. constexpr auto kAkgModule = "_akg";
  38. constexpr auto kArgDataformat = "data_format";
  39. const std::vector<std::string> support_devices = {"aicore", "aicpu", "cuda"};
  40. struct KernelMetaInfo {
  41. uintptr_t func_stub_;
  42. uint32_t block_dim_;
  43. };
  44. using KernelMetaPtr = std::shared_ptr<KernelMetaInfo>;
  45. class KernelMeta {
  46. public:
  47. KernelMeta() = default;
  48. void Initialize();
  49. void RemoveKernelCache();
  50. std::string Search(const std::string &kernel_name) const;
  51. bool Insert(const std::string &kernel_name, const std::string &kernel_json);
  52. std::string GetKernelMetaPath() { return kernel_meta_path_; }
  53. static KernelMeta *GetInstance() {
  54. static KernelMeta kernel_meta;
  55. return &kernel_meta;
  56. }
  57. ~KernelMeta() = default;
  58. private:
  59. bool initialized_ = false;
  60. std::string kernel_meta_path_;
  61. std::unordered_map<std::string, std::string> kernel_meta_map_;
  62. };
  63. bool CheckCache(const std::string &kernel_name);
  64. KernelPackPtr SearchCache(const std::string &kernel_name, const std::string &processor);
  65. KernelPackPtr InsertCache(const std::string &kernel_name, const std::string &processor);
  66. TypeId DtypeToTypeId(const std::string &dtypes);
  67. std::string Dtype2String(const std::string &dtypes);
  68. std::string Dtype2ShortType(const std::string &dtypes);
  69. std::string TypeId2String(TypeId type_id);
  70. size_t GetDtypeNbyte(const std::string &dtypes);
  71. bool ParseMetadata(const CNodePtr &kernel_node, const std::shared_ptr<const OpInfo> &op_info_ptr, Processor processor,
  72. std::vector<std::shared_ptr<KernelBuildInfo>> *const kernel_info_list);
  73. bool IsAtomicNode(const CNodePtr &kernel_node);
  74. void SaveJsonInfo(const std::string &json_name, const std::string &info);
  75. std::string GetProcessor(const AnfNodePtr &anf_node);
  76. } // namespace kernel
  77. } // namespace mindspore
  78. #endif // MINDSPORE_CCSRC_KERNEL_COMMON_UTILS_H_