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 #include "InvalidDevice.h"
18
19 #include "InvalidBuffer.h"
20 #include "InvalidPreparedModel.h"
21
22 #include <nnapi/IBuffer.h>
23 #include <nnapi/IDevice.h>
24 #include <nnapi/IPreparedModel.h>
25 #include <nnapi/Result.h>
26 #include <nnapi/Types.h>
27
28 #include <memory>
29 #include <string>
30 #include <vector>
31
32 namespace android::hardware::neuralnetworks::utils {
33
InvalidDevice(std::string name,std::string versionString,nn::Version featureLevel,nn::DeviceType type,std::vector<nn::Extension> extensions,nn::Capabilities capabilities,std::pair<uint32_t,uint32_t> numberOfCacheFilesNeeded)34 InvalidDevice::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 : kName(std::move(name)),
39 kVersionString(std::move(versionString)),
40 kFeatureLevel(featureLevel),
41 kType(type),
42 kExtensions(std::move(extensions)),
43 kCapabilities(std::move(capabilities)),
44 kNumberOfCacheFilesNeeded(numberOfCacheFilesNeeded) {}
45
getName() const46 const std::string& InvalidDevice::getName() const {
47 return kName;
48 }
49
getVersionString() const50 const std::string& InvalidDevice::getVersionString() const {
51 return kVersionString;
52 }
53
getFeatureLevel() const54 nn::Version InvalidDevice::getFeatureLevel() const {
55 return kFeatureLevel;
56 }
57
getType() const58 nn::DeviceType InvalidDevice::getType() const {
59 return kType;
60 }
61
getSupportedExtensions() const62 const std::vector<nn::Extension>& InvalidDevice::getSupportedExtensions() const {
63 return kExtensions;
64 }
65
getCapabilities() const66 const nn::Capabilities& InvalidDevice::getCapabilities() const {
67 return kCapabilities;
68 }
69
getNumberOfCacheFilesNeeded() const70 std::pair<uint32_t, uint32_t> InvalidDevice::getNumberOfCacheFilesNeeded() const {
71 return kNumberOfCacheFilesNeeded;
72 }
73
wait() const74 nn::GeneralResult<void> InvalidDevice::wait() const {
75 return NN_ERROR() << "InvalidDevice";
76 }
77
getSupportedOperations(const nn::Model &) const78 nn::GeneralResult<std::vector<bool>> InvalidDevice::getSupportedOperations(
79 const nn::Model& /*model*/) const {
80 return NN_ERROR() << "InvalidDevice";
81 }
82
prepareModel(const nn::Model &,nn::ExecutionPreference,nn::Priority,nn::OptionalTimePoint,const std::vector<nn::SharedHandle> &,const std::vector<nn::SharedHandle> &,const nn::CacheToken &,const std::vector<nn::TokenValuePair> &,const std::vector<nn::ExtensionNameAndPrefix> &) const83 nn::GeneralResult<nn::SharedPreparedModel> InvalidDevice::prepareModel(
84 const nn::Model& /*model*/, nn::ExecutionPreference /*preference*/,
85 nn::Priority /*priority*/, nn::OptionalTimePoint /*deadline*/,
86 const std::vector<nn::SharedHandle>& /*modelCache*/,
87 const std::vector<nn::SharedHandle>& /*dataCache*/, const nn::CacheToken& /*token*/,
88 const std::vector<nn::TokenValuePair>& /*hints*/,
89 const std::vector<nn::ExtensionNameAndPrefix>& /*extensionNameToPrefix*/) const {
90 return NN_ERROR() << "InvalidDevice";
91 }
92
prepareModelFromCache(nn::OptionalTimePoint,const std::vector<nn::SharedHandle> &,const std::vector<nn::SharedHandle> &,const nn::CacheToken &) const93 nn::GeneralResult<nn::SharedPreparedModel> InvalidDevice::prepareModelFromCache(
94 nn::OptionalTimePoint /*deadline*/, const std::vector<nn::SharedHandle>& /*modelCache*/,
95 const std::vector<nn::SharedHandle>& /*dataCache*/, const nn::CacheToken& /*token*/) const {
96 return NN_ERROR() << "InvalidDevice";
97 }
98
allocate(const nn::BufferDesc &,const std::vector<nn::SharedPreparedModel> &,const std::vector<nn::BufferRole> &,const std::vector<nn::BufferRole> &) const99 nn::GeneralResult<nn::SharedBuffer> InvalidDevice::allocate(
100 const nn::BufferDesc& /*desc*/,
101 const std::vector<nn::SharedPreparedModel>& /*preparedModels*/,
102 const std::vector<nn::BufferRole>& /*inputRoles*/,
103 const std::vector<nn::BufferRole>& /*outputRoles*/) const {
104 return NN_ERROR() << "InvalidDevice";
105 }
106
107 } // namespace android::hardware::neuralnetworks::utils
108