1 /* 2 * Copyright (C) 2021 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 #pragma once 18 19 #include <memory> 20 #include <utility> 21 #include <vector> 22 23 #include <aidl/android/hardware/neuralnetworks/ErrorStatus.h> 24 #include <aidl/android/hardware/neuralnetworks/Memory.h> 25 #include <aidl/android/hardware/neuralnetworks/Model.h> 26 27 #include "SupportLibrary.h" 28 #include "SupportLibraryWrapper.h" 29 30 namespace aidl::android::hardware::neuralnetworks { 31 32 struct ShimConvertedModel { 33 std::vector<std::unique_ptr<::android::nn::sl_wrapper::Memory>> memory; 34 std::vector<::android::nn::sl_wrapper::Model> models; 35 }; 36 37 bool isValid(const neuralnetworks::Model& model); 38 39 /** 40 * Convert HAL model into Model ready to be consumed by SL Driver. 41 8 42 * @param nnapi NNAPI SL Driver implementation 43 * @param model HAL NNAPI Model 44 * @param copiedOperandValues If model requires it (contains CONSTANT_COPY operands larger 45 * then 128 bytes), this vector will be used to hold a copy of 46 * model operand values. Must be non-null. 47 * @param errorStatus Output error status in case of failure. 48 * @return ShimConvertedModel with all converted memories and models. 49 * 50 */ 51 std::optional<ShimConvertedModel> convertFromHAL(const NnApiSupportLibrary* nnapi, 52 const neuralnetworks::Model& model, 53 std::vector<uint8_t>* copiedOperandValues, 54 ErrorStatus* errorStatus); 55 std::unique_ptr<::android::nn::sl_wrapper::Memory> convertFromHAL( 56 const NnApiSupportLibrary* nnapi, const neuralnetworks::Memory& pool); 57 58 } // namespace aidl::android::hardware::neuralnetworks 59