1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "validation.h"
17 
18 namespace OHOS {
19 namespace NeuralNetworkRuntime {
20 namespace Validation {
ValidateTensorDataType(OH_NN_DataType dataType)21 bool ValidateTensorDataType(OH_NN_DataType dataType)
22 {
23     if (dataType >= OH_NN_UNKNOWN && dataType <= OH_NN_FLOAT64) {
24         return true;
25     }
26     return false;
27 }
28 
ValidateTensorFormat(OH_NN_Format format)29 bool ValidateTensorFormat(OH_NN_Format format)
30 {
31     if ((format >= OH_NN_FORMAT_NONE) && (format <= OH_NN_FORMAT_ND)) {
32         return true;
33     }
34     return false;
35 }
36 
ValidatePerformanceMode(OH_NN_PerformanceMode performanceMode)37 bool ValidatePerformanceMode(OH_NN_PerformanceMode performanceMode)
38 {
39     if ((performanceMode >= OH_NN_PERFORMANCE_NONE) && (performanceMode <= OH_NN_PERFORMANCE_EXTREME)) {
40         return true;
41     }
42     return false;
43 }
44 
ValidatePriority(OH_NN_Priority priority)45 bool ValidatePriority(OH_NN_Priority priority)
46 {
47     if ((priority >= OH_NN_PRIORITY_NONE) && (priority <= OH_NN_PRIORITY_HIGH)) {
48         return true;
49     }
50     return false;
51 }
52 
ValidateFuseType(OH_NN_FuseType fuseType)53 bool ValidateFuseType(OH_NN_FuseType fuseType)
54 {
55     if ((fuseType >= OH_NN_FUSED_NONE) && (fuseType <= OH_NN_FUSED_RELU6)) {
56         return true;
57     }
58     return false;
59 }
60 
ValidateTensorType(OH_NN_TensorType nnTensorType)61 bool ValidateTensorType(OH_NN_TensorType nnTensorType)
62 {
63     if ((nnTensorType >= OH_NN_TENSOR) && (nnTensorType <= OH_NN_REDUCE_L2_COEFF)) {
64         return true;
65     }
66     return false;
67 }
68 } // namespace Validation
69 } // namespace NeuralNetworkRuntime
70 } // namespace OHOS
71