1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @addtogroup NNRt 18 * @{ 19 * 20 * @brief Provides a unified interface for AI chip drivers to access OpenHarmony.\n 21 * Neural Network Runtime (NNRt) is a cross-chip inference computing runtime environment oriented to the AI field. 22 * 23 * @since 3.2 24 * @version 2.1 25 */ 26 27/** 28 * @file IPreparedModel.idl 29 * 30 * @brief Defines the APIs for AI model inference, obtaining the input tensor dimension range,\n 31 * and exporting the AI model built. 32 * 33 * @since 3.2 34 * @version 2.1 35 */ 36 37/** 38 * @brief Defines the package path of the NNRt module. 39 * 40 * @since 3.2 41 * @version 2.1 42 */ 43package ohos.hdi.nnrt.v2_1; 44 45import ohos.hdi.nnrt.v2_1.NnrtTypes; 46 47/** 48 * @brief Provides the APIs for exporting AI models and performing AI model inference. 49 * 50 * @since 3.2 51 * @version 2.1 52 */ 53interface IPreparedModel { 54 /** 55 * @brief Exports an AI model from the cache. 56 * 57 * @param modelCache Array of the model files, which are in the same sequence as they exported.\n 58 * For details, see {@link SharedBuffer}. 59 * 60 * @return Returns <b>0</b> if the operation is successful. 61 * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 62 * and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 63 */ 64 ExportModelCache([out] struct SharedBuffer[] modelCache); 65 66 /** 67 * @brief Obtains the tensor dimension range supported by AI model. If a fixed dimension is used,\n 68 * the maximum dimension value is the same as the minimum dimension value. 69 * 70 * @param minInputDims Two-dimensional array that stores the minimum dimension of the model input data.\n 71 * The first dimension of the array indicates the number of tensors, and the second dimension indicates\n 72 * the number of dimensions of the tensors. 73 * @param maxInputDims Two-dimensional array that stores the maximum dimension of the model input data.\n 74 * The first dimension of the array indicates the number of tensors, and the second dimension indicates\n 75 * the number of dimensions of the tensors. 76 * 77 * @return Returns <b>0</b> if the operation is successful. 78 * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 79 * and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 80 */ 81 GetInputDimRanges([out] unsigned int[][] minInputDims, [out] unsigned int[][] maxInputDims); 82 83 /** 84 * @brief Performs AI model inference. 85 * 86 * @param inputs Input data for AI model inference. The data is input in the sequence defined by the model.\n 87 * For details about the input data type, see {@link IOTensor}. 88 * @param outputs Output data of AI model inference. After inference, the output data is written to the\n 89 * shared buffer. For details about the output data type, see {@link IOTensor}. 90 * @param outputDims Dimensions of the output data. The output sequence is the same as that of <b>outputs</b>. 91 * @param isOutputBufferEnough Whether the shared buffer space is sufficient for the output data.\n 92 * The value <b>true</b> means the shared buffer space is sufficient; the value <b>false</b> means the opposite. 93 * 94 * @return Returns <b>0</b> if the operation is successful. 95 * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 96 * and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 97 */ 98 Run([in] struct IOTensor[] inputs, [in] struct IOTensor[] outputs, [out] int[][] outputDims); 99} 100 101/** @} */ 102