ronnie
2022-10-23 d7a691c7a2527f2da145355a40a0402c95c67aac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef ANDROID_ML_NN_COMMON_VALIDATEHAL_H
#define ANDROID_ML_NN_COMMON_VALIDATEHAL_H
 
#include "HalInterfaces.h"
 
namespace android {
namespace nn {
 
enum class HalVersion : int32_t {
    UNKNOWN,
    V1_0,
    V1_1,
    V1_2,
    LATEST = V1_2,
};
 
// Verifies that the model is valid, i.e. it is consistent, takes
// only acceptable values, the constants don't extend outside the memory
// regions they are part of, etc.
// IMPORTANT: This function cannot validate that OEM operation and operands
// are correctly defined, as these are specific to each implementation.
// Each driver should do their own validation of OEM types.
template <class T_Model>
bool validateModel(const T_Model& model);
 
// Verfies that the request for the given model is valid.
// IMPORTANT: This function cannot validate that OEM operation and operands
// are correctly defined, as these are specific to each implementation.
// Each driver should do their own validation of OEM types.
template <class T_Model>
bool validateRequest(const Request& request, const T_Model& model);
 
// Verfies that the execution preference is valid.
bool validateExecutionPreference(ExecutionPreference preference);
 
bool validOperationType(V1_0::OperationType operation);
bool validOperationType(V1_1::OperationType operation);
bool validOperationType(V1_2::OperationType operation);
 
bool validOperandType(V1_0::OperandType operand);
bool validOperandType(V1_2::OperandType operand);
 
// Verfies that the memory pool is valid in the specified HAL version.
bool validatePool(const hidl_memory& pool, HalVersion ver = HalVersion::LATEST);
 
}  // namespace nn
}  // namespace android
 
#endif  // ANDROID_ML_NN_COMMON_VALIDATEHAL_H