Merge "Downgrade generated test harness for NDK libc++" into oc-mr1-dev am: 61e7b96aa2

am: d5902d6472

Change-Id: I0fd4ea8e598bf3dc5a8cf9c4bf749ba9b6043c99
This commit is contained in:
Michael Butler 2017-09-23 01:08:24 +00:00 committed by android-build-merger
commit f608c54838

View file

@ -42,6 +42,24 @@ using ::generated_tests::MixedTypedExampleType;
using ::generated_tests::Float32Operands;
using ::generated_tests::Int32Operands;
using ::generated_tests::Quant8Operands;
using ::generated_tests::compare;
template <typename ty>
void copy_back_(MixedTyped* dst, const std::vector<RequestArgument>& ra, char* src) {
MixedTyped& test = *dst;
for_each(test, [&ra, src](int index, std::vector<ty>& m) {
ASSERT_EQ(m.size(), ra[index].location.length / sizeof(ty));
char* begin = src + ra[index].location.offset;
memcpy(m.data(), begin, ra[index].location.length);
});
}
void copy_back(MixedTyped* dst, const std::vector<RequestArgument>& ra, char* src) {
copy_back_<float>(dst, ra, src);
copy_back_<int32_t>(dst, ra, src);
copy_back_<uint8_t>(dst, ra, src);
}
// Top level driver for models and examples generated by test_generator.py
// Test driver for those generated from ml/nn/runtime/test/spec
void Execute(const sp<IDevice>& device, std::function<Model(void)> create_model,
@ -97,9 +115,7 @@ void Execute(const sp<IDevice>& device, std::function<Model(void)> create_model,
MixedTyped test; // holding test results
// Go through all outputs, initialize RequestArgument descriptors
resize_accordingly<float>(golden, test);
resize_accordingly<int32_t>(golden, test);
resize_accordingly<uint8_t>(golden, test);
resize_accordingly(golden, test);
for_all(golden, [&outputs_info, &outputSize](int index, auto, auto s) {
if (outputs_info.size() <= static_cast<size_t>(index)) outputs_info.resize(index + 1);
RequestArgument arg = {
@ -156,40 +172,16 @@ void Execute(const sp<IDevice>& device, std::function<Model(void)> create_model,
// validate results
outputMemory->read();
#define COPY_BACK(ty) \
for_each<ty>(test, [&outputs_info, outputPtr](int index, std::vector<ty>& m) { \
RequestArgument& i = outputs_info[index]; \
ASSERT_EQ(m.size(), i.location.length / sizeof(ty)); \
char* begin = outputPtr + i.location.offset; \
memcpy(m.data(), begin, i.location.length); \
});
COPY_BACK(float);
COPY_BACK(int32_t);
COPY_BACK(uint8_t);
#undef COPY_BACK
copy_back(&test, outputs_info, outputPtr);
outputMemory->commit();
// Filter out don't cares
MixedTyped filtered_golden;
MixedTyped filtered_test;
filter<float>(golden, &filtered_golden, is_ignored);
filter<float>(test, &filtered_test, is_ignored);
filter<int32_t>(golden, &filtered_golden, is_ignored);
filter<int32_t>(test, &filtered_test, is_ignored);
filter<uint8_t>(golden, &filtered_golden, is_ignored);
filter<uint8_t>(test, &filtered_test, is_ignored);
filter(golden, &filtered_golden, is_ignored);
filter(test, &filtered_test, is_ignored);
// We want "close-enough" results for float
for_each<float>(filtered_golden, [&filtered_test](int index, auto& golden_float) {
auto& test_float_operands = std::get<Float32Operands>(filtered_test);
auto& test_float = test_float_operands[index];
for (unsigned int i = 0; i < golden_float.size(); i++) {
SCOPED_TRACE(i);
EXPECT_NEAR(golden_float[i], test_float[i], 1.e-5);
}
});
EXPECT_EQ(std::get<Int32Operands>(filtered_golden), std::get<Int32Operands>(filtered_test));
EXPECT_EQ(std::get<Quant8Operands>(filtered_golden),
std::get<Quant8Operands>(filtered_test));
compare(filtered_golden, filtered_test);
}
}