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 <aidl/android/hardware/neuralnetworks/BnBuffer.h> 20 #include <aidl/android/hardware/neuralnetworks/BnDevice.h> 21 #include <aidl/android/hardware/neuralnetworks/BnPreparedModel.h> 22 #include <android/binder_auto_utils.h> 23 24 #include <memory> 25 #include <string> 26 #include <vector> 27 28 namespace aidl::android::hardware::neuralnetworks { 29 30 class InvalidDevice : public BnDevice { 31 public: 32 static std::shared_ptr<InvalidDevice> create(); 33 34 InvalidDevice(Capabilities capabilities, const NumberOfCacheFiles& numberOfCacheFiles, 35 std::vector<Extension> extensions, DeviceType deviceType, 36 std::string versionString); 37 38 ndk::ScopedAStatus allocate(const BufferDesc& desc, 39 const std::vector<IPreparedModelParcel>& preparedModels, 40 const std::vector<BufferRole>& inputRoles, 41 const std::vector<BufferRole>& outputRoles, 42 DeviceBuffer* deviceBuffer) override; 43 ndk::ScopedAStatus getCapabilities(Capabilities* capabilities) override; 44 ndk::ScopedAStatus getNumberOfCacheFilesNeeded(NumberOfCacheFiles* numberOfCacheFiles) override; 45 ndk::ScopedAStatus getSupportedExtensions(std::vector<Extension>* extensions) override; 46 ndk::ScopedAStatus getSupportedOperations(const Model& model, 47 std::vector<bool>* supportedOperations) override; 48 ndk::ScopedAStatus getType(DeviceType* deviceType) override; 49 ndk::ScopedAStatus getVersionString(std::string* versionString) override; 50 ndk::ScopedAStatus prepareModel( 51 const Model& model, ExecutionPreference preference, Priority priority, int64_t deadline, 52 const std::vector<ndk::ScopedFileDescriptor>& modelCache, 53 const std::vector<ndk::ScopedFileDescriptor>& dataCache, 54 const std::vector<uint8_t>& token, 55 const std::shared_ptr<IPreparedModelCallback>& callback) override; 56 ndk::ScopedAStatus prepareModelWithConfig( 57 const Model& model, const PrepareModelConfig& config, 58 const std::shared_ptr<IPreparedModelCallback>& callback) override; 59 ndk::ScopedAStatus prepareModelFromCache( 60 int64_t deadline, const std::vector<ndk::ScopedFileDescriptor>& modelCache, 61 const std::vector<ndk::ScopedFileDescriptor>& dataCache, 62 const std::vector<uint8_t>& token, 63 const std::shared_ptr<IPreparedModelCallback>& callback) override; 64 65 private: 66 const Capabilities kCapabilities; 67 const NumberOfCacheFiles kNumberOfCacheFiles; 68 const std::vector<Extension> kExtensions; 69 const DeviceType kDeviceType; 70 const std::string kVersionString; 71 }; 72 73 } // namespace aidl::android::hardware::neuralnetworks 74