From 534556391ae153b1e8fdd11b233e2dc6ecd1e530 Mon Sep 17 00:00:00 2001 From: Michael Butler Date: Mon, 25 Oct 2021 11:20:33 -0700 Subject: Create NN AIDL adapter This change adds the following adapters: * nn::IDevice -> BnDevice * nn::IPreparedModel -> BnPreparedModel * nn::IBurst -> BnBurst * nn::IBuffer -> BnBuffer Bug: N/A Test: mma Test: locally created a binderized service with this adapter code, which passed VtsHalNeuralnetworksTargetTest Change-Id: I966f65a1e4d75284c050b77f3f40c515e4970130 --- neuralnetworks/utils/adapter/hidl/src/Adapter.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 neuralnetworks/utils/adapter/hidl/src/Adapter.cpp (limited to 'neuralnetworks/utils/adapter/hidl/src/Adapter.cpp') diff --git a/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp b/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp new file mode 100644 index 0000000000..d6f53f05a5 --- /dev/null +++ b/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Adapter.h" + +#include "Device.h" + +#include +#include +#include +#include + +#include +#include +#include + +// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface +// lifetimes across processes and for protecting asynchronous calls across HIDL. + +namespace android::hardware::neuralnetworks::adapter { + +sp adapt(nn::SharedDevice device, Executor executor) { + return sp::make(std::move(device), std::move(executor)); +} + +sp adapt(nn::SharedDevice device) { + Executor defaultExecutor = [](Task task, uid_t /*uid*/, nn::OptionalTimePoint /*deadline*/) { + std::thread(std::move(task)).detach(); + }; + return adapt(std::move(device), std::move(defaultExecutor)); +} + +} // namespace android::hardware::neuralnetworks::adapter -- cgit v1.2.3 From 594cc78a7b5330210397c004d53e52db9148e297 Mon Sep 17 00:00:00 2001 From: Michael Butler Date: Tue, 11 Jan 2022 22:53:49 -0800 Subject: Remove uid from NN HIDL adapter Having the adapter retrieve the uid is redundant because the implementor is already able to get the uid directly themselves with IPCThreadState::self()->getCallingUid(). Bug: N/A Test: mma Change-Id: Ifeffea053cb92556be1aae8b17a94fafa1ac98e0 --- neuralnetworks/utils/adapter/hidl/src/Adapter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'neuralnetworks/utils/adapter/hidl/src/Adapter.cpp') diff --git a/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp b/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp index d6f53f05a5..782e815a83 100644 --- a/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp +++ b/neuralnetworks/utils/adapter/hidl/src/Adapter.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,7 @@ sp adapt(nn::SharedDevice device, Executor executor) { } sp adapt(nn::SharedDevice device) { - Executor defaultExecutor = [](Task task, uid_t /*uid*/, nn::OptionalTimePoint /*deadline*/) { + Executor defaultExecutor = [](Task task, nn::OptionalTimePoint /*deadline*/) { std::thread(std::move(task)).detach(); }; return adapt(std::move(device), std::move(defaultExecutor)); -- cgit v1.2.3