• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# INnrtDevice
2
3
4## 概述
5
6定义了与设备相关的接口,实现设备管理和模型编译等操作。
7
8当有多个设备注册时,需要保证设备名称和设备商名称的组合全局唯一。
9
10**起始版本:** 3.2
11
12**相关模块:**[NNRt](_n_n_rt_v10.md)
13
14
15## 汇总
16
17
18### Public 成员函数
19
20| 名称 | 描述 |
21| -------- | -------- |
22| [GetDeviceName](#getdevicename) ([out] String name) | 获取设备名称  |
23| [GetVendorName](#getvendorname) ([out] String name) | 获取设备商名称  |
24| [GetDeviceType](#getdevicetype) ([out] enum [DeviceType](_n_n_rt_v10.md#devicetype) deviceType) | 获取设备类型  |
25| [GetDeviceStatus](#getdevicestatus) ([out] enum [DeviceStatus](_n_n_rt_v10.md#devicestatus) status) | 获取设备当前状态  |
26| [GetSupportedOperation](#getsupportedoperation) ([in] struct [Model](_model_v10.md) model, [out] boolean[] ops) | 查询设备对指定模型的算子支持程度  |
27| [IsFloat16PrecisionSupported](#isfloat16precisionsupported) ([out] boolean isSupported) | 查询设备是否支持以Float16精度运算Float32的模型。  |
28| [IsPerformanceModeSupported](#isperformancemodesupported) ([out] boolean isSupported) | 查询设备是否支持性能偏好设置,性能偏好的定义可以参考[PerformanceMode](_n_n_rt_v10.md#performancemode)。  |
29| [IsPrioritySupported](#isprioritysupported) ([out] boolean isSupported) | 查询设备是否支持任务优先级设置,优先级的定义可以参考[Priority](_n_n_rt_v10.md#priority)。  |
30| [IsDynamicInputSupported](#isdynamicinputsupported) ([out] boolean isSupported) | 查询设备是否支持变尺寸输入,变尺寸输入意味着同一个模型的不同次运算输入的形状可以不一样。  |
31| [PrepareModel](#preparemodel) ([in] struct [Model](_model_v10.md) model, [in] struct [ModelConfig](_model_config_v10.md) config, [out] [IPreparedModel](interface_i_prepared_model_v10.md) preparedModel) | 编译模型  |
32| [IsModelCacheSupported](#ismodelcachesupported) ([out] boolean isSupported) | 查询是否支持模型缓存功能  |
33| [PrepareModelFromModelCache](#preparemodelfrommodelcache) ([in] struct [SharedBuffer](_shared_buffer_v10.md)[] modelCache, [in] struct [ModelConfig](_model_config_v10.md) config, [out] [IPreparedModel](interface_i_prepared_model_v10.md) preparedModel) | 加载模型缓存,该模型缓存是通过ExportModelCache接口导出的。  |
34| [AllocateBuffer](#allocatebuffer) ([in] unsigned int length, [out] struct [SharedBuffer](_shared_buffer_v10.md) buffer) | 申请设备共享内存,以文件描述符的形式返回,共享内存主要用于推理输入输出数据的快速传递。  |
35| [ReleaseBuffer](#releasebuffer) ([in] struct [SharedBuffer](_shared_buffer_v10.md) buffer) | 释放共享内存。  |
36
37
38## 成员函数说明
39
40
41### AllocateBuffer()
42
43```
44INnrtDevice::AllocateBuffer ([in] unsigned int length, [out] struct SharedBuffer buffer )
45```
46**描述**
47申请设备共享内存,以文件描述符的形式返回,共享内存主要用于推理输入输出数据的快速传递。
48
49**起始版本:** 3.2
50
51**参数:**
52
53| 名称 | 描述 |
54| -------- | -------- |
55| length | 申请共享内存的大小,单位是字节。  |
56| buffer | 共享内存的信息,包含共享内存的文件描述符和空间大小,SharedBuffer定义请查看[SharedBuffer](_shared_buffer_v10.md)。 |
57
58**返回:**
59
60返回0表示成功
61
62返回负数表示失败
63
64
65### GetDeviceName()
66
67```
68INnrtDevice::GetDeviceName ([out] String name)
69```
70**描述**
71获取设备名称
72
73**起始版本:** 3.2
74
75**参数:**
76
77| 名称 | 描述 |
78| -------- | -------- |
79| name | 设备名称 |
80
81**返回:**
82
83返回0表示成功
84
85返回负数表示失败
86
87
88### GetDeviceStatus()
89
90```
91INnrtDevice::GetDeviceStatus ([out] enum DeviceStatus status)
92```
93**描述**
94获取设备当前状态
95
96**起始版本:** 3.2
97
98**参数:**
99
100| 名称 | 描述 |
101| -------- | -------- |
102| status | 设备当前状态,DeviceStatus枚举定义了可选的设备状态,详细定义请查看[DeviceStatus](_n_n_rt_v10.md#devicestatus)。 |
103
104**返回:**
105
106返回0表示成功
107
108返回负数表示失败
109
110
111### GetDeviceType()
112
113```
114INnrtDevice::GetDeviceType ([out] enum DeviceType deviceType)
115```
116**描述**
117获取设备类型
118
119**起始版本:** 3.2
120
121**参数:**
122
123| 名称 | 描述 |
124| -------- | -------- |
125| deviceType | 设备类型,DeviceType枚举定义了可选的设备类型,详细定义请查看[DeviceType](_n_n_rt_v10.md#devicetype)。 |
126
127**返回:**
128
129返回0表示成功
130
131返回负数表示失败
132
133
134### GetSupportedOperation()
135
136```
137INnrtDevice::GetSupportedOperation ([in] struct Model model, [out] boolean[] ops )
138```
139**描述**
140查询设备对指定模型的算子支持程度
141
142**起始版本:** 3.2
143
144**参数:**
145
146| 名称 | 描述 |
147| -------- | -------- |
148| model | AI模型,模型结构由Model定义,详细定义请查看[Model](_model_v10.md)。  |
149| ops | 算子是否支持列表,算子支持列表的顺序与在model中的顺序要一致。 |
150
151**返回:**
152
153返回0表示成功
154
155返回负数表示失败
156
157
158### GetVendorName()
159
160```
161INnrtDevice::GetVendorName ([out] String name)
162```
163**描述**
164获取设备商名称
165
166**起始版本:** 3.2
167
168**参数:**
169
170| 名称 | 描述 |
171| -------- | -------- |
172| name | 设备商名称 |
173
174**返回:**
175
176返回0表示成功
177
178返回负数表示失败
179
180
181### IsDynamicInputSupported()
182
183```
184INnrtDevice::IsDynamicInputSupported ([out] boolean isSupported)
185```
186**描述**
187查询设备是否支持变尺寸输入,变尺寸输入意味着同一个模型的不同次运算输入的形状可以不一样。
188
189如果支持变尺寸输入,模型输入Tensor的形状上用-1标记该维度是否可变。
190
191**起始版本:** 3.2
192
193**参数:**
194
195| 名称 | 描述 |
196| -------- | -------- |
197| isSupported | 是否支持变尺寸输入。 |
198
199**返回:**
200
201返回0表示成功
202
203返回负数表示失败
204
205
206### IsFloat16PrecisionSupported()
207
208```
209INnrtDevice::IsFloat16PrecisionSupported ([out] boolean isSupported)
210```
211**描述**
212查询设备是否支持以Float16精度运算Float32的模型。
213
214**起始版本:** 3.2
215
216**参数:**
217
218| 名称 | 描述 |
219| -------- | -------- |
220| isSupported | 是否支持Float16精度。 |
221
222**返回:**
223
224返回0表示成功
225
226返回负数表示失败
227
228
229### IsModelCacheSupported()
230
231```
232INnrtDevice::IsModelCacheSupported ([out] boolean isSupported)
233```
234**描述**
235查询是否支持模型缓存功能
236
237若支持,则需要实现PrepareModelFromModelCache和ExportModelCache两个接口。
238
239**起始版本:** 3.2
240
241**参数:**
242
243| 名称 | 描述 |
244| -------- | -------- |
245| isSupported | 是否支持模型缓存。 |
246
247**返回:**
248
249返回0表示成功
250
251返回负数表示失败
252
253
254### IsPerformanceModeSupported()
255
256```
257INnrtDevice::IsPerformanceModeSupported ([out] boolean isSupported)
258```
259**描述**
260查询设备是否支持性能偏好设置,性能偏好的定义可以参考[PerformanceMode](_n_n_rt_v10.md#performancemode)。
261
262**起始版本:** 3.2
263
264**参数:**
265
266| 名称 | 描述 |
267| -------- | -------- |
268| isSupported | 是否支持性能偏好设置。 |
269
270**返回:**
271
272返回0表示成功
273
274返回负数表示失败
275
276
277### IsPrioritySupported()
278
279```
280INnrtDevice::IsPrioritySupported ([out] boolean isSupported)
281```
282**描述**
283查询设备是否支持任务优先级设置,优先级的定义可以参考[Priority](_n_n_rt_v10.md#priority)。
284
285**起始版本:** 3.2
286
287**参数:**
288
289| 名称 | 描述 |
290| -------- | -------- |
291| isSupported | 是否支持性能偏好设置。 |
292
293**返回:**
294
295返回0表示成功
296
297返回负数表示失败
298
299
300### PrepareModel()
301
302```
303INnrtDevice::PrepareModel ([in] struct Model model, [in] struct ModelConfig config, [out] IPreparedModel preparedModel )
304```
305**描述**
306编译模型
307
308如果是变尺寸输入模型,则模型输入的维度信息中至少有一个是-1。
309
310**起始版本:** 3.2
311
312**参数:**
313
314| 名称 | 描述 |
315| -------- | -------- |
316| model | 需要编译的模型,Model定义请查看[Model](_model_v10.md)。  |
317| config | 编译模型的配置,ModelConfig定义请查看[ModelConfig](_model_config_v10.md)。  |
318| preparedModel | 编译好的模型对象,用于后续的运算,IPreparedModel定义请查看[IPreparedModel](interface_i_prepared_model_v10.md)。 |
319
320**返回:**
321
322返回0表示成功
323
324返回负数表示失败
325
326
327### PrepareModelFromModelCache()
328
329```
330INnrtDevice::PrepareModelFromModelCache ([in] struct SharedBuffer[] modelCache, [in] struct ModelConfig config, [out] IPreparedModel preparedModel )
331```
332**描述**
333加载模型缓存,该模型缓存是通过ExportModelCache接口导出的。
334
335**起始版本:** 3.2
336
337**参数:**
338
339| 名称 | 描述 |
340| -------- | -------- |
341| modelCache | 模型缓存文件的数组,数组顺序与导出时的数组顺序一致,数组元素类型请查看SharedBuffer定义[SharedBuffer](_shared_buffer_v10.md)。  |
342| config | 加载模型缓存的配置,配置参数的详细定义请参考[ModelConfig](_model_config_v10.md)。  |
343| preparedModel | 加载缓存得到的模型对象,用于后续的运算,IPreparedModel定义请查看[IPreparedModel](interface_i_prepared_model_v10.md)。 |
344
345**返回:**
346
347返回0表示成功
348
349返回负数表示失败
350
351
352### ReleaseBuffer()
353
354```
355INnrtDevice::ReleaseBuffer ([in] struct SharedBuffer buffer)
356```
357**描述**
358释放共享内存。
359
360**起始版本:** 3.2
361
362**参数:**
363
364| 名称 | 描述 |
365| -------- | -------- |
366| buffer | 共享内存的信息,包含共享内存的文件描述符和空间大小,SharedBuffer定义请查看[SharedBuffer](_shared_buffer_v10.md)。 |
367
368**返回:**
369
370返回0表示成功
371
372返回负数表示失败
373