1c5e268c6Sopenharmony_ci/* 2c5e268c6Sopenharmony_ci * Copyright (c) 2023 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.\n 21c5e268c6Sopenharmony_ci * Neural Network Runtime (NNRt) is a cross-chip inference computing runtime environment oriented to the AI field. 22c5e268c6Sopenharmony_ci * 23c5e268c6Sopenharmony_ci * @since 3.2 24c5e268c6Sopenharmony_ci * @version 2.0 25c5e268c6Sopenharmony_ci */ 26c5e268c6Sopenharmony_ci 27c5e268c6Sopenharmony_ci/** 28c5e268c6Sopenharmony_ci * @file IPreparedModel.idl 29c5e268c6Sopenharmony_ci * 30c5e268c6Sopenharmony_ci * @brief Defines the APIs for AI model inference, obtaining the input tensor dimension range,\n 31c5e268c6Sopenharmony_ci * and exporting the AI model built. 32c5e268c6Sopenharmony_ci * 33c5e268c6Sopenharmony_ci * @since 3.2 34c5e268c6Sopenharmony_ci * @version 2.0 35c5e268c6Sopenharmony_ci */ 36c5e268c6Sopenharmony_ci 37c5e268c6Sopenharmony_ci/** 38c5e268c6Sopenharmony_ci * @brief Defines the package path of the NNRt module. 39c5e268c6Sopenharmony_ci * 40c5e268c6Sopenharmony_ci * @since 3.2 41c5e268c6Sopenharmony_ci * @version 2.0 42c5e268c6Sopenharmony_ci */ 43c5e268c6Sopenharmony_cipackage ohos.hdi.nnrt.v2_0; 44c5e268c6Sopenharmony_ci 45c5e268c6Sopenharmony_ciimport ohos.hdi.nnrt.v2_0.NnrtTypes; 46c5e268c6Sopenharmony_ci 47c5e268c6Sopenharmony_ci/** 48c5e268c6Sopenharmony_ci * @brief Provides the APIs for exporting AI models and performing AI model inference. 49c5e268c6Sopenharmony_ci * 50c5e268c6Sopenharmony_ci * @since 3.2 51c5e268c6Sopenharmony_ci * @version 2.0 52c5e268c6Sopenharmony_ci */ 53c5e268c6Sopenharmony_ciinterface IPreparedModel { 54c5e268c6Sopenharmony_ci /** 55c5e268c6Sopenharmony_ci * @brief Exports an AI model from the cache. 56c5e268c6Sopenharmony_ci * 57c5e268c6Sopenharmony_ci * @param modelCache Array of the model files, which are in the same sequence as they exported.\n 58c5e268c6Sopenharmony_ci *For details, see {@link SharedBuffer}. 59c5e268c6Sopenharmony_ci * 60c5e268c6Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 61c5e268c6Sopenharmony_ci * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 62c5e268c6Sopenharmony_ci *and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 63c5e268c6Sopenharmony_ci */ 64c5e268c6Sopenharmony_ci ExportModelCache([out] struct SharedBuffer[] modelCache); 65c5e268c6Sopenharmony_ci 66c5e268c6Sopenharmony_ci /** 67c5e268c6Sopenharmony_ci * @brief Obtains the tensor dimension range supported by AI model. If a fixed dimension is used,\n 68c5e268c6Sopenharmony_ci *the maximum dimension value is the same as the minimum dimension value. 69c5e268c6Sopenharmony_ci * 70c5e268c6Sopenharmony_ci * @param minInputDims Two-dimensional array that stores the minimum dimension of the model input data.\n 71c5e268c6Sopenharmony_ci *The first dimension of the array indicates the number of tensors, and the second dimension indicates the number of dimensions of the tensors. 72c5e268c6Sopenharmony_ci * @param maxInputDims Two-dimensional array that stores the maximum dimension of the model input data.\n 73c5e268c6Sopenharmony_ci *The first dimension of the array indicates the number of tensors, and the second dimension indicates the number of dimensions of the tensors. 74c5e268c6Sopenharmony_ci * 75c5e268c6Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 76c5e268c6Sopenharmony_ci * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 77c5e268c6Sopenharmony_ci *and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 78c5e268c6Sopenharmony_ci */ 79c5e268c6Sopenharmony_ci GetInputDimRanges([out] unsigned int[][] minInputDims, [out] unsigned int[][] maxInputDims); 80c5e268c6Sopenharmony_ci 81c5e268c6Sopenharmony_ci /** 82c5e268c6Sopenharmony_ci * @brief Performs AI model inference. 83c5e268c6Sopenharmony_ci * 84c5e268c6Sopenharmony_ci * @param inputs Input data for AI model inference. The data is input in the sequence defined by the model.\n 85c5e268c6Sopenharmony_ci *For details about the input data type, see {@link IOTensor}. 86c5e268c6Sopenharmony_ci * @param outputs Output data of AI model inference. After inference, the output data is written to the\n 87c5e268c6Sopenharmony_ci *shared buffer. For details about the output data type, see {@link IOTensor}. 88c5e268c6Sopenharmony_ci * @param outputDims Dimensions of the output data. The output sequence is the same as that of <b>outputs</b>. 89c5e268c6Sopenharmony_ci * @param isOutputBufferEnough Whether the shared buffer space is sufficient for the output data.\n 90c5e268c6Sopenharmony_ci *The value <b>true</b> means the shared buffer space is sufficient; the value <b>false</b> means the opposite. 91c5e268c6Sopenharmony_ci * 92c5e268c6Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 93c5e268c6Sopenharmony_ci * @return Returns a non-0 value if the operation fails. A negative value is an HDF standard error code,\n 94c5e268c6Sopenharmony_ci *and a positive value is a dedicated error code defined by NNRt. For details, see {@link NNRT_ReturnCode}. 95c5e268c6Sopenharmony_ci */ 96c5e268c6Sopenharmony_ci Run([in] struct IOTensor[] inputs, [in] struct IOTensor[] outputs, [out] int[][] outputDims); 97c5e268c6Sopenharmony_ci} 98c5e268c6Sopenharmony_ci 99c5e268c6Sopenharmony_ci/** @} */ 100