Viet-Hoa Do | e1c3b46 | 2023-07-31 17:13:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H |
| 26 | #define CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H |
| 27 | |
| 28 | #include "ckw/TileInfo.h" |
| 29 | #include "ckw/types/DataType.h" |
| 30 | #include "ckw/types/Operators.h" |
| 31 | #include "src/cl/CLKernelWriter.h" |
| 32 | #include "validation/tests/common/Common.h" |
| 33 | #include "validation/tests/common/KernelWriterInterceptor.h" |
| 34 | |
| 35 | #include <cstdint> |
| 36 | #include <vector> |
| 37 | |
| 38 | namespace ckw |
| 39 | { |
| 40 | |
| 41 | class CLKernelWriterUnaryExpressionTest : public ITest |
| 42 | { |
| 43 | public: |
| 44 | CLKernelWriterUnaryExpressionTest() |
| 45 | { |
Viet-Hoa Do | 34b6c3a | 2023-08-22 11:11:23 +0100 | [diff] [blame] | 46 | // dst_height, dst_width, src_height, src_width, data_type, op, expected_code |
| 47 | |
Viet-Hoa Do | e1c3b46 | 2023-07-31 17:13:34 +0100 | [diff] [blame] | 48 | _tests.push_back({ 1, 1, 1, 1, DataType::Uint32, UnaryOp::BitwiseNot, "G0__dst = ~G0__src;\n" }); // Scalar. |
| 49 | |
| 50 | _tests.push_back({ 1, 3, 1, 3, DataType::Int16, UnaryOp::LogicalNot, "G0__dst = !G0__src;\n" }); // Whole vector. |
| 51 | |
| 52 | _tests.push_back({ 2, 4, 2, 4, DataType::Int8, UnaryOp::Exp, "G0__dst__0 = exp(G0__src__0);\nG0__dst__1 = exp(G0__src__1);\n" }); // Whole tile. |
| 53 | |
| 54 | _tests.push_back({ 2, 3, 1, 3, DataType::Uint8, UnaryOp::Log, "G0__dst__0 = log(G0__src);\nG0__dst__1 = log(G0__src);\n" }); // Y-dimension broadcast. |
| 55 | |
| 56 | _tests.push_back({ 2, 4, 2, 1, DataType::Uint16, UnaryOp::Sqrt, "G0__dst__0 = (ushort4)sqrt(G0__src__0);\nG0__dst__1 = (ushort4)sqrt(G0__src__1);\n" }); // X-dimension broadcast. |
| 57 | |
| 58 | _tests.push_back({ 2, 3, 1, 1, DataType::Int32, UnaryOp::Round, "G0__dst__0 = (int3)round(G0__src);\nG0__dst__1 = (int3)round(G0__src);\n" }); // X and y dimension broadcast. |
| 59 | } |
| 60 | |
| 61 | bool run() override |
| 62 | { |
| 63 | int32_t test_no = 0; |
| 64 | bool all_tests_passed = true; |
| 65 | |
| 66 | for(const auto &test : _tests) |
| 67 | { |
| 68 | KernelWriterInterceptor<CLKernelWriter> writer; |
| 69 | |
| 70 | auto dst = writer.declare_tile("dst", TileInfo(test.data_type, test.dst_height, test.dst_width)); |
| 71 | auto src = writer.declare_tile("src", TileInfo(test.data_type, test.src_height, test.src_width)); |
| 72 | |
| 73 | writer.start_capture_code(); |
| 74 | |
Viet-Hoa Do | 34b6c3a | 2023-08-22 11:11:23 +0100 | [diff] [blame] | 75 | writer.op_unary(dst, test.op, src); |
Viet-Hoa Do | e1c3b46 | 2023-07-31 17:13:34 +0100 | [diff] [blame] | 76 | |
| 77 | VALIDATE_TEST(writer.check_added_code(test.expected_code), all_tests_passed, test_no++); |
| 78 | } |
| 79 | |
| 80 | return all_tests_passed; |
| 81 | } |
| 82 | |
| 83 | std::string name() override |
| 84 | { |
| 85 | return "CLKernelWriterUnaryExpressionTest"; |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | struct TestInfo |
| 90 | { |
| 91 | int32_t dst_height; |
| 92 | int32_t dst_width; |
| 93 | int32_t src_height; |
| 94 | int32_t src_width; |
| 95 | DataType data_type; |
| 96 | UnaryOp op; |
| 97 | std::string expected_code; |
| 98 | }; |
| 99 | |
| 100 | std::vector<TestInfo> _tests{}; |
| 101 | }; |
| 102 | |
| 103 | } // namespace ckw |
| 104 | |
| 105 | #endif // CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H |