Merge "Downgrade generated test harness for NDK libc++" into oc-mr1-dev
This commit is contained in:
commit
61e7b96aa2
1 changed files with 23 additions and 31 deletions
|
@ -42,6 +42,24 @@ using ::generated_tests::MixedTypedExampleType;
|
||||||
using ::generated_tests::Float32Operands;
|
using ::generated_tests::Float32Operands;
|
||||||
using ::generated_tests::Int32Operands;
|
using ::generated_tests::Int32Operands;
|
||||||
using ::generated_tests::Quant8Operands;
|
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
|
// Top level driver for models and examples generated by test_generator.py
|
||||||
// Test driver for those generated from ml/nn/runtime/test/spec
|
// Test driver for those generated from ml/nn/runtime/test/spec
|
||||||
void Execute(const sp<IDevice>& device, std::function<Model(void)> create_model,
|
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
|
MixedTyped test; // holding test results
|
||||||
|
|
||||||
// Go through all outputs, initialize RequestArgument descriptors
|
// Go through all outputs, initialize RequestArgument descriptors
|
||||||
resize_accordingly<float>(golden, test);
|
resize_accordingly(golden, test);
|
||||||
resize_accordingly<int32_t>(golden, test);
|
|
||||||
resize_accordingly<uint8_t>(golden, test);
|
|
||||||
for_all(golden, [&outputs_info, &outputSize](int index, auto, auto s) {
|
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);
|
if (outputs_info.size() <= static_cast<size_t>(index)) outputs_info.resize(index + 1);
|
||||||
RequestArgument arg = {
|
RequestArgument arg = {
|
||||||
|
@ -156,40 +172,16 @@ void Execute(const sp<IDevice>& device, std::function<Model(void)> create_model,
|
||||||
|
|
||||||
// validate results
|
// validate results
|
||||||
outputMemory->read();
|
outputMemory->read();
|
||||||
#define COPY_BACK(ty) \
|
copy_back(&test, outputs_info, outputPtr);
|
||||||
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
|
|
||||||
outputMemory->commit();
|
outputMemory->commit();
|
||||||
// Filter out don't cares
|
// Filter out don't cares
|
||||||
MixedTyped filtered_golden;
|
MixedTyped filtered_golden;
|
||||||
MixedTyped filtered_test;
|
MixedTyped filtered_test;
|
||||||
filter<float>(golden, &filtered_golden, is_ignored);
|
filter(golden, &filtered_golden, is_ignored);
|
||||||
filter<float>(test, &filtered_test, is_ignored);
|
filter(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);
|
|
||||||
|
|
||||||
// We want "close-enough" results for float
|
// We want "close-enough" results for float
|
||||||
for_each<float>(filtered_golden, [&filtered_test](int index, auto& golden_float) {
|
compare(filtered_golden, filtered_test);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue