1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "common/native_common.h"
17f6603c60Sopenharmony_ci#include "hilog/log.h"
18f6603c60Sopenharmony_ci#include "napi/native_api.h"
19f6603c60Sopenharmony_ci#include <cstring>
20f6603c60Sopenharmony_ci#include <js_native_api.h>
21f6603c60Sopenharmony_ci#include <neural_network_runtime/neural_network_runtime.h>
22f6603c60Sopenharmony_ci#include <node_api.h>
23f6603c60Sopenharmony_ci#include <string>
24f6603c60Sopenharmony_ci
25f6603c60Sopenharmony_ci#define PARAM_0 0
26f6603c60Sopenharmony_ci#define PARAM_1 1
27f6603c60Sopenharmony_ci#define PARAM_2 2
28f6603c60Sopenharmony_ci#define PARAM_3 3
29f6603c60Sopenharmony_ci#define PARAM_4 4
30f6603c60Sopenharmony_ci#define MPARAM_1 (-1)
31f6603c60Sopenharmony_ci#define PARAM_100000 100000
32f6603c60Sopenharmony_ci
33f6603c60Sopenharmony_ci#define SUCCESS 0
34f6603c60Sopenharmony_ci#define RETURN_1 1
35f6603c60Sopenharmony_ci#define FAIL (-1)
36f6603c60Sopenharmony_ci
37f6603c60Sopenharmony_civoid Free(OH_NNModel *model) { OH_NNModel_Destroy(&model); };
38f6603c60Sopenharmony_civoid FreeCompilation(OH_NNCompilation *compilation) { OH_NNCompilation_Destroy(&compilation); };
39f6603c60Sopenharmony_cistruct OHNNOperandTest {
40f6603c60Sopenharmony_ci    OH_NN_DataType dataType;
41f6603c60Sopenharmony_ci    OH_NN_TensorType type;
42f6603c60Sopenharmony_ci    std::vector<int32_t> shape;
43f6603c60Sopenharmony_ci    void *data{nullptr};
44f6603c60Sopenharmony_ci    int32_t length{PARAM_0};
45f6603c60Sopenharmony_ci    const OH_NN_QuantParam *quantParam = nullptr;
46f6603c60Sopenharmony_ci};
47f6603c60Sopenharmony_cistruct OHNNGraphArgs {
48f6603c60Sopenharmony_ci    OH_NN_OperationType operationType;
49f6603c60Sopenharmony_ci    std::vector<OHNNOperandTest> operands;
50f6603c60Sopenharmony_ci    std::vector<uint32_t> paramIndices;
51f6603c60Sopenharmony_ci    std::vector<uint32_t> inputIndices;
52f6603c60Sopenharmony_ci    std::vector<uint32_t> outputIndices;
53f6603c60Sopenharmony_ci    bool build = true;
54f6603c60Sopenharmony_ci    bool specifyIO = true;
55f6603c60Sopenharmony_ci    bool addOperation = true;
56f6603c60Sopenharmony_ci};
57f6603c60Sopenharmony_ci
58f6603c60Sopenharmony_cistatic napi_value OHNNModelConstructOne(napi_env env, napi_callback_info info)
59f6603c60Sopenharmony_ci{
60f6603c60Sopenharmony_ci    int ret = FAIL;
61f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
62f6603c60Sopenharmony_ci    if (model != nullptr) {
63f6603c60Sopenharmony_ci        ret = SUCCESS;
64f6603c60Sopenharmony_ci    }
65f6603c60Sopenharmony_ci    napi_value result = nullptr;
66f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
67f6603c60Sopenharmony_ci
68f6603c60Sopenharmony_ci    return result;
69f6603c60Sopenharmony_ci}
70f6603c60Sopenharmony_ci
71f6603c60Sopenharmony_cistatic napi_value OHNNModelConstructTwo(napi_env env, napi_callback_info info)
72f6603c60Sopenharmony_ci{
73f6603c60Sopenharmony_ci    int ret = FAIL;
74f6603c60Sopenharmony_ci    OH_NNModel *model_first = OH_NNModel_Construct();
75f6603c60Sopenharmony_ci    OH_NNModel *model_second = OH_NNModel_Construct();
76f6603c60Sopenharmony_ci    if ((model_first != nullptr) && (model_second != nullptr) && (model_first != model_second)) {
77f6603c60Sopenharmony_ci        ret = SUCCESS;
78f6603c60Sopenharmony_ci    }
79f6603c60Sopenharmony_ci    Free(model_first);
80f6603c60Sopenharmony_ci    Free(model_second);
81f6603c60Sopenharmony_ci    napi_value result = nullptr;
82f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
83f6603c60Sopenharmony_ci
84f6603c60Sopenharmony_ci    return result;
85f6603c60Sopenharmony_ci}
86f6603c60Sopenharmony_ci
87f6603c60Sopenharmony_cistatic napi_value OHNNModelAddTensorOne(napi_env env, napi_callback_info info)
88f6603c60Sopenharmony_ci{
89f6603c60Sopenharmony_ci    int ret = FAIL;
90f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
91f6603c60Sopenharmony_ci    if (model != nullptr) {
92f6603c60Sopenharmony_ci        int32_t dimensions[PARAM_3]{PARAM_3, PARAM_2, PARAM_2};
93f6603c60Sopenharmony_ci        OH_NN_Tensor operand{OH_NN_FLOAT32, PARAM_3, dimensions, nullptr, OH_NN_TENSOR};
94f6603c60Sopenharmony_ci        OH_NN_ReturnCode addTensor_ret = OH_NNModel_AddTensor(model, &operand);
95f6603c60Sopenharmony_ci        if (addTensor_ret == OH_NN_SUCCESS) {
96f6603c60Sopenharmony_ci            ret = SUCCESS;
97f6603c60Sopenharmony_ci        }
98f6603c60Sopenharmony_ci    }
99f6603c60Sopenharmony_ci    Free(model);
100f6603c60Sopenharmony_ci    napi_value result = nullptr;
101f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
102f6603c60Sopenharmony_ci
103f6603c60Sopenharmony_ci    return result;
104f6603c60Sopenharmony_ci}
105f6603c60Sopenharmony_cistatic napi_value OHNNModelAddTensorTwo(napi_env env, napi_callback_info info)
106f6603c60Sopenharmony_ci{
107f6603c60Sopenharmony_ci    int ret = FAIL;
108f6603c60Sopenharmony_ci    int32_t dimensions[PARAM_3]{PARAM_3, PARAM_2, PARAM_2};
109f6603c60Sopenharmony_ci    OH_NN_Tensor operand{OH_NN_FLOAT32, PARAM_3, dimensions, nullptr, OH_NN_TENSOR};
110f6603c60Sopenharmony_ci    OH_NN_ReturnCode addTensor_ret = OH_NNModel_AddTensor(nullptr, &operand);
111f6603c60Sopenharmony_ci    if (addTensor_ret == OH_NN_INVALID_PARAMETER) {
112f6603c60Sopenharmony_ci        ret = SUCCESS;
113f6603c60Sopenharmony_ci    }
114f6603c60Sopenharmony_ci    napi_value result = nullptr;
115f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
116f6603c60Sopenharmony_ci
117f6603c60Sopenharmony_ci    return result;
118f6603c60Sopenharmony_ci}
119f6603c60Sopenharmony_cistatic napi_value OHNNModelSetTensorDataOne(napi_env env, napi_callback_info info)
120f6603c60Sopenharmony_ci{
121f6603c60Sopenharmony_ci    int ret = FAIL;
122f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
123f6603c60Sopenharmony_ci    if (model != nullptr) {
124f6603c60Sopenharmony_ci
125f6603c60Sopenharmony_ci        float inputValue0[PARAM_4] = {PARAM_0, PARAM_1, PARAM_2, PARAM_3};
126f6603c60Sopenharmony_ci
127f6603c60Sopenharmony_ci        OHNNOperandTest operand;
128f6603c60Sopenharmony_ci        operand.dataType = OH_NN_FLOAT32;
129f6603c60Sopenharmony_ci        operand.type = OH_NN_TENSOR;
130f6603c60Sopenharmony_ci        operand.shape = {PARAM_1, PARAM_2, PARAM_2, PARAM_1};
131f6603c60Sopenharmony_ci        operand.data = inputValue0;
132f6603c60Sopenharmony_ci        operand.length = PARAM_4 * sizeof(float);
133f6603c60Sopenharmony_ci        OH_NN_Tensor operandSor{OH_NN_FLOAT32, PARAM_4, operand.shape.data(), nullptr, OH_NN_TENSOR};
134f6603c60Sopenharmony_ci        OH_NNModel_AddTensor(model, &operandSor);
135f6603c60Sopenharmony_ci
136f6603c60Sopenharmony_ci        OH_NN_ReturnCode setTensor_ret = OH_NNModel_SetTensorData(model, PARAM_0, operand.data, operand.length);
137f6603c60Sopenharmony_ci        if (setTensor_ret == OH_NN_SUCCESS) {
138f6603c60Sopenharmony_ci            ret = SUCCESS;
139f6603c60Sopenharmony_ci        }
140f6603c60Sopenharmony_ci    }
141f6603c60Sopenharmony_ci    Free(model);
142f6603c60Sopenharmony_ci    napi_value result = nullptr;
143f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
144f6603c60Sopenharmony_ci
145f6603c60Sopenharmony_ci    return result;
146f6603c60Sopenharmony_ci}
147f6603c60Sopenharmony_cistatic napi_value OHNNModelSetTensorDataTwo(napi_env env, napi_callback_info info)
148f6603c60Sopenharmony_ci{
149f6603c60Sopenharmony_ci    int ret = FAIL;
150f6603c60Sopenharmony_ci    int8_t activationValue{PARAM_0};
151f6603c60Sopenharmony_ci    OH_NN_ReturnCode setTensor_ret =
152f6603c60Sopenharmony_ci        OH_NNModel_SetTensorData(nullptr, PARAM_1, (void *)&activationValue, sizeof(int8_t));
153f6603c60Sopenharmony_ci    if (setTensor_ret == OH_NN_INVALID_PARAMETER) {
154f6603c60Sopenharmony_ci        ret = SUCCESS;
155f6603c60Sopenharmony_ci    }
156f6603c60Sopenharmony_ci    napi_value result = nullptr;
157f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
158f6603c60Sopenharmony_ci
159f6603c60Sopenharmony_ci    return result;
160f6603c60Sopenharmony_ci}
161f6603c60Sopenharmony_ci
162f6603c60Sopenharmony_ciOHNNGraphArgs addTesorAndSetTensor(OH_NNModel *model)
163f6603c60Sopenharmony_ci{
164f6603c60Sopenharmony_ci    float inputValue[PARAM_4] = {PARAM_0, PARAM_1, PARAM_2, PARAM_3};
165f6603c60Sopenharmony_ci    OHNNOperandTest operand;
166f6603c60Sopenharmony_ci    operand.dataType = OH_NN_FLOAT32;
167f6603c60Sopenharmony_ci    operand.type = OH_NN_TENSOR;
168f6603c60Sopenharmony_ci    operand.shape = {PARAM_1, PARAM_2, PARAM_2, PARAM_1};
169f6603c60Sopenharmony_ci    operand.data = inputValue;
170f6603c60Sopenharmony_ci    operand.length = PARAM_4 * sizeof(float);
171f6603c60Sopenharmony_ci
172f6603c60Sopenharmony_ci    OHNNOperandTest operand2;
173f6603c60Sopenharmony_ci    operand2.dataType = OH_NN_FLOAT32;
174f6603c60Sopenharmony_ci    operand2.type = OH_NN_TENSOR;
175f6603c60Sopenharmony_ci    operand2.shape = {PARAM_1, PARAM_2, PARAM_2, PARAM_1};
176f6603c60Sopenharmony_ci    operand2.data = inputValue;
177f6603c60Sopenharmony_ci    operand2.length = PARAM_4 * sizeof(float);
178f6603c60Sopenharmony_ci
179f6603c60Sopenharmony_ci    float outputValue[PARAM_4] = {PARAM_0};
180f6603c60Sopenharmony_ci    int8_t activationValue = OH_NN_FUSED_NONE;
181f6603c60Sopenharmony_ci    OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)};
182f6603c60Sopenharmony_ci
183f6603c60Sopenharmony_ci    OHNNOperandTest output = {
184f6603c60Sopenharmony_ci        OH_NN_FLOAT32, OH_NN_TENSOR, {PARAM_1, PARAM_2, PARAM_2, PARAM_1}, outputValue, PARAM_4 * sizeof(float)};
185f6603c60Sopenharmony_ci
186f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs;
187f6603c60Sopenharmony_ci    graphArgs.operationType = OH_NN_OPS_ADD;
188f6603c60Sopenharmony_ci    graphArgs.operands = {operand, operand2, activation, output};
189f6603c60Sopenharmony_ci    graphArgs.paramIndices = {PARAM_2};
190f6603c60Sopenharmony_ci    graphArgs.inputIndices = {PARAM_0, PARAM_1};
191f6603c60Sopenharmony_ci    graphArgs.outputIndices = {PARAM_3};
192f6603c60Sopenharmony_ci
193f6603c60Sopenharmony_ci    for (int i = 0; i < graphArgs.operands.size(); i++) {
194f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[i];
195f6603c60Sopenharmony_ci        OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
196f6603c60Sopenharmony_ci                                nullptr, operandTem.type};
197f6603c60Sopenharmony_ci        OH_NNModel_AddTensor(model, &operand);
198f6603c60Sopenharmony_ci
199f6603c60Sopenharmony_ci        if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
200f6603c60Sopenharmony_ci            graphArgs.paramIndices.end()) {
201f6603c60Sopenharmony_ci            OH_NNModel_SetTensorData(model, i, operandTem.data, operandTem.length);
202f6603c60Sopenharmony_ci        }
203f6603c60Sopenharmony_ci    }
204f6603c60Sopenharmony_ci    return graphArgs;
205f6603c60Sopenharmony_ci}
206f6603c60Sopenharmony_cistatic napi_value OHNNModelAddOperationOne(napi_env env, napi_callback_info info)
207f6603c60Sopenharmony_ci{
208f6603c60Sopenharmony_ci    int ret = FAIL;
209f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
210f6603c60Sopenharmony_ci    if (model != nullptr) {
211f6603c60Sopenharmony_ci        OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
212f6603c60Sopenharmony_ci
213f6603c60Sopenharmony_ci        OH_NN_UInt32Array paramIndices;
214f6603c60Sopenharmony_ci        paramIndices.data = graphArgs.paramIndices.data();
215f6603c60Sopenharmony_ci        paramIndices.size = graphArgs.paramIndices.size();
216f6603c60Sopenharmony_ci        OH_NN_UInt32Array inputIndices;
217f6603c60Sopenharmony_ci        inputIndices.data = graphArgs.inputIndices.data();
218f6603c60Sopenharmony_ci        inputIndices.size = graphArgs.inputIndices.size();
219f6603c60Sopenharmony_ci        OH_NN_UInt32Array outputIndices;
220f6603c60Sopenharmony_ci        outputIndices.data = graphArgs.outputIndices.data();
221f6603c60Sopenharmony_ci        outputIndices.size = graphArgs.outputIndices.size();
222f6603c60Sopenharmony_ci
223f6603c60Sopenharmony_ci        OH_NN_ReturnCode addOperation_ret =
224f6603c60Sopenharmony_ci            OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
225f6603c60Sopenharmony_ci        if (addOperation_ret == OH_NN_SUCCESS) {
226f6603c60Sopenharmony_ci            ret = SUCCESS;
227f6603c60Sopenharmony_ci        }
228f6603c60Sopenharmony_ci    }
229f6603c60Sopenharmony_ci    Free(model);
230f6603c60Sopenharmony_ci    napi_value result = nullptr;
231f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
232f6603c60Sopenharmony_ci
233f6603c60Sopenharmony_ci    return result;
234f6603c60Sopenharmony_ci}
235f6603c60Sopenharmony_cistatic napi_value OHNNModelAddOperationTwo(napi_env env, napi_callback_info info)
236f6603c60Sopenharmony_ci{
237f6603c60Sopenharmony_ci    int ret = FAIL;
238f6603c60Sopenharmony_ci    OH_NN_ReturnCode addOperation_ret = OH_NNModel_AddOperation(nullptr, OH_NN_OPS_ADD, nullptr, nullptr, nullptr);
239f6603c60Sopenharmony_ci    if (addOperation_ret == OH_NN_INVALID_PARAMETER) {
240f6603c60Sopenharmony_ci        ret = SUCCESS;
241f6603c60Sopenharmony_ci    }
242f6603c60Sopenharmony_ci    napi_value result = nullptr;
243f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
244f6603c60Sopenharmony_ci
245f6603c60Sopenharmony_ci    return result;
246f6603c60Sopenharmony_ci}
247f6603c60Sopenharmony_ci
248f6603c60Sopenharmony_cistatic napi_value OHNNModelSpecifyInputsAndOutputsOne(napi_env env, napi_callback_info info)
249f6603c60Sopenharmony_ci{
250f6603c60Sopenharmony_ci    int ret = FAIL;
251f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
252f6603c60Sopenharmony_ci    if (model != nullptr) {
253f6603c60Sopenharmony_ci        OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
254f6603c60Sopenharmony_ci
255f6603c60Sopenharmony_ci        OH_NN_UInt32Array inputIndices;
256f6603c60Sopenharmony_ci        inputIndices.data = graphArgs.inputIndices.data();
257f6603c60Sopenharmony_ci        inputIndices.size = graphArgs.inputIndices.size();
258f6603c60Sopenharmony_ci        OH_NN_UInt32Array outputIndices;
259f6603c60Sopenharmony_ci        outputIndices.data = graphArgs.outputIndices.data();
260f6603c60Sopenharmony_ci        outputIndices.size = graphArgs.outputIndices.size();
261f6603c60Sopenharmony_ci
262f6603c60Sopenharmony_ci        OH_NN_ReturnCode specifyInputsAndOutputs_ret =
263f6603c60Sopenharmony_ci            OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
264f6603c60Sopenharmony_ci        if (specifyInputsAndOutputs_ret == OH_NN_SUCCESS) {
265f6603c60Sopenharmony_ci            ret = SUCCESS;
266f6603c60Sopenharmony_ci        }
267f6603c60Sopenharmony_ci    }
268f6603c60Sopenharmony_ci    Free(model);
269f6603c60Sopenharmony_ci    napi_value result = nullptr;
270f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
271f6603c60Sopenharmony_ci
272f6603c60Sopenharmony_ci    return result;
273f6603c60Sopenharmony_ci}
274f6603c60Sopenharmony_cistatic napi_value OHNNModelSpecifyInputsAndOutputsTwo(napi_env env, napi_callback_info info)
275f6603c60Sopenharmony_ci{
276f6603c60Sopenharmony_ci    int ret = FAIL;
277f6603c60Sopenharmony_ci    OH_NN_ReturnCode specifyInputsAndOutputs_ret = OH_NNModel_SpecifyInputsAndOutputs(nullptr, nullptr, nullptr);
278f6603c60Sopenharmony_ci    if (specifyInputsAndOutputs_ret == OH_NN_INVALID_PARAMETER) {
279f6603c60Sopenharmony_ci        ret = SUCCESS;
280f6603c60Sopenharmony_ci    }
281f6603c60Sopenharmony_ci    napi_value result = nullptr;
282f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
283f6603c60Sopenharmony_ci
284f6603c60Sopenharmony_ci    return result;
285f6603c60Sopenharmony_ci}
286f6603c60Sopenharmony_cistatic napi_value OHNNModelFinishOne(napi_env env, napi_callback_info info)
287f6603c60Sopenharmony_ci{
288f6603c60Sopenharmony_ci    int ret = FAIL;
289f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
290f6603c60Sopenharmony_ci    if (model != nullptr) {
291f6603c60Sopenharmony_ci        OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
292f6603c60Sopenharmony_ci
293f6603c60Sopenharmony_ci        OH_NN_UInt32Array paramIndices;
294f6603c60Sopenharmony_ci        paramIndices.data = graphArgs.paramIndices.data();
295f6603c60Sopenharmony_ci        paramIndices.size = graphArgs.paramIndices.size();
296f6603c60Sopenharmony_ci        OH_NN_UInt32Array inputIndices;
297f6603c60Sopenharmony_ci        inputIndices.data = graphArgs.inputIndices.data();
298f6603c60Sopenharmony_ci        inputIndices.size = graphArgs.inputIndices.size();
299f6603c60Sopenharmony_ci        OH_NN_UInt32Array outputIndices;
300f6603c60Sopenharmony_ci        outputIndices.data = graphArgs.outputIndices.data();
301f6603c60Sopenharmony_ci        outputIndices.size = graphArgs.outputIndices.size();
302f6603c60Sopenharmony_ci
303f6603c60Sopenharmony_ci        OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
304f6603c60Sopenharmony_ci        OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
305f6603c60Sopenharmony_ci
306f6603c60Sopenharmony_ci        OH_NN_ReturnCode finish_ret = OH_NNModel_Finish(model);
307f6603c60Sopenharmony_ci        if (finish_ret == OH_NN_SUCCESS) {
308f6603c60Sopenharmony_ci            ret = SUCCESS;
309f6603c60Sopenharmony_ci        }
310f6603c60Sopenharmony_ci    }
311f6603c60Sopenharmony_ci    Free(model);
312f6603c60Sopenharmony_ci    napi_value result = nullptr;
313f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
314f6603c60Sopenharmony_ci
315f6603c60Sopenharmony_ci    return result;
316f6603c60Sopenharmony_ci}
317f6603c60Sopenharmony_cistatic napi_value OHNNModelFinishTwo(napi_env env, napi_callback_info info)
318f6603c60Sopenharmony_ci{
319f6603c60Sopenharmony_ci    int ret = FAIL;
320f6603c60Sopenharmony_ci    OH_NN_ReturnCode finish_ret = OH_NNModel_Finish(nullptr);
321f6603c60Sopenharmony_ci    if (finish_ret == OH_NN_INVALID_PARAMETER) {
322f6603c60Sopenharmony_ci        ret = SUCCESS;
323f6603c60Sopenharmony_ci    }
324f6603c60Sopenharmony_ci    napi_value result = nullptr;
325f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
326f6603c60Sopenharmony_ci
327f6603c60Sopenharmony_ci    return result;
328f6603c60Sopenharmony_ci}
329f6603c60Sopenharmony_cistatic napi_value OHNNModelDestroy(napi_env env, napi_callback_info info)
330f6603c60Sopenharmony_ci{
331f6603c60Sopenharmony_ci    int ret = FAIL;
332f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
333f6603c60Sopenharmony_ci    if (model != nullptr) {
334f6603c60Sopenharmony_ci        OH_NNModel_Destroy(&model);
335f6603c60Sopenharmony_ci        if (model == nullptr) {
336f6603c60Sopenharmony_ci            ret = SUCCESS;
337f6603c60Sopenharmony_ci        }
338f6603c60Sopenharmony_ci    }
339f6603c60Sopenharmony_ci    napi_value result = nullptr;
340f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
341f6603c60Sopenharmony_ci
342f6603c60Sopenharmony_ci    return result;
343f6603c60Sopenharmony_ci}
344f6603c60Sopenharmony_ci
345f6603c60Sopenharmony_cistatic napi_value OHNNModelGetAvailableoperationsOne(napi_env env, napi_callback_info info)
346f6603c60Sopenharmony_ci{
347f6603c60Sopenharmony_ci    int ret = FAIL;
348f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
349f6603c60Sopenharmony_ci    if (model != nullptr) {
350f6603c60Sopenharmony_ci
351f6603c60Sopenharmony_ci        OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
352f6603c60Sopenharmony_ci
353f6603c60Sopenharmony_ci        OH_NN_UInt32Array paramIndices;
354f6603c60Sopenharmony_ci        paramIndices.data = graphArgs.paramIndices.data();
355f6603c60Sopenharmony_ci        paramIndices.size = graphArgs.paramIndices.size();
356f6603c60Sopenharmony_ci        OH_NN_UInt32Array inputIndices;
357f6603c60Sopenharmony_ci        inputIndices.data = graphArgs.inputIndices.data();
358f6603c60Sopenharmony_ci        inputIndices.size = graphArgs.inputIndices.size();
359f6603c60Sopenharmony_ci        OH_NN_UInt32Array outputIndices;
360f6603c60Sopenharmony_ci        outputIndices.data = graphArgs.outputIndices.data();
361f6603c60Sopenharmony_ci        outputIndices.size = graphArgs.outputIndices.size();
362f6603c60Sopenharmony_ci
363f6603c60Sopenharmony_ci        OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
364f6603c60Sopenharmony_ci        OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
365f6603c60Sopenharmony_ci        OH_NNModel_Finish(model);
366f6603c60Sopenharmony_ci
367f6603c60Sopenharmony_ci        const bool *realSupported{nullptr};
368f6603c60Sopenharmony_ci        uint32_t opCount;
369f6603c60Sopenharmony_ci        uint32_t devicesCount{PARAM_0};
370f6603c60Sopenharmony_ci        const size_t *devicesID = nullptr;
371f6603c60Sopenharmony_ci        OH_NN_ReturnCode allDevicesId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
372f6603c60Sopenharmony_ci        if (allDevicesId_ret == OH_NN_SUCCESS) {
373f6603c60Sopenharmony_ci            if (devicesCount > PARAM_0) {
374f6603c60Sopenharmony_ci                size_t targetDevice = devicesID[PARAM_0];
375f6603c60Sopenharmony_ci                OH_NN_ReturnCode availableOperations_ret =
376f6603c60Sopenharmony_ci                    OH_NNModel_GetAvailableOperations(model, targetDevice, &realSupported, &opCount);
377f6603c60Sopenharmony_ci                if (availableOperations_ret == OH_NN_SUCCESS) {
378f6603c60Sopenharmony_ci                    ret = SUCCESS;
379f6603c60Sopenharmony_ci                }
380f6603c60Sopenharmony_ci            } else if (devicesCount == PARAM_0) {
381f6603c60Sopenharmony_ci                OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
382f6603c60Sopenharmony_ci                ret = SUCCESS;
383f6603c60Sopenharmony_ci            }
384f6603c60Sopenharmony_ci        }
385f6603c60Sopenharmony_ci    }
386f6603c60Sopenharmony_ci    Free(model);
387f6603c60Sopenharmony_ci    napi_value result = nullptr;
388f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
389f6603c60Sopenharmony_ci
390f6603c60Sopenharmony_ci    return result;
391f6603c60Sopenharmony_ci}
392f6603c60Sopenharmony_cistatic napi_value OHNNModelGetAvailableoperationsTwo(napi_env env, napi_callback_info info)
393f6603c60Sopenharmony_ci{
394f6603c60Sopenharmony_ci    int ret = FAIL;
395f6603c60Sopenharmony_ci    size_t targetDevice{PARAM_100000};
396f6603c60Sopenharmony_ci    const bool *isSupported{nullptr};
397f6603c60Sopenharmony_ci    uint32_t opCount{PARAM_0};
398f6603c60Sopenharmony_ci    OH_NN_ReturnCode availableOperations_ret =
399f6603c60Sopenharmony_ci        OH_NNModel_GetAvailableOperations(nullptr, targetDevice, &isSupported, &opCount);
400f6603c60Sopenharmony_ci    if (availableOperations_ret == OH_NN_INVALID_PARAMETER) {
401f6603c60Sopenharmony_ci        ret = SUCCESS;
402f6603c60Sopenharmony_ci    }
403f6603c60Sopenharmony_ci    napi_value result = nullptr;
404f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
405f6603c60Sopenharmony_ci
406f6603c60Sopenharmony_ci    return result;
407f6603c60Sopenharmony_ci}
408f6603c60Sopenharmony_cistatic napi_value OHNNCompilationConstructOne(napi_env env, napi_callback_info info)
409f6603c60Sopenharmony_ci{
410f6603c60Sopenharmony_ci    int ret = FAIL;
411f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
412f6603c60Sopenharmony_ci    if (model != nullptr) {
413f6603c60Sopenharmony_ci        OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
414f6603c60Sopenharmony_ci
415f6603c60Sopenharmony_ci        OH_NN_UInt32Array paramIndices;
416f6603c60Sopenharmony_ci        paramIndices.data = graphArgs.paramIndices.data();
417f6603c60Sopenharmony_ci        paramIndices.size = graphArgs.paramIndices.size();
418f6603c60Sopenharmony_ci        OH_NN_UInt32Array inputIndices;
419f6603c60Sopenharmony_ci        inputIndices.data = graphArgs.inputIndices.data();
420f6603c60Sopenharmony_ci        inputIndices.size = graphArgs.inputIndices.size();
421f6603c60Sopenharmony_ci        OH_NN_UInt32Array outputIndices;
422f6603c60Sopenharmony_ci        outputIndices.data = graphArgs.outputIndices.data();
423f6603c60Sopenharmony_ci        outputIndices.size = graphArgs.outputIndices.size();
424f6603c60Sopenharmony_ci
425f6603c60Sopenharmony_ci        OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
426f6603c60Sopenharmony_ci        OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
427f6603c60Sopenharmony_ci        OH_NN_ReturnCode finish_ret = OH_NNModel_Finish(model);
428f6603c60Sopenharmony_ci        if (finish_ret == OH_NN_SUCCESS) {
429f6603c60Sopenharmony_ci            OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
430f6603c60Sopenharmony_ci            if (compilation != nullptr) {
431f6603c60Sopenharmony_ci                ret = SUCCESS;
432f6603c60Sopenharmony_ci            }
433f6603c60Sopenharmony_ci            FreeCompilation(compilation);
434f6603c60Sopenharmony_ci        }
435f6603c60Sopenharmony_ci    }
436f6603c60Sopenharmony_ci    Free(model);
437f6603c60Sopenharmony_ci    napi_value result = nullptr;
438f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
439f6603c60Sopenharmony_ci
440f6603c60Sopenharmony_ci    return result;
441f6603c60Sopenharmony_ci}
442f6603c60Sopenharmony_cistatic napi_value OHNNCompilationConstructTwo(napi_env env, napi_callback_info info)
443f6603c60Sopenharmony_ci{
444f6603c60Sopenharmony_ci    int ret = FAIL;
445f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(nullptr);
446f6603c60Sopenharmony_ci    if (compilation == nullptr) {
447f6603c60Sopenharmony_ci        ret = SUCCESS;
448f6603c60Sopenharmony_ci    }
449f6603c60Sopenharmony_ci    napi_value result = nullptr;
450f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
451f6603c60Sopenharmony_ci
452f6603c60Sopenharmony_ci    return result;
453f6603c60Sopenharmony_ci}
454f6603c60Sopenharmony_ci
455f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetDeviceOne(napi_env env, napi_callback_info info)
456f6603c60Sopenharmony_ci{
457f6603c60Sopenharmony_ci    int ret = FAIL;
458f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
459f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
460f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
461f6603c60Sopenharmony_ci
462f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
463f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
464f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
465f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
466f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
467f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
468f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
469f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
470f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
471f6603c60Sopenharmony_ci
472f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
473f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
474f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
475f6603c60Sopenharmony_ci
476f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
477f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
478f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
479f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
480f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
481f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
482f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
483f6603c60Sopenharmony_ci        const char *name = nullptr;
484f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
485f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
486f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
487f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
488f6603c60Sopenharmony_ci        ret = SUCCESS;
489f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
490f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
491f6603c60Sopenharmony_ci        ret = SUCCESS;
492f6603c60Sopenharmony_ci    }
493f6603c60Sopenharmony_ci    FreeCompilation(compilation);
494f6603c60Sopenharmony_ci
495f6603c60Sopenharmony_ci    napi_value result = nullptr;
496f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
497f6603c60Sopenharmony_ci
498f6603c60Sopenharmony_ci    return result;
499f6603c60Sopenharmony_ci}
500f6603c60Sopenharmony_ci
501f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetDeviceTwo(napi_env env, napi_callback_info info)
502f6603c60Sopenharmony_ci{
503f6603c60Sopenharmony_ci    int ret = FAIL;
504f6603c60Sopenharmony_ci    OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(nullptr, PARAM_0);
505f6603c60Sopenharmony_ci    if (setDevice_ret == OH_NN_INVALID_PARAMETER) {
506f6603c60Sopenharmony_ci        ret = SUCCESS;
507f6603c60Sopenharmony_ci    }
508f6603c60Sopenharmony_ci    napi_value result = nullptr;
509f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
510f6603c60Sopenharmony_ci
511f6603c60Sopenharmony_ci    return result;
512f6603c60Sopenharmony_ci}
513f6603c60Sopenharmony_ci
514f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetCacheOne(napi_env env, napi_callback_info info)
515f6603c60Sopenharmony_ci{
516f6603c60Sopenharmony_ci    int ret = FAIL;
517f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
518f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
519f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
520f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
521f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
522f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
523f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
524f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
525f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
526f6603c60Sopenharmony_ci        const char *name = nullptr;
527f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
528f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetAllDevicesID Error");
529f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
530f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
531f6603c60Sopenharmony_ci        OH_NN_ReturnCode setCache_ret = OH_NNCompilation_SetCache(compilation, "./", PARAM_0);
532f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setCache_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetCache Error");
533f6603c60Sopenharmony_ci        ret = SUCCESS;
534f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
535f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
536f6603c60Sopenharmony_ci        ret = SUCCESS;
537f6603c60Sopenharmony_ci    }
538f6603c60Sopenharmony_ci    FreeCompilation(compilation);
539f6603c60Sopenharmony_ci    napi_value result = nullptr;
540f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
541f6603c60Sopenharmony_ci
542f6603c60Sopenharmony_ci    return result;
543f6603c60Sopenharmony_ci}
544f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetCacheTwo(napi_env env, napi_callback_info info)
545f6603c60Sopenharmony_ci{
546f6603c60Sopenharmony_ci    int ret = FAIL;
547f6603c60Sopenharmony_ci    OH_NN_ReturnCode setCache_ret = OH_NNCompilation_SetCache(nullptr, "./", PARAM_0);
548f6603c60Sopenharmony_ci    if (setCache_ret == OH_NN_INVALID_PARAMETER) {
549f6603c60Sopenharmony_ci        ret = SUCCESS;
550f6603c60Sopenharmony_ci    }
551f6603c60Sopenharmony_ci    napi_value result = nullptr;
552f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
553f6603c60Sopenharmony_ci
554f6603c60Sopenharmony_ci    return result;
555f6603c60Sopenharmony_ci}
556f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPerformanceModeOne(napi_env env, napi_callback_info info)
557f6603c60Sopenharmony_ci{
558f6603c60Sopenharmony_ci    int ret = FAIL;
559f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
560f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNCompilation_SetCache Error");
561f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
562f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
563f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
564f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
565f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
566f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
567f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
568f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
569f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
570f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
571f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
572f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
573f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
574f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
575f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
576f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
577f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
578f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
579f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
580f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
581f6603c60Sopenharmony_ci        const char *name = nullptr;
582f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
583f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
584f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
585f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
586f6603c60Sopenharmony_ci        OH_NN_ReturnCode performanceMode_ret = OH_NNCompilation_SetPerformanceMode(compilation, OH_NN_PERFORMANCE_NONE);
587f6603c60Sopenharmony_ci        if (performanceMode_ret == OH_NN_SUCCESS) {
588f6603c60Sopenharmony_ci            ret = SUCCESS;
589f6603c60Sopenharmony_ci        } else {
590f6603c60Sopenharmony_ci            ret = performanceMode_ret;
591f6603c60Sopenharmony_ci        }
592f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
593f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
594f6603c60Sopenharmony_ci        ret = SUCCESS;
595f6603c60Sopenharmony_ci    }
596f6603c60Sopenharmony_ci    FreeCompilation(compilation);
597f6603c60Sopenharmony_ci    napi_value result = nullptr;
598f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
599f6603c60Sopenharmony_ci    return result;
600f6603c60Sopenharmony_ci}
601f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPerformanceModeTwo(napi_env env, napi_callback_info info)
602f6603c60Sopenharmony_ci{
603f6603c60Sopenharmony_ci    int ret = FAIL;
604f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
605f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNCompilation_SetDevice Error");
606f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
607f6603c60Sopenharmony_ci
608f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
609f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
610f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
611f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
612f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
613f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
614f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
615f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
616f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
617f6603c60Sopenharmony_ci
618f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
619f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
620f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
621f6603c60Sopenharmony_ci
622f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
623f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
624f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
625f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
626f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
627f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
628f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
629f6603c60Sopenharmony_ci        const char *name = nullptr;
630f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
631f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
632f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
633f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
634f6603c60Sopenharmony_ci        OH_NN_ReturnCode performanceMode_ret = OH_NNCompilation_SetPerformanceMode(compilation, OH_NN_PERFORMANCE_LOW);
635f6603c60Sopenharmony_ci        if (performanceMode_ret == OH_NN_SUCCESS) {
636f6603c60Sopenharmony_ci            ret = SUCCESS;
637f6603c60Sopenharmony_ci        } else {
638f6603c60Sopenharmony_ci            ret = performanceMode_ret;
639f6603c60Sopenharmony_ci        }
640f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
641f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
642f6603c60Sopenharmony_ci        ret = SUCCESS;
643f6603c60Sopenharmony_ci    }
644f6603c60Sopenharmony_ci    FreeCompilation(compilation);
645f6603c60Sopenharmony_ci    napi_value result = nullptr;
646f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
647f6603c60Sopenharmony_ci    return result;
648f6603c60Sopenharmony_ci}
649f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPerformanceModeThree(napi_env env, napi_callback_info info)
650f6603c60Sopenharmony_ci{
651f6603c60Sopenharmony_ci    int ret = FAIL;
652f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
653f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
654f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
655f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
656f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
657f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
658f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
659f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
660f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
661f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
662f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
663f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
664f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
665f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
666f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
667f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
668f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
669f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
670f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
671f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
672f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
673f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
674f6603c60Sopenharmony_ci        const char *name = nullptr;
675f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
676f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
677f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
678f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
679f6603c60Sopenharmony_ci        OH_NN_ReturnCode performanceMode_ret =
680f6603c60Sopenharmony_ci            OH_NNCompilation_SetPerformanceMode(compilation, OH_NN_PERFORMANCE_MEDIUM);
681f6603c60Sopenharmony_ci        if (performanceMode_ret == OH_NN_SUCCESS) {
682f6603c60Sopenharmony_ci            ret = SUCCESS;
683f6603c60Sopenharmony_ci        } else {
684f6603c60Sopenharmony_ci            ret = performanceMode_ret;
685f6603c60Sopenharmony_ci        }
686f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
687f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
688f6603c60Sopenharmony_ci        ret = SUCCESS;
689f6603c60Sopenharmony_ci    }
690f6603c60Sopenharmony_ci    FreeCompilation(compilation);
691f6603c60Sopenharmony_ci    napi_value result = nullptr;
692f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
693f6603c60Sopenharmony_ci    return result;
694f6603c60Sopenharmony_ci}
695f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPerformanceModeFour(napi_env env, napi_callback_info info)
696f6603c60Sopenharmony_ci{
697f6603c60Sopenharmony_ci    int ret = FAIL;
698f6603c60Sopenharmony_ci    OH_NN_ReturnCode performanceMode_ret = OH_NNCompilation_SetPerformanceMode(nullptr, OH_NN_PERFORMANCE_MEDIUM);
699f6603c60Sopenharmony_ci    if (performanceMode_ret == OH_NN_INVALID_PARAMETER) {
700f6603c60Sopenharmony_ci        ret = SUCCESS;
701f6603c60Sopenharmony_ci    }
702f6603c60Sopenharmony_ci    napi_value result = nullptr;
703f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
704f6603c60Sopenharmony_ci
705f6603c60Sopenharmony_ci    return result;
706f6603c60Sopenharmony_ci}
707f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPriorityOne(napi_env env, napi_callback_info info)
708f6603c60Sopenharmony_ci{
709f6603c60Sopenharmony_ci    int ret = FAIL;
710f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
711f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
712f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
713f6603c60Sopenharmony_ci
714f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
715f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
716f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
717f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
718f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
719f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
720f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
721f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
722f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
723f6603c60Sopenharmony_ci
724f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
725f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
726f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
727f6603c60Sopenharmony_ci
728f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
729f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
730f6603c60Sopenharmony_ci
731f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
732f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
733f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
734f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
735f6603c60Sopenharmony_ci
736f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
737f6603c60Sopenharmony_ci        const char *name = nullptr;
738f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
739f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
740f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
741f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
742f6603c60Sopenharmony_ci        OH_NN_ReturnCode priority_ret = OH_NNCompilation_SetPriority(compilation, OH_NN_PRIORITY_NONE);
743f6603c60Sopenharmony_ci        NAPI_ASSERT(env, priority_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetPriority Error");
744f6603c60Sopenharmony_ci        ret = SUCCESS;
745f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
746f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
747f6603c60Sopenharmony_ci        ret = SUCCESS;
748f6603c60Sopenharmony_ci    }
749f6603c60Sopenharmony_ci    FreeCompilation(compilation);
750f6603c60Sopenharmony_ci    napi_value result = nullptr;
751f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
752f6603c60Sopenharmony_ci    return result;
753f6603c60Sopenharmony_ci}
754f6603c60Sopenharmony_cistatic napi_value OHNNCompilationSetPriorityTwo(napi_env env, napi_callback_info info)
755f6603c60Sopenharmony_ci{
756f6603c60Sopenharmony_ci    int ret = FAIL;
757f6603c60Sopenharmony_ci    OH_NN_ReturnCode priority_ret = OH_NNCompilation_SetPriority(nullptr, OH_NN_PRIORITY_MEDIUM);
758f6603c60Sopenharmony_ci    if (priority_ret == OH_NN_INVALID_PARAMETER) {
759f6603c60Sopenharmony_ci        ret = SUCCESS;
760f6603c60Sopenharmony_ci    }
761f6603c60Sopenharmony_ci    napi_value result = nullptr;
762f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
763f6603c60Sopenharmony_ci
764f6603c60Sopenharmony_ci    return result;
765f6603c60Sopenharmony_ci}
766f6603c60Sopenharmony_cistatic napi_value OHNNCompilationEnableFloat16One(napi_env env, napi_callback_info info)
767f6603c60Sopenharmony_ci{
768f6603c60Sopenharmony_ci    int ret = FAIL;
769f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
770f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
771f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
772f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
773f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
774f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
775f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
776f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
777f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
778f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
779f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
780f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
781f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
782f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
783f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
784f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
785f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
786f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
787f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
788f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
789f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
790f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
791f6603c60Sopenharmony_ci        const char *name = nullptr;
792f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
793f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
794f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
795f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
796f6603c60Sopenharmony_ci        OH_NN_ReturnCode priority_ret = OH_NNCompilation_EnableFloat16(compilation, false);
797f6603c60Sopenharmony_ci        NAPI_ASSERT(env, priority_ret == OH_NN_SUCCESS, "OH_NNCompilation_EnableFloat16 Error");
798f6603c60Sopenharmony_ci        ret = SUCCESS;
799f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
800f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
801f6603c60Sopenharmony_ci        ret = SUCCESS;
802f6603c60Sopenharmony_ci    }
803f6603c60Sopenharmony_ci    FreeCompilation(compilation);
804f6603c60Sopenharmony_ci    napi_value result = nullptr;
805f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
806f6603c60Sopenharmony_ci    return result;
807f6603c60Sopenharmony_ci}
808f6603c60Sopenharmony_cistatic napi_value OHNNCompilationEnableFloat16Two(napi_env env, napi_callback_info info)
809f6603c60Sopenharmony_ci{
810f6603c60Sopenharmony_ci    int ret = FAIL;
811f6603c60Sopenharmony_ci    OH_NN_ReturnCode priority_ret = OH_NNCompilation_EnableFloat16(nullptr, OH_NN_PRIORITY_MEDIUM);
812f6603c60Sopenharmony_ci    if (priority_ret == OH_NN_INVALID_PARAMETER) {
813f6603c60Sopenharmony_ci        ret = SUCCESS;
814f6603c60Sopenharmony_ci    }
815f6603c60Sopenharmony_ci    napi_value result = nullptr;
816f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
817f6603c60Sopenharmony_ci
818f6603c60Sopenharmony_ci    return result;
819f6603c60Sopenharmony_ci}
820f6603c60Sopenharmony_cistatic napi_value OHNNCompilationBuildOne(napi_env env, napi_callback_info info)
821f6603c60Sopenharmony_ci{
822f6603c60Sopenharmony_ci    int ret = FAIL;
823f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
824f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
825f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
826f6603c60Sopenharmony_ci
827f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
828f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
829f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
830f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
831f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
832f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
833f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
834f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
835f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
836f6603c60Sopenharmony_ci
837f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
838f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
839f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
840f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
841f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
842f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
843f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
844f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
845f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
846f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
847f6603c60Sopenharmony_ci        const char *name = nullptr;
848f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
849f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
850f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
851f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
852f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
853f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
854f6603c60Sopenharmony_ci        ret = SUCCESS;
855f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
856f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
857f6603c60Sopenharmony_ci        ret = SUCCESS;
858f6603c60Sopenharmony_ci    }
859f6603c60Sopenharmony_ci    FreeCompilation(compilation);
860f6603c60Sopenharmony_ci    napi_value result = nullptr;
861f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
862f6603c60Sopenharmony_ci    return result;
863f6603c60Sopenharmony_ci}
864f6603c60Sopenharmony_cistatic napi_value OHNNCompilationBuildTwo(napi_env env, napi_callback_info info)
865f6603c60Sopenharmony_ci{
866f6603c60Sopenharmony_ci    int ret = FAIL;
867f6603c60Sopenharmony_ci    OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(nullptr);
868f6603c60Sopenharmony_ci    if (build_ret == OH_NN_INVALID_PARAMETER) {
869f6603c60Sopenharmony_ci        ret = SUCCESS;
870f6603c60Sopenharmony_ci    }
871f6603c60Sopenharmony_ci    napi_value result = nullptr;
872f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
873f6603c60Sopenharmony_ci
874f6603c60Sopenharmony_ci    return result;
875f6603c60Sopenharmony_ci}
876f6603c60Sopenharmony_cistatic napi_value OHNNCompilationDestroy(napi_env env, napi_callback_info info)
877f6603c60Sopenharmony_ci{
878f6603c60Sopenharmony_ci    int ret = FAIL;
879f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
880f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
881f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
882f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
883f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
884f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
885f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
886f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
887f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
888f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
889f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
890f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
891f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
892f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
893f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
894f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
895f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
896f6603c60Sopenharmony_ci    OH_NNCompilation_Destroy(&compilation);
897f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation == nullptr, "OH_NNCompilation_Destroy Error");
898f6603c60Sopenharmony_ci    ret = SUCCESS;
899f6603c60Sopenharmony_ci    napi_value result = nullptr;
900f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
901f6603c60Sopenharmony_ci    return result;
902f6603c60Sopenharmony_ci}
903f6603c60Sopenharmony_cistatic napi_value OHNNExecutorConstructOne(napi_env env, napi_callback_info info)
904f6603c60Sopenharmony_ci{
905f6603c60Sopenharmony_ci    int ret = FAIL;
906f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
907f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
908f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
909f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
910f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
911f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
912f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
913f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
914f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
915f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
916f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
917f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
918f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
919f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
920f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
921f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
922f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
923f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
924f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
925f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
926f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
927f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
928f6603c60Sopenharmony_ci        const char *name = nullptr;
929f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
930f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
931f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
932f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
933f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
934f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
935f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
936f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
937f6603c60Sopenharmony_ci        ret = SUCCESS;
938f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
939f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
940f6603c60Sopenharmony_ci        ret = SUCCESS;
941f6603c60Sopenharmony_ci    }
942f6603c60Sopenharmony_ci    FreeCompilation(compilation);
943f6603c60Sopenharmony_ci    Free(model);
944f6603c60Sopenharmony_ci    napi_value result = nullptr;
945f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
946f6603c60Sopenharmony_ci    return result;
947f6603c60Sopenharmony_ci}
948f6603c60Sopenharmony_cistatic napi_value OHNNExecutorConstructTwo(napi_env env, napi_callback_info info)
949f6603c60Sopenharmony_ci{
950f6603c60Sopenharmony_ci    int ret = FAIL;
951f6603c60Sopenharmony_ci    OH_NNExecutor *executor = OH_NNExecutor_Construct(nullptr);
952f6603c60Sopenharmony_ci    if (executor == nullptr) {
953f6603c60Sopenharmony_ci        ret = SUCCESS;
954f6603c60Sopenharmony_ci    }
955f6603c60Sopenharmony_ci    napi_value result = nullptr;
956f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
957f6603c60Sopenharmony_ci
958f6603c60Sopenharmony_ci    return result;
959f6603c60Sopenharmony_ci}
960f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetInputOne(napi_env env, napi_callback_info info)
961f6603c60Sopenharmony_ci{
962f6603c60Sopenharmony_ci    int ret = FAIL;
963f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
964f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNExecutor_Construct Error");
965f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
966f6603c60Sopenharmony_ci
967f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
968f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
969f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
970f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
971f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
972f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
973f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
974f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
975f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
976f6603c60Sopenharmony_ci
977f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
978f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
979f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
980f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
981f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
982f6603c60Sopenharmony_ci
983f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
984f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
985f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
986f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
987f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
988f6603c60Sopenharmony_ci        const char *name = nullptr;
989f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
990f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
991f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
992f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
993f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
994f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
995f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
996f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
997f6603c60Sopenharmony_ci        uint32_t inputIndex = PARAM_0;
998f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
999f6603c60Sopenharmony_ci        auto quantParam = operandTem.quantParam;
1000f6603c60Sopenharmony_ci        OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
1001f6603c60Sopenharmony_ci                                quantParam, operandTem.type};
1002f6603c60Sopenharmony_ci        OH_NN_ReturnCode setInput =
1003f6603c60Sopenharmony_ci            OH_NNExecutor_SetInput(executor, inputIndex, &operand, operandTem.data, operandTem.length);
1004f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setInput == OH_NN_SUCCESS, "OH_NNExecutor_SetInput Error");
1005f6603c60Sopenharmony_ci        ret = SUCCESS;
1006f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1007f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1008f6603c60Sopenharmony_ci        ret = SUCCESS;
1009f6603c60Sopenharmony_ci    }
1010f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1011f6603c60Sopenharmony_ci    Free(model);
1012f6603c60Sopenharmony_ci    napi_value result = nullptr;
1013f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1014f6603c60Sopenharmony_ci    return result;
1015f6603c60Sopenharmony_ci}
1016f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetInputTwo(napi_env env, napi_callback_info info)
1017f6603c60Sopenharmony_ci{
1018f6603c60Sopenharmony_ci    int ret = FAIL;
1019f6603c60Sopenharmony_ci    OH_NN_ReturnCode setInput = OH_NNExecutor_SetInput(nullptr, PARAM_0, nullptr, nullptr, PARAM_0);
1020f6603c60Sopenharmony_ci    if (setInput == OH_NN_INVALID_PARAMETER) {
1021f6603c60Sopenharmony_ci        ret = SUCCESS;
1022f6603c60Sopenharmony_ci    }
1023f6603c60Sopenharmony_ci    napi_value result = nullptr;
1024f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1025f6603c60Sopenharmony_ci
1026f6603c60Sopenharmony_ci    return result;
1027f6603c60Sopenharmony_ci}
1028f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetOutputOne(napi_env env, napi_callback_info info)
1029f6603c60Sopenharmony_ci{
1030f6603c60Sopenharmony_ci    int ret = FAIL;
1031f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1032f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1033f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1034f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1035f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1036f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1037f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1038f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1039f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1040f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1041f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1042f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1043f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1044f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1045f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1046f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1047f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1048f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1049f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1050f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1051f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1052f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1053f6603c60Sopenharmony_ci        const char *name = nullptr;
1054f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1055f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1056f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1057f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1058f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1059f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1060f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1061f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1062f6603c60Sopenharmony_ci        uint32_t inputIndex = PARAM_0;
1063f6603c60Sopenharmony_ci        uint32_t outputIndex = PARAM_0;
1064f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1065f6603c60Sopenharmony_ci        auto quantParam = operandTem.quantParam;
1066f6603c60Sopenharmony_ci        OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
1067f6603c60Sopenharmony_ci                                quantParam, operandTem.type};
1068f6603c60Sopenharmony_ci        OH_NN_ReturnCode setInput_ret =
1069f6603c60Sopenharmony_ci            OH_NNExecutor_SetInput(executor, inputIndex, &operand, operandTem.data, operandTem.length);
1070f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setInput_ret == OH_NN_SUCCESS, "OH_NNExecutor_SetInput Error");
1071f6603c60Sopenharmony_ci        inputIndex += 1;
1072f6603c60Sopenharmony_ci        const OHNNOperandTest &operandOut = graphArgs.operands[PARAM_3];
1073f6603c60Sopenharmony_ci        OH_NN_ReturnCode setOutput_ret =
1074f6603c60Sopenharmony_ci            OH_NNExecutor_SetOutput(executor, outputIndex, operandOut.data, operandOut.length);
1075f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setOutput_ret == OH_NN_SUCCESS, "OH_NNExecutor_SetOutput Error");
1076f6603c60Sopenharmony_ci        ret = SUCCESS;
1077f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1078f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1079f6603c60Sopenharmony_ci        ret = SUCCESS;
1080f6603c60Sopenharmony_ci    }
1081f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1082f6603c60Sopenharmony_ci    Free(model);
1083f6603c60Sopenharmony_ci    napi_value result = nullptr;
1084f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1085f6603c60Sopenharmony_ci
1086f6603c60Sopenharmony_ci    return result;
1087f6603c60Sopenharmony_ci}
1088f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetOutputTwo(napi_env env, napi_callback_info info)
1089f6603c60Sopenharmony_ci{
1090f6603c60Sopenharmony_ci    int ret = FAIL;
1091f6603c60Sopenharmony_ci    OH_NN_ReturnCode setOutput_ret = OH_NNExecutor_SetOutput(nullptr, PARAM_0, nullptr, PARAM_0);
1092f6603c60Sopenharmony_ci    if (setOutput_ret == OH_NN_INVALID_PARAMETER) {
1093f6603c60Sopenharmony_ci        ret = SUCCESS;
1094f6603c60Sopenharmony_ci    }
1095f6603c60Sopenharmony_ci    napi_value result = nullptr;
1096f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1097f6603c60Sopenharmony_ci
1098f6603c60Sopenharmony_ci    return result;
1099f6603c60Sopenharmony_ci}
1100f6603c60Sopenharmony_cistatic napi_value OHNNExecutorGetOutputShapeOne(napi_env env, napi_callback_info info)
1101f6603c60Sopenharmony_ci{
1102f6603c60Sopenharmony_ci    int ret = FAIL;
1103f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1104f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1105f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1106f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1107f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1108f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1109f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1110f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1111f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1112f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1113f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1114f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1115f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1116f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1117f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1118f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1119f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1120f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1121f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1122f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1123f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1124f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1125f6603c60Sopenharmony_ci        const char *name = nullptr;
1126f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1127f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1128f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1129f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1130f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1131f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1132f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1133f6603c60Sopenharmony_ci        uint32_t inputIndex = PARAM_0;
1134f6603c60Sopenharmony_ci        uint32_t outputIndex = PARAM_0;
1135f6603c60Sopenharmony_ci        for (auto i = PARAM_0; i < graphArgs.operands.size(); i++) {
1136f6603c60Sopenharmony_ci            const OHNNOperandTest &operandTem = graphArgs.operands[i];
1137f6603c60Sopenharmony_ci            auto quantParam = operandTem.quantParam;
1138f6603c60Sopenharmony_ci            OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
1139f6603c60Sopenharmony_ci                                    quantParam, operandTem.type};
1140f6603c60Sopenharmony_ci            if (std::find(graphArgs.inputIndices.begin(), graphArgs.inputIndices.end(), i) !=
1141f6603c60Sopenharmony_ci                graphArgs.inputIndices.end()) {
1142f6603c60Sopenharmony_ci                OH_NNExecutor_SetInput(executor, inputIndex, &operand, operandTem.data, operandTem.length);
1143f6603c60Sopenharmony_ci                inputIndex += 1;
1144f6603c60Sopenharmony_ci            } else if (std::find(graphArgs.outputIndices.begin(), graphArgs.outputIndices.end(), i) !=
1145f6603c60Sopenharmony_ci                       graphArgs.outputIndices.end()) {
1146f6603c60Sopenharmony_ci                OH_NNExecutor_SetOutput(executor, outputIndex, operandTem.data, operandTem.length);
1147f6603c60Sopenharmony_ci                outputIndex += 1;
1148f6603c60Sopenharmony_ci            }
1149f6603c60Sopenharmony_ci        }
1150f6603c60Sopenharmony_ci        OH_NN_ReturnCode run_ret = OH_NNExecutor_Run(executor);
1151f6603c60Sopenharmony_ci        NAPI_ASSERT(env, run_ret == OH_NN_SUCCESS, "OH_NNExecutor_Run Error");
1152f6603c60Sopenharmony_ci        int32_t *outputDimensions = nullptr;
1153f6603c60Sopenharmony_ci        uint32_t outputDimensionCount{PARAM_0};
1154f6603c60Sopenharmony_ci        uint32_t addOutputIndex = {PARAM_0};
1155f6603c60Sopenharmony_ci        OH_NN_ReturnCode getOutput_ret =
1156f6603c60Sopenharmony_ci            OH_NNExecutor_GetOutputShape(executor, addOutputIndex, &outputDimensions, &outputDimensionCount);
1157f6603c60Sopenharmony_ci        NAPI_ASSERT(env, getOutput_ret == OH_NN_SUCCESS, "OH_NNExecutor_GetOutputShape Error");
1158f6603c60Sopenharmony_ci        ret = SUCCESS;
1159f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1160f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1161f6603c60Sopenharmony_ci        ret = SUCCESS;
1162f6603c60Sopenharmony_ci    }
1163f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1164f6603c60Sopenharmony_ci    Free(model);
1165f6603c60Sopenharmony_ci    napi_value result = nullptr;
1166f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1167f6603c60Sopenharmony_ci    return result;
1168f6603c60Sopenharmony_ci}
1169f6603c60Sopenharmony_cistatic napi_value OHNNExecutorGetOutputShapeTwo(napi_env env, napi_callback_info info)
1170f6603c60Sopenharmony_ci{
1171f6603c60Sopenharmony_ci    int ret = FAIL;
1172f6603c60Sopenharmony_ci    int32_t *outputDimensions = nullptr;
1173f6603c60Sopenharmony_ci    uint32_t outputDimensionCount{PARAM_0};
1174f6603c60Sopenharmony_ci    uint32_t addOutputIndex = {PARAM_0};
1175f6603c60Sopenharmony_ci    OH_NN_ReturnCode getOutput_ret =
1176f6603c60Sopenharmony_ci        OH_NNExecutor_GetOutputShape(nullptr, addOutputIndex, &outputDimensions, &outputDimensionCount);
1177f6603c60Sopenharmony_ci    if (getOutput_ret == OH_NN_INVALID_PARAMETER) {
1178f6603c60Sopenharmony_ci        ret = SUCCESS;
1179f6603c60Sopenharmony_ci    }
1180f6603c60Sopenharmony_ci    napi_value result = nullptr;
1181f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1182f6603c60Sopenharmony_ci
1183f6603c60Sopenharmony_ci    return result;
1184f6603c60Sopenharmony_ci}
1185f6603c60Sopenharmony_cistatic napi_value OHNNExecutorRunOne(napi_env env, napi_callback_info info)
1186f6603c60Sopenharmony_ci{
1187f6603c60Sopenharmony_ci    int ret = FAIL;
1188f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1189f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1190f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1191f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1192f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1193f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1194f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1195f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1196f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1197f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1198f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1199f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1200f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1201f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1202f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1203f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1204f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1205f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1206f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1207f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1208f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1209f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1210f6603c60Sopenharmony_ci        const char *name = nullptr;
1211f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1212f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1213f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1214f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1215f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1216f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1217f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1218f6603c60Sopenharmony_ci        uint32_t inputIndex = PARAM_0;
1219f6603c60Sopenharmony_ci        uint32_t outputIndex = PARAM_0;
1220f6603c60Sopenharmony_ci        for (auto i = 0; i < graphArgs.operands.size(); i++) {
1221f6603c60Sopenharmony_ci            const OHNNOperandTest &operandTem = graphArgs.operands[i];
1222f6603c60Sopenharmony_ci            auto quantParam = operandTem.quantParam;
1223f6603c60Sopenharmony_ci            OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
1224f6603c60Sopenharmony_ci                                    quantParam, operandTem.type};
1225f6603c60Sopenharmony_ci            if (std::find(graphArgs.inputIndices.begin(), graphArgs.inputIndices.end(), i) !=
1226f6603c60Sopenharmony_ci                graphArgs.inputIndices.end()) {
1227f6603c60Sopenharmony_ci                OH_NNExecutor_SetInput(executor, inputIndex, &operand, operandTem.data, operandTem.length);
1228f6603c60Sopenharmony_ci                inputIndex += 1;
1229f6603c60Sopenharmony_ci            } else if (std::find(graphArgs.outputIndices.begin(), graphArgs.outputIndices.end(), i) !=
1230f6603c60Sopenharmony_ci                       graphArgs.outputIndices.end()) {
1231f6603c60Sopenharmony_ci                OH_NNExecutor_SetOutput(executor, outputIndex, operandTem.data, operandTem.length);
1232f6603c60Sopenharmony_ci                outputIndex += 1;
1233f6603c60Sopenharmony_ci            }
1234f6603c60Sopenharmony_ci        }
1235f6603c60Sopenharmony_ci        OH_NN_ReturnCode run_ret = OH_NNExecutor_Run(executor);
1236f6603c60Sopenharmony_ci        NAPI_ASSERT(env, run_ret == OH_NN_SUCCESS, "OH_NNExecutor_Run Error");
1237f6603c60Sopenharmony_ci        ret = SUCCESS;
1238f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1239f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1240f6603c60Sopenharmony_ci        ret = SUCCESS;
1241f6603c60Sopenharmony_ci    }
1242f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1243f6603c60Sopenharmony_ci    Free(model);
1244f6603c60Sopenharmony_ci    napi_value result = nullptr;
1245f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1246f6603c60Sopenharmony_ci    return result;
1247f6603c60Sopenharmony_ci}
1248f6603c60Sopenharmony_cistatic napi_value OHNNExecutorRunTwo(napi_env env, napi_callback_info info)
1249f6603c60Sopenharmony_ci{
1250f6603c60Sopenharmony_ci    int ret = FAIL;
1251f6603c60Sopenharmony_ci    OH_NN_ReturnCode run_ret = OH_NNExecutor_Run(nullptr);
1252f6603c60Sopenharmony_ci    if (run_ret == OH_NN_INVALID_PARAMETER) {
1253f6603c60Sopenharmony_ci        ret = SUCCESS;
1254f6603c60Sopenharmony_ci    }
1255f6603c60Sopenharmony_ci    napi_value result = nullptr;
1256f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1257f6603c60Sopenharmony_ci
1258f6603c60Sopenharmony_ci    return result;
1259f6603c60Sopenharmony_ci}
1260f6603c60Sopenharmony_cistatic napi_value OHNNExecutorAllocateInputMemoryOne(napi_env env, napi_callback_info info)
1261f6603c60Sopenharmony_ci{
1262f6603c60Sopenharmony_ci    int ret = FAIL;
1263f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1264f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1265f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1266f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1267f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1268f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1269f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1270f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1271f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1272f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1273f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1274f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1275f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1276f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1277f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1278f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1279f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1280f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1281f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1282f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1283f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1284f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1285f6603c60Sopenharmony_ci        const char *name = nullptr;
1286f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1287f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1288f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1289f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1290f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1291f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1292f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1293f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1294f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1295f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1296f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory != nullptr, "OH_NNExecutor_AllocateInputMemory Error");
1297f6603c60Sopenharmony_ci        ret = SUCCESS;
1298f6603c60Sopenharmony_ci        OH_NNExecutor_DestroyInputMemory(executor, PARAM_0, &inputMemory);
1299f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1300f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1301f6603c60Sopenharmony_ci        ret = SUCCESS;
1302f6603c60Sopenharmony_ci    }
1303f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1304f6603c60Sopenharmony_ci    Free(model);
1305f6603c60Sopenharmony_ci    napi_value result = nullptr;
1306f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1307f6603c60Sopenharmony_ci    return result;
1308f6603c60Sopenharmony_ci}
1309f6603c60Sopenharmony_cistatic napi_value OHNNExecutorAllocateInputMemoryTwo(napi_env env, napi_callback_info info)
1310f6603c60Sopenharmony_ci{
1311f6603c60Sopenharmony_ci    int ret = FAIL;
1312f6603c60Sopenharmony_ci    OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(nullptr, PARAM_0, PARAM_0);
1313f6603c60Sopenharmony_ci    if (inputMemory == nullptr) {
1314f6603c60Sopenharmony_ci        ret = SUCCESS;
1315f6603c60Sopenharmony_ci    }
1316f6603c60Sopenharmony_ci    napi_value result = nullptr;
1317f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1318f6603c60Sopenharmony_ci
1319f6603c60Sopenharmony_ci    return result;
1320f6603c60Sopenharmony_ci}
1321f6603c60Sopenharmony_cistatic napi_value OHNNExecutorAllocateOutputMemoryOne(napi_env env, napi_callback_info info)
1322f6603c60Sopenharmony_ci{
1323f6603c60Sopenharmony_ci    int ret = FAIL;
1324f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1325f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1326f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1327f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1328f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1329f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1330f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1331f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1332f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1333f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1334f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1335f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1336f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1337f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1338f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1339f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1340f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1341f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1342f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1343f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1344f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1345f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1346f6603c60Sopenharmony_ci        const char *name = nullptr;
1347f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1348f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1349f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1350f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1351f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1352f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1353f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1354f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1355f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1356f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1357f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory != nullptr, "OH_NNExecutor_AllocateInputMemory Error");
1358f6603c60Sopenharmony_ci        OH_NN_Memory *outputMemory = OH_NNExecutor_AllocateOutputMemory(executor, PARAM_0, operandTem.length);
1359f6603c60Sopenharmony_ci        NAPI_ASSERT(env, outputMemory != nullptr, "OH_NNExecutor_AllocateOutputMemory Error");
1360f6603c60Sopenharmony_ci        ret = SUCCESS;
1361f6603c60Sopenharmony_ci        OH_NNExecutor_DestroyOutputMemory(executor, PARAM_0, &outputMemory);
1362f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1363f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1364f6603c60Sopenharmony_ci        ret = SUCCESS;
1365f6603c60Sopenharmony_ci    }
1366f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1367f6603c60Sopenharmony_ci    Free(model);
1368f6603c60Sopenharmony_ci    napi_value result = nullptr;
1369f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1370f6603c60Sopenharmony_ci    return result;
1371f6603c60Sopenharmony_ci}
1372f6603c60Sopenharmony_cistatic napi_value OHNNExecutorAllocateOutputMemoryTwo(napi_env env, napi_callback_info info)
1373f6603c60Sopenharmony_ci{
1374f6603c60Sopenharmony_ci    int ret = FAIL;
1375f6603c60Sopenharmony_ci    OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateOutputMemory(nullptr, PARAM_0, PARAM_0);
1376f6603c60Sopenharmony_ci    if (inputMemory == nullptr) {
1377f6603c60Sopenharmony_ci        ret = SUCCESS;
1378f6603c60Sopenharmony_ci    }
1379f6603c60Sopenharmony_ci    napi_value result = nullptr;
1380f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1381f6603c60Sopenharmony_ci
1382f6603c60Sopenharmony_ci    return result;
1383f6603c60Sopenharmony_ci}
1384f6603c60Sopenharmony_cistatic napi_value OHNNExecutorDestroyInputMemory(napi_env env, napi_callback_info info)
1385f6603c60Sopenharmony_ci{
1386f6603c60Sopenharmony_ci    int ret = FAIL;
1387f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1388f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1389f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1390f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1391f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1392f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1393f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1394f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1395f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1396f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1397f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1398f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1399f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1400f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1401f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1402f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1403f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1404f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1405f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1406f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1407f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1408f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1409f6603c60Sopenharmony_ci        const char *name = nullptr;
1410f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1411f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1412f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1413f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1414f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1415f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1416f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1417f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1418f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1419f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1420f6603c60Sopenharmony_ci        OH_NNExecutor_DestroyInputMemory(executor, PARAM_0, &inputMemory);
1421f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory == nullptr, "OH_NNExecutor_DestroyInputMemory Error");
1422f6603c60Sopenharmony_ci        ret = SUCCESS;
1423f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1424f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1425f6603c60Sopenharmony_ci        ret = SUCCESS;
1426f6603c60Sopenharmony_ci    }
1427f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1428f6603c60Sopenharmony_ci    Free(model);
1429f6603c60Sopenharmony_ci    napi_value result = nullptr;
1430f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1431f6603c60Sopenharmony_ci    return result;
1432f6603c60Sopenharmony_ci}
1433f6603c60Sopenharmony_cistatic napi_value OHNNExecutorDestroyOutputMemory(napi_env env, napi_callback_info info)
1434f6603c60Sopenharmony_ci{
1435f6603c60Sopenharmony_ci    int ret = FAIL;
1436f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1437f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1438f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1439f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1440f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1441f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1442f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1443f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1444f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1445f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1446f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1447f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1448f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1449f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1450f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1451f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1452f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1453f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1454f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1455f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1456f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1457f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1458f6603c60Sopenharmony_ci        const char *name = nullptr;
1459f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1460f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1461f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1462f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1463f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1464f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1465f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1466f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1467f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1468f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1469f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory != nullptr, "OH_NNExecutor_AllocateInputMemory Error");
1470f6603c60Sopenharmony_ci        OH_NN_Memory *outputMemory = OH_NNExecutor_AllocateOutputMemory(executor, PARAM_0, operandTem.length);
1471f6603c60Sopenharmony_ci        OH_NNExecutor_DestroyOutputMemory(executor, PARAM_0, &outputMemory);
1472f6603c60Sopenharmony_ci        NAPI_ASSERT(env, outputMemory == nullptr, "OH_NNExecutor_DestroyOutputMemory Error");
1473f6603c60Sopenharmony_ci        ret = SUCCESS;
1474f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1475f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1476f6603c60Sopenharmony_ci        ret = SUCCESS;
1477f6603c60Sopenharmony_ci    }
1478f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1479f6603c60Sopenharmony_ci    Free(model);
1480f6603c60Sopenharmony_ci    napi_value result = nullptr;
1481f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1482f6603c60Sopenharmony_ci    return result;
1483f6603c60Sopenharmony_ci}
1484f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetInputWithMemoryOne(napi_env env, napi_callback_info info)
1485f6603c60Sopenharmony_ci{
1486f6603c60Sopenharmony_ci    int ret = FAIL;
1487f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1488f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1489f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1490f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1491f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1492f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1493f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1494f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1495f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1496f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1497f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1498f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1499f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1500f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1501f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1502f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1503f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1504f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1505f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1506f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1507f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1508f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1509f6603c60Sopenharmony_ci        const char *name = nullptr;
1510f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1511f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1512f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1513f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1514f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1515f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1516f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1517f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1518f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1519f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1520f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory != nullptr, "OH_NNExecutor_AllocateInputMemory Error");
1521f6603c60Sopenharmony_ci        auto quantParam = operandTem.quantParam;
1522f6603c60Sopenharmony_ci        OH_NN_Tensor operand = {operandTem.dataType, (uint32_t)operandTem.shape.size(), operandTem.shape.data(),
1523f6603c60Sopenharmony_ci                                quantParam, operandTem.type};
1524f6603c60Sopenharmony_ci        OH_NN_ReturnCode setInputMemory_ret =
1525f6603c60Sopenharmony_ci            OH_NNExecutor_SetInputWithMemory(executor, PARAM_0, &operand, inputMemory);
1526f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setInputMemory_ret == OH_NN_SUCCESS, "OH_NNExecutor_SetInputWithMemory Error");
1527f6603c60Sopenharmony_ci        ret = SUCCESS;
1528f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1529f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1530f6603c60Sopenharmony_ci        ret = SUCCESS;
1531f6603c60Sopenharmony_ci    }
1532f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1533f6603c60Sopenharmony_ci    Free(model);
1534f6603c60Sopenharmony_ci    napi_value result = nullptr;
1535f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1536f6603c60Sopenharmony_ci
1537f6603c60Sopenharmony_ci    return result;
1538f6603c60Sopenharmony_ci}
1539f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetInputWithMemoryTwo(napi_env env, napi_callback_info info)
1540f6603c60Sopenharmony_ci{
1541f6603c60Sopenharmony_ci    int ret = FAIL;
1542f6603c60Sopenharmony_ci    OH_NN_ReturnCode setInputMemory_ret = OH_NNExecutor_SetInputWithMemory(nullptr, PARAM_0, nullptr, nullptr);
1543f6603c60Sopenharmony_ci    if (setInputMemory_ret == OH_NN_INVALID_PARAMETER) {
1544f6603c60Sopenharmony_ci        ret = SUCCESS;
1545f6603c60Sopenharmony_ci    }
1546f6603c60Sopenharmony_ci    napi_value result = nullptr;
1547f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1548f6603c60Sopenharmony_ci
1549f6603c60Sopenharmony_ci    return result;
1550f6603c60Sopenharmony_ci}
1551f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetOutputWithMemoryOne(napi_env env, napi_callback_info info)
1552f6603c60Sopenharmony_ci{
1553f6603c60Sopenharmony_ci    int ret = FAIL;
1554f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1555f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1556f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1557f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1558f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1559f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1560f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1561f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1562f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1563f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1564f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1565f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1566f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1567f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1568f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1569f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1570f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1571f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1572f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1573f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1574f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1575f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1576f6603c60Sopenharmony_ci        const char *name = nullptr;
1577f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1578f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1579f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1580f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1581f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1582f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1583f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1584f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor != nullptr, "OH_NNExecutor_Construct Error");
1585f6603c60Sopenharmony_ci        const OHNNOperandTest &operandTem = graphArgs.operands[PARAM_0];
1586f6603c60Sopenharmony_ci        OH_NN_Memory *inputMemory = OH_NNExecutor_AllocateInputMemory(executor, PARAM_0, operandTem.length);
1587f6603c60Sopenharmony_ci        NAPI_ASSERT(env, inputMemory != nullptr, "OH_NNExecutor_AllocateInputMemory Error");
1588f6603c60Sopenharmony_ci        OH_NN_Memory *outputMemory = OH_NNExecutor_AllocateOutputMemory(executor, PARAM_0, operandTem.length);
1589f6603c60Sopenharmony_ci        NAPI_ASSERT(env, outputMemory != nullptr, "OH_NNExecutor_AllocateOutputMemory Error");
1590f6603c60Sopenharmony_ci        OH_NN_ReturnCode setOutputMempry_ret = OH_NNExecutor_SetOutputWithMemory(executor, PARAM_0, outputMemory);
1591f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setOutputMempry_ret == OH_NN_SUCCESS, "OH_NNExecutor_SetOutputWithMemory Error");
1592f6603c60Sopenharmony_ci        ret = SUCCESS;
1593f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1594f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1595f6603c60Sopenharmony_ci        ret = SUCCESS;
1596f6603c60Sopenharmony_ci    }
1597f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1598f6603c60Sopenharmony_ci    Free(model);
1599f6603c60Sopenharmony_ci    napi_value result = nullptr;
1600f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1601f6603c60Sopenharmony_ci    return result;
1602f6603c60Sopenharmony_ci}
1603f6603c60Sopenharmony_cistatic napi_value OHNNExecutorSetOutputWithMemoryTwo(napi_env env, napi_callback_info info)
1604f6603c60Sopenharmony_ci{
1605f6603c60Sopenharmony_ci    int ret = FAIL;
1606f6603c60Sopenharmony_ci    OH_NN_ReturnCode setOutputMempry_ret = OH_NNExecutor_SetOutputWithMemory(nullptr, 0, nullptr);
1607f6603c60Sopenharmony_ci    if (setOutputMempry_ret == OH_NN_INVALID_PARAMETER) {
1608f6603c60Sopenharmony_ci        ret = SUCCESS;
1609f6603c60Sopenharmony_ci    }
1610f6603c60Sopenharmony_ci    napi_value result = nullptr;
1611f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1612f6603c60Sopenharmony_ci
1613f6603c60Sopenharmony_ci    return result;
1614f6603c60Sopenharmony_ci}
1615f6603c60Sopenharmony_cistatic napi_value OHNNExecutorDestroy(napi_env env, napi_callback_info info)
1616f6603c60Sopenharmony_ci{
1617f6603c60Sopenharmony_ci    int ret = FAIL;
1618f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1619f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1620f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1621f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1622f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1623f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1624f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1625f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1626f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1627f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1628f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1629f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1630f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1631f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1632f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1633f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1634f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1635f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1636f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1637f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1638f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1639f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1640f6603c60Sopenharmony_ci        const char *name = nullptr;
1641f6603c60Sopenharmony_ci        OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1642f6603c60Sopenharmony_ci        NAPI_ASSERT(env, name != nullptr, "OH_NNDevice_GetName Error");
1643f6603c60Sopenharmony_ci        OH_NN_ReturnCode setDevice_ret = OH_NNCompilation_SetDevice(compilation, devicesID[PARAM_0]);
1644f6603c60Sopenharmony_ci        NAPI_ASSERT(env, setDevice_ret == OH_NN_SUCCESS, "OH_NNCompilation_SetDevice Error");
1645f6603c60Sopenharmony_ci        OH_NN_ReturnCode build_ret = OH_NNCompilation_Build(compilation);
1646f6603c60Sopenharmony_ci        NAPI_ASSERT(env, build_ret == OH_NN_SUCCESS, "OH_NNCompilation_Build Error");
1647f6603c60Sopenharmony_ci        OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
1648f6603c60Sopenharmony_ci        OH_NNExecutor_Destroy(&executor);
1649f6603c60Sopenharmony_ci        NAPI_ASSERT(env, executor == nullptr, "OH_NNExecutor_Destroy Error");
1650f6603c60Sopenharmony_ci        ret = SUCCESS;
1651f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1652f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1653f6603c60Sopenharmony_ci        ret = SUCCESS;
1654f6603c60Sopenharmony_ci    }
1655f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1656f6603c60Sopenharmony_ci    Free(model);
1657f6603c60Sopenharmony_ci    napi_value result = nullptr;
1658f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1659f6603c60Sopenharmony_ci    return result;
1660f6603c60Sopenharmony_ci}
1661f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetAllDevicesIDOne(napi_env env, napi_callback_info info)
1662f6603c60Sopenharmony_ci{
1663f6603c60Sopenharmony_ci    int ret = FAIL;
1664f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1665f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1666f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1667f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1668f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1669f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1670f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1671f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1672f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1673f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1674f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1675f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1676f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1677f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1678f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1679f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1680f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1681f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1682f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1683f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1684f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1685f6603c60Sopenharmony_ci    ret = SUCCESS;
1686f6603c60Sopenharmony_ci    Free(model);
1687f6603c60Sopenharmony_ci    napi_value result = nullptr;
1688f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1689f6603c60Sopenharmony_ci    return result;
1690f6603c60Sopenharmony_ci}
1691f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetAllDevicesIDTwo(napi_env env, napi_callback_info info)
1692f6603c60Sopenharmony_ci{
1693f6603c60Sopenharmony_ci    int ret = FAIL;
1694f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(nullptr, PARAM_0);
1695f6603c60Sopenharmony_ci    if (allDeviceId_ret == OH_NN_INVALID_PARAMETER) {
1696f6603c60Sopenharmony_ci        ret = SUCCESS;
1697f6603c60Sopenharmony_ci    }
1698f6603c60Sopenharmony_ci    napi_value result = nullptr;
1699f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1700f6603c60Sopenharmony_ci
1701f6603c60Sopenharmony_ci    return result;
1702f6603c60Sopenharmony_ci}
1703f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetNameOne(napi_env env, napi_callback_info info)
1704f6603c60Sopenharmony_ci{
1705f6603c60Sopenharmony_ci    int ret = FAIL;
1706f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1707f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1708f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1709f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1710f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1711f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1712f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1713f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1714f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1715f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1716f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1717f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1718f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1719f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1720f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1721f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1722f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1723f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1724f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1725f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1726f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1727f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1728f6603c60Sopenharmony_ci        const char *name = nullptr;
1729f6603c60Sopenharmony_ci        OH_NN_ReturnCode getDeviceName_ret = OH_NNDevice_GetName(devicesID[PARAM_0], &name);
1730f6603c60Sopenharmony_ci        NAPI_ASSERT(env, getDeviceName_ret == OH_NN_SUCCESS, "OH_NNDevice_GetName Error");
1731f6603c60Sopenharmony_ci        ret = SUCCESS;
1732f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1733f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1734f6603c60Sopenharmony_ci        ret = SUCCESS;
1735f6603c60Sopenharmony_ci    }
1736f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1737f6603c60Sopenharmony_ci    Free(model);
1738f6603c60Sopenharmony_ci    napi_value result = nullptr;
1739f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1740f6603c60Sopenharmony_ci    return result;
1741f6603c60Sopenharmony_ci}
1742f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetNameTwo(napi_env env, napi_callback_info info)
1743f6603c60Sopenharmony_ci{
1744f6603c60Sopenharmony_ci    int ret = FAIL;
1745f6603c60Sopenharmony_ci    const char *name = nullptr;
1746f6603c60Sopenharmony_ci    OH_NN_ReturnCode getDeviceName_ret = OH_NNDevice_GetName(PARAM_1, &name);
1747f6603c60Sopenharmony_ci    if (getDeviceName_ret == OH_NN_FAILED) {
1748f6603c60Sopenharmony_ci        ret = SUCCESS;
1749f6603c60Sopenharmony_ci    }
1750f6603c60Sopenharmony_ci    napi_value result = nullptr;
1751f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1752f6603c60Sopenharmony_ci
1753f6603c60Sopenharmony_ci    return result;
1754f6603c60Sopenharmony_ci}
1755f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetTypeOne(napi_env env, napi_callback_info info)
1756f6603c60Sopenharmony_ci{
1757f6603c60Sopenharmony_ci    int ret = FAIL;
1758f6603c60Sopenharmony_ci    OH_NNModel *model = OH_NNModel_Construct();
1759f6603c60Sopenharmony_ci    NAPI_ASSERT(env, model != nullptr, "OH_NNModel_Construct Error");
1760f6603c60Sopenharmony_ci    OHNNGraphArgs graphArgs = addTesorAndSetTensor(model);
1761f6603c60Sopenharmony_ci    OH_NN_UInt32Array paramIndices;
1762f6603c60Sopenharmony_ci    paramIndices.data = graphArgs.paramIndices.data();
1763f6603c60Sopenharmony_ci    paramIndices.size = graphArgs.paramIndices.size();
1764f6603c60Sopenharmony_ci    OH_NN_UInt32Array inputIndices;
1765f6603c60Sopenharmony_ci    inputIndices.data = graphArgs.inputIndices.data();
1766f6603c60Sopenharmony_ci    inputIndices.size = graphArgs.inputIndices.size();
1767f6603c60Sopenharmony_ci    OH_NN_UInt32Array outputIndices;
1768f6603c60Sopenharmony_ci    outputIndices.data = graphArgs.outputIndices.data();
1769f6603c60Sopenharmony_ci    outputIndices.size = graphArgs.outputIndices.size();
1770f6603c60Sopenharmony_ci    OH_NNModel_AddOperation(model, OH_NN_OPS_ADD, &paramIndices, &inputIndices, &outputIndices);
1771f6603c60Sopenharmony_ci    OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices);
1772f6603c60Sopenharmony_ci    OH_NNModel_Finish(model);
1773f6603c60Sopenharmony_ci    OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
1774f6603c60Sopenharmony_ci    NAPI_ASSERT(env, compilation != nullptr, "OH_NNCompilation_Construct Error");
1775f6603c60Sopenharmony_ci    const size_t *devicesID{nullptr};
1776f6603c60Sopenharmony_ci    uint32_t devicesCount{PARAM_0};
1777f6603c60Sopenharmony_ci    OH_NN_ReturnCode allDeviceId_ret = OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount);
1778f6603c60Sopenharmony_ci    NAPI_ASSERT(env, allDeviceId_ret == OH_NN_SUCCESS, "OH_NNDevice_GetAllDevicesID Error");
1779f6603c60Sopenharmony_ci    if (devicesCount > PARAM_0) {
1780f6603c60Sopenharmony_ci        OH_NN_DeviceType type{OH_NN_OTHERS};
1781f6603c60Sopenharmony_ci        OH_NN_ReturnCode getDeviceName_ret = OH_NNDevice_GetType(devicesID[PARAM_0], &type);
1782f6603c60Sopenharmony_ci        NAPI_ASSERT(env, getDeviceName_ret == OH_NN_SUCCESS, "OH_NNDevice_GetType Error");
1783f6603c60Sopenharmony_ci        ret = SUCCESS;
1784f6603c60Sopenharmony_ci    } else if (devicesCount == PARAM_0) {
1785f6603c60Sopenharmony_ci        OH_LOG_Print(LOG_APP, LOG_INFO, 1, "devicesCount is 0", "no devices");
1786f6603c60Sopenharmony_ci        ret = SUCCESS;
1787f6603c60Sopenharmony_ci    }
1788f6603c60Sopenharmony_ci    FreeCompilation(compilation);
1789f6603c60Sopenharmony_ci    Free(model);
1790f6603c60Sopenharmony_ci    napi_value result = nullptr;
1791f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1792f6603c60Sopenharmony_ci    return result;
1793f6603c60Sopenharmony_ci}
1794f6603c60Sopenharmony_cistatic napi_value OHNNDeviceGetTypeTwo(napi_env env, napi_callback_info info)
1795f6603c60Sopenharmony_ci{
1796f6603c60Sopenharmony_ci    int ret = FAIL;
1797f6603c60Sopenharmony_ci    OH_NN_DeviceType type{OH_NN_OTHERS};
1798f6603c60Sopenharmony_ci    OH_NN_ReturnCode getDeviceName_ret = OH_NNDevice_GetType(MPARAM_1, &type);
1799f6603c60Sopenharmony_ci    if (getDeviceName_ret == OH_NN_INVALID_PARAMETER) {
1800f6603c60Sopenharmony_ci        ret = SUCCESS;
1801f6603c60Sopenharmony_ci    }
1802f6603c60Sopenharmony_ci    napi_value result = nullptr;
1803f6603c60Sopenharmony_ci    napi_create_int32(env, ret, &result);
1804f6603c60Sopenharmony_ci
1805f6603c60Sopenharmony_ci    return result;
1806f6603c60Sopenharmony_ci}
1807f6603c60Sopenharmony_ciEXTERN_C_START
1808f6603c60Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports)
1809f6603c60Sopenharmony_ci{
1810f6603c60Sopenharmony_ci    napi_property_descriptor desc[] = {
1811f6603c60Sopenharmony_ci        {"oHNNModelConstructOne", nullptr, OHNNModelConstructOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1812f6603c60Sopenharmony_ci        {"oHNNModelConstructTwo", nullptr, OHNNModelConstructTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1813f6603c60Sopenharmony_ci        {"oHNNModelAddTensorOne", nullptr, OHNNModelAddTensorOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1814f6603c60Sopenharmony_ci        {"oHNNModelAddTensorTwo", nullptr, OHNNModelAddTensorTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1815f6603c60Sopenharmony_ci        {"oHNNModelSetTensorDataOne", nullptr, OHNNModelSetTensorDataOne, nullptr, nullptr, nullptr, napi_default,
1816f6603c60Sopenharmony_ci         nullptr},
1817f6603c60Sopenharmony_ci        {"oHNNModelSetTensorDataTwo", nullptr, OHNNModelSetTensorDataTwo, nullptr, nullptr, nullptr, napi_default,
1818f6603c60Sopenharmony_ci         nullptr},
1819f6603c60Sopenharmony_ci        {"oHNNModelAddOperationOne", nullptr, OHNNModelAddOperationOne, nullptr, nullptr, nullptr, napi_default,
1820f6603c60Sopenharmony_ci         nullptr},
1821f6603c60Sopenharmony_ci        {"oHNNModelAddOperationTwo", nullptr, OHNNModelAddOperationTwo, nullptr, nullptr, nullptr, napi_default,
1822f6603c60Sopenharmony_ci         nullptr},
1823f6603c60Sopenharmony_ci        {"oHNNModelSpecifyInputsAndOutputsOne", nullptr, OHNNModelSpecifyInputsAndOutputsOne, nullptr, nullptr, nullptr,
1824f6603c60Sopenharmony_ci         napi_default, nullptr},
1825f6603c60Sopenharmony_ci        {"oHNNModelSpecifyInputsAndOutputsTwo", nullptr, OHNNModelSpecifyInputsAndOutputsTwo, nullptr, nullptr, nullptr,
1826f6603c60Sopenharmony_ci         napi_default, nullptr},
1827f6603c60Sopenharmony_ci        {"oHNNModelFinishOne", nullptr, OHNNModelFinishOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1828f6603c60Sopenharmony_ci        {"oHNNModelFinishTwo", nullptr, OHNNModelFinishTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1829f6603c60Sopenharmony_ci        {"oHNNModelDestroy", nullptr, OHNNModelDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
1830f6603c60Sopenharmony_ci        {"oHNNModelGetAvailableoperationsOne", nullptr, OHNNModelGetAvailableoperationsOne, nullptr, nullptr, nullptr,
1831f6603c60Sopenharmony_ci         napi_default, nullptr},
1832f6603c60Sopenharmony_ci        {"oHNNModelGetAvailableoperationsTwo", nullptr, OHNNModelGetAvailableoperationsTwo, nullptr, nullptr, nullptr,
1833f6603c60Sopenharmony_ci         napi_default, nullptr},
1834f6603c60Sopenharmony_ci        {"oHNNCompilationConstructOne", nullptr, OHNNCompilationConstructOne, nullptr, nullptr, nullptr, napi_default,
1835f6603c60Sopenharmony_ci         nullptr},
1836f6603c60Sopenharmony_ci        {"oHNNCompilationConstructTwo", nullptr, OHNNCompilationConstructTwo, nullptr, nullptr, nullptr, napi_default,
1837f6603c60Sopenharmony_ci         nullptr},
1838f6603c60Sopenharmony_ci        {"oHNNCompilationSetDeviceOne", nullptr, OHNNCompilationSetDeviceOne, nullptr, nullptr, nullptr, napi_default,
1839f6603c60Sopenharmony_ci         nullptr},
1840f6603c60Sopenharmony_ci        {"oHNNCompilationSetDeviceTwo", nullptr, OHNNCompilationSetDeviceTwo, nullptr, nullptr, nullptr, napi_default,
1841f6603c60Sopenharmony_ci         nullptr},
1842f6603c60Sopenharmony_ci        {"oHNNCompilationSetCacheOne", nullptr, OHNNCompilationSetCacheOne, nullptr, nullptr, nullptr, napi_default,
1843f6603c60Sopenharmony_ci         nullptr},
1844f6603c60Sopenharmony_ci        {"oHNNCompilationSetCacheTwo", nullptr, OHNNCompilationSetCacheTwo, nullptr, nullptr, nullptr, napi_default,
1845f6603c60Sopenharmony_ci         nullptr},
1846f6603c60Sopenharmony_ci        {"oHNNCompilationSetPerformanceModeOne", nullptr, OHNNCompilationSetPerformanceModeOne, nullptr, nullptr,
1847f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1848f6603c60Sopenharmony_ci        {"oHNNCompilationSetPerformanceModeTwo", nullptr, OHNNCompilationSetPerformanceModeTwo, nullptr, nullptr,
1849f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1850f6603c60Sopenharmony_ci        {"oHNNCompilationSetPerformanceModeThree", nullptr, OHNNCompilationSetPerformanceModeThree, nullptr, nullptr,
1851f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1852f6603c60Sopenharmony_ci        {"oHNNCompilationSetPerformanceModeFour", nullptr, OHNNCompilationSetPerformanceModeFour, nullptr, nullptr,
1853f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1854f6603c60Sopenharmony_ci        {"oHNNCompilationSetPriorityOne", nullptr, OHNNCompilationSetPriorityOne, nullptr, nullptr, nullptr,
1855f6603c60Sopenharmony_ci         napi_default, nullptr},
1856f6603c60Sopenharmony_ci        {"oHNNCompilationSetPriorityTwo", nullptr, OHNNCompilationSetPriorityTwo, nullptr, nullptr, nullptr,
1857f6603c60Sopenharmony_ci         napi_default, nullptr},
1858f6603c60Sopenharmony_ci        {"oHNNCompilationEnableFloat16One", nullptr, OHNNCompilationEnableFloat16One, nullptr, nullptr, nullptr,
1859f6603c60Sopenharmony_ci         napi_default, nullptr},
1860f6603c60Sopenharmony_ci        {"oHNNCompilationEnableFloat16Two", nullptr, OHNNCompilationEnableFloat16Two, nullptr, nullptr, nullptr,
1861f6603c60Sopenharmony_ci         napi_default, nullptr},
1862f6603c60Sopenharmony_ci        {"oHNNCompilationBuildOne", nullptr, OHNNCompilationBuildOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1863f6603c60Sopenharmony_ci        {"oHNNCompilationBuildTwo", nullptr, OHNNCompilationBuildTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1864f6603c60Sopenharmony_ci        {"oHNNCompilationDestroy", nullptr, OHNNCompilationDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
1865f6603c60Sopenharmony_ci        {"oHNNExecutorConstructOne", nullptr, OHNNExecutorConstructOne, nullptr, nullptr, nullptr, napi_default,
1866f6603c60Sopenharmony_ci         nullptr},
1867f6603c60Sopenharmony_ci        {"oHNNExecutorConstructTwo", nullptr, OHNNExecutorConstructTwo, nullptr, nullptr, nullptr, napi_default,
1868f6603c60Sopenharmony_ci         nullptr},
1869f6603c60Sopenharmony_ci        {"oHNNExecutorSetInputOne", nullptr, OHNNExecutorSetInputOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1870f6603c60Sopenharmony_ci        {"oHNNExecutorSetInputTwo", nullptr, OHNNExecutorSetInputTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1871f6603c60Sopenharmony_ci        {"oHNNExecutorSetOutputOne", nullptr, OHNNExecutorSetOutputOne, nullptr, nullptr, nullptr, napi_default,
1872f6603c60Sopenharmony_ci         nullptr},
1873f6603c60Sopenharmony_ci        {"oHNNExecutorSetOutputTwo", nullptr, OHNNExecutorSetOutputTwo, nullptr, nullptr, nullptr, napi_default,
1874f6603c60Sopenharmony_ci         nullptr},
1875f6603c60Sopenharmony_ci        {"oHNNExecutorGetOutputShapeOne", nullptr, OHNNExecutorGetOutputShapeOne, nullptr, nullptr, nullptr,
1876f6603c60Sopenharmony_ci         napi_default, nullptr},
1877f6603c60Sopenharmony_ci        {"oHNNExecutorGetOutputShapeTwo", nullptr, OHNNExecutorGetOutputShapeTwo, nullptr, nullptr, nullptr,
1878f6603c60Sopenharmony_ci         napi_default, nullptr},
1879f6603c60Sopenharmony_ci        {"oHNNExecutorRunOne", nullptr, OHNNExecutorRunOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1880f6603c60Sopenharmony_ci        {"oHNNExecutorRunTwo", nullptr, OHNNExecutorRunTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1881f6603c60Sopenharmony_ci        {"oHNNExecutorAllocateInputMemoryOne", nullptr, OHNNExecutorAllocateInputMemoryOne, nullptr, nullptr, nullptr,
1882f6603c60Sopenharmony_ci         napi_default, nullptr},
1883f6603c60Sopenharmony_ci        {"oHNNExecutorAllocateInputMemoryTwo", nullptr, OHNNExecutorAllocateInputMemoryTwo, nullptr, nullptr, nullptr,
1884f6603c60Sopenharmony_ci         napi_default, nullptr},
1885f6603c60Sopenharmony_ci        {"oHNNExecutorAllocateOutputMemoryOne", nullptr, OHNNExecutorAllocateOutputMemoryOne, nullptr, nullptr, nullptr,
1886f6603c60Sopenharmony_ci         napi_default, nullptr},
1887f6603c60Sopenharmony_ci        {"oHNNExecutorAllocateOutputMemoryTwo", nullptr, OHNNExecutorAllocateOutputMemoryTwo, nullptr, nullptr, nullptr,
1888f6603c60Sopenharmony_ci         napi_default, nullptr},
1889f6603c60Sopenharmony_ci        {"oHNNExecutorDestroyInputMemory", nullptr, OHNNExecutorDestroyInputMemory, nullptr, nullptr, nullptr,
1890f6603c60Sopenharmony_ci         napi_default, nullptr},
1891f6603c60Sopenharmony_ci        {"oHNNExecutorDestroyOutputMemory", nullptr, OHNNExecutorDestroyOutputMemory, nullptr, nullptr, nullptr,
1892f6603c60Sopenharmony_ci         napi_default, nullptr},
1893f6603c60Sopenharmony_ci        {"oHNNExecutorSetInputWithMemoryOne", nullptr, OHNNExecutorSetInputWithMemoryOne, nullptr, nullptr, nullptr,
1894f6603c60Sopenharmony_ci         napi_default, nullptr},
1895f6603c60Sopenharmony_ci        {"oHNNExecutorSetInputWithMemoryTwo", nullptr, OHNNExecutorSetInputWithMemoryTwo, nullptr, nullptr, nullptr,
1896f6603c60Sopenharmony_ci         napi_default, nullptr},
1897f6603c60Sopenharmony_ci        {"oHNNExecutorSetOutputWithMemoryOne", nullptr, OHNNExecutorSetOutputWithMemoryOne, nullptr, nullptr, nullptr,
1898f6603c60Sopenharmony_ci         napi_default, nullptr},
1899f6603c60Sopenharmony_ci        {"oHNNExecutorSetOutputWithMemoryTwo", nullptr, OHNNExecutorSetOutputWithMemoryTwo, nullptr, nullptr, nullptr,
1900f6603c60Sopenharmony_ci         napi_default, nullptr},
1901f6603c60Sopenharmony_ci        {"oHNNExecutorDestroy", nullptr, OHNNExecutorDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
1902f6603c60Sopenharmony_ci        {"oHNNDeviceGetAllDevicesIDOne", nullptr, OHNNDeviceGetAllDevicesIDOne, nullptr, nullptr, nullptr, napi_default,
1903f6603c60Sopenharmony_ci         nullptr},
1904f6603c60Sopenharmony_ci        {"oHNNDeviceGetAllDevicesIDTwo", nullptr, OHNNDeviceGetAllDevicesIDTwo, nullptr, nullptr, nullptr, napi_default,
1905f6603c60Sopenharmony_ci         nullptr},
1906f6603c60Sopenharmony_ci        {"oHNNDeviceGetNameOne", nullptr, OHNNDeviceGetNameOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1907f6603c60Sopenharmony_ci        {"oHNNDeviceGetNameTwo", nullptr, OHNNDeviceGetNameTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1908f6603c60Sopenharmony_ci        {"oHNNDeviceGetTypeOne", nullptr, OHNNDeviceGetTypeOne, nullptr, nullptr, nullptr, napi_default, nullptr},
1909f6603c60Sopenharmony_ci        {"oHNNDeviceGetTypeTwo", nullptr, OHNNDeviceGetTypeTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
1910f6603c60Sopenharmony_ci    };
1911f6603c60Sopenharmony_ci    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1912f6603c60Sopenharmony_ci    return exports;
1913f6603c60Sopenharmony_ci}
1914f6603c60Sopenharmony_ciEXTERN_C_END
1915f6603c60Sopenharmony_ci
1916f6603c60Sopenharmony_cistatic napi_module demoModule = {
1917f6603c60Sopenharmony_ci    .nm_version = 1,
1918f6603c60Sopenharmony_ci    .nm_flags = 0,
1919f6603c60Sopenharmony_ci    .nm_filename = nullptr,
1920f6603c60Sopenharmony_ci    .nm_register_func = Init,
1921f6603c60Sopenharmony_ci    .nm_modname = "nnrt",
1922f6603c60Sopenharmony_ci    .nm_priv = ((void *)0),
1923f6603c60Sopenharmony_ci    .reserved = {0},
1924f6603c60Sopenharmony_ci};
1925f6603c60Sopenharmony_ci
1926f6603c60Sopenharmony_ciextern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
1927