From 2a3bf8da50640220daf5c58eca90ff412bb7f20f Mon Sep 17 00:00:00 2001 From: wangcaoyu Date: Tue, 19 Dec 2023 23:46:16 +0800 Subject: [PATCH 1/3] testclang Signed-off-by: wangcaoyu --- build-tools/capi_parser/requirements.txt | Bin 96 -> 66 bytes .../capi_parser/src/coreImpl/check/check.py | 10 +++ .../capi_parser/src/typedef/check/check.py | 76 ++++++------------ .../capi_parser/src/utils/constants.py | 6 +- 4 files changed, 37 insertions(+), 55 deletions(-) diff --git a/build-tools/capi_parser/requirements.txt b/build-tools/capi_parser/requirements.txt index e623e5c24d68c5da8aed925fa4b4411dc162084f..1e93cca395b59923b468d2583849c14b307511f6 100644 GIT binary patch delta 4 LcmYdrn&1Qg1FQjc delta 35 jcmZ=tnBXK=z>vt0$B+Ufiy3Tz(1<~g!4Qmj8Mqh#gS!Qb diff --git a/build-tools/capi_parser/src/coreImpl/check/check.py b/build-tools/capi_parser/src/coreImpl/check/check.py index b7dea726e93..1869c593ef0 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check.py +++ b/build-tools/capi_parser/src/coreImpl/check/check.py @@ -95,3 +95,13 @@ def get_check_result_list(file_list): check_result_list.extend(check_syntax(file)) return check_result_list + +def get_md_files(url): + file = open(url, "r") + file_list = [] + line = file.readline() + while line: + file_list.append(line.splitlines()[0]) + line = file.readline() + file.close() + return file_list diff --git a/build-tools/capi_parser/src/typedef/check/check.py b/build-tools/capi_parser/src/typedef/check/check.py index b5dbc4eb734..9723fbd2041 100644 --- a/build-tools/capi_parser/src/typedef/check/check.py +++ b/build-tools/capi_parser/src/typedef/check/check.py @@ -32,70 +32,42 @@ class TAGS(enum.Enum): class ErrorType(enum.Enum): - UNKNOW_DECORATOR: { - id: 0, - 'description': 'unknow decorator', + DEFAULT = { + 'id': -1, + 'description': '', } - MISSPELL_WORDS: { - id: 1, + EMPTY_TAG = { + 'id': 0, + 'description': "miss tag value", + } + ERROR_TAG = { + 'id': 1, + 'description': 'error tag name', + } + MISSPELL_WORDS = { + 'id': 1, 'description': 'misspell words', } - NAMING_ERRORS: { - id: 2, + NAMING_ERRORS = { + 'id': 2, 'description': 'naming errors', } - UNKNOW_PERMISSION: { - id: 3, - 'description': 'unknow permission', - } - UNKNOW_SYSCAP: { - id: 4, - 'description': 'unknow syscap', + SYNTAX_ERRORS = { + 'id': 3, + 'description': 'syntax errors', } - UNKNOW_DEPRECATED: { - id: 5, + UNKNOW_DEPRECATED = { + 'id': 5, 'description': 'unknow deprecated', } - WRONG_ORDER: { - id: 6, - 'description': 'wrong order', - } - WRONG_VALUE: { - id: 7, + WRONG_VALUE = { + 'id': 7, 'description': 'wrong value', } - WRONG_SCENE: { - id: 8, + WRONG_SCENE = { + 'id': 8, 'description': 'wrong scene', } - PARAMETER_ERRORS: { - id: 9, - 'description': 'wrong parameter', - } - API_PAIR_ERRORS: { - id: 10, - 'description': 'limited api pair errors', - } - ILLEGAL_ANY: { - id: 11, - 'description': 'illegal any', - } - API_CHANGE_ERRORS: { - id: 12, - 'description': 'api change errors', - } - EMPTY_TAG: { - id: 13, - 'description': 'miss tag value', - } - ERROR_TAG: { - id: 14, - 'description': 'error tag name', - } - SYNTAX_ERRORS: { - id: 15, - 'description': 'syntax errors', - } class LogType(enum.Enum): diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 4142ef41fa5..3fef84c1159 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -19,12 +19,12 @@ import enum class StringConstant(enum.Enum): - LIB_CLG_PATH = r'D:\Environment\LLVM\bin\libclang.dll' # 共享库 + LIB_CLG_PATH = r'D:\LLVM\bin\libclang.dll' # 共享库 FUNK_NAME = "ohos_ndk_headers" REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘) # 拉到本地仓的三方库绝对路径 - INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' - STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' + INCLUDE_LIB = r'third_party\musl\ndk_musl_include' + STD_INCLUDE = r'sysroot\ndk_musl_include_files' RESULT_HEAD_NAME = "result_total.xlsx" -- Gitee From bfc290049ec92e341153d0e90d92e79fcd478fa0 Mon Sep 17 00:00:00 2001 From: wangcaoyu Date: Wed, 20 Dec 2023 19:21:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9linux=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangcaoyu --- build-tools/capi_parser/src/utils/constants.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index d886a91a12a..23df32bd907 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -23,9 +23,9 @@ class StringConstant(enum.Enum): FUNK_NAME = "ohos_ndk_headers" REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘) # 拉到本地仓的三方库绝对路径 - INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' - STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' - SELF_INCLUDE = r'.\sysroot\self_include_files' + INCLUDE_LIB = r'third_party/musl/ndk_musl_include' + STD_INCLUDE = r'sysroot/ndk_musl_include_files' + SELF_INCLUDE = r'sysroot/self_include_files' RESULT_HEAD_NAME = "result_total.xlsx" -- Gitee From 58c501b1b4a20cff1797c522b45327571aacbc51 Mon Sep 17 00:00:00 2001 From: wangcaoyu Date: Thu, 21 Dec 2023 09:07:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9.h=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B5=8B=E8=AF=95check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangcaoyu --- ai/neural_network_runtime/TestFileName.h | 294 ++++++++++++++++++ .../neural_network_core.h | 5 +- 2 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 ai/neural_network_runtime/TestFileName.h diff --git a/ai/neural_network_runtime/TestFileName.h b/ai/neural_network_runtime/TestFileName.h new file mode 100644 index 00000000000..0e73606773e --- /dev/null +++ b/ai/neural_network_runtime/TestFileName.h @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup NeuralNeworkRuntime + * @{ + * + * @brief Provides APIs of Neural Network Runtime for accelerating the model inference. + * + * @Syscap SystemCapability.Ai.NeuralNetworkRuntime + * @since 9 + * @version 2.0 + */ + +/** + * @file neural_network_runtime_compat.h + * + * @brief The APIs defined in this document are all compatible APIs of the previous version, which will be deprecated after five versions. + * It is recommended to use the new APIs defined by neural_network_core.h and neural_network_runtime.h. + * + * Note: Currently, the APIs of Neural Network Runtime do not support multi-thread calling. \n + * + * include "neural_network_runtime/neural_network_runtime_compat.h" + * @library libneural_network_runtime.so + * @since 11 + * @version 1.0 + */ + +#ifndef NEURAL_NETWORK_RUNTIME_COMPAT_H +#define NEURAL_NETWORK_RUNTIME_COMPAT_H + +#include "neural_network_runtime_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Adds a tensor to a model instance. + * + * The data node and operator parameters in the Neural Network Runtime model are composed of tensors of the model. + * This method is used to add tensors to a model instance based on the tensor parameter. + * The sequence of adding tensors is specified by the index value recorded in the model. The {@link OH_NNModel_SetTensorData}, {@link OH_NNModel_AddOperation}, + * and {@link OH_NNModel_SpecifyInputsAndOutputs} methods specifies tensors based on the index value. \n + * + * Neural Network Runtime supports inputs and outputs of the dynamic shape. When adding a data node with a dynamic shape, + * you need to set the dimensions that support dynamic changes in tensor.dimensions to -1. + * For example, if tensor.dimensions of a four-dimensional tensor is set to [1, -1, 2, 2], the second dimension supports dynamic changes. \n + * + * @param model Pointer to the {@link OH_NNModel} instance. + * @param tensor Pointer to the {@link OH_NN_Tensor} tensor. The tensor specifies the attributes of the tensor added to the model instance. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. + * If the operation fails, an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNModel_AddTensorToModel} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNModel_AddTensor(OH_NNModel *model, const OH_NN_Tensor *tensor); + +/** + * @brief Sets the single input data for a model. + * + * This method copies the data whose length is specified by length (in bytes) in dataBuffer to the shared memory + * of the underlying device. inputIndex specifies the input to be set and tensor sets information such as the input shape, + * type, and quantization parameters. \n + * + * Neural Network Runtime supports models with dynamical shape input. For fixed shape input and dynamic shape input scenarios, + * this method uses different processing policies. \n + * + * - Fixed shape input: The attributes of tensor must be the same as those of the tensor added by calling + * {@link OH_NNModel_AddTensor} in the composition phase. + * - Dynamic shape input: In the composition phase, because the shape is not fixed, each value in tensor.dimensions must be greater than + * 0 in the method calls to determine the shape input in the calculation phase. When setting the shape, you can modify + * only the dimension whose value is -1. Assume that [-1, 224, 224, 3] is input as the the dimension of A in the composition phase. + * When this method is called, only the size of the first dimension can be modified, for example, to [3, 224, 224, 3]. + * If other dimensions are adjusted, {@link OH_NN_INVALID_PARAMETER} is returned. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param inputIndex Input index value, which is in the same sequence of the data input when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of inputIndices is {1, 5, 9} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * In input settings, the index value for the three inputs is {0, 1, 2}. \n + * + * @param tensor Sets the tensor corresponding to the input data. + * @param dataBuffer Pointer to the input data. + * @param length Length of the data buffer, in bytes. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. If the operation fails, + * an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNExecutor_RunSync} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNExecutor_SetInput(OH_NNExecutor *executor, + uint32_t inputIndex, + const OH_NN_Tensor *tensor, + const void *dataBuffer, + size_t length); + +/** + * @brief Sets the buffer for a single output of a model. + * + * This method binds the buffer to which dataBuffer points to the output specified by outputIndex. + * The length of the buffer is specified by length. \n + * + * After {@link OH_NNExecutor_Run} is called to complete a single model inference, Neural Network Runtime compares + * the length of the buffer to which dataBuffer points with the length of the output data and returns different results + * based on the actual situation. \n + * + * - If the buffer length is greater than or equal to the data length, the inference result is copied to the buffer and + * {@link OH_NN_SUCCESS} is returned. You can read the inference result from dataBuffer. + * - If the buffer length is smaller than the data length, {@link OH_NNExecutor_Run} returns {@link OH_NN_INVALID_PARAMETER} + * and generates a log indicating that the buffer is too small. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param outputIndex Output Index value, which is in the same sequence of the data output when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of outputIndices is {4, 6, 8} when {@link OH_NNModel_SpecifyInputsAndOutputs} + * is called. In output buffer settings, the index value for the three outputs is {0, 1, 2}. + * @param dataBuffer Pointer to the output data. + * @param length Length of the data buffer, in bytes. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. If the operation fails, + * an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNExecutor_RunSync} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNExecutor_SetOutput(OH_NNExecutor *executor, + uint32_t outputIndex, + void *dataBuffer, + size_t length); + +/** + * @brief Performs inference. + * + * Performs end-to-end inference and computing of the model on the device associated with the executor. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. If the operation fails, + * an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNExecutor_RunSync} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNExecutor_Run(OH_NNExecutor *executor); + +/** + * @brief Allocates shared memory to a single input on a device. + * + * Neural Network Runtime provides a method for proactively allocating shared memory on a device. By specifying the executor and input index value, + * this method allocates shared memory whose size is specified by length on the device associated with a single input and returns the + * operation result through the {@link OH_NN_Memory} instance. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param inputIndex Input index value, which is in the same sequence of the data input when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of inputIndices is {1, 5, 9} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * In the memory input application, the index value for the three inputs is {0, 1, 2}. + * @param length Memory size to be applied for, in bytes. + * @return Pointer to a {@link OH_NN_Memory} instance, or NULL if it fails to create. + * @deprecated since 11 + * @useinstead {@link OH_NNTensor_CreateWithSize} + * @since 9 + * @version 1.0 + */ +OH_NN_Memory *OH_NNExecutor_AllocateInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, size_t length); + +/** + * @brief Allocates shared memory to a single output on a device. + * + * Neural Network Runtime provides a method for proactively allocating shared memory on a device. By specifying the executor and + * output index value, this method allocates shared memory whose size is specified by length on the device associated with + * a single output and returns the operation result through the {@link OH_NN_Memory} instance. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param outputIndex Output Index value, which is in the same sequence of the data output when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of outputIndices is {4, 6, 8} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * In output memory application, the index value for the three outputs is {0, 1, 2}. + * @param length Memory size to be applied for, in bytes. + * @return Pointer to a {@link OH_NN_Memory} instance, or NULL if it fails to create. + * @deprecated since 11 + * @useinstead {@link OH_NNTensor_CreateWithSize} + * @since 9 + * @version 1.0 + */ +OH_NN_Memory *OH_NNExecutor_AllocateOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, size_t length); + +/** + * @brief Releases the input memory to which the {@link OH_NN_Memory} instance points. + * + * This method needs to be called to release the memory instance created by calling {@link OH_NNExecutor_AllocateInputMemory}. + * Otherwise, memory leak will occur. + * The mapping between inputIndex and memory must be the same as that in memory instance creation. \n + * + * If memory or *memory is a null pointer, this method only prints warning logs and does not execute the release logic. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param inputIndex Input index value, which is in the same sequence of the data input when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of inputIndices is {1, 5, 9} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * In memory input release, the index value for the three inputs is {0, 1, 2}. + * @param memory Double pointer to the {@link OH_NN_Memory} instance. After shared memory is destroyed, this method sets *memory to a null pointer. + * @deprecated since 11 + * @useinstead {@link OH_NNTensor_Destroy} + * @since 9 + * @version 1.0 + */ +void OH_NNExecutor_DestroyInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory); + +/** + * @brief Releases the output memory to which the {@link OH_NN_Memory} instance points. + * + * This method needs to be called to release the memory instance created by calling {@link OH_NNExecutor_AllocateOutputMemory}. Otherwise, memory leak will occur. + * The mapping between outputIndex and memory must be the same as that in memory instance creation. \n + * + * If memory or *memory is a null pointer, this method only prints warning logs and does not execute the release logic. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param outputIndex Output Index value, which is in the same sequence of the data output when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of outputIndices is {4, 6, 8} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * In output memory release, the index value for the three outputs is {0, 1, 2}. + * @param memory Double pointer to the {@link OH_NN_Memory} instance. After shared memory is destroyed, this method sets *memory to a null pointer. + * @deprecated since 11 + * @useinstead {@link OH_NNTensor_Destroy} + * @since 9 + * @version 1.0 + */ +void OH_NNExecutor_DestroyOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory); + +/** + * @brief Specifies the hardware shared memory pointed to by the {@link OH_NN_Memory} instance as the shared memory used by a single input. + * + * In scenarios where memory needs to be managed by yourself, this method binds the execution input to the {@link OH_NN_Memory} memory instance. + * During computing, the underlying device reads the input data from the shared memory pointed to by the memory instance. + * By using this method, concurrent execution of input setting, computing, and read can be implemented to improve inference efficiency of a data flow. \n + * + * @param executor Pointer to the {@link OH_NNExecutor} instance. + * @param inputIndex Input index value, which is in the same sequence of the data input when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of inputIndices is {1, 5, 9} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * When the input shared memory is specified, the index value for the three inputs is {0, 1, 2}. + * @param tensor Pointer to {@link OH_NN_Tensor}, used to set the tensor corresponding to a single input. + * @param memory Pointer to {@link OH_NN_Memory}. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. If the operation fails, + * an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNExecutor_RunSync} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory(OH_NNExecutor *executor, + uint32_t inputIndex, + const OH_NN_Tensor *tensor, + const OH_NN_Memory *memory); + +/** + * @brief Specifies the hardware shared memory pointed to by the {@link OH_NN_Memory} instance as the shared memory used by a single output. + * + * In scenarios where memory needs to be managed by yourself, this method binds the execution output to the {@link OH_NN_Memory} memory instance. + * When computing is performed, the underlying hardware directly writes the computing result to the shared memory to which the memory instance points. + * By using this method, concurrent execution of input setting, computing, and read can be implemented to improve inference efficiency of a data flow. \n + * + * @param executor Executor. + * @param outputIndex Output Index value, which is in the same sequence of the data output when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * Assume that the value of outputIndices is {4, 6, 8} when {@link OH_NNModel_SpecifyInputsAndOutputs} is called. + * When output shared memory is specified, the index value for the three outputs is {0, 1, 2}. + * @param memory Pointer to {@link OH_NN_Memory}. + * @return Execution result of the function. If the operation is successful, OH_NN_SUCCESS is returned. If the operation fails, + * an error code is returned. For details about the error codes, see {@link OH_NN_ReturnCode}. + * @deprecated since 11 + * @useinstead {@link OH_NNExecutor_RunSync} + * @since 9 + * @version 1.0 + */ +OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory(OH_NNExecutor *executor, + uint32_t outputIndex, + const OH_NN_Memory *memory); + +#ifdef __cplusplus +} +#endif // __cplusplus + +/** @} */ +#endif // NEURAL_NETWORK_RUNTIME_COMPAT_H diff --git a/ai/neural_network_runtime/neural_network_core.h b/ai/neural_network_runtime/neural_network_core.h index 6ab1c86acca..b4f19f755f8 100644 --- a/ai/neural_network_runtime/neural_network_core.h +++ b/ai/neural_network_runtime/neural_network_core.h @@ -65,11 +65,12 @@ extern "C" { * After {@link OH_NNCompilation_Build} is called, the {@link OH_NNModel} instance can be released. \n * * @param model Pointer to the {@link OH_NNModel} instance. + * @param model2 Pointer to the {@link OH_NNModel} instance. * @return Pointer to a {@link OH_NNCompilation} instance, or NULL if it fails to create. * @since 9 * @version 1.0 */ -OH_NNCompilation *OH_NNCompilation_Construct(const OH_NNModel *model); +OH_NNCompilation *OH_NNCompilation_Construct(const OH_NNModel *model, const OH_NNModel *model2); /** * @brief Creates a compilation instance based on an offline model file. @@ -119,7 +120,7 @@ OH_NNCompilation *OH_NNCompilation_ConstructWithOfflineModelBuffer(const void *m * @since 11 * @version 1.0 */ -OH_NNCompilation *OH_NNCompilation_ConstructForCache(); +OH_NNCompilation *changeFunctionName(); /** * @brief Exports the cache to a given buffer. -- Gitee