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 #include +#include + 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 +constexpr std::underlying_type_t underlyingType(Type value) { + return static_cast>(value); +} + nn::GeneralResult clone(const Memory& memory); nn::GeneralResult clone(const Request& request); nn::GeneralResult 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::max())) return NN_ERROR() namespace { -template -constexpr std::underlying_type_t underlyingType(Type value) { - return static_cast>(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 using UnvalidatedConvertOutput = @@ -404,7 +401,7 @@ GeneralResult 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 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 clone(const Memory& memory) { return Memory::make(std::move(handle)); } } - return (NN_ERROR() << "Unrecognized Memory::Tag: " << memory.getTag()) + return (NN_ERROR() << "Unrecognized Memory::Tag: " << underlyingType(memory.getTag())) . operator nn::GeneralResult(); } @@ -103,7 +103,7 @@ nn::GeneralResult 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(); }