Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49d95e04 authored by Michael Butler's avatar Michael Butler
Browse files

Move NN HandleError from utils/common to 1.0/utils

This change is part of a larger chain of changes to remove HIDL and AIDL
libraries from neuralnetworks_utils_hal_common.

Bug: N/A
Test: mma
Change-Id: Iae9f692ffc72700294aae694c256e75c7e353fef
parent e8645c3b
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
 * limitations under the License.
 */

#ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_HANDLE_ERROR_H
#define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_HANDLE_ERROR_H
#ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_HANDLE_ERROR_H
#define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_HANDLE_ERROR_H

#include <android/hidl/base/1.0/IBase.h>
#include <hidl/HidlSupport.h>
@@ -27,7 +27,7 @@
namespace android::hardware::neuralnetworks::utils {

template <typename Type>
nn::GeneralResult<Type> handleTransportError(const hardware::Return<Type>& ret) {
nn::GeneralResult<Type> handleTransportError(const Return<Type>& ret) {
    if (ret.isDeadObject()) {
        return nn::error(nn::ErrorStatus::DEAD_OBJECT)
               << "Return<>::isDeadObject returned true: " << ret.description();
@@ -52,8 +52,8 @@ nn::GeneralResult<Type> handleTransportError(const hardware::Return<Type>& ret)
        std::move(result).value();                                                           \
    })

#define HANDLE_HAL_STATUS(status)                                       \
    if (const auto canonical = ::android::nn::convert(status).value_or( \
#define HANDLE_STATUS_HIDL(status)                                                            \
    if (const ::android::nn::ErrorStatus canonical = ::android::nn::convert(status).value_or( \
                ::android::nn::ErrorStatus::GENERAL_FAILURE);                                 \
        canonical == ::android::nn::ErrorStatus::NONE) {                                      \
    } else                                                                                    \
@@ -61,4 +61,4 @@ nn::GeneralResult<Type> handleTransportError(const hardware::Return<Type>& ret)

}  // namespace android::hardware::neuralnetworks::utils

#endif  // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_HANDLE_ERROR_H
#endif  // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_HANDLE_ERROR_H
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/HandleError.h>

namespace android::hardware::neuralnetworks::V1_0::utils {

+4 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "Callbacks.h"

#include "Conversions.h"
#include "HandleError.h"
#include "PreparedModel.h"
#include "ProtectCallback.h"
#include "Utils.h"
@@ -28,7 +29,6 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>

#include <utility>
@@ -40,19 +40,19 @@ namespace android::hardware::neuralnetworks::V1_0::utils {

nn::GeneralResult<std::vector<bool>> supportedOperationsCallback(
        ErrorStatus status, const hidl_vec<bool>& supportedOperations) {
    HANDLE_HAL_STATUS(status) << "get supported operations failed with " << toString(status);
    HANDLE_STATUS_HIDL(status) << "get supported operations failed with " << toString(status);
    return supportedOperations;
}

nn::GeneralResult<nn::SharedPreparedModel> prepareModelCallback(
        ErrorStatus status, const sp<IPreparedModel>& preparedModel) {
    HANDLE_HAL_STATUS(status) << "model preparation failed with " << toString(status);
    HANDLE_STATUS_HIDL(status) << "model preparation failed with " << toString(status);
    return NN_TRY(PreparedModel::create(preparedModel));
}

nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> executionCallback(
        ErrorStatus status) {
    HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
    HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
    return {};
}

+3 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "Callbacks.h"
#include "Conversions.h"
#include "HandleError.h"
#include "ProtectCallback.h"
#include "Utils.h"

@@ -30,7 +31,6 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>

#include <functional>
@@ -47,7 +47,7 @@ namespace {

nn::GeneralResult<nn::Capabilities> capabilitiesCallback(ErrorStatus status,
                                                         const Capabilities& capabilities) {
    HANDLE_HAL_STATUS(status) << "getting capabilities failed with " << toString(status);
    HANDLE_STATUS_HIDL(status) << "getting capabilities failed with " << toString(status);
    return nn::convert(capabilities);
}

@@ -156,7 +156,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModel(

    const auto ret = kDevice->prepareModel(hidlModel, cb);
    const auto status = HANDLE_TRANSPORT_FAILURE(ret);
    HANDLE_HAL_STATUS(status) << "model preparation failed with " << toString(status);
    HANDLE_STATUS_HIDL(status) << "model preparation failed with " << toString(status);

    return cb->get();
}
+1 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "Callbacks.h"
#include "Conversions.h"
#include "HandleError.h"
#include "ProtectCallback.h"
#include "Utils.h"

@@ -28,7 +29,6 @@
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>

#include <memory>
#include <utility>
Loading