1 /* 2 * Copyright (C) 2020 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_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_INVALID_DEVICE_H 18 #define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_INVALID_DEVICE_H 19 20 #include <nnapi/IBuffer.h> 21 #include <nnapi/IDevice.h> 22 #include <nnapi/IPreparedModel.h> 23 #include <nnapi/Result.h> 24 #include <nnapi/Types.h> 25 26 #include <memory> 27 #include <string> 28 #include <vector> 29 30 namespace android::hardware::neuralnetworks::utils { 31 32 class InvalidDevice final : public nn::IDevice { 33 public: 34 InvalidDevice(std::string name, std::string versionString, nn::Version featureLevel, 35 nn::DeviceType type, std::vector<nn::Extension> extensions, 36 nn::Capabilities capabilities, 37 std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded); 38 39 const std::string& getName() const override; 40 const std::string& getVersionString() const override; 41 nn::Version getFeatureLevel() const override; 42 nn::DeviceType getType() const override; 43 const std::vector<nn::Extension>& getSupportedExtensions() const override; 44 const nn::Capabilities& getCapabilities() const override; 45 std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override; 46 47 nn::GeneralResult<void> wait() const override; 48 49 nn::GeneralResult<std::vector<bool>> getSupportedOperations( 50 const nn::Model& model) const override; 51 52 nn::GeneralResult<nn::SharedPreparedModel> prepareModel( 53 const nn::Model& model, nn::ExecutionPreference preference, nn::Priority priority, 54 nn::OptionalTimePoint deadline, const std::vector<nn::SharedHandle>& modelCache, 55 const std::vector<nn::SharedHandle>& dataCache, 56 const nn::CacheToken& token) const override; 57 58 nn::GeneralResult<nn::SharedPreparedModel> prepareModelFromCache( 59 nn::OptionalTimePoint deadline, const std::vector<nn::SharedHandle>& modelCache, 60 const std::vector<nn::SharedHandle>& dataCache, 61 const nn::CacheToken& token) const override; 62 63 nn::GeneralResult<nn::SharedBuffer> allocate( 64 const nn::BufferDesc& desc, const std::vector<nn::SharedPreparedModel>& preparedModels, 65 const std::vector<nn::BufferRole>& inputRoles, 66 const std::vector<nn::BufferRole>& outputRoles) const override; 67 68 private: 69 const std::string kName; 70 const std::string kVersionString; 71 const nn::Version kFeatureLevel; 72 const nn::DeviceType kType; 73 const std::vector<nn::Extension> kExtensions; 74 const nn::Capabilities kCapabilities; 75 const std::pair<uint32_t, uint32_t> kNumberOfCacheFilesNeeded; 76 }; 77 78 } // namespace android::hardware::neuralnetworks::utils 79 80 #endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_INVALID_DEVICE_H 81