• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef OHOS_MINDSPORE_TEST_MODEL_UTILS_H
16 #define OHOS_MINDSPORE_TEST_MODEL_UTILS_H
17 
18 #include "gtest/gtest.h"
19 #include "include/c_api/context_c.h"
20 #include "include/c_api/model_c.h"
21 #include "include/c_api/types_c.h"
22 #include "include/c_api/status_c.h"
23 #include "include/c_api/data_type_c.h"
24 #include "include/c_api/tensor_c.h"
25 #include "include/c_api/format_c.h"
26 
27 // function before callback
28 bool PrintBeforeCallback(const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs,
29                          const OH_AI_CallBackParam kernelInfo);
30 // function after callback
31 bool PrintAfterCallback(const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs,
32                         const OH_AI_CallBackParam kernelInfo);
33 // add cpu device info
34 void AddContextDeviceCPU(OH_AI_ContextHandle context);
35 bool IsNPU();
36 // add nnrt device info
37 void AddContextDeviceNNRT(OH_AI_ContextHandle context);
38 // fill data to inputs tensor
39 void FillInputsData(OH_AI_TensorHandleArray inputs, std::string modelName, bool isTranspose);
40 // compare result after predict
41 void CompareResult(OH_AI_TensorHandleArray outputs, std::string modelName, float atol = 0.01, float rtol = 0.01);
42 // model build and predict
43 void ModelPredict(OH_AI_ModelHandle model, OH_AI_ContextHandle context, std::string modelName,
44                   OH_AI_ShapeInfo shapeInfos, bool buildByGraph, bool isTranspose, bool isCallback);
45 void ModelTrain(OH_AI_ModelHandle model, OH_AI_ContextHandle context, std::string modelName,
46                 OH_AI_ShapeInfo shapeInfos, bool buildByGraph, bool isTranspose, bool isCallback);
47 
48 #endif //OHOS_MINDSPORE_TEST_MODEL_UTILS_H
49