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 #ifndef NEURAL_NETWORK_RUNTIME_VALIDATION_H
17 #define NEURAL_NETWORK_RUNTIME_VALIDATION_H
18 
19 #include "common/log.h"
20 #include "interfaces/kits/c/neural_network_runtime/neural_network_runtime_type.h"
21 
22 namespace OHOS {
23 namespace NeuralNetworkRuntime {
24 namespace Validation {
25 template<typename T>
ValidateArray(const T * data,size_t size)26 OH_NN_ReturnCode ValidateArray(const T* data, size_t size)
27 {
28     if ((data != nullptr) != (size > 0)) {
29         LOGE("ValidateArray failed, data should passed a valid pointer when size is larger than 0, "
30             "otherwise, data should be nullptr when size is 0.");
31         return OH_NN_INVALID_PARAMETER;
32     }
33     return OH_NN_SUCCESS;
34 }
35 
36 bool ValidateTensorType(OH_NN_TensorType nnTensorType);
37 bool ValidateTensorDataType(OH_NN_DataType dataType);
38 bool ValidateTensorFormat(OH_NN_Format format);
39 bool ValidatePerformanceMode(OH_NN_PerformanceMode performanceMode);
40 bool ValidatePriority(OH_NN_Priority priority);
41 bool ValidateFuseType(OH_NN_FuseType fuseType);
42 } // namespace Validation
43 } // NeuralNetworkRuntime
44 } // namespace OHOS
45 
46 #endif // NEURAL_NETWORK_RUNTIME_VALIDATION_H
47