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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 = "/tmp/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. bool ReadIndex(const std::string &bin_dir);
  49. std::string Search(const std::string &kernel_name) const;
  50. bool Insert(const std::string &kernel_name, const std::string &cce_json);
  51. static KernelMeta *GetInstance() {
  52. static KernelMeta kernel_meta;
  53. return &kernel_meta;
  54. }
  55. ~KernelMeta() = default;
  56. private:
  57. bool initialized_ = false;
  58. std::unordered_map<std::string, std::string> kernel_meta_map_;
  59. };
  60. bool CheckCache(const std::string &kernel_name);
  61. KernelPackPtr SearchCache(const std::string &kernel_name, const std::string &processor);
  62. KernelPackPtr InsertCache(const std::string &kernel_name, const std::string &processor);
  63. TypeId DtypeToTypeId(const std::string &dtypes);
  64. std::string Dtype2String(const std::string &dtypes);
  65. std::string Dtype2ShortType(const std::string &dtypes);
  66. std::string TypeId2String(TypeId type_id);
  67. size_t GetDtypeNbyte(const std::string &dtypes);
  68. bool ParseMetadata(const CNodePtr &kernel_node, const std::shared_ptr<const OpInfo> &op_info_ptr, Processor processor,
  69. std::vector<std::shared_ptr<KernelBuildInfo>> *const kernel_info_list);
  70. bool IsAtomicNode(const CNodePtr &kernel_node);
  71. void SaveJsonInfo(const std::string &json_name, const std::string &info);
  72. std::string GetProcessor(const AnfNodePtr &anf_node);
  73. } // namespace kernel
  74. } // namespace mindspore
  75. #endif // MINDSPORE_CCSRC_KERNEL_COMMON_UTILS_H_