Merge "Update sync fence related API for NNAPI" am: 1eb640d440

Change-Id: I83808f988b7e27d405b66c63feae311ed175e46b
This commit is contained in:
Automerger Merge Worker 2020-02-04 00:33:30 +00:00
commit f48c750c10
7 changed files with 118 additions and 65 deletions

View file

@ -633,10 +633,10 @@ ac429fca0da4ce91218768ec31b64ded88251f8a26d8c4f27c06abdc5b1926d9 android.hardwar
65c16331e57f6dd68b3971f06f78fe9e3209afb60630c31705aa355f9a52bf0d android.hardware.neuralnetworks@1.3::IBuffer 65c16331e57f6dd68b3971f06f78fe9e3209afb60630c31705aa355f9a52bf0d android.hardware.neuralnetworks@1.3::IBuffer
d1f382d14e1384b907d5bb5780df7f01934650d556fedbed2f15a90773c657d6 android.hardware.neuralnetworks@1.3::IDevice d1f382d14e1384b907d5bb5780df7f01934650d556fedbed2f15a90773c657d6 android.hardware.neuralnetworks@1.3::IDevice
4167dc3ad35e9cd0d2057d4868c7675ae2c3c9d05bbd614c1f5dccfa5fd68797 android.hardware.neuralnetworks@1.3::IExecutionCallback 4167dc3ad35e9cd0d2057d4868c7675ae2c3c9d05bbd614c1f5dccfa5fd68797 android.hardware.neuralnetworks@1.3::IExecutionCallback
29e26e83399b69c7998b787bd30426dd5baa2da350effca76bbee1ba877355c9 android.hardware.neuralnetworks@1.3::IFencedExecutionCallback 2fa3679ad7c94b5e88724adcd560c561041068a4ca565c63830e68101988746a android.hardware.neuralnetworks@1.3::IFencedExecutionCallback
384fd9fd6e4d43ea11d407e52ea81da5242c3c5f4b458b8707d8feb652a13e36 android.hardware.neuralnetworks@1.3::IPreparedModel 237b23b126a66f3432658020fed78cdd06ba6297459436fe6bae0ba753370833 android.hardware.neuralnetworks@1.3::IPreparedModel
0439a1fbbec7f16e5e4c653d85ac685d51bfafbae15b8f8cca530acdd7d6a8ce android.hardware.neuralnetworks@1.3::IPreparedModelCallback 0439a1fbbec7f16e5e4c653d85ac685d51bfafbae15b8f8cca530acdd7d6a8ce android.hardware.neuralnetworks@1.3::IPreparedModelCallback
5f1a4e0c29fc686ed476f9f04eed35e4405d21288cb2746b978d6891de5cc37d android.hardware.neuralnetworks@1.3::types 3646950b10f7cacdafca13609b0e18496cea942f3bdfe920494661856eff48bb android.hardware.neuralnetworks@1.3::types
3e01d4446cd69fd1c48f8572efd97487bc179564b32bd795800b97bbe10be37b android.hardware.wifi@1.4::IWifi 3e01d4446cd69fd1c48f8572efd97487bc179564b32bd795800b97bbe10be37b android.hardware.wifi@1.4::IWifi
a64467bae843569f0d465c5be7f0c7a5b987985b55a3ef4794dd5afc68538650 android.hardware.wifi.supplicant@1.3::ISupplicant a64467bae843569f0d465c5be7f0c7a5b987985b55a3ef4794dd5afc68538650 android.hardware.wifi.supplicant@1.3::ISupplicant
44445b8a03d7b9e68b2fbd954672c18a8fce9e32851b0692f4f4ab3407f86ecb android.hardware.wifi.supplicant@1.3::ISupplicantStaIface 44445b8a03d7b9e68b2fbd954672c18a8fce9e32851b0692f4f4ab3407f86ecb android.hardware.wifi.supplicant@1.3::ISupplicantStaIface

View file

