diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-03-01 01:29:04 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-03-01 01:29:04 +0000 |
commit | c5087c06b38abafe6cb8154f733f7c1305cc1e31 (patch) | |
tree | 78a3e35e28e9a5999fc103d245bf1b0c8110f26d /neuralnetworks | |
parent | 5974f5869b8a656f8dcaa98d8c0f6b5e1b0ff6e2 (diff) | |
parent | bbd66d27a0515d1d9994adb3d8a43f6c71e8badc (diff) |
Merge "Cast to the underlying type for union tags" am: 6cd0d474b2 am: 5eb895c047 am: bbd66d27a0
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1999055
Change-Id: Ie0a38cc29d50c65b8168435c70786321fc9de199
Diffstat (limited to 'neuralnetworks')
-rw-r--r-- | neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h | 7 | ||||
-rw-r--r-- | neuralnetworks/aidl/utils/src/Conversions.cpp | 7 | ||||
-rw-r--r-- | neuralnetworks/aidl/utils/src/Utils.cpp | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h index beca38b1ee..7ed54371db 100644 --- a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h +++ b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h @@ -26,6 +26,8 @@ #include <nnapi/Types.h> #include <nnapi/Validation.h> +#include <type_traits> + namespace aidl::android::hardware::neuralnetworks::utils { constexpr auto kDefaultPriority = Priority::MEDIUM; @@ -80,6 +82,11 @@ auto convertFromNonCanonical(const Type& nonCanonicalObject) return convert(NN_TRY(nn::convert(nonCanonicalObject))); } +template <typename Type> +constexpr std::underlying_type_t<Type> underlyingType(Type value) { + return static_cast<std::underlying_type_t<Type>>(value); +} + nn::GeneralResult<Memory> clone(const Memory& memory); nn::GeneralResult<Request> clone(const Request& request); nn::GeneralResult<RequestMemoryPool> clone(const RequestMemoryPool& requestPool); diff --git a/neuralnetworks/aidl/utils/src/Conversions.cpp b/neuralnetworks/aidl/utils/src/Conversions.cpp index 83fda10ce2..081e3d7142 100644 --- a/neuralnetworks/aidl/utils/src/Conversions.cpp +++ b/neuralnetworks/aidl/utils/src/Conversions.cpp @@ -57,10 +57,6 @@ while (UNLIKELY(value > std::numeric_limits<int32_t>::max())) return NN_ERROR() namespace { -template <typename Type> -constexpr std::underlying_type_t<Type> underlyingType(Type value) { - return static_cast<std::underlying_type_t<Type>>(value); -} constexpr int64_t kNoTiming = -1; @@ -70,6 +66,7 @@ namespace android::nn { namespace { using ::aidl::android::hardware::common::NativeHandle; +using ::aidl::android::hardware::neuralnetworks::utils::underlyingType; template <typename Input> using UnvalidatedConvertOutput = @@ -404,7 +401,7 @@ GeneralResult<SharedMemory> unvalidatedConvert(const aidl_hal::Memory& memory) { #endif // __ANDROID__ } } - return NN_ERROR() << "Unrecognized Memory::Tag: " << memory.getTag(); + return NN_ERROR() << "Unrecognized Memory::Tag: " << underlyingType(memory.getTag()); } GeneralResult<Timing> unvalidatedConvert(const aidl_hal::Timing& timing) { diff --git a/neuralnetworks/aidl/utils/src/Utils.cpp b/neuralnetworks/aidl/utils/src/Utils.cpp index 03407be4ce..76a0b07d86 100644 --- a/neuralnetworks/aidl/utils/src/Utils.cpp +++ b/neuralnetworks/aidl/utils/src/Utils.cpp @@ -88,7 +88,7 @@ nn::GeneralResult<Memory> clone(const Memory& memory) { return Memory::make<Memory::Tag::hardwareBuffer>(std::move(handle)); } } - return (NN_ERROR() << "Unrecognized Memory::Tag: " << memory.getTag()) + return (NN_ERROR() << "Unrecognized Memory::Tag: " << underlyingType(memory.getTag())) . operator nn::GeneralResult<Memory>(); } @@ -103,7 +103,7 @@ nn::GeneralResult<RequestMemoryPool> clone(const RequestMemoryPool& requestPool) } // Using explicit type conversion because std::variant inside the RequestMemoryPool confuses the // compiler. - return (NN_ERROR() << "Unrecognized request pool tag: " << requestPool.getTag()) + return (NN_ERROR() << "Unrecognized request pool tag: " << underlyingType(requestPool.getTag())) . operator nn::GeneralResult<RequestMemoryPool>(); } |