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