Change NN adapter to use ExecutionBurstServer utility

Bug: 180492058
Bug: 177267324
Test: mma, presubmit
Change-Id: I589668efe187641a67934463bcdea8d19f095bb4
This commit is contained in:
Michael Butler 2021-05-25 12:26:45 -07:00
parent be7f81f58d
commit cfc16f94b2

View file

@ -16,7 +16,6 @@
#include "PreparedModel.h"
#include <ExecutionBurstServer.h>
#include <android-base/logging.h>
#include <android/hardware/neuralnetworks/1.0/IExecutionCallback.h>
#include <android/hardware/neuralnetworks/1.0/types.h>
@ -33,6 +32,7 @@
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/1.0/Utils.h>
#include <nnapi/hal/1.2/ExecutionBurstServer.h>
#include <nnapi/hal/1.2/Utils.h>
#include <nnapi/hal/1.3/Conversions.h>
#include <nnapi/hal/1.3/Utils.h>
@ -272,6 +272,16 @@ nn::GeneralResult<std::vector<nn::SyncFence>> convertSyncFences(
return syncFences;
}
nn::GeneralResult<sp<V1_2::IBurstContext>> configureExecutionBurst(
const nn::SharedPreparedModel& preparedModel, const sp<V1_2::IBurstCallback>& callback,
const MQDescriptorSync<V1_2::FmqRequestDatum>& requestChannel,
const MQDescriptorSync<V1_2::FmqResultDatum>& resultChannel) {
auto burstExecutor = NN_TRY(preparedModel->configureExecutionBurst());
return V1_2::utils::ExecutionBurstServer::create(
callback, requestChannel, resultChannel, std::move(burstExecutor),
V1_2::utils::getBurstServerPollingTimeWindow());
}
nn::GeneralResult<std::pair<hidl_handle, sp<V1_3::IFencedExecutionCallback>>> executeFenced(
const nn::SharedPreparedModel& preparedModel, const V1_3::Request& request,
const hidl_vec<hidl_handle>& waitFor, V1_2::MeasureTiming measure,
@ -388,14 +398,17 @@ Return<void> PreparedModel::configureExecutionBurst(
const MQDescriptorSync<V1_2::FmqRequestDatum>& requestChannel,
const MQDescriptorSync<V1_2::FmqResultDatum>& resultChannel,
configureExecutionBurst_cb cb) {
const sp<V1_2::IBurstContext> burst = nn::ExecutionBurstServer::create(
callback, requestChannel, resultChannel, this, std::chrono::microseconds{0});
if (burst == nullptr) {
cb(V1_0::ErrorStatus::GENERAL_FAILURE, {});
} else {
cb(V1_0::ErrorStatus::NONE, burst);
auto result = adapter::configureExecutionBurst(kPreparedModel, callback, requestChannel,
resultChannel);
if (!result.has_value()) {
auto [message, code] = std::move(result).error();
LOG(ERROR) << "adapter::PreparedModel::configureExecutionBurst failed with " << code << ": "
<< message;
cb(V1_2::utils::convert(code).value(), nullptr);
return Void();
}
auto burstContext = std::move(result).value();
cb(V1_0::ErrorStatus::NONE, std::move(burstContext));
return Void();
}