diff options
author | Grant Watson <grant.watson@arm.com> | 2023-10-31 19:02:14 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2023-10-31 20:58:15 +0000 |
commit | ce53cd103cc2ac09b43b4fdf586249e626bd5627 (patch) | |
tree | fc2b664693a3d11587f9e875b6e3496d38f62a21 /reference_model/test | |
parent | 72dcab775c7a84037135bf365086ca976f3220ef (diff) | |
download | reference_model-ce53cd103cc2ac09b43b4fdf586249e626bd5627.tar.gz |
Fix Reshape in operator API
- The API incorrectly requires the new shape to be passed in twice.
- This fix changes the name of the attribute from new_shape to shape in the generate_api.py script.
- Adds a unit test to verify that the reshape operator works correctly.
Signed-off-by: Grant Watson <grant.watson@arm.com>
Change-Id: I07dd0ef786c747896b6e54f4eada0e7b97c6cef3
Diffstat (limited to 'reference_model/test')
-rw-r--r-- | reference_model/test/model_runner_tests.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/reference_model/test/model_runner_tests.cpp b/reference_model/test/model_runner_tests.cpp index 7cf9d68..e838ea1 100644 --- a/reference_model/test/model_runner_tests.cpp +++ b/reference_model/test/model_runner_tests.cpp @@ -327,6 +327,47 @@ TEST_SUITE("model_runner") compareOutput(dstData, expectedData, expectedData.size()); } + TEST_CASE("op_entry_reshape") + { + // Inputs/Outputs + tosa_datatype_t dt = tosa_datatype_fp32_t; + std::vector<int32_t> input_shape = { 2, 2 }; + std::vector<int32_t> new_shape = { 1, 2 }; + std::vector<int32_t> output_shape = { 4, 1 }; + std::vector<float> srcData1(4, 4.0f); + std::vector<int32_t> shapeData = { 4, 1 }; + std::vector<float> dstData(4, 0.0f); + + tosa_tensor_t input1; + input1.shape = input_shape.data(); + input1.num_dims = input_shape.size(); + input1.data_type = dt; + input1.data = reinterpret_cast<uint8_t*>(srcData1.data()); + input1.size = srcData1.size() * sizeof(float); + + tosa_tensor_t shape; + shape.shape = new_shape.data(); + shape.num_dims = new_shape.size(); + shape.data_type = tosa_datatype_int32_t; + shape.data = reinterpret_cast<uint8_t*>(shapeData.data()); + shape.size = shapeData.size() * sizeof(int32_t); + + tosa_tensor_t output; + output.shape = output_shape.data(); + output.num_dims = output_shape.size(); + output.data_type = dt; + output.data = reinterpret_cast<uint8_t*>(dstData.data()); + output.size = dstData.size() * sizeof(float); + + // Execution + auto status = tosa_run_reshape(input1, shape, output, func_ctx_t{}); + CHECK((status == tosa_status_valid)); + + // Compare results + std::vector<float> expectedData(4, 4.0f); + compareOutput(dstData, expectedData, expectedData.size()); + } + TEST_CASE("op_entry_tile") { // Inputs/Outputs |