• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "SampleDriverUtils.h"
18 
19 #include <android-base/logging.h>
20 #include <hidl/HidlTransportSupport.h>
21 
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #include "SampleDriver.h"
27 
28 namespace android {
29 namespace nn {
30 namespace sample_driver {
31 
run(const sp<V1_3::IDevice> & device,const std::string & name)32 int run(const sp<V1_3::IDevice>& device, const std::string& name) {
33     constexpr size_t kNumberOfThreads = 4;
34     android::hardware::configureRpcThreadpool(kNumberOfThreads, true);
35 
36     if (device->registerAsService(name) != android::OK) {
37         LOG(ERROR) << "Could not register service " << name;
38         return 1;
39     }
40 
41     android::hardware::joinRpcThreadpool();
42     LOG(ERROR) << "Service exited!";
43     return 1;
44 }
45 
notify(const sp<V1_0::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)46 void notify(const sp<V1_0::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
47             const sp<SamplePreparedModel>& preparedModel) {
48     const auto ret = callback->notify(convertToV1_0(status), preparedModel);
49     if (!ret.isOk()) {
50         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify: " << ret.description();
51     }
52 }
53 
notify(const sp<V1_2::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)54 void notify(const sp<V1_2::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
55             const sp<SamplePreparedModel>& preparedModel) {
56     const auto ret = callback->notify_1_2(convertToV1_0(status), preparedModel);
57     if (!ret.isOk()) {
58         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify_1_2: "
59                    << ret.description();
60     }
61 }
62 
notify(const sp<V1_3::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)63 void notify(const sp<V1_3::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
64             const sp<SamplePreparedModel>& preparedModel) {
65     const auto ret = callback->notify_1_3(status, preparedModel);
66     if (!ret.isOk()) {
67         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify_1_3: "
68                    << ret.description();
69     }
70 }
71 
notify(const sp<V1_0::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> &,V1_2::Timing)72 void notify(const sp<V1_0::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
73             const hardware::hidl_vec<V1_2::OutputShape>&, V1_2::Timing) {
74     const auto ret = callback->notify(convertToV1_0(status));
75     if (!ret.isOk()) {
76         LOG(ERROR) << "Error when calling IExecutionCallback::notify: " << ret.description();
77     }
78 }
79 
notify(const sp<V1_2::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> & outputShapes,V1_2::Timing timing)80 void notify(const sp<V1_2::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
81             const hardware::hidl_vec<V1_2::OutputShape>& outputShapes, V1_2::Timing timing) {
82     const auto ret = callback->notify_1_2(convertToV1_0(status), outputShapes, timing);
83     if (!ret.isOk()) {
84         LOG(ERROR) << "Error when calling IExecutionCallback::notify_1_2: " << ret.description();
85     }
86 }
87 
notify(const sp<V1_3::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> & outputShapes,V1_2::Timing timing)88 void notify(const sp<V1_3::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
89             const hardware::hidl_vec<V1_2::OutputShape>& outputShapes, V1_2::Timing timing) {
90     const auto ret = callback->notify_1_3(status, outputShapes, timing);
91     if (!ret.isOk()) {
92         LOG(ERROR) << "Error when calling IExecutionCallback::notify_1_3" << ret.description();
93     }
94 }
95 
96 }  // namespace sample_driver
97 }  // namespace nn
98 }  // namespace android
99