diff options
author | Xusong Wang <xusongw@google.com> | 2020-05-12 16:43:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-12 16:43:34 +0000 |
commit | 9926f82774463e258dcf2189341a2d36dd56f100 (patch) | |
tree | 4e7787eab0244d4bb6f71ba0f17568965d00aa51 /nn/common/Utils.cpp | |
parent | ef9c23ee28a3f36e494b3e9fc2aeba1cc284ae3c (diff) | |
parent | ca8c1cba4c7ba6612e0471be620c899e27032f77 (diff) | |
download | ml-9926f82774463e258dcf2189341a2d36dd56f100.tar.gz |
Merge "Avoid sending ahwb requests to 1.0 and 1.1 drivers." into rvc-dev
Diffstat (limited to 'nn/common/Utils.cpp')
-rw-r--r-- | nn/common/Utils.cpp | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/nn/common/Utils.cpp b/nn/common/Utils.cpp index cd97ffa52..81e5cf1e1 100644 --- a/nn/common/Utils.cpp +++ b/nn/common/Utils.cpp @@ -21,6 +21,8 @@ #include <android-base/logging.h> #include <android-base/properties.h> #include <android-base/strings.h> +#include <errno.h> +#include <poll.h> #include <sys/system_properties.h> #include <algorithm> @@ -32,9 +34,6 @@ #include <utility> #include <vector> -#include <errno.h> -#include <poll.h> - #include "ControlFlow.h" #include "NeuralNetworks.h" #include "NeuralNetworksOEM.h" @@ -3100,7 +3099,22 @@ bool compliantWithV1_0(const V1_0::Request& request) { bool compliantWithV1_0(const V1_3::Request& request) { return std::all_of(request.pools.begin(), request.pools.end(), [](const auto& pool) { - return pool.getDiscriminator() == V1_3::Request::MemoryPool::hidl_discriminator::hidlMemory; + if (pool.getDiscriminator() != V1_3::Request::MemoryPool::hidl_discriminator::hidlMemory) { + return false; + } + const auto& name = pool.hidlMemory().name(); + return name == "ashmem" || name == "mmap_fd"; + }); +} + +bool compliantWithV1_2(const V1_3::Request& request) { + return std::all_of(request.pools.begin(), request.pools.end(), [](const auto& pool) { + if (pool.getDiscriminator() != V1_3::Request::MemoryPool::hidl_discriminator::hidlMemory) { + return false; + } + const auto& name = pool.hidlMemory().name(); + return name == "ashmem" || name == "mmap_fd" || name == "hardware_buffer_blob" || + name == "hardware_buffer"; }); } @@ -3123,17 +3137,29 @@ V1_0::Request convertToV1_0(const V1_0::Request& request) { return request; } -V1_0::Request convertToV1_0(const V1_3::Request& request) { - if (!compliantWithV1_0(request)) { - LOG(ERROR) << "Upcasting non-compliant request " << SHOW_IF_DEBUG(toString(request)) - << " from V1_3::Request to V1_0::Request"; - } +static V1_0::Request uncheckedConvertToV1_0(const V1_3::Request& request) { hidl_vec<hidl_memory> pools(request.pools.size()); std::transform(request.pools.begin(), request.pools.end(), pools.begin(), [](const auto& pool) { return convertToV1_0(pool); }); return {.inputs = request.inputs, .outputs = request.outputs, .pools = std::move(pools)}; } +V1_0::Request convertToV1_0(const V1_3::Request& request) { + if (!compliantWithV1_0(request)) { + LOG(ERROR) << "Upcasting non-compliant request " << SHOW_IF_DEBUG(toString(request)) + << " from V1_3::Request to V1_0::Request of version 1.0"; + } + return uncheckedConvertToV1_0(request); +} + +V1_0::Request convertToV1_2(const V1_3::Request& request) { + if (!compliantWithV1_2(request)) { + LOG(ERROR) << "Upcasting non-compliant request " << SHOW_IF_DEBUG(toString(request)) + << " from V1_3::Request to V1_0::Request of version 1.2"; + } + return uncheckedConvertToV1_0(request); +} + V1_3::Request convertToV1_3(const V1_0::Request& request) { hidl_vec<V1_3::Request::MemoryPool> pools(request.pools.size()); std::transform(request.pools.begin(), request.pools.end(), pools.begin(), |