1 /*
2 * Copyright (C) 2019 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 "SampleDriverPartial"
18
19 #include "SampleDriverPartial.h"
20
21 #include <android-base/logging.h>
22 #include <hidl/LegacySupport.h>
23
24 #include <thread>
25 #include <vector>
26
27 #include "HalInterfaces.h"
28 #include "SampleDriverUtils.h"
29 #include "Utils.h"
30 #include "ValidateHal.h"
31
32 namespace android {
33 namespace nn {
34 namespace sample_driver {
35
36 using namespace hal;
37
getSupportedOperations_1_3(const V1_3::Model & model,getSupportedOperations_1_3_cb cb)38 Return<void> SampleDriverPartial::getSupportedOperations_1_3(const V1_3::Model& model,
39 getSupportedOperations_1_3_cb cb) {
40 VLOG(DRIVER) << "getSupportedOperations()";
41 if (validateModel(model)) {
42 std::vector<bool> supported = getSupportedOperationsImpl(model);
43 cb(ErrorStatus::NONE, supported);
44 } else {
45 std::vector<bool> supported;
46 cb(ErrorStatus::INVALID_ARGUMENT, supported);
47 }
48 return Void();
49 }
50
prepareModel_1_3(const V1_3::Model & model,ExecutionPreference preference,Priority priority,const OptionalTimePoint & deadline,const hidl_vec<hidl_handle> &,const hidl_vec<hidl_handle> &,const CacheToken &,const sp<V1_3::IPreparedModelCallback> & callback)51 Return<ErrorStatus> SampleDriverPartial::prepareModel_1_3(
52 const V1_3::Model& model, ExecutionPreference preference, Priority priority,
53 const OptionalTimePoint& deadline, const hidl_vec<hidl_handle>&,
54 const hidl_vec<hidl_handle>&, const CacheToken&,
55 const sp<V1_3::IPreparedModelCallback>& callback) {
56 std::vector<bool> supported = getSupportedOperationsImpl(model);
57 bool isModelFullySupported =
58 std::all_of(supported.begin(), supported.end(), [](bool v) { return v; });
59 return prepareModelBase(model, this, preference, priority, deadline, callback,
60 isModelFullySupported);
61 }
62
63 } // namespace sample_driver
64 } // namespace nn
65 } // namespace android
66