diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2023-10-12 16:03:15 +0100 |
---|---|---|
committer | Jeremy Johnson <jeremy.johnson@arm.com> | 2023-10-26 11:20:00 +0100 |
commit | d41feb7138406832cfe045f41f254180e9c91ef4 (patch) | |
tree | 1539f57224123c34044ae1d1ad0e9bc468d26b1f /reference_model/test | |
parent | fc5e34e41afc07ea5ed03e3c5d4b5be92bef7fd7 (diff) | |
download | reference_model-d41feb7138406832cfe045f41f254180e9c91ef4.tar.gz |
Compliance testing support for MAX_POOL2D & PAD
Added Pseudo Random number generator in generate library.
Enabled MAX_POOL2D, PAD FP32 tests to use new generator and compliance.
Fixed verify library exact mode to expect reference data as FP64.
Simplified tosa_verif_build_tests internal interfaces for new tests.
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: Icc0ffa924cf38107c3a212efd452c47a650c9d98
Diffstat (limited to 'reference_model/test')
-rw-r--r-- | reference_model/test/generate_tests.cpp | 79 | ||||
-rw-r--r-- | reference_model/test/verify_tests.cpp | 19 |
2 files changed, 89 insertions, 9 deletions
diff --git a/reference_model/test/generate_tests.cpp b/reference_model/test/generate_tests.cpp index 503ecfe..c24a369 100644 --- a/reference_model/test/generate_tests.cpp +++ b/reference_model/test/generate_tests.cpp @@ -56,6 +56,24 @@ void check_output(const std::vector<T>& results, const std::vector<uint32_t>& ex } } +template <typename T> +void check_output(const std::vector<T>& results, const std::vector<T>& expected) +{ + for (size_t idx = 0; idx < expected.size(); ++idx) + { + check_value(true, *(uint32_t*)&results[idx], *(uint32_t*)&expected[idx], idx); + } +} + +template <typename T> +void check_not_output(const std::vector<T>& results, const std::vector<T>& expected) +{ + for (size_t idx = 0; idx < expected.size(); ++idx) + { + check_value(false, *(uint32_t*)&results[idx], *(uint32_t*)&expected[idx], idx); + } +} + } // namespace TEST_SUITE_BEGIN("generate"); @@ -268,4 +286,65 @@ TEST_CASE("positive - FP32 matmul dot product (first 3 values)") matmul_test_FP32(tosaName, tosaElements, templateJsonCfg, "5", 1, expected); } } +TEST_CASE("positive - pseudo random") +{ + std::string templateJsonCfg = R"({ + "tensors" : { + "input0" : { + "generator": "PSEUDO_RANDOM", + "data_type": "FP32", + "input_type": "VARIABLE", + "shape" : [ 12, 3 ], + "input_pos": 0, + "op" : "PAD", + "pseudo_random_info": { + "rng_seed": _SEED0_ + } + }, + "input1" : { + "generator": "PSEUDO_RANDOM", + "data_type": "FP32", + "input_type": "VARIABLE", + "shape" : [ 1, 3 ], + "input_pos": 1, + "op" : "PAD", + "pseudo_random_info": { + "rng_seed": _SEED1_ + } + } + + } + })"; + + const std::string tosaNameP0 = "input0"; + const size_t tosaElementsP0 = 12 * 3; + const std::string tosaNameP1 = "input1"; + const size_t tosaElementsP1 = 1 * 3; + + SUBCASE("pad - same rng") + { + std::string jsonCfg = templateJsonCfg; + update_json_template(jsonCfg, "_SEED0_", "0"); + update_json_template(jsonCfg, "_SEED1_", "0"); + + std::vector<float> bufferP0(tosaElementsP0); + std::vector<float> bufferP1(tosaElementsP1); + REQUIRE(tgd_generate_data(jsonCfg.c_str(), tosaNameP0.c_str(), (void*)bufferP0.data(), tosaElementsP0 * 4)); + REQUIRE(tgd_generate_data(jsonCfg.c_str(), tosaNameP1.c_str(), (void*)bufferP1.data(), tosaElementsP1 * 4)); + check_output<float>(bufferP0, bufferP1); + } + + SUBCASE("pad - different rng") + { + std::string jsonCfg = templateJsonCfg; + update_json_template(jsonCfg, "_SEED0_", "0"); + update_json_template(jsonCfg, "_SEED1_", "1000"); + + std::vector<float> bufferP0(tosaElementsP0); + std::vector<float> bufferP1(tosaElementsP1); + REQUIRE(tgd_generate_data(jsonCfg.c_str(), tosaNameP0.c_str(), (void*)bufferP0.data(), tosaElementsP0 * 4)); + REQUIRE(tgd_generate_data(jsonCfg.c_str(), tosaNameP1.c_str(), (void*)bufferP1.data(), tosaElementsP1 * 4)); + check_not_output<float>(bufferP0, bufferP1); + } +} TEST_SUITE_END(); // generate diff --git a/reference_model/test/verify_tests.cpp b/reference_model/test/verify_tests.cpp index 3aa477f..369a8cd 100644 --- a/reference_model/test/verify_tests.cpp +++ b/reference_model/test/verify_tests.cpp @@ -75,7 +75,7 @@ template <typename FP> std::enable_if_t<std::is_floating_point_v<FP>, std::add_lvalue_reference_t<std::uniform_real_distribution<FP>>> getUniformRealDist() { - // Uniform real distribution generates real values in the range [a, b) + // Uniform real distribution generates real values in the range [a, b] // and requires that b - a <= std::numeric_limits<FP>::max() so here // we choose some arbitrary values that satisfy that condition. constexpr auto min = std::numeric_limits<FP>::lowest() / 2; @@ -261,13 +261,14 @@ TEST_CASE("positive - exact") const auto elementCount = std::accumulate(std::begin(shape), std::end(shape), 1, std::multiplies<>()); // Generate some random floats using the full range of fp32. - auto data = generateRandomTensorData<float>(elementCount); + auto data_fp32 = generateRandomTensorData<float>(elementCount); + std::vector<double> data_fp64(data_fp32.begin(), data_fp32.end()); SUBCASE("same") { const auto referenceTensor = - TosaTensor("out1", tosa_datatype_fp64_t, shape, reinterpret_cast<uint8_t*>(data.data())); + TosaTensor("out1", tosa_datatype_fp64_t, shape, reinterpret_cast<uint8_t*>(data_fp64.data())); const auto implementationTensor = - TosaTensor("out1", tosa_datatype_fp32_t, shape, reinterpret_cast<uint8_t*>(data.data())); + TosaTensor("out1", tosa_datatype_fp32_t, shape, reinterpret_cast<uint8_t*>(data_fp32.data())); REQUIRE(tvf_verify_data(referenceTensor.cTensor(), nullptr, implementationTensor.cTensor(), jsonCfg.c_str())); } @@ -275,16 +276,16 @@ TEST_CASE("positive - exact") { // Generate some mismatched tensors by setting every other value to an incrementing counter. // In theory this could be the same, but the probability is tiny. - auto otherData = std::vector<float>(elementCount); - std::generate(std::begin(otherData), std::end(otherData), [&, i = 0]() mutable { + auto otherData_fp32 = std::vector<float>(elementCount); + std::generate(std::begin(otherData_fp32), std::end(otherData_fp32), [&, i = 0]() mutable { auto oldIndex = i++; - return oldIndex % 2 ? data[oldIndex] : static_cast<float>(oldIndex); + return oldIndex % 2 ? data_fp32[oldIndex] : static_cast<float>(oldIndex); }); const auto referenceTensor = - TosaTensor("out1", tosa_datatype_fp64_t, shape, reinterpret_cast<uint8_t*>(data.data())); + TosaTensor("out1", tosa_datatype_fp64_t, shape, reinterpret_cast<uint8_t*>(data_fp64.data())); const auto implementationTensor = - TosaTensor("out1", tosa_datatype_fp32_t, shape, reinterpret_cast<uint8_t*>(otherData.data())); + TosaTensor("out1", tosa_datatype_fp32_t, shape, reinterpret_cast<uint8_t*>(otherData_fp32.data())); REQUIRE_FALSE( tvf_verify_data(referenceTensor.cTensor(), nullptr, implementationTensor.cTensor(), jsonCfg.c_str())); } |