@ -38,11 +38,24 @@ interface IFencedExecutionCallback {
* - DEVICE_UNAVAILABLE if driver is offline or busy * - DEVICE_UNAVAILABLE if driver is offline or busy
* - GENERAL_FAILURE if the asynchronous task resulted in an * - GENERAL_FAILURE if the asynchronous task resulted in an
* unspecified error * unspecified error
* @return timing Duration of execution. Unless MeasureTiming::YES was passed when * - MISSED_DEADLINE_* if the deadline for executing a model
* launching the execution and status is NONE, all times must * cannot be met
* be reported as UINT64_MAX. A driver may choose to report * - RESOURCE_EXHAUSTED_* if the task was aborted by the
* any time as UINT64_MAX, indicating that particular measurement is * driver
* not available. * @return timingLaunched The duration starts when executeFenced is called and ends when
* executeFenced signals the returned syncFence.
* Unless MeasureTiming::YES was passed when
* launching the execution and status is NONE, all times
* must be reported as UINT64_MAX. A driver may choose to
* report any time as UINT64_MAX, indicating that particular
* measurement is not available.
* @return timingFenced The duration starts when all waitFor sync fences have been signaled
* and ends when executeFenced signals the returned syncFence.
* Unless MeasureTiming::YES was passed when
* launching the execution and status is NONE, all times
* must be reported as UINT64_MAX. A driver may choose to
* report any time as UINT64_MAX, indicating that particular
* measurement is not available.
*/ */
getExecutionInfo() generates (ErrorStatus status, Timing timing); getExecutionInfo() generates (ErrorStatus status, Timing timingLaunched, Timing timingFenced);
}; };

View file

