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
This commit is contained in:
Michael Butler
2021-10-15 18:52:52 -07:00
parent e8645c3b8d
commit 49d95e0457
34 changed files with 69 additions and 83 deletions

View File

@@ -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,13 +52,13 @@ 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( \
::android::nn::ErrorStatus::GENERAL_FAILURE); \
canonical == ::android::nn::ErrorStatus::NONE) { \
} else \
#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 \
return NN_ERROR(canonical)
} // 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

View File

@@ -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 {

View File

@@ -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 {};
}

View File

@@ -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();
}

View File

@@ -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>

View File

@@ -20,6 +20,7 @@
#include "Callbacks.h"
#include "Conversions.h"
#include "Execution.h"
#include "HandleError.h"
#include "ProtectCallback.h"
#include "Utils.h"
@@ -29,7 +30,6 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <tuple>
@@ -84,7 +84,7 @@ PreparedModel::executeInternal(const V1_0::Request& request,
const auto ret = kPreparedModel->execute(request, cb);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
auto result = NN_TRY(cb->get());
if (relocation.output) {

View File

@@ -22,7 +22,8 @@
#include <android/hidl/base/1.0/IBase.h>
#include <hidl/HidlSupport.h>
#include <nnapi/Result.h>
#include <nnapi/hal/HandleError.h>
#include "HandleError.h"
#include <algorithm>
#include <functional>

View File

@@ -26,7 +26,6 @@
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/HandleError.h>
namespace android::hardware::neuralnetworks::V1_1::utils {

View File

@@ -29,9 +29,9 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/Callbacks.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <functional>
#include <memory>
@@ -47,7 +47,7 @@ namespace {
nn::GeneralResult<nn::Capabilities> capabilitiesCallback(V1_0::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);
}
@@ -157,7 +157,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModel(
const auto ret = kDevice->prepareModel_1_1(hidlModel, hidlPreference, 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();
}

View File

@@ -28,7 +28,6 @@
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.1/Conversions.h>
#include <nnapi/hal/1.1/Utils.h>
#include <nnapi/hal/HandleError.h>
#include <limits>

View File

@@ -29,10 +29,10 @@
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/Callbacks.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/PreparedModel.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>
#include <utility>
@@ -62,7 +62,7 @@ convertExecutionGeneralResultsHelper(const hidl_vec<OutputShape>& outputShapes,
nn::GeneralResult<nn::SharedPreparedModel> prepareModelCallback(
V1_0::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, /*executeSynchronously=*/true));
}
@@ -74,7 +74,7 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> executi
return NN_ERROR(nn::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, std::move(canonicalOutputShapes))
<< "execution failed with " << toString(status);
}
HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
return convertExecutionGeneralResultsHelper(outputShapes, timing);
}

View File

@@ -28,7 +28,6 @@
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.1/Conversions.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <algorithm>
#include <functional>

View File

@@ -30,10 +30,10 @@
#include <nnapi/OperandTypes.h>
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/1.1/Conversions.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <functional>
#include <memory>
@@ -49,31 +49,31 @@ namespace {
nn::GeneralResult<nn::Capabilities> capabilitiesCallback(V1_0::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);
}
nn::GeneralResult<std::string> versionStringCallback(V1_0::ErrorStatus status,
const hidl_string& versionString) {
HANDLE_HAL_STATUS(status) << "getVersionString failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "getVersionString failed with " << toString(status);
return versionString;
}
nn::GeneralResult<nn::DeviceType> deviceTypeCallback(V1_0::ErrorStatus status,
DeviceType deviceType) {
HANDLE_HAL_STATUS(status) << "getDeviceType failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "getDeviceType failed with " << toString(status);
return nn::convert(deviceType);
}
nn::GeneralResult<std::vector<nn::Extension>> supportedExtensionsCallback(
V1_0::ErrorStatus status, const hidl_vec<Extension>& extensions) {
HANDLE_HAL_STATUS(status) << "getExtensions failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "getExtensions failed with " << toString(status);
return nn::convert(extensions);
}
nn::GeneralResult<std::pair<uint32_t, uint32_t>> numberOfCacheFilesNeededCallback(
V1_0::ErrorStatus status, uint32_t numModelCache, uint32_t numDataCache) {
HANDLE_HAL_STATUS(status) << "getNumberOfCacheFilesNeeded failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "getNumberOfCacheFilesNeeded failed with " << toString(status);
if (numModelCache > nn::kMaxNumberOfCacheFiles) {
return NN_ERROR() << "getNumberOfCacheFilesNeeded returned numModelCache files greater "
"than allowed max ("
@@ -254,7 +254,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModel(
const auto ret = kDevice->prepareModel_1_2(hidlModel, hidlPreference, hidlModelCache,
hidlDataCache, hidlToken, 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();
}
@@ -271,7 +271,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModelFromCache(
const auto ret = kDevice->prepareModelFromCache(hidlModelCache, hidlDataCache, hidlToken, cb);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
HANDLE_HAL_STATUS(status) << "model preparation from cache failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "model preparation from cache failed with " << toString(status);
return cb->get();
}

View File

@@ -29,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>

View File

@@ -28,9 +28,9 @@
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>
#include <algorithm>
@@ -82,8 +82,8 @@ class BurstExecution final : public nn::IExecution,
nn::GeneralResult<sp<IBurstContext>> executionBurstResultCallback(
V1_0::ErrorStatus status, const sp<IBurstContext>& burstContext) {
HANDLE_HAL_STATUS(status) << "IPreparedModel::configureExecutionBurst failed with status "
<< toString(status);
HANDLE_STATUS_HIDL(status) << "IPreparedModel::configureExecutionBurst failed with status "
<< toString(status);
if (burstContext == nullptr) {
return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
<< "IPreparedModel::configureExecutionBurst returned nullptr for burst";

View File

@@ -27,8 +27,8 @@
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>
#include <algorithm>
@@ -50,7 +50,7 @@ constexpr V1_2::Timing kNoTiming = {std::numeric_limits<uint64_t>::max(),
nn::GeneralResult<std::vector<nn::SharedMemory>> getMemoriesCallback(
V1_0::ErrorStatus status, const hidl_vec<hidl_memory>& memories) {
HANDLE_HAL_STATUS(status) << "getting burst memories failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "getting burst memories failed with " << toString(status);
std::vector<nn::SharedMemory> canonicalMemories;
canonicalMemories.reserve(memories.size());
for (const auto& memory : memories) {

View File

@@ -31,9 +31,9 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <chrono>
#include <memory>
@@ -82,7 +82,7 @@ PreparedModel::executeAsynchronously(const V1_0::Request& request, MeasureTiming
const auto ret = kPreparedModel->execute_1_2(request, measure, cb);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
if (status != V1_0::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) {
HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
}
return cb->get();

View File

@@ -30,7 +30,6 @@
#include <nnapi/hal/1.1/Utils.h>
#include <nnapi/hal/1.2/Conversions.h>
#include <nnapi/hal/1.2/Utils.h>
#include <nnapi/hal/HandleError.h>
namespace android::hardware::neuralnetworks::V1_3::utils {

View File

@@ -25,7 +25,7 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/1.0/HandleError.h>
#include "Conversions.h"
#include "Utils.h"
@@ -66,7 +66,7 @@ nn::GeneralResult<void> Buffer::copyTo(const nn::SharedMemory& dst) const {
const auto ret = kBuffer->copyTo(hidlDst);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
HANDLE_HAL_STATUS(status) << "IBuffer::copyTo failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "IBuffer::copyTo failed with " << toString(status);
return {};
}
@@ -78,7 +78,7 @@ nn::GeneralResult<void> Buffer::copyFrom(const nn::SharedMemory& src,
const auto ret = kBuffer->copyFrom(hidlSrc, hidlDimensions);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
HANDLE_HAL_STATUS(status) << "IBuffer::copyFrom failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "IBuffer::copyFrom failed with " << toString(status);
return {};
}

View File

@@ -30,13 +30,13 @@
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/Callbacks.h>
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/PreparedModel.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/1.2/Callbacks.h>
#include <nnapi/hal/1.2/Conversions.h>
#include <nnapi/hal/1.2/PreparedModel.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <nnapi/hal/TransferValue.h>
#include <utility>
@@ -71,13 +71,13 @@ convertExecutionGeneralResultsHelper(const hidl_vec<V1_2::OutputShape>& outputSh
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, /*executeSynchronously=*/true));
}
@@ -90,7 +90,7 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> executi
return NN_ERROR(nn::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, std::move(canonicalOutputShapes))
<< "execution failed with " << toString(status);
}
HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
return convertExecutionGeneralResultsHelper(outputShapes, timing);
}

View File

@@ -28,7 +28,6 @@
#include <nnapi/hal/1.0/Conversions.h>
#include <nnapi/hal/1.2/Conversions.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <algorithm>
#include <chrono>

View File

@@ -33,13 +33,13 @@
#include <nnapi/OperandTypes.h>
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/1.1/Conversions.h>
#include <nnapi/hal/1.2/Conversions.h>
#include <nnapi/hal/1.2/Device.h>
#include <nnapi/hal/1.2/Utils.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <any>
#include <functional>
@@ -72,7 +72,7 @@ nn::GeneralResult<hidl_vec<sp<IPreparedModel>>> convert(
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);
}
@@ -89,7 +89,7 @@ nn::GeneralResult<nn::Capabilities> getCapabilitiesFrom(V1_3::IDevice* device) {
nn::GeneralResult<nn::SharedBuffer> allocationCallback(ErrorStatus status,
const sp<IBuffer>& buffer, uint32_t token) {
HANDLE_HAL_STATUS(status) << "IDevice::allocate failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "IDevice::allocate failed with " << toString(status);
return Buffer::create(buffer, static_cast<nn::Request::MemoryDomainToken>(token));
}
@@ -208,7 +208,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModel(
kDevice->prepareModel_1_3(hidlModel, hidlPreference, hidlPriority, hidlDeadline,
hidlModelCache, hidlDataCache, hidlToken, 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();
}
@@ -227,7 +227,7 @@ nn::GeneralResult<nn::SharedPreparedModel> Device::prepareModelFromCache(
const auto ret = kDevice->prepareModelFromCache_1_3(hidlDeadline, hidlModelCache, hidlDataCache,
hidlToken, cb);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
HANDLE_HAL_STATUS(status) << "model preparation from cache failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "model preparation from cache failed with " << toString(status);
return cb->get();
}

View File

@@ -29,7 +29,6 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <utility>

View File

@@ -30,12 +30,12 @@
#include <nnapi/Result.h>
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/hal/1.0/HandleError.h>
#include <nnapi/hal/1.0/ProtectCallback.h>
#include <nnapi/hal/1.2/Conversions.h>
#include <nnapi/hal/1.2/ExecutionBurstController.h>
#include <nnapi/hal/1.2/ExecutionBurstUtils.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <tuple>
@@ -50,14 +50,14 @@ namespace {
nn::GeneralResult<std::pair<nn::Timing, nn::Timing>> convertFencedExecutionCallbackResults(
ErrorStatus status, const V1_2::Timing& timingLaunched, const V1_2::Timing& timingFenced) {
HANDLE_HAL_STATUS(status) << "fenced execution callback info failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "fenced execution callback info failed with " << toString(status);
return std::make_pair(NN_TRY(nn::convert(timingLaunched)), NN_TRY(nn::convert(timingFenced)));
}
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> fencedExecutionCallback(
ErrorStatus status, const hidl_handle& syncFence,
const sp<IFencedExecutionCallback>& callback) {
HANDLE_HAL_STATUS(status) << "fenced execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "fenced execution failed with " << toString(status);
auto resultSyncFence = nn::SyncFence::createAsSignaled();
if (syncFence.getNativeHandle() != nullptr) {
@@ -127,7 +127,7 @@ PreparedModel::executeAsynchronously(const Request& request, V1_2::MeasureTiming
kPreparedModel->execute_1_3(request, measure, deadline, loopTimeoutDuration, cb);
const auto status = HANDLE_TRANSPORT_FAILURE(ret);
if (status != ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) {
HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status);
HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status);
}
return cb->get();

View File

@@ -40,7 +40,6 @@ cc_library_static {
shared_libs: [
"android.hardware.neuralnetworks-V2-ndk",
"libbinder_ndk",
"libhidlbase",
],
target: {
android: {

View File

@@ -24,7 +24,6 @@
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/HandleError.h>
namespace aidl::android::hardware::neuralnetworks::utils {
@@ -75,6 +74,13 @@ nn::GeneralResult<void> handleTransportError(const ndk::ScopedAStatus& ret);
for (const auto status = handleTransportError(ret); !status.ok();) \
return NN_ERROR(status.error().code) << status.error().message << ": "
#define HANDLE_STATUS_AIDL(status) \
if (const ::android::nn::ErrorStatus canonical = ::android::nn::convert(status).value_or( \
::android::nn::ErrorStatus::GENERAL_FAILURE); \
canonical == ::android::nn::ErrorStatus::NONE) { \
} else \
return NN_ERROR(canonical)
} // namespace aidl::android::hardware::neuralnetworks::utils
#endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_AIDL_UTILS_H

View File

@@ -26,7 +26,6 @@
#include <nnapi/Result.h>
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <mutex>

View File

@@ -38,7 +38,7 @@ namespace {
// nn::Version::ANDROID_S. On failure, this function returns with the appropriate nn::GeneralError.
nn::GeneralResult<nn::SharedPreparedModel> prepareModelCallback(
ErrorStatus status, const std::shared_ptr<IPreparedModel>& preparedModel) {
HANDLE_HAL_STATUS(status) << "model preparation failed with " << toString(status);
HANDLE_STATUS_AIDL(status) << "model preparation failed with " << toString(status);
return NN_TRY(PreparedModel::create(preparedModel));
}

View File

@@ -34,7 +34,6 @@
#include <nnapi/Types.h>
#include <nnapi/Validation.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <algorithm>
#include <chrono>

View File

@@ -25,7 +25,6 @@
#include <nnapi/Result.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <utility>

View File

@@ -30,7 +30,6 @@
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
#include <nnapi/hal/CommonUtils.h>
#include <nnapi/hal/HandleError.h>
#include <memory>
#include <tuple>
@@ -51,7 +50,7 @@ nn::GeneralResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> convertEx
nn::GeneralResult<std::pair<nn::Timing, nn::Timing>> convertFencedExecutionResults(
ErrorStatus status, const aidl_hal::Timing& timingLaunched,
const aidl_hal::Timing& timingFenced) {
HANDLE_HAL_STATUS(status) << "fenced execution callback info failed with " << toString(status);
HANDLE_STATUS_AIDL(status) << "fenced execution callback info failed with " << toString(status);
return std::make_pair(NN_TRY(nn::convert(timingLaunched)), NN_TRY(nn::convert(timingFenced)));
}

View File

@@ -36,7 +36,6 @@
#include <nnapi/hal/1.2/Utils.h>
#include <nnapi/hal/1.3/Conversions.h>
#include <nnapi/hal/1.3/Utils.h>
#include <nnapi/hal/HandleError.h>
#include <sys/types.h>
#include <memory>

View File

@@ -30,13 +30,8 @@ cc_library_static {
local_include_dirs: ["include/nnapi/hal"],
export_include_dirs: ["include"],
cflags: ["-Wthread-safety"],
static_libs: [
"neuralnetworks_types",
],
shared_libs: [
"libhidlbase",
"libbinder_ndk",
],
static_libs: ["neuralnetworks_types"],
shared_libs: ["libbinder_ndk"],
}
cc_test {

View File

@@ -16,8 +16,6 @@
#include "CommonUtils.h"
#include "HandleError.h"
#include <android-base/logging.h>
#include <nnapi/Result.h>
#include <nnapi/SharedMemory.h>