• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "SampleDriverAidlFull"
18 
19 #include "SampleDriverAidlFull.h"
20 
21 #include <nnapi/Validation.h>
22 #include <nnapi/hal/aidl/Conversions.h>
23 #include <nnapi/hal/aidl/HalUtils.h>
24 
25 #include <string>
26 #include <vector>
27 
28 #include "LegacyUtils.h"
29 #include "SampleDriverAidlUtils.h"
30 
31 namespace android {
32 namespace nn {
33 namespace sample_driver_aidl {
34 
getCapabilities(aidl_hal::Capabilities * capabilities)35 ndk::ScopedAStatus SampleDriverFull::getCapabilities(aidl_hal::Capabilities* capabilities) {
36     android::nn::initVLogMask();
37     VLOG(DRIVER) << "getCapabilities()";
38     *capabilities = {.relaxedFloat32toFloat16PerformanceScalar = mPerf,
39                      .relaxedFloat32toFloat16PerformanceTensor = mPerf,
40                      .operandPerformance = nonExtensionOperandPerformance(mPerf),
41                      .ifPerformance = mPerf,
42                      .whilePerformance = mPerf};
43     return ndk::ScopedAStatus::ok();
44 }
45 
getSupportedOperations(const aidl_hal::Model & model,std::vector<bool> * supportedOperations)46 ndk::ScopedAStatus SampleDriverFull::getSupportedOperations(
47         const aidl_hal::Model& model, std::vector<bool>* supportedOperations) {
48     VLOG(DRIVER) << "getSupportedOperations()";
49     const auto canonicalModel = convert(model);
50     if (!canonicalModel.has_value()) {
51         return toAStatus(aidl_hal::ErrorStatus::INVALID_ARGUMENT, canonicalModel.error().message);
52     }
53     const size_t count = canonicalModel.value().main.operations.size();
54     *supportedOperations = std::vector<bool>(count, true);
55     for (size_t i = 0; i < count; i++) {
56         const Operation& operation = canonicalModel.value().main.operations[i];
57         supportedOperations->at(i) = !isExtensionOperationType(operation.type);
58     }
59     return ndk::ScopedAStatus::ok();
60 }
61 
62 }  // namespace sample_driver_aidl
63 }  // namespace nn
64 }  // namespace android
65