@ -21,6 +21,7 @@ import @1.2::MeasureTiming;
import @1.2::OutputShape; import @1.2::OutputShape;
import @1.2::Timing; import @1.2::Timing;
import ErrorStatus; import ErrorStatus;
import OptionalTimeoutDuration;
import OptionalTimePoint; import OptionalTimePoint;
import Request; import Request;
import IExecutionCallback; import IExecutionCallback;
@ -68,7 +69,7 @@ interface IPreparedModel extends @1.2::IPreparedModel {
* There must be no failure unless the device itself is in a bad state. * There must be no failure unless the device itself is in a bad state.
* *
* execute_1_3 can be called with an optional deadline. If the execution * execute_1_3 can be called with an optional deadline. If the execution
* is not able to completed before the provided deadline, the execution * is not able to be completed before the provided deadline, the execution
* must be aborted, and either {@link * must be aborted, and either {@link
* ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
* ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
@ -88,7 +89,7 @@ interface IPreparedModel extends @1.2::IPreparedModel {
* The duration runs from the time the driver sees the call * The duration runs from the time the driver sees the call
* to the execute_1_3 function to the time the driver invokes * to the execute_1_3 function to the time the driver invokes
* the callback. * the callback.
* @param deadline The time by which execution must complete. If the * @param deadline The time by which the execution must complete. If the
* execution cannot be finished by the deadline, the * execution cannot be finished by the deadline, the
* execution must be aborted. * execution must be aborted.
* @param callback A callback object used to return the error status of * @param callback A callback object used to return the error status of
@ -139,7 +140,7 @@ interface IPreparedModel extends @1.2::IPreparedModel {
* in a bad state. * in a bad state.
* *
* executeSynchronously_1_3 can be called with an optional deadline. If the * executeSynchronously_1_3 can be called with an optional deadline. If the
* execution is not able to completed before the provided deadline, the * execution is not able to be completed before the provided deadline, the
* execution must be aborted, and either {@link * execution must be aborted, and either {@link
* ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
* ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
@ -159,7 +160,7 @@ interface IPreparedModel extends @1.2::IPreparedModel {
* The duration runs from the time the driver sees the call * The duration runs from the time the driver sees the call
* to the executeSynchronously_1_3 function to the time the driver * to the executeSynchronously_1_3 function to the time the driver
* returns from the function. * returns from the function.
* @param deadline The time by which execution must complete. If the * @param deadline The time by which the execution must complete. If the
* execution cannot be finished by the deadline, the * execution cannot be finished by the deadline, the
* execution must be aborted. * execution must be aborted.
* @return status Error status of the execution, must be: * @return status Error status of the execution, must be:
@ -194,52 +195,75 @@ interface IPreparedModel extends @1.2::IPreparedModel {
* Launch a fenced asynchronous execution on a prepared model. * Launch a fenced asynchronous execution on a prepared model.
* *
* The execution is performed asynchronously with respect to the caller. * The execution is performed asynchronously with respect to the caller.
* executeFenced must fully validate the request, and only accept one that is * executeFenced must verify the inputs to the function are correct, and the usages
* guaranteed to be completed, unless a hardware failure or kernel panic happens on the device. * of memory pools allocated by IDevice::allocate are valid. If there is an error,
* If there is an error during validation, executeFenced must immediately return with * executeFenced must immediately return with the corresponding ErrorStatus, an empty
* the corresponding ErrorStatus. If the request is valid and there is no error launching, * handle for syncFence, and nullptr for callback. If the inputs to the function
* executeFenced must dispatch an asynchronous task to perform the execution in the * are valid and there is no error, executeFenced must dispatch an asynchronous task
* background, and immediately return with ErrorStatus::NONE, a sync_fence that will be * to perform the execution in the background, and immediately return with
* signaled once the execution is completed, and a callback that can be used by the client * ErrorStatus::NONE, a sync fence that will be signaled once the execution is completed,
* to query the duration and runtime error status. If the task has finished * and a callback that can be used by the client to query the duration and runtime error
* before the call returns, empty handle may be returned for the sync fence. If the * status. If the task has finished before the call returns, an empty handle may be returned
* asynchronous task fails to launch, executeFenced must immediately return with * for syncFence. The execution must wait for all the sync fences (if any) in waitFor
* ErrorStatus::GENERAL_FAILURE, and empty handle for the sync fence and nullptr * to be signaled before starting the actual execution.
* for callback. The execution must wait for all the sync fences (if any) in wait_for to be
* signaled before starting the actual execution.
*
* If any of sync fences in wait_for changes to error status after the executeFenced
* call succeeds, the driver must immediately set the returned sync fence to error status.
* *
* When the asynchronous task has finished its execution, it must * When the asynchronous task has finished its execution, it must
* immediately signal the sync_fence created when dispatching. After * immediately signal the syncFence returned from the executeFenced call. After
* the sync_fence is signaled, the task must not modify the content of * the syncFence is signaled, the task must not modify the content of
* any data object referenced by 'request' (described by the * any data object referenced by 'request' (described by the
* {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}). * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}).
* *
* executeFenced can be called with an optional deadline and an optional duration.
* If the execution is not able to be completed before the provided deadline or
* within the timeout duration (measured from when all sync fences in waitFor are
* signaled), whichever comes earlier, the execution must be aborted, and either
* {@link ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
* ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
* to an abort must be sent the same way as other errors, described above.
* If the service reports that it does not support execution deadlines via
* IDevice::supportsDeadlines, and executeFenced is called with a
* deadline or duration, then the argument is invalid, and
* {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
*
* If any of the sync fences in waitFor changes to error status after the executeFenced
* call succeeds, or the execution is aborted because it cannot finish before the deadline
* has been reached or the duration has elapsed, the driver must immediately set the returned
* syncFence to error status.
*
* Any number of calls to the executeFenced, execute* and executeSynchronously* * Any number of calls to the executeFenced, execute* and executeSynchronously*
* functions, in any combination, may be made concurrently, even on the same * functions, in any combination, may be made concurrently, even on the same
* IPreparedModel object. * IPreparedModel object.
* *
* @param request The input and output information on which the prepared * @param request The input and output information on which the prepared
* model is to be executed. * model is to be executed. The outputs in the request must have
* fully specified dimensions.
* @param waitFor A vector of sync fence file descriptors. * @param waitFor A vector of sync fence file descriptors.
* Execution must not start until all sync fences have been signaled. * Execution must not start until all sync fences have been signaled.
* @param measure Specifies whether or not to measure duration of the execution. * @param measure Specifies whether or not to measure duration of the execution.
* The duration runs from the time the driver sees the call * @param deadline The time by which the execution must complete. If the
* to the executeFenced function to the time sync_fence is triggered. * execution cannot be finished by the deadline, the
* execution must be aborted.
* @param duration The length of time within which the execution must
* complete after all sync fences in waitFor are signaled. If the
* execution cannot be finished within the duration, the execution
* must be aborted.
* @return status Error status of the call, must be: * @return status Error status of the call, must be:
* - NONE if task is successfully launched * - NONE if task is successfully launched
* - DEVICE_UNAVAILABLE if driver is offline or busy * - DEVICE_UNAVAILABLE if driver is offline or busy
* - GENERAL_FAILURE if there is an unspecified error * - GENERAL_FAILURE if there is an unspecified error
* - INVALID_ARGUMENT if one of the input arguments is invalid, including * - INVALID_ARGUMENT if one of the input arguments is invalid, including
* fences in error states. * fences in error states.
* @return syncFence The sync fence that will be triggered when the task is completed. * - MISSED_DEADLINE_* if the deadline for executing a model
* cannot be met
* - RESOURCE_EXHAUSTED_* if the task was aborted by the
* driver
* @return syncFence The sync fence that will be signaled when the task is completed.
* The sync fence will be set to error if a critical error, * The sync fence will be set to error if a critical error,
* e.g. hardware failure or kernel panic, occurs when doing execution. * e.g. hardware failure or kernel panic, occurs when doing execution.
* @return callback The IFencedExecutionCallback can be used to query information like duration * @return callback The IFencedExecutionCallback can be used to query information like duration
* and error status when the execution is completed. * and error status when the execution is completed.
*/ */
executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure) executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure,
OptionalTimePoint deadline, OptionalTimeoutDuration duration)
generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback); generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback);
}; };

View file

@ -5576,6 +5576,19 @@ safe_union OptionalTimePoint {
uint64_t nanoseconds; uint64_t nanoseconds;
}; };
/**
* Optional timeout duration measured in nanoseconds.
*/
safe_union OptionalTimeoutDuration {
/** No time point provided. */
Monostate none;
/**
* Timeout duration measured in nanoseconds.
*/
uint64_t nanoseconds;
};
/** /**
* Return status of a function. * Return status of a function.
*/ */

View file

@ -80,6 +80,13 @@ enum class MemoryType { SHARED, DEVICE };
enum class IOType { INPUT, OUTPUT }; enum class IOType { INPUT, OUTPUT };
static void waitForSyncFence(int syncFd) {
constexpr int kInfiniteTimeout = -1;
ASSERT_GT(syncFd, 0);
int r = sync_wait(syncFd, kInfiniteTimeout);
ASSERT_GE(r, 0);
}
struct TestConfig { struct TestConfig {
Executor executor; Executor executor;
MeasureTiming measureTiming; MeasureTiming measureTiming;
@ -567,33 +574,29 @@ void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>&
case Executor::FENCED: { case Executor::FENCED: {
SCOPED_TRACE("fenced"); SCOPED_TRACE("fenced");
ErrorStatus result; ErrorStatus result;
hidl_handle sync_fence_handle; hidl_handle syncFenceHandle;
sp<IFencedExecutionCallback> fenced_callback; sp<IFencedExecutionCallback> fencedCallback;
Return<void> ret = preparedModel->executeFenced( Return<void> ret = preparedModel->executeFenced(
request, {}, testConfig.measureTiming, request, {}, testConfig.measureTiming, {}, {},
[&result, &sync_fence_handle, &fenced_callback]( [&result, &syncFenceHandle, &fencedCallback](
ErrorStatus error, const hidl_handle& handle, ErrorStatus error, const hidl_handle& handle,
const sp<IFencedExecutionCallback>& callback) { const sp<IFencedExecutionCallback>& callback) {
result = error; result = error;
sync_fence_handle = handle; syncFenceHandle = handle;
fenced_callback = callback; fencedCallback = callback;
}); });
ASSERT_TRUE(ret.isOk()); ASSERT_TRUE(ret.isOk());
if (result != ErrorStatus::NONE) { if (result != ErrorStatus::NONE) {
ASSERT_EQ(sync_fence_handle.getNativeHandle(), nullptr); ASSERT_EQ(syncFenceHandle.getNativeHandle(), nullptr);
ASSERT_EQ(fenced_callback, nullptr); ASSERT_EQ(fencedCallback, nullptr);
executionStatus = ErrorStatus::GENERAL_FAILURE; executionStatus = ErrorStatus::GENERAL_FAILURE;
} else if (sync_fence_handle.getNativeHandle()) { } else if (syncFenceHandle.getNativeHandle()) {
constexpr int kInfiniteTimeout = -1; waitForSyncFence(syncFenceHandle.getNativeHandle()->data[0]);
int sync_fd = sync_fence_handle.getNativeHandle()->data[0];
ASSERT_GT(sync_fd, 0);
int r = sync_wait(sync_fd, kInfiniteTimeout);
ASSERT_GE(r, 0);
} }
if (result == ErrorStatus::NONE) { if (result == ErrorStatus::NONE) {
ASSERT_NE(fenced_callback, nullptr); ASSERT_NE(fencedCallback, nullptr);
Return<void> ret = fenced_callback->getExecutionInfo( Return<void> ret = fencedCallback->getExecutionInfo(
[&executionStatus, &timing](ErrorStatus error, Timing t) { [&executionStatus, &timing](ErrorStatus error, Timing t, Timing) {
executionStatus = error; executionStatus = error;
timing = t; timing = t;
}); });

View file

@ -143,7 +143,7 @@ static void validate(const sp<IPreparedModel>& preparedModel, const std::string&
{ {
SCOPED_TRACE(message + " [executeFenced]"); SCOPED_TRACE(message + " [executeFenced]");
Return<void> ret = preparedModel->executeFenced( Return<void> ret = preparedModel->executeFenced(
request, {}, MeasureTiming::NO, request, {}, MeasureTiming::NO, {}, {},
[](ErrorStatus error, const hidl_handle& handle, [](ErrorStatus error, const hidl_handle& handle,
const sp<IFencedExecutionCallback>& callback) { const sp<IFencedExecutionCallback>& callback) {
if (error != ErrorStatus::DEVICE_UNAVAILABLE) { if (error != ErrorStatus::DEVICE_UNAVAILABLE) {

View file

@ -136,17 +136,17 @@ void validateBurst(const sp<IPreparedModel>& preparedModel, const V1_0::Request&
// Validate sync_fence handles for dispatch with valid input // Validate sync_fence handles for dispatch with valid input
void validateExecuteFenced(const sp<IPreparedModel>& preparedModel, const Request& request) { void validateExecuteFenced(const sp<IPreparedModel>& preparedModel, const Request& request) {
SCOPED_TRACE("Expecting request to fail [executeFenced]"); SCOPED_TRACE("Expecting request to fail [executeFenced]");
Return<void> ret_null = Return<void> ret_null = preparedModel->executeFenced(
preparedModel->executeFenced(request, {hidl_handle(nullptr)}, V1_2::MeasureTiming::NO, request, {hidl_handle(nullptr)}, V1_2::MeasureTiming::NO, {}, {},
[](ErrorStatus error, const hidl_handle& handle, [](ErrorStatus error, const hidl_handle& handle,
const sp<IFencedExecutionCallback>& callback) { const sp<IFencedExecutionCallback>& callback) {
// TODO: fix this once sample driver impl is merged. // TODO: fix this once sample driver impl is merged.
if (error != ErrorStatus::DEVICE_UNAVAILABLE) { if (error != ErrorStatus::DEVICE_UNAVAILABLE) {
ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, error); ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, error);
} }
ASSERT_EQ(handle.getNativeHandle(), nullptr); ASSERT_EQ(handle.getNativeHandle(), nullptr);
ASSERT_EQ(callback, nullptr); ASSERT_EQ(callback, nullptr);
}); });
ASSERT_TRUE(ret_null.isOk()); ASSERT_TRUE(ret_null.isOk());
} }