1c5e268c6Sopenharmony_ci/*
2c5e268c6Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3c5e268c6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c5e268c6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c5e268c6Sopenharmony_ci * You may obtain a copy of the License at
6c5e268c6Sopenharmony_ci *
7c5e268c6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c5e268c6Sopenharmony_ci *
9c5e268c6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c5e268c6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c5e268c6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c5e268c6Sopenharmony_ci * See the License for the specific language governing permissions and
13c5e268c6Sopenharmony_ci * limitations under the License.
14c5e268c6Sopenharmony_ci */
15c5e268c6Sopenharmony_ci
16c5e268c6Sopenharmony_ci/**
17c5e268c6Sopenharmony_ci * @addtogroup NNRt
18c5e268c6Sopenharmony_ci * @{
19c5e268c6Sopenharmony_ci *
20c5e268c6Sopenharmony_ci * @brief Provides a unified interface for AI chip drivers to access OpenHarmony. 
21c5e268c6Sopenharmony_ci * Neural Network Runtime (NNRt) is a cross-chip inference computing runtime environment oriented to the AI field.
22c5e268c6Sopenharmony_ci * It serves as a bridge between the upper-layer AI inference framework and the underlying acceleration chip to implement cross-chip inference computing of AI models.
23c5e268c6Sopenharmony_ci * @since 3.2
24c5e268c6Sopenharmony_ci * @version 1.0
25c5e268c6Sopenharmony_ci */
26c5e268c6Sopenharmony_ci
27c5e268c6Sopenharmony_ci/**
28c5e268c6Sopenharmony_ci * @file INnrtDevice.idl
29c5e268c6Sopenharmony_ci *
30c5e268c6Sopenharmony_ci * @brief Defines methods related to chip devices.
31c5e268c6Sopenharmony_ci *
32c5e268c6Sopenharmony_ci * You can use the methods to query chip device information and build AI models.
33c5e268c6Sopenharmony_ci *
34c5e268c6Sopenharmony_ci * @since 3.2
35c5e268c6Sopenharmony_ci * @version 1.0
36c5e268c6Sopenharmony_ci */
37c5e268c6Sopenharmony_ci
38c5e268c6Sopenharmony_ci/**
39c5e268c6Sopenharmony_ci * @brief Defines the package path of the NNRt module.
40c5e268c6Sopenharmony_ci *
41c5e268c6Sopenharmony_ci * @since 3.2
42c5e268c6Sopenharmony_ci * @version 1.0
43c5e268c6Sopenharmony_ci */
44c5e268c6Sopenharmony_cipackage ohos.hdi.nnrt.v1_0;
45c5e268c6Sopenharmony_ci
46c5e268c6Sopenharmony_ciimport ohos.hdi.nnrt.v1_0.NnrtTypes;
47c5e268c6Sopenharmony_ciimport ohos.hdi.nnrt.v1_0.ModelTypes;
48c5e268c6Sopenharmony_ciimport ohos.hdi.nnrt.v1_0.IPreparedModel;
49c5e268c6Sopenharmony_ci
50c5e268c6Sopenharmony_ci/**
51c5e268c6Sopenharmony_ci * @brief Provides methods for device management and model building.
52c5e268c6Sopenharmony_ci *
53c5e268c6Sopenharmony_ci * When multiple devices are registered, ensure that the combination of the device name and vendor name is globally unique.
54c5e268c6Sopenharmony_ci *
55c5e268c6Sopenharmony_ci * @since 3.2
56c5e268c6Sopenharmony_ci * @version 1.0
57c5e268c6Sopenharmony_ci */
58c5e268c6Sopenharmony_ciinterface INnrtDevice {
59c5e268c6Sopenharmony_ci    /**
60c5e268c6Sopenharmony_ci     * @brief Obtains the device name.
61c5e268c6Sopenharmony_ci     *
62c5e268c6Sopenharmony_ci     * @param name Indicates the device name obtained.
63c5e268c6Sopenharmony_ci     *
64c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
65c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
66c5e268c6Sopenharmony_ci     */
67c5e268c6Sopenharmony_ci    GetDeviceName([out] String name);
68c5e268c6Sopenharmony_ci
69c5e268c6Sopenharmony_ci    /**
70c5e268c6Sopenharmony_ci     * @brief Obtains the device vendor name.
71c5e268c6Sopenharmony_ci     *
72c5e268c6Sopenharmony_ci     * @param name Indicates the device vendor name obtained.
73c5e268c6Sopenharmony_ci     *
74c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
75c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
76c5e268c6Sopenharmony_ci     */
77c5e268c6Sopenharmony_ci    GetVendorName([out] String name);
78c5e268c6Sopenharmony_ci
79c5e268c6Sopenharmony_ci    /**
80c5e268c6Sopenharmony_ci     * @brief Obtains the device type.
81c5e268c6Sopenharmony_ci     *
82c5e268c6Sopenharmony_ci     * @param deviceType Indicates the device type obtained. For details, see {@link DeviceType}.
83c5e268c6Sopenharmony_ci     *
84c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
85c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
86c5e268c6Sopenharmony_ci     */
87c5e268c6Sopenharmony_ci    GetDeviceType([out] enum DeviceType deviceType);
88c5e268c6Sopenharmony_ci
89c5e268c6Sopenharmony_ci    /**
90c5e268c6Sopenharmony_ci      * @brief Obtains the device status.
91c5e268c6Sopenharmony_ci     *
92c5e268c6Sopenharmony_ci     * @param deviceType Indicates the device status obtained. For details, see {@link DeviceStatus}.
93c5e268c6Sopenharmony_ci     *
94c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
95c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
96c5e268c6Sopenharmony_ci     */
97c5e268c6Sopenharmony_ci    GetDeviceStatus([out] enum DeviceStatus status);
98c5e268c6Sopenharmony_ci
99c5e268c6Sopenharmony_ci    /**
100c5e268c6Sopenharmony_ci     * @brief Obtains the device's support for the operators of the specified AI model.
101c5e268c6Sopenharmony_ci     *
102c5e268c6Sopenharmony_ci     * @param model Indicates the AI model. For details, see {@link Model}.
103c5e268c6Sopenharmony_ci     * @param ops Indicates the operators supported and not supported by the device. The operators are listed in the same sequence as they listed in the API model.
104c5e268c6Sopenharmony_ci     *
105c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
106c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
107c5e268c6Sopenharmony_ci     */
108c5e268c6Sopenharmony_ci    GetSupportedOperation([in] struct Model model, [out] boolean[] ops);
109c5e268c6Sopenharmony_ci
110c5e268c6Sopenharmony_ci    /**
111c5e268c6Sopenharmony_ci     * @brief Checks whether the device supports the Float32 model with the Float16 precision.
112c5e268c6Sopenharmony_ci     *
113c5e268c6Sopenharmony_ci     * @param isSupported Indicates whether the Float16 precision is supported.
114c5e268c6Sopenharmony_ci     *
115c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
116c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
117c5e268c6Sopenharmony_ci     */
118c5e268c6Sopenharmony_ci    IsFloat16PrecisionSupported([out] boolean isSupported);
119c5e268c6Sopenharmony_ci
120c5e268c6Sopenharmony_ci    /**
121c5e268c6Sopenharmony_ci     * @brief Checks whether the device supports performance preference settings. For details about the performance preference, see {@link PerformanceMode}.
122c5e268c6Sopenharmony_ci     *
123c5e268c6Sopenharmony_ci     * @param isSupported Indicates whether the device supports performance preference settings.
124c5e268c6Sopenharmony_ci     *
125c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
126c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
127c5e268c6Sopenharmony_ci     */
128c5e268c6Sopenharmony_ci    IsPerformanceModeSupported([out] boolean isSupported);
129c5e268c6Sopenharmony_ci
130c5e268c6Sopenharmony_ci    /**
131c5e268c6Sopenharmony_ci     * @brief Checks whether the device supports task priority settings. For details about the priority, see {@link Priority}.
132c5e268c6Sopenharmony_ci     *
133c5e268c6Sopenharmony_ci     * @param isSupported Indicates whether the device supports task priority settings.
134c5e268c6Sopenharmony_ci     *
135c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
136c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
137c5e268c6Sopenharmony_ci     */
138c5e268c6Sopenharmony_ci    IsPrioritySupported([out] boolean isSupported);
139c5e268c6Sopenharmony_ci
140c5e268c6Sopenharmony_ci    /**
141c5e268c6Sopenharmony_ci     * @brief Checks whether the device supports dynamic input, which allows a model of different shapes to be used for different operations.
142c5e268c6Sopenharmony_ci     *
143c5e268c6Sopenharmony_ci     * If dynamic input is supported, <b>-1</b> is added in the shape of the input tensor.
144c5e268c6Sopenharmony_ci     *
145c5e268c6Sopenharmony_ci     * @param isSupported Indicates whether dynamic input is supported.
146c5e268c6Sopenharmony_ci     *
147c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
148c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
149c5e268c6Sopenharmony_ci     */
150c5e268c6Sopenharmony_ci    IsDynamicInputSupported([out] boolean isSupported);
151c5e268c6Sopenharmony_ci
152c5e268c6Sopenharmony_ci    /**
153c5e268c6Sopenharmony_ci     * @brief Builds a model.
154c5e268c6Sopenharmony_ci     *
155c5e268c6Sopenharmony_ci     * If the AI model supports dynamic input, at least one dimension of the input tensor contains <b>-1</b>.
156c5e268c6Sopenharmony_ci     *
157c5e268c6Sopenharmony_ci     * @param model indicates the module to build. For details, see {@link Model}.
158c5e268c6Sopenharmony_ci     * @param config Indicates the module configuration. For details, see {@link ModelConfig}.
159c5e268c6Sopenharmony_ci     * @param preparedModel Indicates the model object built. For details, see {@link IPreparedModel}.
160c5e268c6Sopenharmony_ci     *
161c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
162c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
163c5e268c6Sopenharmony_ci     */
164c5e268c6Sopenharmony_ci    PrepareModel([in] struct Model model, [in] struct ModelConfig config, [out] IPreparedModel preparedModel);
165c5e268c6Sopenharmony_ci
166c5e268c6Sopenharmony_ci    /**
167c5e268c6Sopenharmony_ci     * @brief Checks whether the device supports caching of the AI models built.
168c5e268c6Sopenharmony_ci     *
169c5e268c6Sopenharmony_ci     * If yes, <b>PrepareModelFromModelCache()</b> and <b>ExportModelCache()</b> need to be implemented.
170c5e268c6Sopenharmony_ci     *
171c5e268c6Sopenharmony_ci     * @param isSupported Indicates whether the device supports caching of the AI models built.
172c5e268c6Sopenharmony_ci     *
173c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
174c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
175c5e268c6Sopenharmony_ci     */
176c5e268c6Sopenharmony_ci    IsModelCacheSupported([out] boolean isSupported);
177c5e268c6Sopenharmony_ci
178c5e268c6Sopenharmony_ci    /**
179c5e268c6Sopenharmony_ci     * @brief Loads an AI model from the cache. The AI model is exported by using <b>ExportModelCache()</b>.
180c5e268c6Sopenharmony_ci     *
181c5e268c6Sopenharmony_ci     * @param modelCache Indicates an array of the model files, which are in the same sequence as they exported. For details, see {@link SharedBuffer}.
182c5e268c6Sopenharmony_ci     * @param config Indicates the configuration for loading the model. For details, see {@link ModelConfig}.
183c5e268c6Sopenharmony_ci     * @param preparedModel Indicates the model object obtained. For details, see {@link IPreparedModel}.
184c5e268c6Sopenharmony_ci     *
185c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
186c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
187c5e268c6Sopenharmony_ci     */
188c5e268c6Sopenharmony_ci    PrepareModelFromModelCache([in] struct SharedBuffer[] modelCache, [in] struct ModelConfig config,
189c5e268c6Sopenharmony_ci                               [out] IPreparedModel preparedModel);
190c5e268c6Sopenharmony_ci
191c5e268c6Sopenharmony_ci    /**
192c5e268c6Sopenharmony_ci     * @brief Allocates the shared memory for the device. The shared memory allows quick access to the input and output data for AI inference.
193c5e268c6Sopenharmony_ci     *
194c5e268c6Sopenharmony_ci     * @param length Indicates the shared memory to allocate, in bytes.
195c5e268c6Sopenharmony_ci     * @param buffer Indicates the information about the shared memory allocated, including the file descriptor and size of the shared memory. For details, see {@link SharedBuffer}.
196c5e268c6Sopenharmony_ci     *
197c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
198c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
199c5e268c6Sopenharmony_ci     */
200c5e268c6Sopenharmony_ci    AllocateBuffer([in] unsigned int length, [out] struct SharedBuffer buffer);
201c5e268c6Sopenharmony_ci
202c5e268c6Sopenharmony_ci    /**
203c5e268c6Sopenharmony_ci      * @brief Releases the shared memory.
204c5e268c6Sopenharmony_ci     *
205c5e268c6Sopenharmony_ci     * @param buffer Indicates the shared memory to release. For details, see {@link SharedBuffer}.
206c5e268c6Sopenharmony_ci     *
207c5e268c6Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
208c5e268c6Sopenharmony_ci     * @return Returns a negative number if the operation fails.
209c5e268c6Sopenharmony_ci     */
210c5e268c6Sopenharmony_ci    ReleaseBuffer([in] struct SharedBuffer buffer);
211c5e268c6Sopenharmony_ci}
212c5e268c6Sopenharmony_ci
213c5e268c6Sopenharmony_ci/** @} */
214