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 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_AIDL_SAMPLE_DRIVER_AIDL_PARTIAL_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_AIDL_SAMPLE_DRIVER_AIDL_PARTIAL_H 19 20 #include <android-base/logging.h> 21 22 #include <memory> 23 #include <thread> 24 #include <vector> 25 26 #include "SampleDriverAidl.h" 27 28 namespace android { 29 namespace nn { 30 namespace sample_driver_aidl { 31 32 // A base class for sample drivers that support only a subset of NNAPI 33 // operations. Classes of such drivers should inherit from this class and 34 // implement getSupportedOperationsImpl function which is used for filtering out 35 // unsupported ops. 36 class SampleDriverPartial : public SampleDriver { 37 public: 38 SampleDriverPartial(const char* name, const IOperationResolver* operationResolver = 39 BuiltinOperationResolver::get()) SampleDriver(name,operationResolver)40 : SampleDriver(name, operationResolver) {} 41 ndk::ScopedAStatus getSupportedOperations(const aidl_hal::Model& model, 42 std::vector<bool>* supportedOperations) override; 43 ndk::ScopedAStatus prepareModel( 44 const aidl_hal::Model& model, aidl_hal::ExecutionPreference preference, 45 aidl_hal::Priority priority, int64_t deadline, 46 const std::vector<ndk::ScopedFileDescriptor>& modelCache, 47 const std::vector<ndk::ScopedFileDescriptor>& dataCache, 48 const std::vector<uint8_t>& token, 49 const std::shared_ptr<aidl_hal::IPreparedModelCallback>& callback) override; 50 51 protected: 52 // Given a valid NNAPI Model returns a boolean vector that indicates which 53 // ops in the model are supported by a driver. 54 virtual std::vector<bool> getSupportedOperationsImpl(const Model& model) const = 0; 55 }; 56 57 } // namespace sample_driver_aidl 58 } // namespace nn 59 } // namespace android 60 61 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_AIDL_SAMPLE_DRIVER_AIDL_PARTIAL_H 62