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 2.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "include/lite_types.h"
  24. namespace mindspore {
  25. namespace lite {
  26. class Allocator;
  27. } // namespace lite
  28. struct MS_API Context {
  29. public:
  30. static void Clear(const std::shared_ptr<Context> &context);
  31. static void SetAsDefault(const std::shared_ptr<Context> &context);
  32. static void SetVendorName(const std::shared_ptr<Context> &context, const std::string &name);
  33. static std::string GetVendorName(const std::shared_ptr<Context> &context);
  34. static void SetThreadNum(const std::shared_ptr<Context> &context, int num);
  35. static int GetThreadNum(const std::shared_ptr<Context> &context);
  36. static void SetAllocator(const std::shared_ptr<Context> &context, std::shared_ptr<lite::Allocator> alloc);
  37. static std::shared_ptr<lite::Allocator> GetAllocator(const std::shared_ptr<Context> &context);
  38. static void ConfigCPU(const std::shared_ptr<Context> &context, bool config);
  39. static bool IfCPUEnabled(const std::shared_ptr<Context> &context);
  40. static void ConfigCPUFp16(const std::shared_ptr<Context> &context, bool config);
  41. static bool IfCPUFp16Enabled(const std::shared_ptr<Context> &context);
  42. static void SetCPUBindMode(const std::shared_ptr<Context> &context, lite::CpuBindMode mode);
  43. static lite::CpuBindMode GetCPUBindMode(const std::shared_ptr<Context> &context);
  44. static void ConfigGPU(const std::shared_ptr<Context> &context, bool config);
  45. static bool IfGPUEnabled(const std::shared_ptr<Context> &context);
  46. static void ConfigGPUFp16(const std::shared_ptr<Context> &context, bool config);
  47. static bool IfGPUFp16Enabled(const std::shared_ptr<Context> &context);
  48. static void ConfigNPU(const std::shared_ptr<Context> &context, bool config);
  49. static bool IfNPUEnabled(const std::shared_ptr<Context> &context);
  50. static void SetNPUFrequency(const std::shared_ptr<Context> &context, int freq);
  51. static int GetNPUFrequency(const std::shared_ptr<Context> &context);
  52. private:
  53. std::map<std::string, std::any> context_;
  54. };
  55. } // namespace mindspore
  56. #endif // MINDSPORE_INCLUDE_API_LITE_CONTEXT_H