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.

lite_context.h 3.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright 2021 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_INCLUDE_API_LITE_CONTEXT_H
  17. #define MINDSPORE_INCLUDE_API_LITE_CONTEXT_H
  18. #include <string>
  19. #include <memory>
  20. #include <map>
  21. #include <any>
  22. #include "include/api/types.h"
  23. namespace mindspore {
  24. namespace lite {
  25. /// \brief CpuBindMode defined for holding bind cpu strategy argument.
  26. typedef enum : uint32_t {
  27. NO_BIND = 0, /**< no bind */
  28. HIGHER_CPU = 1, /**< bind higher cpu first */
  29. MID_CPU = 2 /**< bind middle cpu first */
  30. } CpuBindMode;
  31. class Allocator;
  32. } // namespace lite
  33. struct MS_API Context {
  34. public:
  35. static void Clear(const std::shared_ptr<Context> &contxet);
  36. static void SetAsDefault(const std::shared_ptr<Context> &contxet);
  37. static void SetVendorName(const std::shared_ptr<Context> &contxet, const std::string &name);
  38. static std::string GetVendorName(const std::shared_ptr<Context> &contxet);
  39. static void SetThreadNum(const std::shared_ptr<Context> &contxet, int num);
  40. static int GetThreadNum(const std::shared_ptr<Context> &contxet);
  41. static void SetAllocator(const std::shared_ptr<Context> &contxet, std::shared_ptr<lite::Allocator> alloc);
  42. static std::shared_ptr<lite::Allocator> GetAllocator(const std::shared_ptr<Context> &contxet);
  43. static void ConfigCPU(const std::shared_ptr<Context> &contxet, bool config);
  44. static bool IfCPUEnabled(const std::shared_ptr<Context> &contxet);
  45. static void ConfigCPUFp16(const std::shared_ptr<Context> &contxet, bool config);
  46. static bool IfCPUFp16Enabled(const std::shared_ptr<Context> &contxet);
  47. static void SetCPUBindMode(const std::shared_ptr<Context> &contxet, lite::CpuBindMode mode);
  48. static lite::CpuBindMode GetCPUBindMode(const std::shared_ptr<Context> &contxet);
  49. static void ConfigGPU(const std::shared_ptr<Context> &contxet, bool config);
  50. static bool IfGPUEnabled(const std::shared_ptr<Context> &contxet);
  51. static void ConfigGPUFp16(const std::shared_ptr<Context> &contxet, bool config);
  52. static bool IfGPUFp16Enabled(const std::shared_ptr<Context> &contxet);
  53. static void ConfigNPU(const std::shared_ptr<Context> &contxet, bool config);
  54. static bool IfNPUEnabled(const std::shared_ptr<Context> &contxet);
  55. static void SetNPUFrequency(const std::shared_ptr<Context> &contxet, int freq);
  56. static int GetNPUFrequency(const std::shared_ptr<Context> &contxet);
  57. private:
  58. std::map<std::string, std::any> context_;
  59. };
  60. } // namespace mindspore
  61. #endif // MINDSPORE_INCLUDE_API_LITE_CONTEXT_H