Add 1.2 NN HAL: IPreparedModel & callbacks.
Create 1.2 version IPreparedModel, IPreparedModelCallback, and
IExecutionCallback.
Currently the new interfaces are created the same as 1.0 version,
but will have more methods introduced in later CLs.
Bug: 73506513
Test: VtsHalNeuralnetworksV1_xTargetTest with 1.2 sample driver
Change-Id: Icf4d04c22f88e825d87562f1489377fdf6bf585d
Merged-In: Icf4d04c22f88e825d87562f1489377fdf6bf585d
(cherry picked from commit b5cb8f76321f2217c47e9183506c94dfa5627dbf)
diff --git a/neuralnetworks/1.0/vts/functional/Callbacks.h b/neuralnetworks/1.0/vts/functional/Callbacks.h
index 570a4fb..e89980d 100644
--- a/neuralnetworks/1.0/vts/functional/Callbacks.h
+++ b/neuralnetworks/1.0/vts/functional/Callbacks.h
@@ -1,22 +1,42 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_0_CALLBACKS_H
#define ANDROID_HARDWARE_NEURALNETWORKS_V1_0_CALLBACKS_H
#include <android/hardware/neuralnetworks/1.0/IExecutionCallback.h>
#include <android/hardware/neuralnetworks/1.0/IPreparedModelCallback.h>
+#include <android/hardware/neuralnetworks/1.2/IExecutionCallback.h>
+#include <android/hardware/neuralnetworks/1.2/IPreparedModelCallback.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
#include <chrono>
#include <condition_variable>
#include <functional>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
#include <mutex>
#include <thread>
namespace android {
namespace hardware {
namespace neuralnetworks {
-namespace V1_0 {
+namespace V1_2 {
namespace implementation {
+using V1_0::ErrorStatus;
+
/**
* The CallbackBase class is used internally by the NeuralNetworks runtime to
* synchronize between different threads. An asynchronous task is launched
@@ -156,11 +176,11 @@
* asynchronously with respect to the runtime. If a calling thread calls wait*
* or get* on a PreparedModelCallback object and the corresponding asynchronous
* task has not finished preparing the model, the calling thread will block
- * until the asynchronous task has called notify. For more information on the
- * synchronization behavior, refer to the CallbackBase class.
+ * until the asynchronous task has either called notify or notify_1_2. For more
+ * information on the synchronization behavior, refer to the CallbackBase class.
*
* This class inherits the basic blocking and signaling calls from
- * CallbackBase, and implements the HIDL notify call from
+ * CallbackBase, and implements the HIDL notify and notify_1_2 calls from
* IPreparedModelCallback. This callback object is passed as an argument to
* IDevice::prepareModel.
*/
@@ -170,15 +190,15 @@
~PreparedModelCallback() override;
/**
- * IPreparedModelCallback::notify marks the callback object with the return
- * status of the asynchronous model preparation along with the prepared
- * model, and calls CallbackBase::notify, enabling all prior and future
- * wait* calls on the PreparedModelCallback object to proceed. For more
- * information on the synchronization behavior, refer to the CallbackBase
- * class.
+ * IPreparedModelCallback::notify and IPreparedModelCallback::notify_1_2
+ * mark the callback object with the return status of the asynchronous
+ * model preparation along with the prepared model, and call
+ * CallbackBase::notify, enabling all prior and future wait* calls on the
+ * PreparedModelCallback object to proceed. For more information on the
+ * synchronization behavior, refer to the CallbackBase class.
*
- * IPreparedModelCallback::notify must be called exactly once on a given
- * PreparedModelCallback object.
+ * Either IPreparedModelCallback::notify or IPreparedModelCallback::notify_1_2
+ * must be called exactly once on a given PreparedModelCallback object.
*
* @param status Error status returned from asynchronously preparing the
* model; will be:
@@ -189,7 +209,9 @@
* @param preparedModel Returned model that has been prepared for execution,
* nullptr if the model was unable to be prepared.
*/
- Return<void> notify(ErrorStatus status, const sp<IPreparedModel>& preparedModel) override;
+ Return<void> notify(ErrorStatus status, const sp<V1_0::IPreparedModel>& preparedModel) override;
+ Return<void> notify_1_2(ErrorStatus status,
+ const sp<V1_2::IPreparedModel>& preparedModel) override;
/**
* Retrieves the error status returned from the asynchronous task launched
@@ -217,11 +239,11 @@
* execution, nullptr if the model was unable to be
* prepared.
*/
- sp<IPreparedModel> getPreparedModel();
+ sp<V1_0::IPreparedModel> getPreparedModel();
- private:
+ private:
ErrorStatus mErrorStatus;
- sp<IPreparedModel> mPreparedModel;
+ sp<V1_0::IPreparedModel> mPreparedModel;
};
/**
@@ -229,12 +251,12 @@
* execution from a task executing asynchronously with respect to the runtime.
* If a calling thread calls wait* or get* on a PreparedModelCallback object and
* the corresponding asynchronous task has not finished the execution, the
- * calling thread will block until the asynchronous task has called notify. For
- * more information on the synchronization behavior, refer to the CallbackBase
- * class.
+ * calling thread will block until the asynchronous task has either called notify
+ * or notify_1_2. For more information on the synchronization behavior, refer to
+ * the CallbackBase class.
*
* This class inherits the basic blocking and signaling calls from
- * CallbackBase, and implements the HIDL notify call from
+ * CallbackBase, and implements the HIDL notify and notify_1_2 calls from
* IExecutionCallback. This callback object is passed as an argument to
* IPreparedModel::execute.
*/
@@ -244,14 +266,14 @@
~ExecutionCallback() override;
/**
- * IExecutionCallback::notify marks the callback object with the return
- * status of the asynchronous execution that held this callback and enables
- * all prior and future wait* calls on the ExecutionCallback object to
- * proceed. For more information on the synchronization behavior, refer to
- * the CallbackBase class.
+ * IExecutionCallback::notify and IExecutionCallback::notify_1_2 mark the
+ * callback object with the return status of the asynchronous execution that
+ * held this callback and enable all prior and future wait* calls on the
+ * ExecutionCallback object to proceed. For more information on the
+ * synchronization behavior, refer to the CallbackBase class.
*
- * IExecutionCallback::notify must be called exactly once on a given
- * ExecutionCallback object.
+ * Either IExecutionCallback::notify or IExecutionCallback::notify_1_2 must
+ * be called exactly once on a given ExecutionCallback object.
*
* @param status Error status returned from asynchronously preparing the
* model; will be:
@@ -263,6 +285,7 @@
* - INVALID_ARGUMENT if the input request is invalid
*/
Return<void> notify(ErrorStatus status) override;
+ Return<void> notify_1_2(ErrorStatus status) override;
/**
* Retrieves the error status returned from the asynchronous task launched
@@ -299,7 +322,7 @@
}
} // namespace implementation
-} // namespace V1_0
+} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android