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