aboutsummaryrefslogtreecommitdiff
path: root/reference_model/test
diff options
context:
space:
mode:
authorevacha01 <evan.chandler@arm.com>2024-03-08 16:39:24 +0000
committerEric Kunze <eric.kunze@arm.com>2024-04-16 16:02:16 +0000
commit4a2051146f498cb9ec35d7213720540c5c3e81e2 (patch)
tree543000b3ef22bd587c3c7702100742e4b94eb5fb /reference_model/test
parent5d0e9c7f3748e80d6f14a3eeaef858eeb912e1fd (diff)
downloadreference_model-4a2051146f498cb9ec35d7213720540c5c3e81e2.tar.gz
SPECIAL data gen mode for FP16 and FP32
Signed-off-by: evacha01 <evan.chandler@arm.com> Change-Id: I5a9a1c63345bd83ca04bc6c2a99b0ef3612971ee
Diffstat (limited to 'reference_model/test')
-rw-r--r--reference_model/test/generate_tests.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/reference_model/test/generate_tests.cpp b/reference_model/test/generate_tests.cpp
index 73db631..19b808b 100644
--- a/reference_model/test/generate_tests.cpp
+++ b/reference_model/test/generate_tests.cpp
@@ -1609,4 +1609,101 @@ TEST_CASE("positive - FP16 full range")
}
}
+void fp_special_test_FP32(const std::string tosaName,
+ const size_t tosaElements,
+ const std::string templateJsonCfg,
+ const std::string opStr,
+ const std::string startIndexStr,
+ const std::vector<uint32_t> expected)
+{
+ std::string jsonCfg = templateJsonCfg;
+ update_json_template(jsonCfg, "_OP_", opStr);
+ update_json_template(jsonCfg, "_START_", startIndexStr);
+
+ std::vector<float> buffer(tosaElements);
+ REQUIRE(tgd_generate_data(jsonCfg.c_str(), tosaName.c_str(), (void*)buffer.data(), tosaElements * 4));
+ check_output<float>(buffer, expected);
+}
+
+TEST_CASE("positive - FP32 FP Special")
+{
+ std::string templateJsonCfg = R"({
+ "tensors" : {
+ "input0" : {
+ "generator": "FP_SPECIAL",
+ "data_type": "FP32",
+ "input_type": "VARIABLE",
+ "shape" : [ 5, 6, 7 ],
+ "input_pos": 0,
+ "op" : "_OP_",
+ "fp_special_info": {
+ "start_idx": _START_
+ }
+ },
+ "input1" : {
+ "generator": "FP_SPECIAL",
+ "data_type": "FP32",
+ "input_type": "VARIABLE",
+ "shape" : [ 5, 6, 7 ],
+ "input_pos": 1,
+ "op" : "_OP_",
+ "fp_special_info": {
+ "start_idx": _START_
+ }
+ }
+ }
+ })";
+
+ const std::string tosaName0 = "input0";
+ const std::string tosaName1 = "input1";
+ const size_t tosaElements = 5 * 6 * 7;
+
+ SUBCASE("equal, input 0")
+ {
+ std::vector<uint32_t> expected = { 0x0, 0x7F800000, 0x0 };
+ fp_special_test_FP32(tosaName0, tosaElements, templateJsonCfg, "EQUAL", "0", expected);
+ }
+ SUBCASE("equal, input 1")
+ {
+ std::vector<uint32_t> expected = { 0x80000000, 0xFF800000, 0x80000000 };
+ fp_special_test_FP32(tosaName1, tosaElements, templateJsonCfg, "EQUAL", "0", expected);
+ }
+ SUBCASE("greater, input 0")
+ {
+ std::vector<uint32_t> expected = { 0x0, 0x7F800000, 0x0 };
+ fp_special_test_FP32(tosaName0, tosaElements, templateJsonCfg, "GREATER", "0", expected);
+ }
+ SUBCASE("greater, input 1")
+ {
+ std::vector<uint32_t> expected = { 0x80000000, 0xFF800000, 0x80000000 };
+ fp_special_test_FP32(tosaName1, tosaElements, templateJsonCfg, "GREATER", "0", expected);
+ }
+ SUBCASE("add, input 0")
+ {
+ std::vector<uint32_t> expected = { 0x7F7FFFFF, 0x7F800000, 0x7F7FFFFF };
+ fp_special_test_FP32(tosaName0, tosaElements, templateJsonCfg, "ADD", "0", expected);
+ }
+ SUBCASE("add, input 1")
+ {
+ std::vector<uint32_t> expected = { 0x3F800000, 0xFF800000, 0x3F800000 };
+ fp_special_test_FP32(tosaName1, tosaElements, templateJsonCfg, "ADD", "0", expected);
+ }
+ SUBCASE("maximum, input 0")
+ {
+ std::vector<uint32_t> expected = { 0x0, 0x80000000, 0x7F800000 };
+ fp_special_test_FP32(tosaName0, tosaElements, templateJsonCfg, "MAXIMUM", "0", expected);
+ }
+ SUBCASE("maximum, input 1")
+ {
+ std::vector<uint32_t> expected = { 0x0, 0x80000000, 0x7F800000 };
+ fp_special_test_FP32(tosaName1, tosaElements, templateJsonCfg, "MAXIMUM", "0", expected);
+ }
+ SUBCASE("maximum, startIndex 100")
+ {
+ // A startIndex of 100 creates an offset of 2 in the MAXIMUM op's test data (size: 7) 100 % 7 = 2
+ std::vector<uint32_t> expected = { 0x7F800000, 0xFF800000, 0x7FC00000 };
+ fp_special_test_FP32(tosaName0, tosaElements, templateJsonCfg, "MAXIMUM", "100", expected);
+ }
+}
+
TEST_SUITE_END(); // generate