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_CANONICAL_DEVICE_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_DEVICE_H 19 20 #include <BufferTracker.h> 21 #include <CpuExecutor.h> 22 #include <nnapi/IBuffer.h> 23 #include <nnapi/IDevice.h> 24 #include <nnapi/OperandTypes.h> 25 #include <nnapi/Result.h> 26 #include <nnapi/Types.h> 27 28 #include <functional> 29 #include <memory> 30 #include <optional> 31 #include <string> 32 #include <utility> 33 #include <vector> 34 35 namespace android::nn::sample { 36 37 class Device final : public IDevice { 38 public: 39 explicit Device(std::string name, 40 const IOperationResolver* operationResolver = BuiltinOperationResolver::get()); 41 42 const std::string& getName() const override; 43 const std::string& getVersionString() const override; 44 Version getFeatureLevel() const override; 45 DeviceType getType() const override; 46 const std::vector<Extension>& getSupportedExtensions() const override; 47 const Capabilities& getCapabilities() const override; 48 std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override; 49 50 GeneralResult<void> wait() const override; 51 52 GeneralResult<std::vector<bool>> getSupportedOperations(const Model& model) const override; 53 54 GeneralResult<SharedPreparedModel> prepareModel(const Model& model, 55 ExecutionPreference preference, 56 Priority priority, OptionalTimePoint deadline, 57 const std::vector<SharedHandle>& modelCache, 58 const std::vector<SharedHandle>& dataCache, 59 const CacheToken& token) const override; 60 61 GeneralResult<SharedPreparedModel> prepareModelFromCache( 62 OptionalTimePoint deadline, const std::vector<SharedHandle>& modelCache, 63 const std::vector<SharedHandle>& dataCache, const CacheToken& token) const override; 64 65 GeneralResult<SharedBuffer> allocate(const BufferDesc& desc, 66 const std::vector<SharedPreparedModel>& preparedModels, 67 const std::vector<BufferRole>& inputRoles, 68 const std::vector<BufferRole>& outputRoles) const override; 69 70 private: 71 const std::string kName; 72 const IOperationResolver& kOperationResolver; 73 const std::shared_ptr<BufferTracker> kBufferTracker = BufferTracker::create(); 74 }; 75 76 } // namespace android::nn::sample 77 78 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_DEVICE_H 79