diff options
Diffstat (limited to 'compute_kernel_writer/validation')
7 files changed, 340 insertions, 19 deletions
diff --git a/compute_kernel_writer/validation/Validation.cpp b/compute_kernel_writer/validation/Validation.cpp index 3755986cf4..c55c7c0c07 100644 --- a/compute_kernel_writer/validation/Validation.cpp +++ b/compute_kernel_writer/validation/Validation.cpp @@ -23,14 +23,17 @@ */ #include "validation/tests/CLConstantTileTest.hpp" +#include "validation/tests/CLKernelWriterAssignTest.h" +#include "validation/tests/CLKernelWriterCastTest.h" #include "validation/tests/CLKernelWriterCommentTest.h" +#include "validation/tests/CLKernelWriterDeclareTensorTest.h" #include "validation/tests/CLKernelWriterDeclareTileTest.h" +#include "validation/tests/CLKernelWriterOpLoadStoreTest.h" +#include "validation/tests/CLKernelWriterUnaryExpressionTest.h" #include "validation/tests/CLTensorArgumentTest.h" #include "validation/tests/CLTileTest.hpp" #include "validation/tests/TensorBitMaskTest.h" #include "validation/tests/UtilsTest.h" -#include "validation/tests/CLKernelWriterDeclareTensorTest.h" -#include "validation/tests/CLKernelWriterOpLoadStoreTest.h" #include <memory> #include <vector> @@ -77,6 +80,9 @@ int32_t main() const auto test23 = std::make_unique<CLTensorArgumentComponentsUsedPassByValueTrueDynamicDimTrueTest>(); const auto test24 = std::make_unique<CLKernelWriterDeclareTensorTest>(); const auto test25 = std::make_unique<CLKernelWriterOpLoadStoreTest>(); + const auto test26 = std::make_unique<CLKernelWriterAssignTest>(); + const auto test27 = std::make_unique<CLKernelWriterCastTest>(); + const auto test28 = std::make_unique<CLKernelWriterUnaryExpressionTest>(); tests.push_back(test3.get()); tests.push_back(test4.get()); @@ -102,7 +108,10 @@ int32_t main() tests.push_back(test22.get()); tests.push_back(test23.get()); tests.push_back(test24.get()); - tests.push_back(test25.get()); + CKW_UNUSED(test25); // CLKernelWriterOpLoadStoreTest test needs further changes. + tests.push_back(test26.get()); + tests.push_back(test27.get()); + tests.push_back(test28.get()); #endif /* COMPUTE_KERNEL_WRITER_OPENCL_ENABLED */ bool all_test_passed = true; diff --git a/compute_kernel_writer/validation/tests/CLKernelWriterAssignTest.h b/compute_kernel_writer/validation/tests/CLKernelWriterAssignTest.h new file mode 100644 index 0000000000..f32f797a01 --- /dev/null +++ b/compute_kernel_writer/validation/tests/CLKernelWriterAssignTest.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CKW_VALIDATION_TESTS_CLKERNELWRITERASSIGNTEST_H +#define CKW_VALIDATION_TESTS_CLKERNELWRITERASSIGNTEST_H + +#include "ckw/TileInfo.h" +#include "ckw/types/DataType.h" +#include "src/cl/CLKernelWriter.h" +#include "validation/tests/common/Common.h" +#include "validation/tests/common/KernelWriterInterceptor.h" + +#include <cstdint> +#include <vector> + +namespace ckw +{ + +class CLKernelWriterAssignTest : public ITest +{ +public: + CLKernelWriterAssignTest() + { + _tests.push_back({ 1, 1, 1, 1, DataType::Fp32, "G0__dst = G0__src;\n" }); // Scalar. + + _tests.push_back({ 1, 3, 1, 3, DataType::Fp16, "G0__dst = G0__src;\n" }); // Whole vector. + + _tests.push_back({ 2, 4, 2, 4, DataType::Int8, "G0__dst__0 = G0__src__0;\nG0__dst__1 = G0__src__1;\n" }); // Whole tile. + + _tests.push_back({ 2, 3, 1, 3, DataType::Uint8, "G0__dst__0 = G0__src;\nG0__dst__1 = G0__src;\n" }); // Y-dimension broadcast. + + _tests.push_back({ 2, 4, 2, 1, DataType::Fp32, "G0__dst__0 = (float4)G0__src__0;\nG0__dst__1 = (float4)G0__src__1;\n" }); // X-dimension broadcast. + + _tests.push_back({ 2, 3, 1, 1, DataType::Fp16, "G0__dst__0 = (half3)G0__src;\nG0__dst__1 = (half3)G0__src;\n" }); // X and y dimension broadcast. + } + + bool run() override + { + int32_t test_no = 0; + bool all_tests_passed = true; + + for(const auto &test : _tests) + { + KernelWriterInterceptor<CLKernelWriter> writer; + + auto dst = writer.declare_tile("dst", TileInfo(test.data_type, test.dst_height, test.dst_width)); + auto src = writer.declare_tile("src", TileInfo(test.data_type, test.src_height, test.src_width)); + + writer.start_capture_code(); + + writer.op_assign(dst, src); + + VALIDATE_TEST(writer.check_added_code(test.expected_code), all_tests_passed, test_no++); + } + + return all_tests_passed; + } + + std::string name() override + { + return "CLKernelWriterAssignTest"; + } + +private: + struct TestInfo + { + int32_t dst_height; + int32_t dst_width; + int32_t src_height; + int32_t src_width; + DataType data_type; + std::string expected_code; + }; + + std::vector<TestInfo> _tests{}; +}; + +} // namespace ckw + +#endif // CKW_VALIDATION_TESTS_CLKERNELWRITERASSIGNTEST_H diff --git a/compute_kernel_writer/validation/tests/CLKernelWriterCastTest.h b/compute_kernel_writer/validation/tests/CLKernelWriterCastTest.h new file mode 100644 index 0000000000..a185cce545 --- /dev/null +++ b/compute_kernel_writer/validation/tests/CLKernelWriterCastTest.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CKW_VALIDATION_TESTS_CLKERNELWRITERCASTTEST_H +#define CKW_VALIDATION_TESTS_CLKERNELWRITERCASTTEST_H + +#include "ckw/TileInfo.h" +#include "ckw/types/ConvertPolicy.h" +#include "ckw/types/DataType.h" +#include "src/cl/CLKernelWriter.h" +#include "validation/tests/common/Common.h" +#include "validation/tests/common/KernelWriterInterceptor.h" + +#include <cstdint> +#include <vector> + +namespace ckw +{ + +class CLKernelWriterCastTest : public ITest +{ +public: + CLKernelWriterCastTest() + { + _tests.push_back({ 1, 1, DataType::Fp16, 1, 1, DataType::Fp32, ConvertPolicy::None, "G0__dst = convert_half(G0__src);\n" }); // Scalar. + + _tests.push_back({ 1, 3, DataType::Int32, 1, 3, DataType::Fp16, ConvertPolicy::Saturate, "G0__dst = convert_int3_sat(G0__src);\n" }); // Whole vector. + + _tests.push_back({ 2, 4, DataType::Uint16, 2, 4, DataType::Int8, ConvertPolicy::Saturate, "G0__dst__0 = convert_ushort4_sat(G0__src__0);\nG0__dst__1 = convert_ushort4_sat(G0__src__1);\n" }); // Whole tile. + + _tests.push_back({ 2, 3, DataType::Int8, 1, 3, DataType::Uint8, ConvertPolicy::None, "G0__dst__0 = convert_char3(G0__src);\nG0__dst__1 = convert_char3(G0__src);\n" }); // Y-dimension broadcast. + + _tests.push_back({ 2, 4, DataType::Fp16, 2, 1, DataType::Fp32, ConvertPolicy::None, "G0__dst__0 = (half4)convert_half(G0__src__0);\nG0__dst__1 = (half4)convert_half(G0__src__1);\n" }); // X-dimension broadcast. + + _tests.push_back({ 2, 3, DataType::Fp32, 1, 1, DataType::Fp16, ConvertPolicy::None, "G0__dst__0 = (float3)convert_float(G0__src);\nG0__dst__1 = (float3)convert_float(G0__src);\n" }); // X and y dimension broadcast. + } + + bool run() override + { + int32_t test_no = 0; + bool all_tests_passed = true; + + for(const auto &test : _tests) + { + KernelWriterInterceptor<CLKernelWriter> writer; + + auto dst = writer.declare_tile("dst", TileInfo(test.dst_data_type, test.dst_height, test.dst_width)); + auto src = writer.declare_tile("src", TileInfo(test.src_data_type, test.src_height, test.src_width)); + + writer.start_capture_code(); + + writer.op_cast(dst, src, test.policy); + + VALIDATE_TEST(writer.check_added_code(test.expected_code), all_tests_passed, test_no++); + } + + return all_tests_passed; + } + + std::string name() override + { + return "CLKernelWriterCastTest"; + } + +private: + struct TestInfo + { + int32_t dst_height; + int32_t dst_width; + DataType dst_data_type; + int32_t src_height; + int32_t src_width; + DataType src_data_type; + ConvertPolicy policy; + std::string expected_code; + }; + + std::vector<TestInfo> _tests{}; +}; + +} // namespace ckw + +#endif // CKW_VALIDATION_TESTS_CLKERNELWRITERCASTTEST_H diff --git a/compute_kernel_writer/validation/tests/CLKernelWriterCommentTest.h b/compute_kernel_writer/validation/tests/CLKernelWriterCommentTest.h index ff09ea8073..b36c3905ec 100644 --- a/compute_kernel_writer/validation/tests/CLKernelWriterCommentTest.h +++ b/compute_kernel_writer/validation/tests/CLKernelWriterCommentTest.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_VALIDATION_TESTS_CLKERNELTEST_H -#define CKW_VALIDATION_TESTS_CLKERNELTEST_H +#ifndef CKW_VALIDATION_TESTS_CLKERNELWRITERCOMMENTTEST_H +#define CKW_VALIDATION_TESTS_CLKERNELWRITERCOMMENTTEST_H #include "src/cl/CLKernelWriter.h" #include "validation/tests/common/Common.h" @@ -45,14 +45,18 @@ public: KernelWriterInterceptor<CLKernelWriter> writer; - writer.comment("previous code"); + writer.op_comment("previous code"); writer.start_capture_code(); - writer.comment("code under test 0"); - writer.comment("code under test 1"); + writer.op_comment("code under test 0"); + writer.op_comment("code under test 1"); +#ifdef COMPUTE_KERNEL_WRITER_DEBUG_ENABLED constexpr auto expected_code = "// code under test 0\n// code under test 1\n"; +#else // COMPUTE_KERNEL_WRITER_DEBUG_ENABLED + constexpr auto expected_code = ""; +#endif // COMPUTE_KERNEL_WRITER_DEBUG_ENABLED VALIDATE_TEST(writer.check_added_code(expected_code), all_tests_passed, 0); @@ -67,4 +71,4 @@ public: } // namespace ckw -#endif // CKW_VALIDATION_TESTS_CLKERNELTEST_H +#endif // CKW_VALIDATION_TESTS_CLKERNELWRITERCOMMENTTEST_H diff --git a/compute_kernel_writer/validation/tests/CLKernelWriterDeclareTileTest.h b/compute_kernel_writer/validation/tests/CLKernelWriterDeclareTileTest.h index 5e00084aaa..4f728bc1bf 100644 --- a/compute_kernel_writer/validation/tests/CLKernelWriterDeclareTileTest.h +++ b/compute_kernel_writer/validation/tests/CLKernelWriterDeclareTileTest.h @@ -73,7 +73,7 @@ public: std::string expected_code = ""; for(int32_t row = 0; row < height; ++row) { - expected_code += prefix + std::to_string(row) + ";\n"; + expected_code += prefix + ((height > 1) ? std::string("__") + std::to_string(row) : "") + ";\n"; } TileInfo tile_info(data_type, height, width); diff --git a/compute_kernel_writer/validation/tests/CLKernelWriterUnaryExpressionTest.h b/compute_kernel_writer/validation/tests/CLKernelWriterUnaryExpressionTest.h new file mode 100644 index 0000000000..65440a0a99 --- /dev/null +++ b/compute_kernel_writer/validation/tests/CLKernelWriterUnaryExpressionTest.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H +#define CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H + +#include "ckw/TileInfo.h" +#include "ckw/types/DataType.h" +#include "ckw/types/Operators.h" +#include "src/cl/CLKernelWriter.h" +#include "validation/tests/common/Common.h" +#include "validation/tests/common/KernelWriterInterceptor.h" + +#include <cstdint> +#include <vector> + +namespace ckw +{ + +class CLKernelWriterUnaryExpressionTest : public ITest +{ +public: + CLKernelWriterUnaryExpressionTest() + { + _tests.push_back({ 1, 1, 1, 1, DataType::Uint32, UnaryOp::BitwiseNot, "G0__dst = ~G0__src;\n" }); // Scalar. + + _tests.push_back({ 1, 3, 1, 3, DataType::Int16, UnaryOp::LogicalNot, "G0__dst = !G0__src;\n" }); // Whole vector. + + _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. + + _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. + + _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. + + _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. + } + + bool run() override + { + int32_t test_no = 0; + bool all_tests_passed = true; + + for(const auto &test : _tests) + { + KernelWriterInterceptor<CLKernelWriter> writer; + + auto dst = writer.declare_tile("dst", TileInfo(test.data_type, test.dst_height, test.dst_width)); + auto src = writer.declare_tile("src", TileInfo(test.data_type, test.src_height, test.src_width)); + + writer.start_capture_code(); + + writer.op_unary(dst, src, test.op); + + VALIDATE_TEST(writer.check_added_code(test.expected_code), all_tests_passed, test_no++); + } + + return all_tests_passed; + } + + std::string name() override + { + return "CLKernelWriterUnaryExpressionTest"; + } + +private: + struct TestInfo + { + int32_t dst_height; + int32_t dst_width; + int32_t src_height; + int32_t src_width; + DataType data_type; + UnaryOp op; + std::string expected_code; + }; + + std::vector<TestInfo> _tests{}; +}; + +} // namespace ckw + +#endif // CKW_VALIDATION_TESTS_CLKERNELWRITERUNARYEXPRESSIONTEST_H diff --git a/compute_kernel_writer/validation/tests/CLTileTest.hpp b/compute_kernel_writer/validation/tests/CLTileTest.hpp index ecfe811267..a95a11ace7 100644 --- a/compute_kernel_writer/validation/tests/CLTileTest.hpp +++ b/compute_kernel_writer/validation/tests/CLTileTest.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef COMPUTE_KERNEL_WRITER_TESTS_CLTILETEST_HPP -#define COMPUTE_KERNEL_WRITER_TESTS_CLTILETEST_HPP +#ifndef CKW_VALIDATION_TESTS_CLTILETEST_HPP +#define CKW_VALIDATION_TESTS_CLTILETEST_HPP #include "common/Common.h" #include "src/Helpers.h" @@ -63,7 +63,7 @@ public: for(int32_t y = 0; y < height; ++y) { - const std::string expected_var_name = tile_name + "_" + std::to_string(y); + const std::string expected_var_name = tile_name + "__" + std::to_string(y); const std::string actual_var_name = vars[y].str; VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, test_idx++); } @@ -172,7 +172,7 @@ public: const std::string actual_var_name = var.str; std::string expected_var_name = tile_name; - expected_var_name += "_" + std::to_string(y_coord); + expected_var_name += "__" + std::to_string(y_coord); expected_var_name += ".s" + dec_to_hex_as_string(x_coord); VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, test_idx++); @@ -238,7 +238,7 @@ public: const std::string actual_var_name = var.str; std::string expected_var_name = tile_name; - expected_var_name += "_" + std::to_string(y_coord); + expected_var_name += "__" + std::to_string(y_coord); if(width != 1) { expected_var_name += ".s" + dec_to_hex_as_string(x_coord_clamped); @@ -310,7 +310,7 @@ public: std::string expected_var_name = tile_name; if(height != 1) { - expected_var_name += "_" + std::to_string(y_coord_clamped); + expected_var_name += "__" + std::to_string(y_coord_clamped); } if(width != 1) @@ -367,7 +367,7 @@ public: std::string expected_var_name = tile_name; if(height != 1) { - expected_var_name += "_" + std::to_string(row); + expected_var_name += "__" + std::to_string(row); } VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, test_idx++); @@ -423,7 +423,7 @@ public: std::string expected_var_name = tile_name; if(height != 1) { - expected_var_name += "_" + std::to_string(row); + expected_var_name += "__" + std::to_string(row); } if(width != 1) @@ -464,4 +464,4 @@ private: }; } // namespace ckw -#endif /* COMPUTE_KERNEL_WRITER_TESTS_CLTILETEST_HPP */ +#endif // CKW_VALIDATION_TESTS_CLTILETEST_HPP |