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