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, const nn::CacheToken& token,
56             const std::vector<nn::TokenValuePair>& hints,
57             const std::vector<nn::ExtensionNameAndPrefix>& extensionNameToPrefix) const override;
58 
59     nn::GeneralResult<nn::SharedPreparedModel> prepareModelFromCache(
60             nn::OptionalTimePoint deadline, const std::vector<nn::SharedHandle>& modelCache,
61             const std::vector<nn::SharedHandle>& dataCache,
62             const nn::CacheToken& token) const override;
63 
64     nn::GeneralResult<nn::SharedBuffer> allocate(
65             const nn::BufferDesc& desc, const std::vector<nn::SharedPreparedModel>& preparedModels,
66             const std::vector<nn::BufferRole>& inputRoles,
67             const std::vector<nn::BufferRole>& outputRoles) const override;
68 
69   private:
70     const std::string kName;
71     const std::string kVersionString;
72     const nn::Version kFeatureLevel;
73     const nn::DeviceType kType;
74     const std::vector<nn::Extension> kExtensions;
75     const nn::Capabilities kCapabilities;
76     const std::pair<uint32_t, uint32_t> kNumberOfCacheFilesNeeded;
77 };
78 
79 }  // namespace android::hardware::neuralnetworks::utils
80 
81 #endif  // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_INVALID_DEVICE_H
82