aboutsummaryrefslogtreecommitdiff
path: root/compute_kernel_writer/validation
diff options
context:
space:
mode:
authorGian Marco Iodice <gianmarco.iodice@arm.com>2023-01-19 17:14:26 +0000
committerGian Marco Iodice <gianmarco.iodice@arm.com>2023-05-24 08:30:23 +0000
commit6c113ed1a95a08d17c2d556bd7b03c901512a34f (patch)
treec616a085e1eb3b4b9ac01a1f261182d4d10c481a /compute_kernel_writer/validation
parent1355ec4797cd77060af51c8b27d99ea1d25c08da (diff)
downloadComputeLibrary-6c113ed1a95a08d17c2d556bd7b03c901512a34f.tar.gz
Prepare the basic types for the compute kernel writer (CKW)
- Add TensorInfo - Add TileInfo - Add CLTile - Add basic utility methods to get tensor components - Add unit tests Resolves COMPMID-5782, COMPMID-5785 Signed-off-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Change-Id: I5e590bddd240d2f1fc876cac7129947558d7d53b Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/486221 Tested-by: bsgcomp <bsgcomp@arm.com> Reviewed-by: Jakub Sujak <jakub.sujak@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Comments-Addressed: bsgcomp <bsgcomp@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9687 Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Reviewed-by: Pablo Marquez Tello <pablo.tello@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'compute_kernel_writer/validation')
-rw-r--r--compute_kernel_writer/validation/SConscript100
-rw-r--r--compute_kernel_writer/validation/Validation.cpp76
-rw-r--r--compute_kernel_writer/validation/tests/CLTileTest.hpp311
-rw-r--r--compute_kernel_writer/validation/tests/TensorBitMaskTest.hpp217
-rw-r--r--compute_kernel_writer/validation/tests/UtilsTest.hpp102
-rw-r--r--compute_kernel_writer/validation/tests/common/Common.h69
6 files changed, 875 insertions, 0 deletions
diff --git a/compute_kernel_writer/validation/SConscript b/compute_kernel_writer/validation/SConscript
new file mode 100644
index 0000000000..452cc0a9ea
--- /dev/null
+++ b/compute_kernel_writer/validation/SConscript
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# 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.
+import os.path
+
+Import('env')
+Import('vars')
+Import('install_bin')
+
+# vars is imported from compute_kernel_writer:
+variables = [
+ BoolVariable("validation_tests", "Build validation test programs", False)
+]
+
+# We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice)
+new_options = Variables('scons')
+
+for v in variables:
+ new_options.Add(v)
+ vars.Add(v)
+
+# Clone the environment to make sure we're not polluting the compute_kernel_writer one:
+test_env = env.Clone()
+vars.Update(test_env)
+
+Help(new_options.GenerateHelpText(test_env))
+
+# Check if we need to build the test framework
+build_test_framework = False
+for opt in new_options.keys():
+ option_value = test_env[opt]
+ if type(option_value) is bool and option_value:
+ build_test_framework = True
+ break
+
+if not build_test_framework:
+ Return()
+
+# Remove -Wnoexcept from tests
+if 'g++' in test_env['CXX'] and '-Wnoexcept' in test_env['CXXFLAGS']:
+ test_env['CXXFLAGS'].remove("-Wnoexcept")
+
+load_whole_archive = '-Wl,--whole-archive'
+noload_whole_archive = '-Wl,--no-whole-archive'
+
+if env['os'] in ['android']:
+ Import("ckw_a")
+
+ test_env.Append(LIBS = [ckw_a])
+ ckw_lib = ckw_a
+else:
+ Import("ckw_so")
+ test_env.Append(LIBS = ["ckw"])
+ ckw_lib = ckw_so
+
+# Add main file
+files_validation = Glob('Validation.cpp')
+
+# Add unit tests
+files_validation += Glob('tests/*.cpp')
+
+extra_link_flags = []
+
+test_env.Append(LIBS = ["rt"])
+extra_link_flags += ['-fstack-protector-strong']
+
+bm_link_flags = []
+if test_env['linker_script']:
+ bm_link_flags += ['-Wl,--build-id=none', '-T', env['linker_script']]
+
+if test_env['validation_tests']:
+ program_objects = files_validation
+
+ ckw_validation = test_env.Program('ckw_validation', program_objects, LIBS=test_env['LIBS'], LINKFLAGS=test_env['LINKFLAGS'] + bm_link_flags)
+ ckw_validation = install_bin(ckw_validation)
+ Depends(ckw_validation, ckw_lib)
+
+ Default(ckw_validation)
+ Export('ckw_validation')
diff --git a/compute_kernel_writer/validation/Validation.cpp b/compute_kernel_writer/validation/Validation.cpp
new file mode 100644
index 0000000000..cc9dbfa7d0
--- /dev/null
+++ b/compute_kernel_writer/validation/Validation.cpp
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#include "tests/CLTileTest.hpp"
+#include "tests/TensorBitMaskTest.hpp"
+#include "tests/UtilsTest.hpp"
+
+#include <memory>
+#include <vector>
+
+using namespace ckw;
+
+/** Main test program
+ */
+int32_t main()
+{
+ std::vector<ITest*> tests;
+
+ // Add your test here
+ const auto test0 = std::make_unique<UtilsTest>();
+ const auto test1 = std::make_unique<TensorBitMaskTrueTest>();
+ const auto test2 = std::make_unique<TensorBitMaskFalseTest>();
+ const auto test3 = std::make_unique<CLTileInternalVariableNamesTest>();
+ const auto test4 = std::make_unique<CLTileInternalNumVariablesTest>();
+ const auto test5 = std::make_unique<CLTileAccessScalarVariableTest>();
+ const auto test6 = std::make_unique<CLTileAccessScalarVariableBroadcastXTest>();
+ const auto test7 = std::make_unique<CLTileAccessScalarVariableBroadcastYTest>();
+ tests.push_back(test0.get());
+ tests.push_back(test1.get());
+ tests.push_back(test2.get());
+ tests.push_back(test3.get());
+ tests.push_back(test4.get());
+ tests.push_back(test5.get());
+ tests.push_back(test6.get());
+ tests.push_back(test7.get());
+
+ bool all_test_passed = true;
+
+ for(auto &x : tests)
+ {
+ std::cout << x->name() << std::endl;
+ all_test_passed &= x->run();
+ }
+
+ if(all_test_passed == true)
+ {
+ std::cout << "All tests passed" << std::endl;
+ }
+ else
+ {
+ std::cout << "One or more tests failed" << std::endl;
+ }
+
+ return 0;
+}
diff --git a/compute_kernel_writer/validation/tests/CLTileTest.hpp b/compute_kernel_writer/validation/tests/CLTileTest.hpp
new file mode 100644
index 0000000000..9fb47941f4
--- /dev/null
+++ b/compute_kernel_writer/validation/tests/CLTileTest.hpp
@@ -0,0 +1,311 @@
+#ifndef COMPUTE_KERNEL_WRITER_TESTS_CLTENSOR_HPP
+#define COMPUTE_KERNEL_WRITER_TESTS_CLTENSOR_HPP
+
+#include "src/Helpers.h"
+#include "src/cl/CLTile.h"
+#include "common/Common.h"
+
+#include <string>
+#include <vector>
+
+namespace ckw
+{
+class CLTileInternalVariableNamesTest : public ITest
+{
+public:
+ const int32_t width = 4;
+ const int32_t height = 4;
+ const DataType dt = DataType::Fp32;
+
+ CLTileInternalVariableNamesTest()
+ {
+ _tile_name.push_back("dst");
+ _tile_name.push_back("_G0_dst");
+ _tile_name.push_back("_SRC");
+ }
+
+ bool run() override
+ {
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ const TileInfo info(dt, width, height);
+
+ const size_t num_tests = _tile_name.size();
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const std::string tile_name = _tile_name[i];
+ const CLTile tile(tile_name, info);
+ const auto vars = tile.all();
+
+ for(int32_t y = 0; y < height; ++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, i);
+ }
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "CLTileInternalVariableNamesTest";
+ }
+
+private:
+ std::vector<std::string> _tile_name {};
+};
+
+class CLTileInternalNumVariablesTest : public ITest
+{
+public:
+ CLTileInternalNumVariablesTest()
+ {
+ _width.push_back(4);
+ _width.push_back(1);
+ _width.push_back(16);
+
+ _height.push_back(1);
+ _height.push_back(5);
+ _height.push_back(3);
+ }
+
+ bool run() override
+ {
+ VALIDATE_ON_MSG(_width.size() == _height.size(), "The number of widths and heights does not match");
+
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ const size_t num_tests = _width.size();
+
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const int32_t width = _width[i];
+ const int32_t height = _height[i];
+ const TileInfo info(DataType::Fp32, width, height);
+ const CLTile tile("src", info);
+ const auto vars = tile.all();
+ const int32_t num_vars = vars.size();
+
+ // We expect the number of variables to match the heigth of the tile
+ VALIDATE_TEST(num_vars == height, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "CLTileInternalNumVariablesTest";
+ }
+
+private:
+ std::vector<int32_t> _width {};
+ std::vector<int32_t> _height {};
+};
+
+class CLTileAccessScalarVariableTest : public ITest
+{
+public:
+ const std::string tile_name = "src";
+ const int32_t width = 16;
+ const int32_t height = 8;
+ const DataType dt = DataType::Fp32;
+
+ CLTileAccessScalarVariableTest()
+ {
+ _x_coord.push_back(4);
+ _x_coord.push_back(1);
+ _x_coord.push_back(15);
+ _x_coord.push_back(10);
+
+ _y_coord.push_back(1);
+ _y_coord.push_back(5);
+ _y_coord.push_back(3);
+ _y_coord.push_back(4);
+ }
+
+ bool run() override
+ {
+ const TileInfo info(dt, width, height);
+ const CLTile tile(tile_name, info);
+
+ VALIDATE_ON_MSG(_x_coord.size() == _y_coord.size(), "The number of x-coords and y-coords does not match");
+
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ const size_t num_tests = _x_coord.size();
+
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const int32_t x_coord = _x_coord[i];
+ const int32_t y_coord = _y_coord[i];
+
+ const TileVariable var = tile.scalar(x_coord, y_coord);
+
+ const std::string expected_var_name = var.str;
+ std::string actual_var_name = tile_name;
+ actual_var_name += "_" + std::to_string(y_coord);
+ actual_var_name += ".s" + dec_to_hex_as_string(x_coord);
+
+ VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "CLTileAccessScalarVariableTest";
+ }
+
+private:
+ std::vector<int32_t> _x_coord {};
+ std::vector<int32_t> _y_coord {};
+};
+
+class CLTileAccessScalarVariableBroadcastXTest : public ITest
+{
+public:
+ const std::string tile_name = "src";
+ const int32_t height = 8;
+ const DataType dt = DataType::Fp32;
+
+ CLTileAccessScalarVariableBroadcastXTest()
+ {
+ _width.push_back(1);
+ _width.push_back(2);
+ _width.push_back(3);
+
+ _x_coord.push_back(4);
+ _x_coord.push_back(5);
+ _x_coord.push_back(6);
+
+ _y_coord.push_back(1);
+ _y_coord.push_back(3);
+ _y_coord.push_back(2);
+ }
+
+ bool run() override
+ {
+ VALIDATE_ON_MSG(_width.size() == _y_coord.size(), "The number of widths and y-coords does not match");
+ VALIDATE_ON_MSG(_x_coord.size() == _y_coord.size(), "The number of x-coords and y-coords does not match");
+
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ const size_t num_tests = _x_coord.size();
+
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const int32_t width = _width[i];
+ const int32_t x_coord = _x_coord[i];
+ const int32_t y_coord = _y_coord[i];
+
+ const int32_t x_coord_clamped = clamp(x_coord, static_cast<int32_t>(0), width - 1);
+
+ const TileInfo info(dt, width, height);
+ const CLTile tile(tile_name, info);
+
+ const TileVariable var = tile.scalar(x_coord, y_coord);
+
+ const std::string expected_var_name = var.str;
+ std::string actual_var_name = tile_name;
+ actual_var_name += "_" + std::to_string(y_coord);
+ if(width != 1)
+ {
+ actual_var_name += ".s" + dec_to_hex_as_string(x_coord_clamped);
+ }
+
+ VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "CLTileAccessScalarVariableBroadcastXTest";
+ }
+
+private:
+ std::vector<int32_t> _width {};
+ std::vector<int32_t> _x_coord {};
+ std::vector<int32_t> _y_coord {};
+};
+
+class CLTileAccessScalarVariableBroadcastYTest : public ITest
+{
+public:
+ const std::string tile_name = "src";
+ const int32_t width = 8;
+ const DataType dt = DataType::Fp32;
+
+ CLTileAccessScalarVariableBroadcastYTest()
+ {
+ _height.push_back(1);
+ _height.push_back(2);
+ _height.push_back(3);
+
+ _x_coord.push_back(4);
+ _x_coord.push_back(5);
+ _x_coord.push_back(6);
+
+ _y_coord.push_back(3);
+ _y_coord.push_back(4);
+ _y_coord.push_back(5);
+ }
+
+ bool run() override
+ {
+ VALIDATE_ON_MSG(_height.size() == _y_coord.size(), "The number of widths and y-coords does not match");
+ VALIDATE_ON_MSG(_x_coord.size() == _y_coord.size(), "The number of x-coords and y-coords does not match");
+
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ const size_t num_tests = _x_coord.size();
+
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const int32_t height = _height[i];
+ const int32_t x_coord = _x_coord[i];
+ const int32_t y_coord = _y_coord[i];
+
+ const int32_t y_coord_clamped = clamp(y_coord, static_cast<int32_t>(0), height - 1);
+
+ const TileInfo info(dt, width, height);
+ const CLTile tile(tile_name, info);
+
+ const TileVariable var = tile.scalar(x_coord, y_coord);
+
+ const std::string expected_var_name = var.str;
+ std::string actual_var_name = tile_name;
+ if(height != 1)
+ {
+ actual_var_name += "_" + std::to_string(y_coord_clamped);
+ }
+
+ if(width != 1)
+ {
+ actual_var_name += ".s" + dec_to_hex_as_string(x_coord);
+ }
+
+ VALIDATE_TEST(actual_var_name.compare(expected_var_name) == 0, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "CLTileAccessScalarVariableBroadcastYTest";
+ }
+
+private:
+ std::vector<int32_t> _height {};
+ std::vector<int32_t> _x_coord {};
+ std::vector<int32_t> _y_coord {};
+};
+}
+
+#endif /* COMPUTE_KERNEL_WRITER_TESTS_CLTENSOR_HPP */
diff --git a/compute_kernel_writer/validation/tests/TensorBitMaskTest.hpp b/compute_kernel_writer/validation/tests/TensorBitMaskTest.hpp
new file mode 100644
index 0000000000..a1a3588394
--- /dev/null
+++ b/compute_kernel_writer/validation/tests/TensorBitMaskTest.hpp
@@ -0,0 +1,217 @@
+/*
+ * 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 COMPUTE_KERNEL_WRITER_TESTS_TENSORBITMASK_HPP
+#define COMPUTE_KERNEL_WRITER_TESTS_TENSORBITMASK_HPP
+
+#include "ckw/TensorInfo.h"
+#include "common/Common.h"
+
+#include <vector>
+
+namespace ckw
+{
+class TensorBitMaskTrueTest : public ITest
+{
+public:
+ TensorBitMaskTrueTest()
+ {
+ _component.push_back(TensorComponent::Dim0);
+ _component.push_back(TensorComponent::Dim1);
+ _component.push_back(TensorComponent::Dim2);
+ _component.push_back(TensorComponent::Dim3);
+ _component.push_back(TensorComponent::Dim4);
+ _component.push_back(TensorComponent::Stride0);
+ _component.push_back(TensorComponent::Stride1);
+ _component.push_back(TensorComponent::Stride2);
+ _component.push_back(TensorComponent::Stride3);
+ _component.push_back(TensorComponent::Stride4);
+ _component.push_back(TensorComponent::Dim1xDim2);
+ _component.push_back(TensorComponent::Dim1xDim2xDim3);
+ _component.push_back(TensorComponent::Dim2xDim3);
+ _component.push_back(TensorComponent::OffsetFirstElement);
+
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ }
+
+ bool run() override
+ {
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ VALIDATE_ON_MSG(_component.size() == _bitmask.size(), "The number of layouts and components does not match");
+ const size_t num_tests = _component.size();
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const TensorComponent component = _component[i];
+ const TensorComponentBitmask bitmask = _bitmask[i];
+ const bool out = static_cast<uint32_t>(component) & static_cast<uint32_t>(bitmask);
+ VALIDATE_TEST(out == true, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "TensorBitMaskTrueTest";
+ }
+
+private:
+ std::vector<TensorComponent> _component {};
+ std::vector<TensorComponentBitmask> _bitmask {};
+};
+
+class TensorBitMaskFalseTest : public ITest
+{
+public:
+ TensorBitMaskFalseTest()
+ {
+ _component.push_back(TensorComponent::Dim0);
+ _component.push_back(TensorComponent::Dim1);
+ _component.push_back(TensorComponent::Dim2);
+ _component.push_back(TensorComponent::Dim3);
+ _component.push_back(TensorComponent::Dim4);
+ _component.push_back(TensorComponent::Dim0);
+ _component.push_back(TensorComponent::Dim1);
+ _component.push_back(TensorComponent::Dim2);
+ _component.push_back(TensorComponent::Dim3);
+ _component.push_back(TensorComponent::Dim4);
+ _component.push_back(TensorComponent::Dim0);
+ _component.push_back(TensorComponent::Dim1);
+ _component.push_back(TensorComponent::Dim2);
+ _component.push_back(TensorComponent::Dim3);
+ _component.push_back(TensorComponent::Dim4);
+ _component.push_back(TensorComponent::Stride0);
+ _component.push_back(TensorComponent::Stride1);
+ _component.push_back(TensorComponent::Stride2);
+ _component.push_back(TensorComponent::Stride3);
+ _component.push_back(TensorComponent::Stride4);
+ _component.push_back(TensorComponent::Stride0);
+ _component.push_back(TensorComponent::Stride1);
+ _component.push_back(TensorComponent::Stride2);
+ _component.push_back(TensorComponent::Stride3);
+ _component.push_back(TensorComponent::Stride4);
+ _component.push_back(TensorComponent::Stride0);
+ _component.push_back(TensorComponent::Stride1);
+ _component.push_back(TensorComponent::Stride2);
+ _component.push_back(TensorComponent::Stride3);
+ _component.push_back(TensorComponent::Stride4);
+ _component.push_back(TensorComponent::Dim1xDim2);
+ _component.push_back(TensorComponent::Dim1xDim2xDim3);
+ _component.push_back(TensorComponent::Dim2xDim3);
+ _component.push_back(TensorComponent::Dim1xDim2);
+ _component.push_back(TensorComponent::Dim1xDim2xDim3);
+ _component.push_back(TensorComponent::Dim2xDim3);
+ _component.push_back(TensorComponent::Dim1xDim2);
+ _component.push_back(TensorComponent::Dim1xDim2xDim3);
+ _component.push_back(TensorComponent::Dim2xDim3);
+ _component.push_back(TensorComponent::OffsetFirstElement);
+ _component.push_back(TensorComponent::OffsetFirstElement);
+ _component.push_back(TensorComponent::OffsetFirstElement);
+
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::OffsetFirstElement);
+ _bitmask.push_back(TensorComponentBitmask::Dimension);
+ _bitmask.push_back(TensorComponentBitmask::Stride);
+ _bitmask.push_back(TensorComponentBitmask::FoldedDimensions);
+ }
+
+ bool run() override
+ {
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ VALIDATE_ON_MSG(_component.size() == _bitmask.size(), "The number of layouts and components does not match");
+ const size_t num_tests = _component.size();
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const TensorComponent component = _component[i];
+ const TensorComponentBitmask bitmask = _bitmask[i];
+ const bool out = static_cast<uint32_t>(component) & static_cast<uint32_t>(bitmask);
+ VALIDATE_TEST(out == false, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "TensorBitMaskFalseTest";
+ }
+
+private:
+ std::vector<TensorComponent> _component {};
+ std::vector<TensorComponentBitmask> _bitmask {};
+};
+}
+
+#endif /* COMPUTE_KERNEL_WRITER_TESTS_TENSORBITMASK_HPP */
diff --git a/compute_kernel_writer/validation/tests/UtilsTest.hpp b/compute_kernel_writer/validation/tests/UtilsTest.hpp
new file mode 100644
index 0000000000..4a09d53f73
--- /dev/null
+++ b/compute_kernel_writer/validation/tests/UtilsTest.hpp
@@ -0,0 +1,102 @@
+/*
+ * 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 COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP
+#define COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP
+
+#include "ckw/TensorInfo.h"
+#include "src/TensorUtils.h"
+#include "common/Common.h"
+
+#include <vector>
+
+namespace ckw
+{
+class UtilsTest : public ITest
+{
+public:
+ UtilsTest()
+ {
+ _layout.push_back(TensorDataLayout::Nhwc);
+ _layout.push_back(TensorDataLayout::Nhwc);
+ _layout.push_back(TensorDataLayout::Nhwc);
+ _layout.push_back(TensorDataLayout::Nhwc);
+ _layout.push_back(TensorDataLayout::Ndhwc);
+ _layout.push_back(TensorDataLayout::Ndhwc);
+ _layout.push_back(TensorDataLayout::Ndhwc);
+ _layout.push_back(TensorDataLayout::Ndhwc);
+ _layout.push_back(TensorDataLayout::Ndhwc);
+
+ _component.push_back(TensorDataLayoutComponent::N);
+ _component.push_back(TensorDataLayoutComponent::H);
+ _component.push_back(TensorDataLayoutComponent::W);
+ _component.push_back(TensorDataLayoutComponent::C);
+ _component.push_back(TensorDataLayoutComponent::N);
+ _component.push_back(TensorDataLayoutComponent::D);
+ _component.push_back(TensorDataLayoutComponent::H);
+ _component.push_back(TensorDataLayoutComponent::W);
+ _component.push_back(TensorDataLayoutComponent::C);
+
+ _expected.push_back(TensorComponent::Dim3);
+ _expected.push_back(TensorComponent::Dim2);
+ _expected.push_back(TensorComponent::Dim1);
+ _expected.push_back(TensorComponent::Dim0);
+ _expected.push_back(TensorComponent::Dim4);
+ _expected.push_back(TensorComponent::Dim3);
+ _expected.push_back(TensorComponent::Dim2);
+ _expected.push_back(TensorComponent::Dim1);
+ _expected.push_back(TensorComponent::Dim0);
+ }
+
+ bool run() override
+ {
+ // The status of this variable can change in VALIDATE_TEST()
+ bool all_tests_passed = true;
+
+ VALIDATE_ON_MSG(_layout.size() == _component.size(), "The number of layouts and components does not match");
+ VALIDATE_ON_MSG(_layout.size() == _expected.size(), "The number of layouts and expected outputs does not match");
+ const size_t num_tests = _layout.size();
+ for(size_t i = 0; i < num_tests; ++i)
+ {
+ const TensorDataLayout layout = _layout[i];
+ const TensorDataLayoutComponent component = _component[i];
+ const TensorComponent expected = _expected[i];
+ const TensorComponent out = get_tensor_dimension(layout, component);
+ VALIDATE_TEST(out == expected, all_tests_passed, i);
+ }
+ return all_tests_passed;
+ }
+
+ std::string name() override
+ {
+ return "UtilsTest";
+ }
+
+private:
+ std::vector<TensorDataLayout> _layout {};
+ std::vector<TensorDataLayoutComponent> _component {};
+ std::vector<TensorComponent> _expected {};
+};
+}
+
+#endif /* COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP */
diff --git a/compute_kernel_writer/validation/tests/common/Common.h b/compute_kernel_writer/validation/tests/common/Common.h
new file mode 100644
index 0000000000..d33d7f6688
--- /dev/null
+++ b/compute_kernel_writer/validation/tests/common/Common.h
@@ -0,0 +1,69 @@
+/*
+ * 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 COMPUTE_KERNEL_WRITER_TEST_COMMON_COMMON_H
+#define COMPUTE_KERNEL_WRITER_TEST_COMMON_COMMON_H
+
+#include <cassert>
+#include <iostream>
+#include <string>
+
+namespace ckw
+{
+#define VALIDATE_ON_MSG(exp, msg) assert(((void)msg, exp))
+
+#define VALIDATE_TEST(exp, all_tests_passed, id_test) \
+ do \
+ { \
+ if((exp) == true) \
+ { \
+ all_tests_passed &= true; \
+ const std::string msg = "TEST " + std::to_string((id_test)) + ": [PASSED]"; \
+ std::cout << msg << std::endl; \
+ } \
+ else \
+ { \
+ all_tests_passed &= false; \
+ const std::string msg = "TEST " + std::to_string((id_test)) + ": [FAILED]"; \
+ std::cout << msg << std::endl; \
+ } \
+ } while(false)
+
+class ITest
+{
+public:
+ virtual ~ITest() = default;
+ /** Method to run the test
+ *
+ * @return it returns true if all tests passed
+ */
+ virtual bool run() = 0;
+ /** Name of the test
+ *
+ * @return it returns the name of the test
+ */
+ virtual std::string name() = 0;
+};
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_TEST_COMMON_COMMON_H */