mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge "Use proper alignment and padding for pointer arguments -- HAL." am: 0a3ca7b629 am: 56ffb53709
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1702587 Change-Id: I860fb3ff5fccc5bb047f543ccb3c9322b17d1e83
This commit is contained in:
@@ -65,7 +65,8 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Prepare
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
const auto hidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared)));
|
||||
|
||||
@@ -111,7 +112,8 @@ nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution(
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
auto hidlRequest = NN_TRY(convert(requestInShared));
|
||||
return Execution::create(shared_from_this(), std::move(hidlRequest), std::move(relocation));
|
||||
|
||||
@@ -328,7 +328,8 @@ ExecutionBurstController::execute(const nn::Request& request, nn::MeasureTiming
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
// clear pools field of request, as they will be provided via slots
|
||||
const auto requestWithoutPools = nn::Request{
|
||||
@@ -373,7 +374,8 @@ nn::GeneralResult<nn::SharedExecution> ExecutionBurstController::createReusableE
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
// clear pools field of request, as they will be provided via slots
|
||||
const auto requestWithoutPools = nn::Request{
|
||||
|
||||
@@ -97,7 +97,8 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Prepare
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
const auto hidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared)));
|
||||
const auto hidlMeasure = NN_TRY(hal::utils::makeExecutionFailure(convert(measure)));
|
||||
@@ -140,7 +141,8 @@ nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution(
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
auto hidlRequest = NN_TRY(convert(requestInShared));
|
||||
auto hidlMeasure = NN_TRY(convert(measure));
|
||||
|
||||
@@ -143,7 +143,8 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Prepare
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
const auto hidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared)));
|
||||
const auto hidlMeasure = NN_TRY(hal::utils::makeExecutionFailure(convert(measure)));
|
||||
@@ -184,7 +185,8 @@ PreparedModel::executeFenced(const nn::Request& request, const std::vector<nn::S
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
const auto hidlRequest = NN_TRY(convert(requestInShared));
|
||||
const auto hidlWaitFor = NN_TRY(hal::utils::convertSyncFences(waitFor));
|
||||
@@ -236,7 +238,8 @@ nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution(
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
auto hidlRequest = NN_TRY(convert(requestInShared));
|
||||
auto hidlMeasure = NN_TRY(convert(measure));
|
||||
|
||||
@@ -178,7 +178,8 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Burst::
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kDefaultRequestMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
const auto aidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared)));
|
||||
const auto aidlMeasure = NN_TRY(hal::utils::makeExecutionFailure(convert(measure)));
|
||||
@@ -248,7 +249,8 @@ nn::GeneralResult<nn::SharedExecution> Burst::createReusableExecution(
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kDefaultRequestMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
auto aidlRequest = NN_TRY(convert(requestInShared));
|
||||
const auto aidlMeasure = NN_TRY(convert(measure));
|
||||
|
||||
@@ -80,7 +80,8 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Prepare
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared =
|
||||
NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation)));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kDefaultRequestMemoryPadding,
|
||||
&maybeRequestInShared, &relocation)));
|
||||
|
||||
const auto aidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared)));
|
||||
const auto aidlMeasure = NN_TRY(hal::utils::makeExecutionFailure(convert(measure)));
|
||||
@@ -127,7 +128,8 @@ PreparedModel::executeFenced(const nn::Request& request, const std::vector<nn::S
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kDefaultRequestMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
const auto aidlRequest = NN_TRY(convert(requestInShared));
|
||||
const auto aidlWaitFor = NN_TRY(convert(waitFor));
|
||||
@@ -197,7 +199,8 @@ nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution(
|
||||
std::optional<nn::Request> maybeRequestInShared;
|
||||
hal::utils::RequestRelocation relocation;
|
||||
const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared(
|
||||
&request, &maybeRequestInShared, &relocation));
|
||||
&request, nn::kDefaultRequestMemoryAlignment, nn::kDefaultRequestMemoryPadding,
|
||||
&maybeRequestInShared, &relocation));
|
||||
|
||||
auto aidlRequest = NN_TRY(convert(requestInShared));
|
||||
auto aidlMeasure = NN_TRY(convert(measure));
|
||||
|
||||
@@ -122,8 +122,8 @@ struct RequestRelocation {
|
||||
// Unlike `flushDataFromPointerToShared`, this method will not copy the input pointer data to the
|
||||
// shared memory pool. Use `relocationOut` to flush the input or output data after the call.
|
||||
nn::GeneralResult<std::reference_wrapper<const nn::Request>> convertRequestFromPointerToShared(
|
||||
const nn::Request* request, std::optional<nn::Request>* maybeRequestInSharedOut,
|
||||
RequestRelocation* relocationOut);
|
||||
const nn::Request* request, uint32_t alignment, uint32_t padding,
|
||||
std::optional<nn::Request>* maybeRequestInSharedOut, RequestRelocation* relocationOut);
|
||||
|
||||
nn::GeneralResult<std::vector<uint32_t>> countNumberOfConsumers(
|
||||
size_t numberOfOperands, const std::vector<nn::Operation>& operations);
|
||||
|
||||
@@ -220,8 +220,8 @@ void OutputRelocationTracker::flush() const {
|
||||
}
|
||||
|
||||
nn::GeneralResult<std::reference_wrapper<const nn::Request>> convertRequestFromPointerToShared(
|
||||
const nn::Request* request, std::optional<nn::Request>* maybeRequestInSharedOut,
|
||||
RequestRelocation* relocationOut) {
|
||||
const nn::Request* request, uint32_t alignment, uint32_t padding,
|
||||
std::optional<nn::Request>* maybeRequestInSharedOut, RequestRelocation* relocationOut) {
|
||||
CHECK(request != nullptr);
|
||||
CHECK(maybeRequestInSharedOut != nullptr);
|
||||
CHECK(relocationOut != nullptr);
|
||||
@@ -249,7 +249,7 @@ nn::GeneralResult<std::reference_wrapper<const nn::Request>> convertRequestFromP
|
||||
const void* data = std::visit([](auto ptr) { return static_cast<const void*>(ptr); },
|
||||
location.pointer);
|
||||
CHECK(data != nullptr);
|
||||
input.location = inputBuilder.append(location.length);
|
||||
input.location = inputBuilder.append(location.length, alignment, padding);
|
||||
inputRelocationInfos.push_back({data, input.location.length, input.location.offset});
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ nn::GeneralResult<std::reference_wrapper<const nn::Request>> convertRequestFromP
|
||||
output.lifetime = nn::Request::Argument::LifeTime::POOL;
|
||||
void* data = std::get<void*>(location.pointer);
|
||||
CHECK(data != nullptr);
|
||||
output.location = outputBuilder.append(location.length);
|
||||
output.location = outputBuilder.append(location.length, alignment, padding);
|
||||
outputRelocationInfos.push_back({data, output.location.length, output.location.offset});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user