1 /* 2 * Copyright (C) 2019 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_SAMPLE_DRIVER_PARTIAL_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_SAMPLE_DRIVER_PARTIAL_H 19 20 #include <HalInterfaces.h> 21 #include <Utils.h> 22 #include <android-base/logging.h> 23 24 #include <thread> 25 #include <vector> 26 27 #include "SampleDriver.h" 28 29 namespace android { 30 namespace nn { 31 namespace sample_driver { 32 33 // A base class for sample drivers that support only a subset of NNAPI 34 // operations. Classes of such drivers should inherit from this class and 35 // implement getSupportedOperationsImpl function which is used for filtering out 36 // unsupported ops. 37 class SampleDriverPartial : public SampleDriver { 38 public: 39 SampleDriverPartial(const char* name, const IOperationResolver* operationResolver = 40 BuiltinOperationResolver::get()) SampleDriver(name,operationResolver)41 : SampleDriver(name, operationResolver) {} 42 hardware::Return<void> getSupportedOperations_1_3(const V1_3::Model& model, 43 getSupportedOperations_1_3_cb cb) override; 44 hardware::Return<V1_3::ErrorStatus> prepareModel_1_3( 45 const V1_3::Model& model, V1_1::ExecutionPreference preference, V1_3::Priority priority, 46 const V1_3::OptionalTimePoint& deadline, 47 const hardware::hidl_vec<hardware::hidl_handle>& modelCache, 48 const hardware::hidl_vec<hardware::hidl_handle>& dataCache, const HalCacheToken& token, 49 const sp<V1_3::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 V1_3::Model& model) const = 0; 55 }; 56 57 } // namespace sample_driver 58 } // namespace nn 59 } // namespace android 60 61 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_SAMPLE_DRIVER_PARTIAL_H 62