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.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 is %p but the length is %zu", data, size);
30 return OH_NN_INVALID_PARAMETER;
31 }
32 return OH_NN_SUCCESS;
33 }
34
35 bool ValidateTensorType(OH_NN_TensorType nnTensorType);
36 bool ValidateTensorDataType(OH_NN_DataType dataType);
37 bool ValidatePerformanceMode(OH_NN_PerformanceMode performanceMode);
38 bool ValidatePriority(OH_NN_Priority priority);
39 bool ValidateFuseType(OH_NN_FuseType fuseType);
40 bool ValidatePadMode(int8_t padMode);
41 } // namespace Validation
42 } // NeuralNetworkRuntime
43 } // namespace OHOS
44
45 #endif // NEURAL_NETWORK_RUNTIME_VALIDATION_H
46