• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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 
17 #ifndef MINDSPORE_LITE_SRC_INNER_CONTEXT_H
18 #define MINDSPORE_LITE_SRC_INNER_CONTEXT_H
19 #include <set>
20 #include <string>
21 #include "include/context.h"
22 #include "src/runtime/inner_allocator.h"
23 #include "thread/threadpool.h"
24 #ifdef ENABLE_ARM
25 #include "src/cpu_info.h"
26 #endif
27 
28 namespace mindspore::lite {
29 struct InnerContext : public Context {
30  public:
InnerContextInnerContext31   InnerContext() { InitDeviceFp16(); }
32 
33   explicit InnerContext(const Context *context);
34 
35   int Init();
36 
37   bool IsCpuFloat16Enabled() const;
38 
39   bool IsGpuFloat16Enabled() const;
40 
41   bool IsCpuEnabled() const;
42 
43   const CpuDeviceInfo *GetCpuDeviceInfo() const;
44 
45   bool IsGpuEnabled() const;
46 
47   bool IsNpuEnabled() const;
48 
49   bool IsNNRtEnabled() const;
50 
51   bool IsProviderEnabled() const;
52 
53   std::set<std::string> GetProviders() const;
54 
55   CpuDeviceInfo GetCpuInfo() const;
56 
57   GpuDeviceInfo GetGpuInfo() const;
58 
59   NpuDeviceInfo GetNpuInfo() const;
60 
61   int IsValid() const;
62 
63   ThreadPool *thread_pool() const;
64 
65   virtual ~InnerContext();
66 
67   bool device_and_pkg_support_fp16() const;
68 
69  private:
70   bool IsAllDeviceTypeValid() const;
71 
72   bool IsCpuBindModeInvalid() const;
73 
74   bool IsUserSetCpu() const;
75 
76   bool IsUserSetGpu() const;
77 
78   bool IsUserSetNpu() const;
79 
80   bool IsUserSetNNRt() const;
81 
82   void SetContextDevice(const Context *context);
83 
84   void InitDeviceFp16();
85 
86   bool device_and_pkg_support_fp16_ = false;
87 
88   ThreadPool *thread_pool_{nullptr};
89 };
90 
91 int ParallelLaunch(const Context *context, const Func &func, Content content, int task_num);
92 }  // namespace mindspore::lite
93 
94 #endif  // MINDSPORE_LITE_SRC_INNER_CONTEXT_H
95