1/* 2 * Copyright (c) 2023 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.0 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.0 35 */ 36 37/** 38 * @brief Defines the package path of the NNRt module. 39 * 40 * @since 3.2 41 * @version 2.0 42 */ 43package ohos.hdi.nnrt.v2_0; 44 45import ohos.hdi.nnrt.v2_0.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.0 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 the number of dimensions of the tensors. 72 * @param maxInputDims Two-dimensional array that stores the maximum dimension of the model input data.\n 73 *The first dimension of the array indicates the number of tensors, and the second dimension indicates the number of dimensions of the tensors. 74 * 75 * @return Returns <b>0</b> if the operation is successful. 76 * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 77 *and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 78 */ 79 GetInputDimRanges([out] unsigned int[][] minInputDims, [out] unsigned int[][] maxInputDims); 80 81 /** 82 * @brief Performs AI model inference. 83 * 84 * @param inputs Input data for AI model inference. The data is input in the sequence defined by the model.\n 85 *For details about the input data type, see {@link IOTensor}. 86 * @param outputs Output data of AI model inference. After inference, the output data is written to the\n 87 *shared buffer. For details about the output data type, see {@link IOTensor}. 88 * @param outputDims Dimensions of the output data. The output sequence is the same as that of <b>outputs</b>. 89 * @param isOutputBufferEnough Whether the shared buffer space is sufficient for the output data.\n 90 *The value <b>true</b> means the shared buffer space is sufficient; the value <b>false</b> means the opposite. 91 * 92 * @return Returns <b>0</b> if the operation is successful. 93 * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 94 *and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 95 */ 96 Run([in] struct IOTensor[] inputs, [in] struct IOTensor[] outputs, [out] int[][] outputDims); 97} 98 99/** @} */ 100