Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 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 "Conversions.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <android/hardware/neuralnetworks/1.2/types.h> |
| 21 | #include <nnapi/OperandTypes.h> |
| 22 | #include <nnapi/OperationTypes.h> |
| 23 | #include <nnapi/Result.h> |
| 24 | #include <nnapi/SharedMemory.h> |
| 25 | #include <nnapi/TypeUtils.h> |
| 26 | #include <nnapi/Types.h> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 27 | #include <nnapi/Validation.h> |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 28 | #include <nnapi/hal/1.0/Conversions.h> |
| 29 | #include <nnapi/hal/CommonUtils.h> |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 30 | #include <nnapi/hal/HandleError.h> |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 31 | |
| 32 | #include <algorithm> |
| 33 | #include <functional> |
| 34 | #include <iterator> |
| 35 | #include <memory> |
| 36 | #include <type_traits> |
| 37 | #include <utility> |
| 38 | |
| 39 | namespace { |
| 40 | |
| 41 | template <typename Type> |
| 42 | constexpr std::underlying_type_t<Type> underlyingType(Type value) { |
| 43 | return static_cast<std::underlying_type_t<Type>>(value); |
| 44 | } |
| 45 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 46 | constexpr auto kVersion = android::nn::Version::ANDROID_Q; |
| 47 | |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 48 | } // namespace |
| 49 | |
| 50 | namespace android::nn { |
| 51 | namespace { |
| 52 | |
| 53 | constexpr bool validOperandType(OperandType operandType) { |
| 54 | switch (operandType) { |
| 55 | case OperandType::FLOAT32: |
| 56 | case OperandType::INT32: |
| 57 | case OperandType::UINT32: |
| 58 | case OperandType::TENSOR_FLOAT32: |
| 59 | case OperandType::TENSOR_INT32: |
| 60 | case OperandType::TENSOR_QUANT8_ASYMM: |
| 61 | case OperandType::BOOL: |
| 62 | case OperandType::TENSOR_QUANT16_SYMM: |
| 63 | case OperandType::TENSOR_FLOAT16: |
| 64 | case OperandType::TENSOR_BOOL8: |
| 65 | case OperandType::FLOAT16: |
| 66 | case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: |
| 67 | case OperandType::TENSOR_QUANT16_ASYMM: |
| 68 | case OperandType::TENSOR_QUANT8_SYMM: |
| 69 | case OperandType::OEM: |
| 70 | case OperandType::TENSOR_OEM_BYTE: |
| 71 | return true; |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | return isExtension(operandType); |
| 76 | } |
| 77 | |
| 78 | using hardware::hidl_handle; |
| 79 | using hardware::hidl_vec; |
| 80 | |
| 81 | template <typename Input> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 82 | using unvalidatedConvertOutput = |
| 83 | std::decay_t<decltype(unvalidatedConvert(std::declval<Input>()).value())>; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 84 | |
| 85 | template <typename Type> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 86 | GeneralResult<std::vector<unvalidatedConvertOutput<Type>>> unvalidatedConvertVec( |
| 87 | const hidl_vec<Type>& arguments) { |
| 88 | std::vector<unvalidatedConvertOutput<Type>> canonical; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 89 | canonical.reserve(arguments.size()); |
| 90 | for (const auto& argument : arguments) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 91 | canonical.push_back(NN_TRY(nn::unvalidatedConvert(argument))); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 92 | } |
| 93 | return canonical; |
| 94 | } |
| 95 | |
| 96 | template <typename Type> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 97 | GeneralResult<std::vector<unvalidatedConvertOutput<Type>>> unvalidatedConvert( |
| 98 | const hidl_vec<Type>& arguments) { |
| 99 | return unvalidatedConvertVec(arguments); |
| 100 | } |
| 101 | |
| 102 | template <typename Type> |
| 103 | decltype(nn::unvalidatedConvert(std::declval<Type>())) validatedConvert(const Type& halObject) { |
| 104 | auto canonical = NN_TRY(nn::unvalidatedConvert(halObject)); |
| 105 | const auto maybeVersion = validate(canonical); |
| 106 | if (!maybeVersion.has_value()) { |
| 107 | return error() << maybeVersion.error(); |
| 108 | } |
| 109 | const auto version = maybeVersion.value(); |
| 110 | if (version > kVersion) { |
| 111 | return NN_ERROR() << "Insufficient version: " << version << " vs required " << kVersion; |
| 112 | } |
| 113 | return canonical; |
| 114 | } |
| 115 | |
| 116 | template <typename Type> |
| 117 | GeneralResult<std::vector<unvalidatedConvertOutput<Type>>> validatedConvert( |
| 118 | const hidl_vec<Type>& arguments) { |
| 119 | std::vector<unvalidatedConvertOutput<Type>> canonical; |
| 120 | canonical.reserve(arguments.size()); |
| 121 | for (const auto& argument : arguments) { |
| 122 | canonical.push_back(NN_TRY(validatedConvert(argument))); |
| 123 | } |
| 124 | return canonical; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | } // anonymous namespace |
| 128 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 129 | GeneralResult<OperandType> unvalidatedConvert(const hal::V1_2::OperandType& operandType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 130 | return static_cast<OperandType>(operandType); |
| 131 | } |
| 132 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 133 | GeneralResult<OperationType> unvalidatedConvert(const hal::V1_2::OperationType& operationType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 134 | return static_cast<OperationType>(operationType); |
| 135 | } |
| 136 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 137 | GeneralResult<DeviceType> unvalidatedConvert(const hal::V1_2::DeviceType& deviceType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 138 | return static_cast<DeviceType>(deviceType); |
| 139 | } |
| 140 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 141 | GeneralResult<Capabilities> unvalidatedConvert(const hal::V1_2::Capabilities& capabilities) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 142 | const bool validOperandTypes = std::all_of( |
| 143 | capabilities.operandPerformance.begin(), capabilities.operandPerformance.end(), |
| 144 | [](const hal::V1_2::Capabilities::OperandPerformance& operandPerformance) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 145 | const auto maybeType = unvalidatedConvert(operandPerformance.type); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 146 | return !maybeType.has_value() ? false : validOperandType(maybeType.value()); |
| 147 | }); |
| 148 | if (!validOperandTypes) { |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 149 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 150 | << "Invalid OperandType when converting OperandPerformance in Capabilities"; |
| 151 | } |
| 152 | |
| 153 | const auto relaxedFloat32toFloat16PerformanceScalar = |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 154 | NN_TRY(unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceScalar)); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 155 | const auto relaxedFloat32toFloat16PerformanceTensor = |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 156 | NN_TRY(unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceTensor)); |
| 157 | auto operandPerformance = NN_TRY(unvalidatedConvert(capabilities.operandPerformance)); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 158 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 159 | auto table = NN_TRY(hal::utils::makeGeneralFailure( |
| 160 | Capabilities::OperandPerformanceTable::create(std::move(operandPerformance)), |
| 161 | nn::ErrorStatus::GENERAL_FAILURE)); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 162 | |
| 163 | return Capabilities{ |
| 164 | .relaxedFloat32toFloat16PerformanceScalar = relaxedFloat32toFloat16PerformanceScalar, |
| 165 | .relaxedFloat32toFloat16PerformanceTensor = relaxedFloat32toFloat16PerformanceTensor, |
| 166 | .operandPerformance = std::move(table), |
| 167 | }; |
| 168 | } |
| 169 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 170 | GeneralResult<Capabilities::OperandPerformance> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 171 | const hal::V1_2::Capabilities::OperandPerformance& operandPerformance) { |
| 172 | return Capabilities::OperandPerformance{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 173 | .type = NN_TRY(unvalidatedConvert(operandPerformance.type)), |
| 174 | .info = NN_TRY(unvalidatedConvert(operandPerformance.info)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 175 | }; |
| 176 | } |
| 177 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 178 | GeneralResult<Operation> unvalidatedConvert(const hal::V1_2::Operation& operation) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 179 | return Operation{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 180 | .type = NN_TRY(unvalidatedConvert(operation.type)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 181 | .inputs = operation.inputs, |
| 182 | .outputs = operation.outputs, |
| 183 | }; |
| 184 | } |
| 185 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 186 | GeneralResult<Operand::SymmPerChannelQuantParams> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 187 | const hal::V1_2::SymmPerChannelQuantParams& symmPerChannelQuantParams) { |
| 188 | return Operand::SymmPerChannelQuantParams{ |
| 189 | .scales = symmPerChannelQuantParams.scales, |
| 190 | .channelDim = symmPerChannelQuantParams.channelDim, |
| 191 | }; |
| 192 | } |
| 193 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 194 | GeneralResult<Operand> unvalidatedConvert(const hal::V1_2::Operand& operand) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 195 | return Operand{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 196 | .type = NN_TRY(unvalidatedConvert(operand.type)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 197 | .dimensions = operand.dimensions, |
| 198 | .scale = operand.scale, |
| 199 | .zeroPoint = operand.zeroPoint, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 200 | .lifetime = NN_TRY(unvalidatedConvert(operand.lifetime)), |
| 201 | .location = NN_TRY(unvalidatedConvert(operand.location)), |
| 202 | .extraParams = NN_TRY(unvalidatedConvert(operand.extraParams)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 203 | }; |
| 204 | } |
| 205 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 206 | GeneralResult<Operand::ExtraParams> unvalidatedConvert( |
| 207 | const hal::V1_2::Operand::ExtraParams& extraParams) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 208 | using Discriminator = hal::V1_2::Operand::ExtraParams::hidl_discriminator; |
| 209 | switch (extraParams.getDiscriminator()) { |
| 210 | case Discriminator::none: |
| 211 | return Operand::NoParams{}; |
| 212 | case Discriminator::channelQuant: |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 213 | return unvalidatedConvert(extraParams.channelQuant()); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 214 | case Discriminator::extension: |
| 215 | return extraParams.extension(); |
| 216 | } |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 217 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) |
| 218 | << "Unrecognized Operand::ExtraParams discriminator: " |
| 219 | << underlyingType(extraParams.getDiscriminator()); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 222 | GeneralResult<Model> unvalidatedConvert(const hal::V1_2::Model& model) { |
| 223 | auto operations = NN_TRY(unvalidatedConvert(model.operations)); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 224 | |
| 225 | // Verify number of consumers. |
| 226 | const auto numberOfConsumers = |
| 227 | hal::utils::countNumberOfConsumers(model.operands.size(), operations); |
| 228 | CHECK(model.operands.size() == numberOfConsumers.size()); |
| 229 | for (size_t i = 0; i < model.operands.size(); ++i) { |
| 230 | if (model.operands[i].numberOfConsumers != numberOfConsumers[i]) { |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 231 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) |
| 232 | << "Invalid numberOfConsumers for operand " << i << ", expected " |
| 233 | << numberOfConsumers[i] << " but found " << model.operands[i].numberOfConsumers; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
| 237 | auto main = Model::Subgraph{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 238 | .operands = NN_TRY(unvalidatedConvert(model.operands)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 239 | .operations = std::move(operations), |
| 240 | .inputIndexes = model.inputIndexes, |
| 241 | .outputIndexes = model.outputIndexes, |
| 242 | }; |
| 243 | |
| 244 | return Model{ |
| 245 | .main = std::move(main), |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 246 | .operandValues = NN_TRY(unvalidatedConvert(model.operandValues)), |
| 247 | .pools = NN_TRY(unvalidatedConvert(model.pools)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 248 | .relaxComputationFloat32toFloat16 = model.relaxComputationFloat32toFloat16, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 249 | .extensionNameToPrefix = NN_TRY(unvalidatedConvert(model.extensionNameToPrefix)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 250 | }; |
| 251 | } |
| 252 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 253 | GeneralResult<Model::ExtensionNameAndPrefix> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 254 | const hal::V1_2::Model::ExtensionNameAndPrefix& extensionNameAndPrefix) { |
| 255 | return Model::ExtensionNameAndPrefix{ |
| 256 | .name = extensionNameAndPrefix.name, |
| 257 | .prefix = extensionNameAndPrefix.prefix, |
| 258 | }; |
| 259 | } |
| 260 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 261 | GeneralResult<OutputShape> unvalidatedConvert(const hal::V1_2::OutputShape& outputShape) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 262 | return OutputShape{ |
| 263 | .dimensions = outputShape.dimensions, |
| 264 | .isSufficient = outputShape.isSufficient, |
| 265 | }; |
| 266 | } |
| 267 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 268 | GeneralResult<MeasureTiming> unvalidatedConvert(const hal::V1_2::MeasureTiming& measureTiming) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 269 | return static_cast<MeasureTiming>(measureTiming); |
| 270 | } |
| 271 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 272 | GeneralResult<Timing> unvalidatedConvert(const hal::V1_2::Timing& timing) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 273 | return Timing{.timeOnDevice = timing.timeOnDevice, .timeInDriver = timing.timeInDriver}; |
| 274 | } |
| 275 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 276 | GeneralResult<Extension> unvalidatedConvert(const hal::V1_2::Extension& extension) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 277 | return Extension{ |
| 278 | .name = extension.name, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 279 | .operandTypes = NN_TRY(unvalidatedConvert(extension.operandTypes)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 280 | }; |
| 281 | } |
| 282 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 283 | GeneralResult<Extension::OperandTypeInformation> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 284 | const hal::V1_2::Extension::OperandTypeInformation& operandTypeInformation) { |
| 285 | return Extension::OperandTypeInformation{ |
| 286 | .type = operandTypeInformation.type, |
| 287 | .isTensor = operandTypeInformation.isTensor, |
| 288 | .byteSize = operandTypeInformation.byteSize, |
| 289 | }; |
| 290 | } |
| 291 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 292 | GeneralResult<SharedHandle> unvalidatedConvert(const hidl_handle& hidlHandle) { |
Slava Shklyaev | d4290b8 | 2020-10-27 18:44:01 +0000 | [diff] [blame] | 293 | return hal::utils::sharedHandleFromNativeHandle(hidlHandle.getNativeHandle()); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 296 | GeneralResult<DeviceType> convert(const hal::V1_2::DeviceType& deviceType) { |
| 297 | return validatedConvert(deviceType); |
| 298 | } |
| 299 | |
| 300 | GeneralResult<Capabilities> convert(const hal::V1_2::Capabilities& capabilities) { |
| 301 | return validatedConvert(capabilities); |
| 302 | } |
| 303 | |
| 304 | GeneralResult<Model> convert(const hal::V1_2::Model& model) { |
| 305 | return validatedConvert(model); |
| 306 | } |
| 307 | |
| 308 | GeneralResult<MeasureTiming> convert(const hal::V1_2::MeasureTiming& measureTiming) { |
| 309 | return validatedConvert(measureTiming); |
| 310 | } |
| 311 | |
| 312 | GeneralResult<Timing> convert(const hal::V1_2::Timing& timing) { |
| 313 | return validatedConvert(timing); |
| 314 | } |
| 315 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 316 | GeneralResult<std::vector<Extension>> convert(const hidl_vec<hal::V1_2::Extension>& extensions) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 317 | return validatedConvert(extensions); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Slava Shklyaev | d4290b8 | 2020-10-27 18:44:01 +0000 | [diff] [blame] | 320 | GeneralResult<std::vector<SharedHandle>> convert(const hidl_vec<hidl_handle>& handles) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 321 | return validatedConvert(handles); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 324 | GeneralResult<std::vector<OutputShape>> convert( |
| 325 | const hidl_vec<hal::V1_2::OutputShape>& outputShapes) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 326 | return validatedConvert(outputShapes); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | } // namespace android::nn |
| 330 | |
| 331 | namespace android::hardware::neuralnetworks::V1_2::utils { |
| 332 | namespace { |
| 333 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 334 | using utils::unvalidatedConvert; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 335 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 336 | nn::GeneralResult<V1_0::OperandLifeTime> unvalidatedConvert(const nn::Operand::LifeTime& lifetime) { |
| 337 | return V1_0::utils::unvalidatedConvert(lifetime); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 340 | nn::GeneralResult<V1_0::PerformanceInfo> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 341 | const nn::Capabilities::PerformanceInfo& performanceInfo) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 342 | return V1_0::utils::unvalidatedConvert(performanceInfo); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 345 | nn::GeneralResult<V1_0::DataLocation> unvalidatedConvert(const nn::DataLocation& location) { |
| 346 | return V1_0::utils::unvalidatedConvert(location); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 349 | nn::GeneralResult<hidl_vec<uint8_t>> unvalidatedConvert( |
| 350 | const nn::Model::OperandValues& operandValues) { |
| 351 | return V1_0::utils::unvalidatedConvert(operandValues); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 354 | nn::GeneralResult<hidl_memory> unvalidatedConvert(const nn::Memory& memory) { |
| 355 | return V1_0::utils::unvalidatedConvert(memory); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | template <typename Input> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 359 | using unvalidatedConvertOutput = |
| 360 | std::decay_t<decltype(unvalidatedConvert(std::declval<Input>()).value())>; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 361 | |
| 362 | template <typename Type> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 363 | nn::GeneralResult<hidl_vec<unvalidatedConvertOutput<Type>>> unvalidatedConvertVec( |
| 364 | const std::vector<Type>& arguments) { |
| 365 | hidl_vec<unvalidatedConvertOutput<Type>> halObject(arguments.size()); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 366 | for (size_t i = 0; i < arguments.size(); ++i) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 367 | halObject[i] = NN_TRY(unvalidatedConvert(arguments[i])); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 368 | } |
| 369 | return halObject; |
| 370 | } |
| 371 | |
| 372 | template <typename Type> |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 373 | nn::GeneralResult<hidl_vec<unvalidatedConvertOutput<Type>>> unvalidatedConvert( |
| 374 | const std::vector<Type>& arguments) { |
| 375 | return unvalidatedConvertVec(arguments); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 378 | nn::GeneralResult<Operand::ExtraParams> makeExtraParams(nn::Operand::NoParams /*noParams*/) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 379 | return Operand::ExtraParams{}; |
| 380 | } |
| 381 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 382 | nn::GeneralResult<Operand::ExtraParams> makeExtraParams( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 383 | const nn::Operand::SymmPerChannelQuantParams& channelQuant) { |
| 384 | Operand::ExtraParams ret; |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 385 | ret.channelQuant(NN_TRY(unvalidatedConvert(channelQuant))); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 386 | return ret; |
| 387 | } |
| 388 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 389 | nn::GeneralResult<Operand::ExtraParams> makeExtraParams( |
| 390 | const nn::Operand::ExtensionParams& extension) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 391 | Operand::ExtraParams ret; |
| 392 | ret.extension(extension); |
| 393 | return ret; |
| 394 | } |
| 395 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 396 | template <typename Type> |
| 397 | decltype(utils::unvalidatedConvert(std::declval<Type>())) validatedConvert(const Type& canonical) { |
| 398 | const auto maybeVersion = nn::validate(canonical); |
| 399 | if (!maybeVersion.has_value()) { |
| 400 | return nn::error() << maybeVersion.error(); |
| 401 | } |
| 402 | const auto version = maybeVersion.value(); |
| 403 | if (version > kVersion) { |
| 404 | return NN_ERROR() << "Insufficient version: " << version << " vs required " << kVersion; |
| 405 | } |
| 406 | return utils::unvalidatedConvert(canonical); |
| 407 | } |
| 408 | |
| 409 | template <typename Type> |
| 410 | nn::GeneralResult<hidl_vec<unvalidatedConvertOutput<Type>>> validatedConvert( |
| 411 | const std::vector<Type>& arguments) { |
| 412 | hidl_vec<unvalidatedConvertOutput<Type>> halObject(arguments.size()); |
| 413 | for (size_t i = 0; i < arguments.size(); ++i) { |
| 414 | halObject[i] = NN_TRY(validatedConvert(arguments[i])); |
| 415 | } |
| 416 | return halObject; |
| 417 | } |
| 418 | |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 419 | } // anonymous namespace |
| 420 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 421 | nn::GeneralResult<OperandType> unvalidatedConvert(const nn::OperandType& operandType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 422 | return static_cast<OperandType>(operandType); |
| 423 | } |
| 424 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 425 | nn::GeneralResult<OperationType> unvalidatedConvert(const nn::OperationType& operationType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 426 | return static_cast<OperationType>(operationType); |
| 427 | } |
| 428 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 429 | nn::GeneralResult<DeviceType> unvalidatedConvert(const nn::DeviceType& deviceType) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 430 | switch (deviceType) { |
| 431 | case nn::DeviceType::UNKNOWN: |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 432 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) << "Invalid DeviceType UNKNOWN"; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 433 | case nn::DeviceType::OTHER: |
| 434 | case nn::DeviceType::CPU: |
| 435 | case nn::DeviceType::GPU: |
| 436 | case nn::DeviceType::ACCELERATOR: |
| 437 | return static_cast<DeviceType>(deviceType); |
| 438 | } |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 439 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) |
| 440 | << "Invalid DeviceType " << underlyingType(deviceType); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 443 | nn::GeneralResult<Capabilities> unvalidatedConvert(const nn::Capabilities& capabilities) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 444 | std::vector<nn::Capabilities::OperandPerformance> operandPerformance; |
| 445 | operandPerformance.reserve(capabilities.operandPerformance.asVector().size()); |
| 446 | std::copy_if(capabilities.operandPerformance.asVector().begin(), |
| 447 | capabilities.operandPerformance.asVector().end(), |
| 448 | std::back_inserter(operandPerformance), |
| 449 | [](const nn::Capabilities::OperandPerformance& operandPerformance) { |
| 450 | return nn::validOperandType(operandPerformance.type); |
| 451 | }); |
| 452 | |
| 453 | return Capabilities{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 454 | .relaxedFloat32toFloat16PerformanceScalar = NN_TRY( |
| 455 | unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceScalar)), |
| 456 | .relaxedFloat32toFloat16PerformanceTensor = NN_TRY( |
| 457 | unvalidatedConvert(capabilities.relaxedFloat32toFloat16PerformanceTensor)), |
| 458 | .operandPerformance = NN_TRY(unvalidatedConvert(operandPerformance)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 459 | }; |
| 460 | } |
| 461 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 462 | nn::GeneralResult<Capabilities::OperandPerformance> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 463 | const nn::Capabilities::OperandPerformance& operandPerformance) { |
| 464 | return Capabilities::OperandPerformance{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 465 | .type = NN_TRY(unvalidatedConvert(operandPerformance.type)), |
| 466 | .info = NN_TRY(unvalidatedConvert(operandPerformance.info)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 467 | }; |
| 468 | } |
| 469 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 470 | nn::GeneralResult<Operation> unvalidatedConvert(const nn::Operation& operation) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 471 | return Operation{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 472 | .type = NN_TRY(unvalidatedConvert(operation.type)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 473 | .inputs = operation.inputs, |
| 474 | .outputs = operation.outputs, |
| 475 | }; |
| 476 | } |
| 477 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 478 | nn::GeneralResult<SymmPerChannelQuantParams> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 479 | const nn::Operand::SymmPerChannelQuantParams& symmPerChannelQuantParams) { |
| 480 | return SymmPerChannelQuantParams{ |
| 481 | .scales = symmPerChannelQuantParams.scales, |
| 482 | .channelDim = symmPerChannelQuantParams.channelDim, |
| 483 | }; |
| 484 | } |
| 485 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 486 | nn::GeneralResult<Operand> unvalidatedConvert(const nn::Operand& operand) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 487 | return Operand{ |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 488 | .type = NN_TRY(unvalidatedConvert(operand.type)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 489 | .dimensions = operand.dimensions, |
| 490 | .numberOfConsumers = 0, |
| 491 | .scale = operand.scale, |
| 492 | .zeroPoint = operand.zeroPoint, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 493 | .lifetime = NN_TRY(unvalidatedConvert(operand.lifetime)), |
| 494 | .location = NN_TRY(unvalidatedConvert(operand.location)), |
| 495 | .extraParams = NN_TRY(unvalidatedConvert(operand.extraParams)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 496 | }; |
| 497 | } |
| 498 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 499 | nn::GeneralResult<Operand::ExtraParams> unvalidatedConvert( |
| 500 | const nn::Operand::ExtraParams& extraParams) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 501 | return std::visit([](const auto& x) { return makeExtraParams(x); }, extraParams); |
| 502 | } |
| 503 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 504 | nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 505 | if (!hal::utils::hasNoPointerData(model)) { |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 506 | return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT) |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 507 | << "Model cannot be unvalidatedConverted because it contains pointer-based memory"; |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 510 | auto operands = NN_TRY(unvalidatedConvert(model.main.operands)); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 511 | |
| 512 | // Update number of consumers. |
| 513 | const auto numberOfConsumers = |
| 514 | hal::utils::countNumberOfConsumers(operands.size(), model.main.operations); |
| 515 | CHECK(operands.size() == numberOfConsumers.size()); |
| 516 | for (size_t i = 0; i < operands.size(); ++i) { |
| 517 | operands[i].numberOfConsumers = numberOfConsumers[i]; |
| 518 | } |
| 519 | |
| 520 | return Model{ |
| 521 | .operands = std::move(operands), |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 522 | .operations = NN_TRY(unvalidatedConvert(model.main.operations)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 523 | .inputIndexes = model.main.inputIndexes, |
| 524 | .outputIndexes = model.main.outputIndexes, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 525 | .operandValues = NN_TRY(unvalidatedConvert(model.operandValues)), |
| 526 | .pools = NN_TRY(unvalidatedConvert(model.pools)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 527 | .relaxComputationFloat32toFloat16 = model.relaxComputationFloat32toFloat16, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 528 | .extensionNameToPrefix = NN_TRY(unvalidatedConvert(model.extensionNameToPrefix)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 529 | }; |
| 530 | } |
| 531 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 532 | nn::GeneralResult<Model::ExtensionNameAndPrefix> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 533 | const nn::Model::ExtensionNameAndPrefix& extensionNameAndPrefix) { |
| 534 | return Model::ExtensionNameAndPrefix{ |
| 535 | .name = extensionNameAndPrefix.name, |
| 536 | .prefix = extensionNameAndPrefix.prefix, |
| 537 | }; |
| 538 | } |
| 539 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 540 | nn::GeneralResult<OutputShape> unvalidatedConvert(const nn::OutputShape& outputShape) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 541 | return OutputShape{.dimensions = outputShape.dimensions, |
| 542 | .isSufficient = outputShape.isSufficient}; |
| 543 | } |
| 544 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 545 | nn::GeneralResult<MeasureTiming> unvalidatedConvert(const nn::MeasureTiming& measureTiming) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 546 | return static_cast<MeasureTiming>(measureTiming); |
| 547 | } |
| 548 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 549 | nn::GeneralResult<Timing> unvalidatedConvert(const nn::Timing& timing) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 550 | return Timing{.timeOnDevice = timing.timeOnDevice, .timeInDriver = timing.timeInDriver}; |
| 551 | } |
| 552 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 553 | nn::GeneralResult<Extension> unvalidatedConvert(const nn::Extension& extension) { |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 554 | return Extension{ |
| 555 | .name = extension.name, |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 556 | .operandTypes = NN_TRY(unvalidatedConvert(extension.operandTypes)), |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 557 | }; |
| 558 | } |
| 559 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 560 | nn::GeneralResult<Extension::OperandTypeInformation> unvalidatedConvert( |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 561 | const nn::Extension::OperandTypeInformation& operandTypeInformation) { |
| 562 | return Extension::OperandTypeInformation{ |
| 563 | .type = operandTypeInformation.type, |
| 564 | .isTensor = operandTypeInformation.isTensor, |
| 565 | .byteSize = operandTypeInformation.byteSize, |
| 566 | }; |
| 567 | } |
| 568 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 569 | nn::GeneralResult<hidl_handle> unvalidatedConvert(const nn::SharedHandle& handle) { |
Slava Shklyaev | d4290b8 | 2020-10-27 18:44:01 +0000 | [diff] [blame] | 570 | return hal::utils::hidlHandleFromSharedHandle(handle); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 573 | nn::GeneralResult<DeviceType> convert(const nn::DeviceType& deviceType) { |
| 574 | return validatedConvert(deviceType); |
| 575 | } |
| 576 | |
| 577 | nn::GeneralResult<Capabilities> convert(const nn::Capabilities& capabilities) { |
| 578 | return validatedConvert(capabilities); |
| 579 | } |
| 580 | |
| 581 | nn::GeneralResult<Model> convert(const nn::Model& model) { |
| 582 | return validatedConvert(model); |
| 583 | } |
| 584 | |
| 585 | nn::GeneralResult<MeasureTiming> convert(const nn::MeasureTiming& measureTiming) { |
| 586 | return validatedConvert(measureTiming); |
| 587 | } |
| 588 | |
| 589 | nn::GeneralResult<Timing> convert(const nn::Timing& timing) { |
| 590 | return validatedConvert(timing); |
| 591 | } |
| 592 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 593 | nn::GeneralResult<hidl_vec<Extension>> convert(const std::vector<nn::Extension>& extensions) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 594 | return validatedConvert(extensions); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Slava Shklyaev | d4290b8 | 2020-10-27 18:44:01 +0000 | [diff] [blame] | 597 | nn::GeneralResult<hidl_vec<hidl_handle>> convert(const std::vector<nn::SharedHandle>& handles) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 598 | return validatedConvert(handles); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Michael Butler | 3670c38 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 601 | nn::GeneralResult<hidl_vec<OutputShape>> convert(const std::vector<nn::OutputShape>& outputShapes) { |
Michael Butler | 32acc06 | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 602 | return validatedConvert(outputShapes); |
Michael Butler | a685c3d | 2020-02-22 22:37:59 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | } // namespace android::hardware::neuralnetworks::V1_2::utils |