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

Commit 1d6b4659 authored by Slava Shklyaev's avatar Slava Shklyaev
Browse files

Refactor NNAPI VTS to remove unreasonable dependence between versions

To make it easier to create the next version of NNAPI, this change
removes the following nonsensical dependence:
- NNAPI 1.0 VTS depends on NNAPI 1.1 and 1.2
- NNAPI 1.1 VTS depends on NNAPI 1.2

In particular, I made the following changes:
- split GeneratedTestHarness.cpp into three separate implementations,
- created a restricted version of Callbacks.h for 1.0 and 1.1,
- removed the dependency on frameworks/ml/nn/HalInterfaces.h,
- refactored Android.bp files for more autonomy between 1.0, 1.1, and 1.2,
- consolidated some common code into Utils.h,
- created structure for sharing code between VTS versions (VtsHalNeuralNetworksV1_0_utils).

Bug: 74827824
Bug: 124462414
Test: VtsHalNeuralnetworksV1_0TargetTest
Test: VtsHalNeuralnetworksV1_1TargetTest
Test: VtsHalNeuralnetworksV1_1CompatV1_0TargetTest
Test: VtsHalNeuralnetworksV1_2TargetTest
Test: VtsHalNeuralnetworksV1_2CompatV1_0TargetTest
Test: VtsHalNeuralnetworksV1_2CompatV1_1TargetTest
Change-Id: I4243d0b5e574255cef1070850f4d0a284f65f54e
parent f11a1a9b
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -15,21 +15,19 @@
//

