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.

tbe_utils.h 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_TBE_TBE_UTILS_H_
  17. #define MINDSPORE_CCSRC_KERNEL_TBE_TBE_UTILS_H_
  18. #include <string>
  19. #include <memory>
  20. #include <vector>
  21. #include <utility>
  22. #include <map>
  23. #include <unordered_map>
  24. #include "session/kernel_graph.h"
  25. #include "ir/anf.h"
  26. #include "kernel/kernel.h"
  27. namespace mindspore {
  28. namespace kernel {
  29. namespace tbe {
  30. using std::string;
  31. using std::vector;
  32. class TbeUtils {
  33. public:
  34. TbeUtils() = default;
  35. ~TbeUtils() = default;
  36. static void SaveJsonInfo(const std::string &json_name, const std::string &info);
  37. static void LoadCache();
  38. static KernelPackPtr SearchCache(const std::string &kernel_name, const std::string &processor);
  39. static KernelPackPtr InsertCache(const std::string &kernel_name, const std::string &processor);
  40. };
  41. struct KernelMetaInfo {
  42. uintptr_t func_stub_;
  43. uint32_t block_dim_;
  44. };
  45. using KernelMetaPtr = std::shared_ptr<KernelMetaInfo>;
  46. class KernelManager {
  47. public:
  48. static uintptr_t GenFuncStub(const KernelPack &kernel_pack, bool force_reload, uint32_t *block_dim);
  49. static std::string GetStubFuncName(const KernelPackPtr &kernel_pack);
  50. private:
  51. KernelManager() = default;
  52. ~KernelManager() = default;
  53. static int BinaryRegister(const FlexArray &kernel_buffer, void **module, const string &magic);
  54. static std::unordered_map<string, KernelMetaPtr> info_table_;
  55. static uintptr_t kernel_stub_gen_;
  56. };
  57. class KernelMeta {
  58. public:
  59. static KernelMeta *GetInstance();
  60. bool ReadIndex(const std::string &bin_dir);
  61. KernelPackPtr GetKernelPack(const std::string &kernel_name, const std::string &processor);
  62. private:
  63. KernelMeta() = default;
  64. ~KernelMeta() = default;
  65. std::unordered_map<std::string, std::string> kernel_index_map_{};
  66. std::unordered_map<std::string, KernelPackPtr> kernel_pack_map_{};
  67. };
  68. } // namespace tbe
  69. } // namespace kernel
  70. } // namespace mindspore
  71. #endif // MINDSPORE_CCSRC_KERNEL_TBE_TBE_UTILS_H_