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/aidl/src/Adapter.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 neuralnetworks/utils/adapter/aidl/src/Adapter.cpp (limited to 'neuralnetworks/utils/adapter/aidl/src/Adapter.cpp') diff --git a/neuralnetworks/utils/adapter/aidl/src/Adapter.cpp b/neuralnetworks/utils/adapter/aidl/src/Adapter.cpp new file mode 100644 index 0000000000..d0b56e89cc --- /dev/null +++ b/neuralnetworks/utils/adapter/aidl/src/Adapter.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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 AIDL interface +// lifetimes across processes and for protecting asynchronous calls across AIDL. + +namespace aidl::android::hardware::neuralnetworks::adapter { + +std::shared_ptr adapt(::android::nn::SharedDevice device, Executor executor) { + return ndk::SharedRefBase::make(std::move(device), std::move(executor)); +} + +std::shared_ptr adapt(::android::nn::SharedDevice device) { + Executor defaultExecutor = [](Task task, ::android::nn::OptionalTimePoint /*deadline*/) { + std::thread(std::move(task)).detach(); + }; + return adapt(std::move(device), std::move(defaultExecutor)); +} + +} // namespace aidl::android::hardware::neuralnetworks::adapter -- cgit v1.2.3