cc_library_static {
    name: "VtsHalNeuralnetworksTest_utils",
    name: "VtsHalNeuralNetworksV1_0_utils",
    srcs: [
        "Callbacks.cpp",
        "GeneratedTestHarness.cpp",
        "Utils.cpp",
    ],
    defaults: ["VtsHalTargetTestDefaults"],
    export_include_dirs: ["."],
    export_include_dirs: ["include"],
    shared_libs: [
        "libfmq",
        "libnativewindow",
    ],
    static_libs: [
        "android.hardware.neuralnetworks@1.0",
        "android.hardware.neuralnetworks@1.1",
        "android.hardware.neuralnetworks@1.2",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "libgmock",
@@ -44,12 +42,13 @@ cc_library_static {
}

cc_defaults {
    name: "VtsHalNeuralNetworksTargetTestDefaults",
    name: "VtsHalNeuralNetworksV1_0TargetTestDefaults",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "ValidateModel.cpp",
        "ValidateRequest.cpp",
        "VtsHalNeuralnetworks.cpp",
        "GeneratedTestHarness.cpp",
    ],
    shared_libs: [
        "libfmq",
@@ -57,14 +56,12 @@ cc_defaults {
    ],
    static_libs: [
        "android.hardware.neuralnetworks@1.0",
        "android.hardware.neuralnetworks@1.1",
        "android.hardware.neuralnetworks@1.2",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "libgmock",
        "libhidlmemory",
        "libneuralnetworks_utils",
        "VtsHalNeuralnetworksTest_utils",
        "VtsHalNeuralNetworksV1_0_utils",
    ],
    header_libs: [
        "libneuralnetworks_headers",
@@ -76,19 +73,19 @@ cc_defaults {

cc_test {
    name: "VtsHalNeuralnetworksV1_0TargetTest",
    defaults: ["VtsHalNeuralNetworksTargetTestDefaults"],
    defaults: ["VtsHalNeuralNetworksV1_0TargetTestDefaults"],
    srcs: [
        "BasicTests.cpp",
        "GeneratedTests.cpp",
        "GeneratedTestsV1_0.cpp",
    ],
}

cc_test {
    name: "PresubmitHalNeuralnetworksV1_0TargetTest",
    defaults: ["VtsHalNeuralNetworksTargetTestDefaults"],
    defaults: ["VtsHalNeuralNetworksV1_0TargetTestDefaults"],
    srcs: [
        "BasicTests.cpp",
        "GeneratedTests.cpp",
        "GeneratedTestsV1_0.cpp",
    ],
    cflags: [
        "-DPRESUBMIT_NOT_VTS",
+3 −33
Original line number Diff line number Diff line
@@ -14,13 +14,13 @@
 * limitations under the License.
 */

#include "Callbacks.h"
#include "1.0/Callbacks.h"
#include <android-base/logging.h>

namespace android {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace V1_0 {
namespace implementation {

CallbackBase::CallbackBase() : mNotified(false) {}
@@ -111,14 +111,6 @@ Return<void> PreparedModelCallback::notify(ErrorStatus errorStatus,
    return Void();
}

Return<void> PreparedModelCallback::notify_1_2(ErrorStatus errorStatus,
                                               const sp<V1_2::IPreparedModel>& preparedModel) {
    mErrorStatus = errorStatus;
    mPreparedModel = preparedModel;
    CallbackBase::notify();
    return Void();
}

ErrorStatus PreparedModelCallback::getStatus() {
    wait();
    return mErrorStatus;
@@ -135,18 +127,6 @@ ExecutionCallback::~ExecutionCallback() {}

Return<void> ExecutionCallback::notify(ErrorStatus errorStatus) {
    mErrorStatus = errorStatus;
    mOutputShapes = {};
    mTiming = {.timeOnDevice = UINT64_MAX, .timeInDriver = UINT64_MAX};
    CallbackBase::notify();
    return Void();
}

Return<void> ExecutionCallback::notify_1_2(ErrorStatus errorStatus,
                                           const hidl_vec<OutputShape>& outputShapes,
                                           const Timing& timing) {
    mErrorStatus = errorStatus;
    mOutputShapes = outputShapes;
    mTiming = timing;
    CallbackBase::notify();
    return Void();
}
@@ -156,18 +136,8 @@ ErrorStatus ExecutionCallback::getStatus() {
    return mErrorStatus;
}

const std::vector<OutputShape>& ExecutionCallback::getOutputShapes() {
    wait();
    return mOutputShapes;
}

Timing ExecutionCallback::getTiming() {
    wait();
    return mTiming;
}

}  // namespace implementation
}  // namespace V1_2
}  // namespace V1_0
}  // namespace neuralnetworks
}  // namespace hardware
}  // namespace android
+48 −412

File changed.

Preview size limit exceeded, changes collapsed.

+4 −22
Original line number Diff line number Diff line
@@ -14,14 +14,11 @@
 * limitations under the License.
 */

#ifndef VTS_HAL_NEURALNETWORKS_GENERATED_TEST_HARNESS_H
#define VTS_HAL_NEURALNETWORKS_GENERATED_TEST_HARNESS_H

#include "TestHarness.h"
#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_0_GENERATED_TEST_HARNESS_H
#define ANDROID_HARDWARE_NEURALNETWORKS_V1_0_GENERATED_TEST_HARNESS_H

#include <android/hardware/neuralnetworks/1.0/IDevice.h>
#include <android/hardware/neuralnetworks/1.1/IDevice.h>
#include <android/hardware/neuralnetworks/1.2/IDevice.h>
#include "TestHarness.h"

namespace android {
namespace hardware {
@@ -30,28 +27,13 @@ namespace neuralnetworks {
namespace generated_tests {
using ::test_helper::MixedTypedExample;

void PrepareModel(const sp<V1_2::IDevice>& device, const V1_2::Model& model,
                  sp<V1_2::IPreparedModel>* preparedModel);

void EvaluatePreparedModel(sp<V1_2::IPreparedModel>& preparedModel,
                           std::function<bool(int)> is_ignored,
                           const std::vector<MixedTypedExample>& examples,
                           bool hasRelaxedFloat32Model, bool testDynamicOutputShape);

void Execute(const sp<V1_0::IDevice>& device, std::function<V1_0::Model(void)> create_model,
             std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples);

void Execute(const sp<V1_1::IDevice>& device, std::function<V1_1::Model(void)> create_model,
             std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples);

void Execute(const sp<V1_2::IDevice>& device, std::function<V1_2::Model(void)> create_model,
             std::function<bool(int)> is_ignored, const std::vector<MixedTypedExample>& examples,
             bool testDynamicOutputShape = false);

}  // namespace generated_tests

}  // namespace neuralnetworks
}  // namespace hardware
}  // namespace android

#endif  // VTS_HAL_NEURALNETWORKS_GENERATED_TEST_HARNESS_H
#endif  // ANDROID_HARDWARE_NEURALNETWORKS_V1_0_GENERATED_TEST_HARNESS_H
+9 −9
Original line number Diff line number Diff line
@@ -16,17 +16,16 @@

#define LOG_TAG "neuralnetworks_hidl_hal_test"

#include "VtsHalNeuralnetworks.h"

#include "Callbacks.h"
#include "GeneratedTestHarness.h"
#include "TestHarness.h"
#include "Utils.h"

#include <android-base/logging.h>
#include <android/hidl/memory/1.0/IMemory.h>
#include <hidlmemory/mapping.h>

#include "1.0/Callbacks.h"
#include "GeneratedTestHarness.h"
#include "MemoryUtils.h"
#include "TestHarness.h"
#include "VtsHalNeuralnetworks.h"

namespace android {
namespace hardware {
namespace neuralnetworks {
@@ -34,8 +33,9 @@ namespace V1_0 {
namespace vts {
namespace functional {

using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback;
using ::android::hidl::memory::V1_0::IMemory;
using ::android::nn::allocateSharedMemory;
using ::test_helper::MixedTypedExample;

Loading