aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--compute_kernel_writer/SConscript81
-rw-r--r--compute_kernel_writer/SConstruct254
-rw-r--r--compute_kernel_writer/include/ckw/Error.h59
-rw-r--r--compute_kernel_writer/include/ckw/TensorInfo.h135
-rw-r--r--compute_kernel_writer/include/ckw/TileInfo.h84
-rw-r--r--compute_kernel_writer/include/ckw/Types.h45
-rw-r--r--compute_kernel_writer/src/Error.cpp40
-rw-r--r--compute_kernel_writer/src/Helpers.cpp63
-rw-r--r--compute_kernel_writer/src/Helpers.h56
-rw-r--r--compute_kernel_writer/src/ITile.h134
-rw-r--r--compute_kernel_writer/src/TensorInfo.cpp77
-rw-r--r--compute_kernel_writer/src/TensorUtils.cpp116
-rw-r--r--compute_kernel_writer/src/TensorUtils.h56
-rw-r--r--compute_kernel_writer/src/TileInfo.cpp76
-rw-r--r--compute_kernel_writer/src/cl/CLHelpers.cpp91
-rw-r--r--compute_kernel_writer/src/cl/CLHelpers.h53
-rw-r--r--compute_kernel_writer/src/cl/CLTile.cpp156
-rw-r--r--compute_kernel_writer/src/cl/CLTile.h61
-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
-rwxr-xr-xscripts/clang_tidy_rules.py3
25 files changed, 2515 insertions, 0 deletions
diff --git a/compute_kernel_writer/SConscript b/compute_kernel_writer/SConscript
new file mode 100644
index 0000000000..8fc2b11dec
--- /dev/null
+++ b/compute_kernel_writer/SConscript
@@ -0,0 +1,81 @@
+#!/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
+
+LIB_PREFIX = "ckw" # Compute Kernel Writer (CKW)
+VERSION = "v0.0-unreleased"
+LIBRARY_VERSION_MAJOR = 1
+LIBRARY_VERSION_MINOR = 0
+LIBRARY_VERSION_PATCH = 0
+SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
+
+Import('env')
+Import('vars')
+Import('install_lib')
+
+def build_library(name, build_env, sources, static=False, libs=[]):
+ cloned_build_env = build_env.Clone()
+ if env['os'] == 'android' and static == False:
+ cloned_build_env["LINKFLAGS"].remove('-pie')
+ cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
+
+ if static:
+ obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = ckw_env["LIBS"] + libs)
+ else:
+ obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = ckw_env["LIBS"] + libs)
+
+ obj = install_lib(obj)
+ build_env.Default(obj)
+ return obj
+
+ckw_env = env.Clone()
+
+default_cpp_compiler = 'g++' if env['os'] not in ['android'] else 'clang++'
+cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
+
+ckw_env.Append(CPPPATH =[Dir("./src/").path] )
+
+# Append version defines for semantic versioning
+ckw_env.Append(CPPDEFINES = [('COMPUTE_KERNEL_WRITER_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
+ ('COMPUTE_KERNEL_WRITER_VERSION_MINOR', LIBRARY_VERSION_MINOR),
+ ('COMPUTE_KERNEL_WRITER_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
+
+# Don't allow undefined references in the libraries:
+undefined_flag = '-Wl,--no-undefined'
+ckw_env.Append(LINKFLAGS=[undefined_flag])
+
+# Kernel writer files
+kernel_writer_files = Glob('./src/*.cpp')
+
+# OpenCL specific files
+kernel_writer_files += Glob('./src/cl/*.cpp')
+
+ckw_a = build_library(LIB_PREFIX + '-static', ckw_env, kernel_writer_files, static=True)
+Export('ckw_a')
+
+# SHARED library build.
+ckw_so = build_library(LIB_PREFIX, ckw_env, kernel_writer_files, static=False)
+Export('ckw_so') \ No newline at end of file
diff --git a/compute_kernel_writer/SConstruct b/compute_kernel_writer/SConstruct
new file mode 100644
index 0000000000..a67522fedd
--- /dev/null
+++ b/compute_kernel_writer/SConstruct
@@ -0,0 +1,254 @@
+# -*- 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 SCons
+import os
+from subprocess import check_output
+
+def version_at_least(version, required):
+
+ version_list = version.split('.')
+ required_list = required.split('.')
+ end = min(len(version_list), len(required_list))
+ for i in range(0, end):
+ if int(version_list[i]) < int(required_list[i]):
+ return False
+ elif int(version_list[i]) > int(required_list[i]):
+ return True
+
+ return True
+
+vars = Variables("scons")
+vars.AddVariables(
+ BoolVariable("debug", "Debug", False),
+ BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
+ EnumVariable("arch", "Target Architecture.", "armv8.2-a",
+ allowed_values=("x86_64", "armv8.2-a")),
+ EnumVariable("os", "Target OS.", "linux", allowed_values=("linux", "android")),
+ EnumVariable("build", "Either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
+ BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
+ PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
+ PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
+ BoolVariable("exceptions", "Enable/disable C++ exception support", True),
+ PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
+ ("toolchain_prefix", "Override the toolchain prefix; used by all toolchain components: compilers, linker, assembler etc. If unspecified, use default(auto) prefixes; if passed an empty string '' prefixes would be disabled", "auto"),
+ ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"),
+ ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
+ ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
+ ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
+ ("specs_file", "Specs file to use (e.g. rdimon.specs)", "")
+)
+
+if version_at_least(SCons.__version__, "4.0"):
+ vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False))
+
+env = Environment(variables=vars, ENV = os.environ)
+
+build_path = env['build_dir']
+# If build_dir is a relative path then add a #build/ prefix:
+if not env['build_dir'].startswith('/'):
+ SConsignFile('build/%s/.scons' % build_path)
+ build_path = "#build/%s" % build_path
+else:
+ SConsignFile('%s/.scons' % build_path)
+
+install_path = env['install_dir']
+#If the install_dir is a relative path then assume it's from inside build_dir
+if not env['install_dir'].startswith('/') and install_path != "":
+ install_path = "%s/%s" % (build_path, install_path)
+
+env.Append(LIBPATH = [build_path])
+Export('env')
+Export('vars')
+
+def install_lib( lib ):
+ # If there is no install folder, then there is nothing to do:
+ if install_path == "":
+ return lib
+ return env.Install( "%s/lib/" % install_path, lib)
+def install_bin( bin ):
+ # If there is no install folder, then there is nothing to do:
+ if install_path == "":
+ return bin
+ return env.Install( "%s/bin/" % install_path, bin)
+def install_include( inc ):
+ if install_path == "":
+ return inc
+ return env.Install( "%s/include/" % install_path, inc)
+
+Export('install_lib')
+Export('install_bin')
+
+Help(vars.GenerateHelpText(env))
+
+env.Append(CXXFLAGS = [
+ '-Wextra','-Wdisabled-optimization','-Wformat=2',
+ '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
+ '-Woverloaded-virtual', '-Wformat-security',
+ '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
+
+env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ])
+
+env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
+
+cpp_tool = {'linux': 'g++', 'android' : 'clang++'}
+
+c_tool = {'linux':'gcc', 'android': 'clang'}
+
+default_cpp_compiler = cpp_tool[env['os']]
+default_c_compiler = c_tool[env['os']]
+cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
+c_compiler = os.environ.get('CC', default_c_compiler)
+
+if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
+ print( "WARNING: Only clang is officially supported to build the Compute Kernel Writer (CKW) for Android")
+
+if 'clang++' in cpp_compiler:
+ env.Append(CXXFLAGS = ['-Wno-vla-extension'])
+elif 'armclang' in cpp_compiler:
+ pass
+else:
+ env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation'])
+
+if cpp_compiler == 'g++':
+ # Don't strip comments that could include markers
+ env.Append(CXXFLAGS = ['-C'])
+
+if 'armv8-a' in env['arch']:
+ env.Append(CXXFLAGS = ['-march=armv8-a'])
+
+if 'x86_64' in env['arch']:
+ env.Append(CXXFLAGS = ['-fPIC'])
+ env.Append(CCFLAGS = ['-m64'])
+ env.Append(LINKFLAGS = ['-m64'])
+
+# Define toolchain
+# The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a
+# different prefix than the compilers. An example is the NDK r20 toolchain
+auto_toolchain_prefix = ""
+if 'x86' not in env['arch']:
+ if env['os'] == 'linux':
+ auto_toolchain_prefix = "aarch64-linux-gnu-"
+ elif env['os'] == 'android':
+ auto_toolchain_prefix = "aarch64-tizen-linux-gnu-"
+
+if env['build'] == 'native' or env["toolchain_prefix"] == "":
+ toolchain_prefix = ""
+elif env["toolchain_prefix"] == "auto":
+ toolchain_prefix = auto_toolchain_prefix
+else:
+ toolchain_prefix = env["toolchain_prefix"]
+
+if env['build'] == 'native' or env["compiler_prefix"] == "":
+ compiler_prefix = ""
+elif env["compiler_prefix"] == "auto":
+ compiler_prefix = toolchain_prefix
+else:
+ compiler_prefix = env["compiler_prefix"]
+
+env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
+env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
+env['LD'] = toolchain_prefix + "ld"
+env['AS'] = toolchain_prefix + "as"
+env['AR'] = toolchain_prefix + "ar"
+env['RANLIB'] = toolchain_prefix + "ranlib"
+
+print("Using compilers:")
+print("CC", env['CC'])
+print("CXX", env['CXX'])
+
+if not GetOption("help"):
+ try:
+ compiler_ver = check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
+ except OSError:
+ print("ERROR: Compiler '%s' not found" % env['CXX'])
+ Exit(1)
+
+ if 'armclang' in cpp_compiler:
+ pass
+ elif 'clang++' not in cpp_compiler:
+ if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
+ print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
+ Exit(1)
+
+ if version_at_least(compiler_ver, '6.1'):
+ env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
+
+ if compiler_ver == '4.8.3':
+ env.Append(CXXFLAGS = ['-Wno-array-bounds'])
+
+ # Add Android NDK toolchain specific flags
+ if 'clang++' in cpp_compiler and env['os'] == 'android':
+ # For NDK >= r21, clang 9 or above is used
+ if version_at_least(compiler_ver, '9.0.0'):
+ env['ndk_above_r21'] = True
+
+ # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23
+ if not version_at_least(compiler_ver, '12.0.0'):
+ # System assembler is deprecated and integrated assembler is preferred since r23.
+ # However integrated assembler has always been suppressed for NDK < r23.
+ # Thus for backward compatibility, we include this flag only for NDK < r23
+ env.Append(CXXFLAGS = ['-no-integrated-as'])
+
+if env['Werror']:
+ env.Append(CXXFLAGS = ['-Werror'])
+
+if env['os'] == 'android':
+ env.Append(CPPDEFINES = ['ANDROID'])
+ env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
+
+if env['specs_file'] != "":
+ env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
+
+if env['debug']:
+ env['asserts'] = True
+ env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
+ env.Append(CPPDEFINES = ['COMPUTE_KERNEL_WRITER_DEBUG_ENABLED'])
+else:
+ # Optimize for size
+ env.Append(CXXFLAGS = ['-Os'])
+
+if env['asserts']:
+ env.Append(CPPDEFINES = ['COMPUTE_KERNEL_WRITER_ASSERTS_ENABLED'])
+ env.Append(CXXFLAGS = ['-fstack-protector-strong'])
+
+env.Append(CPPPATH = ['#/include', "#"])
+env.Append(CXXFLAGS = env['extra_cxx_flags'])
+env.Append(LINKFLAGS = env['extra_link_flags'])
+env.Append(LIBS = [])
+
+Export('version_at_least')
+
+SConscript('./SConscript', variant_dir=build_path, duplicate=0)
+
+# Tests
+SConscript('./validation/SConscript', variant_dir='%s/validation' % build_path, duplicate=0)
+
+# Unknown variables are not allowed
+# Note: we must delay the call of UnknownVariables until after
+# we have applied the Variables object to the construction environment
+unknown = vars.UnknownVariables()
+if unknown:
+ print("Unknown variables: %s" % " ".join(unknown.keys()))
+ Exit(1)
diff --git a/compute_kernel_writer/include/ckw/Error.h b/compute_kernel_writer/include/ckw/Error.h
new file mode 100644
index 0000000000..996893823e
--- /dev/null
+++ b/compute_kernel_writer/include/ckw/Error.h
@@ -0,0 +1,59 @@
+/*
+ * 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_INCLUDE_CKW_ERROR_H
+#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H
+
+#include <string>
+#include <stdexcept>
+
+namespace ckw
+{
+/** Creates the error message
+ *
+ * @param[in] file File in which the error occurred.
+ * @param[in] func Function in which the error occurred.
+ * @param[in] line Line in which the error occurred.
+ * @param[in] msg Message to display before abandoning.
+ *
+ * @return status containing the error
+ */
+std::string create_error_msg(const std::string &file, const std::string &func, const std::string &line, const std::string &msg);
+
+/** Print the given message then throw an std::runtime_error.
+ *
+ * @param[in] msg Message to display.
+ */
+#define COMPUTE_KERNEL_WRITER_ERROR_ON_MSG(msg) \
+ do \
+ { \
+ const std::string arg0(__FILE__); \
+ const std::string arg1(__func__); \
+ const std::string arg2(std::to_string(__LINE__)); \
+ const std::string arg3(msg); \
+ std::runtime_error(create_error_msg(arg0, arg1, arg2, arg3)); \
+ } while(false)
+
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H */
diff --git a/compute_kernel_writer/include/ckw/TensorInfo.h b/compute_kernel_writer/include/ckw/TensorInfo.h
new file mode 100644
index 0000000000..b5f76cffa5
--- /dev/null
+++ b/compute_kernel_writer/include/ckw/TensorInfo.h
@@ -0,0 +1,135 @@
+/*
+ * 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_INCLUDE_CKW_TENSORINFO_H
+#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H
+
+#include "ckw/Types.h"
+
+#include <array>
+#include <cstdint>
+
+namespace ckw
+{
+/** Compute Kernel Writer tensor data layout (or memory format) */
+enum class TensorDataLayout
+{
+ Unknown,
+ Nhwc,
+ Ndhwc
+};
+
+/** Compute Kernel Writer tensor data layout component */
+enum class TensorDataLayoutComponent
+{
+ Unknown,
+ N,
+ D,
+ H,
+ W,
+ C,
+};
+
+/** Compute Kernel Writer tensor component bitmask. The bitmask can be used to retrieve
+ * the info from @ref TensorComponent.
+ */
+enum class TensorComponentBitmask : uint32_t
+{
+ OffsetFirstElement = 0x01000000, // For example, OffsetFirstElement in @ref TensorComponent
+ Stride = 0x02000000, // For example, stride0 in @ref TensorComponent
+ Dimension = 0x04000000, // For example, Dim0 in @ref TensorComponent
+ FoldedDimensions = 0x08000000, // For example, Dim0xDim1 in @ref TensorComponent
+};
+
+/** Compute Kernel Writer tensor component. The tensor components are used to access specific backend-agnostic tensor arguments,
+ * such as the tensor dimensions and tensor strides.
+ * The data type is represented as an integer. The value of the integer value
+ * is assigned to retrieve the information through the @ref TensorComponentBitmask.
+ */
+enum class TensorComponent : uint32_t
+{
+ Unknown = 0x00000000,
+ OffsetFirstElement = 0x01000000,
+ Stride0 = 0x02000001,
+ Stride1 = 0x02000010,
+ Stride2 = 0x02000100,
+ Stride3 = 0x02001000,
+ Stride4 = 0x02010000,
+ Dim0 = 0x04000001,
+ Dim1 = 0x04000010,
+ Dim2 = 0x04000100,
+ Dim3 = 0x04001000,
+ Dim4 = 0x04010000,
+ Dim1xDim2 = 0x08000110,
+ Dim2xDim3 = 0x08001100,
+ Dim1xDim2xDim3 = 0x08001110
+};
+
+/** Compute Kernel Writer tensor shape
+ * Negative dimensions can be interpreted as dynamic dimensions by the Compute Kernel Writer
+ */
+using TensorShape = std::array<int32_t, 5>;
+
+/** Compute Kernel Writer tensor info */
+class TensorInfo
+{
+public:
+ /** Constructor
+ *
+ * @param[in] dt Tensor data type
+ * @param[in] shape Tensor shape
+ * @param[in] dl Tensor data layout
+ * @param[in] id Tensor id. The id is used to keep track of the user tensor binded. Through the id,
+ * the user can know what tensor has been used by the Compute Kernel Writer.
+ * Possible id values:
+ * - greater than or equal to 0: bind a user specific tensors
+ * - less than 0: bind a virtual tensor (tile)
+ */
+ TensorInfo(DataType dt, const TensorShape &shape, TensorDataLayout dl, int32_t id);
+ /** Set shape */
+ TensorInfo &shape(const TensorShape &shape);
+ /** Get shape */
+ TensorShape shape() const;
+ /** Set data type */
+ TensorInfo &data_type(DataType dt);
+ /** Get data type */
+ DataType data_type() const;
+ /** Set data layout */
+ TensorInfo &data_layout(TensorDataLayout dl);
+ /** Get data layout */
+ TensorDataLayout data_layout() const;
+ /** Set id */
+ TensorInfo &id(int32_t id);
+ /** Get layout */
+ int32_t id() const;
+
+private:
+ TensorShape _shape{ { 0 } };
+ DataType _dt{ DataType::Unknown };
+ TensorDataLayout _dl{ TensorDataLayout::Unknown };
+ int32_t _id{ -1 };
+};
+} // namespace kw
+
+#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H */
diff --git a/compute_kernel_writer/include/ckw/TileInfo.h b/compute_kernel_writer/include/ckw/TileInfo.h
new file mode 100644
index 0000000000..4f801513b0
--- /dev/null
+++ b/compute_kernel_writer/include/ckw/TileInfo.h
@@ -0,0 +1,84 @@
+/*
+ * 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_INCLUDE_CKW_TILEINFO_H
+#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TILEINFO_H
+
+#include "ckw/Types.h"
+
+#include <array>
+#include <cstdint>
+
+namespace ckw
+{
+// Constants to access the tile width and height in the TileShape
+constexpr int32_t kTileWidthIdx = 0;
+constexpr int32_t kTileHeightIdx = 1;
+
+/** Compute Kernel Writer tile shape */
+using TileShape = std::array<int32_t, 2>;
+
+/** Compute Kernel Writer tile info */
+class TileInfo
+{
+public:
+ /** Constructor used to initialize a scalar variable with a given data type
+ *
+ * @param[in] dt Tile data type
+ */
+ TileInfo(DataType dt);
+ /** Constructor used to initialize a vector with a given data type and vector length.
+ *
+ * @param[in] dt Tile data type
+ * @param[in] w Tile width (or vector length)
+ */
+ TileInfo(DataType dt, int32_t w);
+ /** Constructor used to initialize a tile with a given data type and tile sizes.
+ *
+ * @param[in] dt Tile data type
+ * @param[in] w Tile width
+ * @param[in] h Tile height
+ */
+ TileInfo(DataType dt, int32_t w, int32_t h);
+ /** Set width */
+ TileInfo &width(int32_t w);
+ /** Get width */
+ int32_t width() const;
+ /** Set height */
+ TileInfo &height(int32_t h);
+ /** Get height */
+ int32_t height() const;
+ /** Set data type */
+ TileInfo &data_type(DataType dt);
+ /** Get data type */
+ DataType data_type() const;
+
+private:
+ DataType _dt{ DataType::Unknown };
+ TileShape _shape{};
+};
+
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TILEINFO_H */
diff --git a/compute_kernel_writer/include/ckw/Types.h b/compute_kernel_writer/include/ckw/Types.h
new file mode 100644
index 0000000000..c9f80b65e0
--- /dev/null
+++ b/compute_kernel_writer/include/ckw/Types.h
@@ -0,0 +1,45 @@
+/*
+ * 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_INCLUDE_CKW_TYPES_H
+#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TYPES_H
+
+namespace ckw
+{
+/** Compute Kernel Writer data types. This data type is used by the code variables and tensor arguments. */
+enum class DataType
+{
+ Unknown,
+ Fp32,
+ Fp16,
+ Int32,
+ Int16,
+ Int8,
+ Uint32,
+ Uint16,
+ Uint8,
+ Bool
+};
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TYPES_H */
diff --git a/compute_kernel_writer/src/Error.cpp b/compute_kernel_writer/src/Error.cpp
new file mode 100644
index 0000000000..7f2fb41187
--- /dev/null
+++ b/compute_kernel_writer/src/Error.cpp
@@ -0,0 +1,40 @@
+/*
+ * 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 "ckw/Error.h"
+
+#include <string>
+
+namespace ckw
+{
+std::string create_error_msg(const std::string &file, const std::string &func, const std::string &line, const std::string &msg)
+{
+ std::string err;
+ err += "[COMPUTE_KERNEL_WRITER][ERROR]:";
+ err += " " + file + ":" + line;
+ err += " " + func;
+ err += " " + msg;
+ return err;
+}
+} // namespace ckw \ No newline at end of file
diff --git a/compute_kernel_writer/src/Helpers.cpp b/compute_kernel_writer/src/Helpers.cpp
new file mode 100644
index 0000000000..799f79a187
--- /dev/null
+++ b/compute_kernel_writer/src/Helpers.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "ckw/Error.h"
+
+#include "src/Helpers.h"
+
+namespace ckw
+{
+std::string dec_to_hex_as_string(int32_t dec)
+{
+ switch(dec)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ return std::to_string(dec);
+ case 10:
+ return "A";
+ case 11:
+ return "B";
+ case 12:
+ return "C";
+ case 13:
+ return "D";
+ case 14:
+ return "E";
+ case 15:
+ return "F";
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported decimal number");
+ return "";
+ }
+}
+} // namespace ckw
diff --git a/compute_kernel_writer/src/Helpers.h b/compute_kernel_writer/src/Helpers.h
new file mode 100644
index 0000000000..f7ba7cec1c
--- /dev/null
+++ b/compute_kernel_writer/src/Helpers.h
@@ -0,0 +1,56 @@
+/*
+ * 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_SRC_HELPERS_H
+#define COMPUTE_KERNEL_WRITER_SRC_HELPERS_H
+
+#include <cstdint>
+#include <string>
+
+/** Generic helper functions */
+namespace ckw
+{
+/** Helper function to convert a decimal number passed as int32_t variable to hexadecimal number as string
+ *
+ * @param[in] dec Decimal number. It must be >= 0 and < 16
+ *
+ * @return the OpenCL datatype as a string
+ */
+std::string dec_to_hex_as_string(int32_t dec);
+
+/** Helper function to clamp a value between min_val and max_val
+ *
+ * @param[in] val Value to clamp
+ * @param[in] min_val Lower value
+ * @param[in] max_val Upper value
+ *
+ * @return the clamped value
+ */
+template <typename T>
+T clamp(const T& val, const T& min_val, const T& max_val)
+{
+ return std::max(min_val, std::min(val, max_val));
+}
+}
+#endif /* COMPUTE_KERNEL_WRITER_SRC_HELPERS_H */
diff --git a/compute_kernel_writer/src/ITile.h b/compute_kernel_writer/src/ITile.h
new file mode 100644
index 0000000000..283e6fa236
--- /dev/null
+++ b/compute_kernel_writer/src/ITile.h
@@ -0,0 +1,134 @@
+/*
+ * 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_SRC_ITILE_H
+#define COMPUTE_KERNEL_WRITER_SRC_ITILE_H
+
+#include "ckw/TileInfo.h"
+
+#include <string>
+#include <vector>
+
+namespace ckw
+{
+/** Tile descriptor which reports the underlying datatype and vector length */
+struct TileVariableDescriptor
+{
+ DataType dt { DataType::Unknown }; /** Data type */
+ int32_t len { 1 }; /** Number of elements in a single variable. For example, 1 for scalar */
+};
+
+/** Tile variable */
+struct TileVariable
+{
+ std::string str {""}; /** Tile variable as a string */
+ TileVariableDescriptor desc {}; /** Tile value descriptor which reports the datatype and vector length */
+};
+
+/** Tile base class.
+ * A Tile is a collection of variables (either program variables or constants) used to express a 2D data.
+ */
+class ITile
+{
+public:
+ virtual ~ITile() = default;
+ /** Method to get all TileVariable objects
+ *
+ * @return a vector containing all @ref TileVariable objects
+ */
+ virtual std::vector<TileVariable> all() const = 0;
+ /** Method to get the name of the tile.
+ *
+ * @return the name of the tile
+ */
+ std::string name() const
+ {
+ return _basename;
+ }
+ /** Method to get the tile info
+ *
+ * @return the @ref TileInfo
+ */
+ TileInfo info() const
+ {
+ return _info;
+ }
+ /** Method to know whether the tile is assignable or not.
+ * For example, a constant tile is not assignable.
+ *
+ * @return true if the tile is assignable
+ */
+ virtual bool is_assignable() const = 0;
+
+protected:
+ TileInfo _info { DataType::Unknown }; // Tile info
+ std::string _basename { "" }; // Tile name
+};
+
+/** Tile base class to store scalar variables.
+ */
+class IScalarTile : public ITile
+{
+public:
+ virtual ~IScalarTile() = default;
+ /** Method to get the scalar variable from a tile as a string
+ * @param[in] col Tile column. If out-of-bound, the column is clamped to the nearest valid edge
+ * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
+ *
+ * @return the @ref TileVariable
+ */
+ virtual TileVariable scalar(int32_t col, int32_t row) const = 0;
+};
+
+/** Tile base class to store vector variables. It derives from IScalarTile since we can still access the scalar variable
+ */
+class IVectorTile : public IScalarTile
+{
+public:
+ virtual ~IVectorTile() = default;
+ /** Method to get the vector variable from a tile.
+ * The user can query the list of supported vector lengths through the supported_vector_lengths() method.
+ *
+ * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
+ *
+ * @return the vector variable as a @ref TileVariable
+ */
+ virtual TileVariable vector(int32_t row) const = 0;
+ /** Method to get a sub-vector variable. The length of the sub-vector must be supported by the derived IVectorTile class
+ *
+ * @param[in] col_start Tile starting column to get the sub-vector. If out-of-bound, the derived IVectorTile class may throw an assert.
+ * @param[in] width The width of the sub-vector. The width must be supported by the derived IVectorTile class and the last element must be in-bound.
+ * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
+ *
+ * @return the vector variable as a @ref TileVariable
+ */
+ virtual TileVariable vector(int32_t col_start, int32_t width, int32_t row) const = 0;
+ /** Method to get the supported vector length.
+ *
+ * @return a vector containing the supported vector lengths
+ */
+ virtual std::vector<int32_t> supported_vector_lengths() const = 0;
+};
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_SRC_ITILE_H */
diff --git a/compute_kernel_writer/src/TensorInfo.cpp b/compute_kernel_writer/src/TensorInfo.cpp
new file mode 100644
index 0000000000..561c126469
--- /dev/null
+++ b/compute_kernel_writer/src/TensorInfo.cpp
@@ -0,0 +1,77 @@
+/*
+ * 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 "ckw/TensorInfo.h"
+
+namespace ckw
+{
+TensorInfo::TensorInfo(DataType dt, const TensorShape &shape, TensorDataLayout dl, int32_t id)
+ : _shape(shape), _dt(dt), _dl(dl), _id(id)
+{
+}
+
+TensorInfo &TensorInfo::shape(const TensorShape &shape)
+{
+ _shape = shape;
+ return *this;
+}
+
+TensorShape TensorInfo::shape() const
+{
+ return _shape;
+}
+
+TensorInfo &TensorInfo::data_type(DataType dt)
+{
+ _dt = dt;
+ return *this;
+}
+
+DataType TensorInfo::data_type() const
+{
+ return _dt;
+}
+
+TensorInfo &TensorInfo::data_layout(TensorDataLayout dl)
+{
+ _dl = dl;
+ return *this;
+}
+
+TensorDataLayout TensorInfo::data_layout() const
+{
+ return _dl;
+}
+
+TensorInfo &TensorInfo::id(int32_t id)
+{
+ _id = id;
+ return *this;
+}
+
+int32_t TensorInfo::id() const
+{
+ return _id;
+}
+} // namespace ckw
diff --git a/compute_kernel_writer/src/TensorUtils.cpp b/compute_kernel_writer/src/TensorUtils.cpp
new file mode 100644
index 0000000000..cc179b4b51
--- /dev/null
+++ b/compute_kernel_writer/src/TensorUtils.cpp
@@ -0,0 +1,116 @@
+/*
+ * 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 "ckw/Error.h"
+#include "ckw/TensorInfo.h"
+#include "ckw/Types.h"
+
+#include "src/TensorUtils.h"
+
+namespace ckw
+{
+TensorComponent get_tensor_dimension(TensorDataLayout layout, TensorDataLayoutComponent component)
+{
+ switch(layout)
+ {
+ case TensorDataLayout::Nhwc:
+ switch(component)
+ {
+ case TensorDataLayoutComponent::C:
+ return TensorComponent::Dim0;
+ case TensorDataLayoutComponent::W:
+ return TensorComponent::Dim1;
+ case TensorDataLayoutComponent::H:
+ return TensorComponent::Dim2;
+ case TensorDataLayoutComponent::N:
+ return TensorComponent::Dim3;
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor component for NHWC");
+ return TensorComponent::Unknown;
+ }
+ case TensorDataLayout::Ndhwc:
+ switch(component)
+ {
+ case TensorDataLayoutComponent::C:
+ return TensorComponent::Dim0;
+ case TensorDataLayoutComponent::W:
+ return TensorComponent::Dim1;
+ case TensorDataLayoutComponent::H:
+ return TensorComponent::Dim2;
+ case TensorDataLayoutComponent::D:
+ return TensorComponent::Dim3;
+ case TensorDataLayoutComponent::N:
+ return TensorComponent::Dim4;
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor component for NDHWC");
+ return TensorComponent::Unknown;
+ }
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor data layout");
+ return TensorComponent::Unknown;
+ }
+}
+
+TensorComponent get_tensor_stride(TensorDataLayout layout, TensorDataLayoutComponent component)
+{
+ switch(layout)
+ {
+ case TensorDataLayout::Nhwc:
+ switch(component)
+ {
+ case TensorDataLayoutComponent::C:
+ return TensorComponent::Stride0;
+ case TensorDataLayoutComponent::W:
+ return TensorComponent::Stride1;
+ case TensorDataLayoutComponent::H:
+ return TensorComponent::Stride2;
+ case TensorDataLayoutComponent::N:
+ return TensorComponent::Stride3;
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor component for NHWC");
+ return TensorComponent::Unknown;
+ }
+ case TensorDataLayout::Ndhwc:
+ switch(component)
+ {
+ case TensorDataLayoutComponent::C:
+ return TensorComponent::Stride0;
+ case TensorDataLayoutComponent::W:
+ return TensorComponent::Stride1;
+ case TensorDataLayoutComponent::H:
+ return TensorComponent::Stride2;
+ case TensorDataLayoutComponent::D:
+ return TensorComponent::Stride3;
+ case TensorDataLayoutComponent::N:
+ return TensorComponent::Stride4;
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor component for NDHWC");
+ return TensorComponent::Unknown;
+ }
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported tensor data layout");
+ return TensorComponent::Unknown;
+ }
+}
+} // namespace ckw
diff --git a/compute_kernel_writer/src/TensorUtils.h b/compute_kernel_writer/src/TensorUtils.h
new file mode 100644
index 0000000000..4be0395435
--- /dev/null
+++ b/compute_kernel_writer/src/TensorUtils.h
@@ -0,0 +1,56 @@
+/*
+ * 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_SRC_TENSORUTILS_H
+#define COMPUTE_KERNEL_WRITER_SRC_TENSORUTILS_H
+
+#include <cstdint>
+
+/** Tensor specific utility functions */
+namespace ckw
+{
+// Forward declarations
+enum class TensorDataLayout;
+enum class TensorDataLayoutComponent;
+enum class TensorComponent : uint32_t;
+
+/** Get tensor dimension from a given data layout and data layout component
+ *
+ * @param[in] layout Layout of the tensor
+ * @param[in] component Data layout component
+ *
+ * @return the @ref TensorComponent
+ */
+TensorComponent get_tensor_dimension(TensorDataLayout layout, TensorDataLayoutComponent component);
+
+/** Get tensor stride from a given data layout and data layout component
+ *
+ * @param[in] layout Layout of the tensor
+ * @param[in] component Data layout component
+ *
+ * @return the @ref TensorComponent
+ */
+TensorComponent get_tensor_stride(TensorDataLayout layout, TensorDataLayoutComponent component);
+}
+#endif /* COMPUTE_KERNEL_WRITER_SRC_TENSORUTILS_H */
diff --git a/compute_kernel_writer/src/TileInfo.cpp b/compute_kernel_writer/src/TileInfo.cpp
new file mode 100644
index 0000000000..6dd1957a7a
--- /dev/null
+++ b/compute_kernel_writer/src/TileInfo.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 "ckw/TileInfo.h"
+
+namespace ckw
+{
+TileInfo::TileInfo(DataType dt)
+ : _dt(dt), _shape({{1, 1}})
+{
+}
+
+TileInfo::TileInfo(DataType dt, int32_t w)
+ : _dt(dt), _shape({{w, 1}})
+{
+}
+
+TileInfo::TileInfo(DataType dt, int32_t w, int32_t h)
+ : _dt(dt), _shape({{w, h}})
+{
+}
+
+TileInfo &TileInfo::width(int32_t w)
+{
+ _shape[kTileWidthIdx] = w;
+ return *this;
+}
+
+int32_t TileInfo::width() const
+{
+ return _shape[kTileWidthIdx];
+}
+
+TileInfo &TileInfo::height(int32_t h)
+{
+ _shape[kTileHeightIdx] = h;
+ return *this;
+}
+
+int32_t TileInfo::height() const
+{
+ return _shape[kTileHeightIdx];
+}
+
+TileInfo &TileInfo::data_type(DataType dt)
+{
+ _dt = dt;
+ return *this;
+}
+
+DataType TileInfo::data_type() const
+{
+ return _dt;
+}
+} // namespace ckw
diff --git a/compute_kernel_writer/src/cl/CLHelpers.cpp b/compute_kernel_writer/src/cl/CLHelpers.cpp
new file mode 100644
index 0000000000..68d7db252b
--- /dev/null
+++ b/compute_kernel_writer/src/cl/CLHelpers.cpp
@@ -0,0 +1,91 @@
+/*
+ * 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 "ckw/Error.h"
+#include "ckw/Types.h"
+
+#include "src/cl/CLHelpers.h"
+
+namespace ckw
+{
+bool cl_validate_vector_length(int32_t len)
+{
+ bool valid_vector_length = true;
+ if(len < 1 || len > 16 || (len > 4 && len < 8) || (len > 8 && len < 16))
+ {
+ valid_vector_length = false;
+ }
+ return valid_vector_length;
+}
+
+std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len)
+{
+ if(cl_validate_vector_length(len) == false)
+ {
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported vector length");
+ return "";
+ }
+
+ std::string res;
+ switch(dt)
+ {
+ case DataType::Fp32:
+ res += "float";
+ break;
+ case DataType::Fp16:
+ res += "half";
+ break;
+ case DataType::Int8:
+ res += "char";
+ break;
+ case DataType::Uint8:
+ res += "uchar";
+ break;
+ case DataType::Uint16:
+ res += "ushort";
+ break;
+ case DataType::Int16:
+ res += "short";
+ break;
+ case DataType::Uint32:
+ res += "uint";
+ break;
+ case DataType::Int32:
+ res += "int";
+ break;
+ case DataType::Bool:
+ res += "bool";
+ break;
+ default:
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported datatype");
+ return "";
+ }
+
+ if(len > 1)
+ {
+ res += std::to_string(len);
+ }
+
+ return res;
+}
+} // namespace ckw \ No newline at end of file
diff --git a/compute_kernel_writer/src/cl/CLHelpers.h b/compute_kernel_writer/src/cl/CLHelpers.h
new file mode 100644
index 0000000000..915d59f458
--- /dev/null
+++ b/compute_kernel_writer/src/cl/CLHelpers.h
@@ -0,0 +1,53 @@
+/*
+ * 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_SRC_CL_CLHELPERS_H
+#define COMPUTE_KERNEL_WRITER_SRC_CL_CLHELPERS_H
+
+#include <string>
+
+/** OpenCL specific helper functions */
+namespace ckw
+{
+// Forward declarations
+enum class DataType;
+
+/** Helper function to validate the vector length of OpenCL vector data types
+ *
+ * @param[in] len Vector length
+ *
+ * @return true if the vector lenght is valid. It returns false, otherwise.
+ */
+bool cl_validate_vector_length(int32_t len);
+
+/** Helper function to return the OpenCL datatype as a string from a @ref DataType and vector length as int32_t variable
+ *
+ * @param[in] dt Datatype
+ * @param[in] len Vector length
+ *
+ * @return the OpenCL datatype as a string
+ */
+std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len);
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_SRC_CL_CLHELPERS_H */
diff --git a/compute_kernel_writer/src/cl/CLTile.cpp b/compute_kernel_writer/src/cl/CLTile.cpp
new file mode 100644
index 0000000000..a46f692a5c
--- /dev/null
+++ b/compute_kernel_writer/src/cl/CLTile.cpp
@@ -0,0 +1,156 @@
+/*
+ * 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 "ckw/Error.h"
+#include "ckw/TileInfo.h"
+
+#include "src/Helpers.h"
+#include "src/cl/CLHelpers.h"
+#include "src/cl/CLTile.h"
+
+#include <algorithm>
+#include <vector>
+
+namespace ckw
+{
+CLTile::CLTile(const std::string &name, const TileInfo &info)
+{
+ validate_tile_info(info);
+
+ _basename = name;
+ _info = info;
+}
+
+TileVariable CLTile::scalar(int32_t col, int32_t row) const
+{
+ // Clamp to nearest valid edge
+ col = clamp(col, static_cast<int32_t>(0), _info.width() - 1);
+ row = clamp(row, static_cast<int32_t>(0), _info.height() - 1);
+
+ TileVariable t;
+ t.str = create_var_name(row);
+ t.desc.dt = _info.data_type();
+ t.desc.len = 1;
+
+ // This check is required because if the width has only one element, we cannot use .s0
+ if(_info.width() != 1)
+ {
+ // Automatic broadcasting
+ t.str += ".s" + dec_to_hex_as_string(col);
+ }
+
+ return t;
+}
+
+TileVariable CLTile::vector(int32_t row) const
+{
+ // Clamp to nearest valid edge
+ row = clamp(row, static_cast<int32_t>(0), _info.height() - 1);
+
+ TileVariable t;
+ t.str = create_var_name(row);
+ t.desc.dt = _info.data_type();
+ t.desc.len = _info.width();
+ return t;
+}
+
+TileVariable CLTile::vector(int32_t col_start, int32_t width, int32_t row) const
+{
+ // Validate the new vector length
+ cl_validate_vector_length(width);
+
+ // Clamp to nearest valid edge
+ row = clamp(row, static_cast<int32_t>(0), _info.height() - 1);
+
+ TileVariable t;
+ t.str = create_var_name(row);
+ t.desc.dt = _info.data_type();
+ t.desc.len = width;
+
+ if(_info.width() != 1)
+ {
+ t.str += ".s";
+ for(int i = 0; i < width; ++i)
+ {
+ t.str += dec_to_hex_as_string(col_start + i);
+ }
+ }
+ return t;
+}
+
+std::vector<TileVariable> CLTile::all() const
+{
+ std::vector<TileVariable> vars;
+ for(int32_t y = 0; y < _info.height(); ++y)
+ {
+ TileVariable t;
+ t.str = create_var_name(y);
+ t.desc.dt = _info.data_type();
+ t.desc.len = _info.width();
+ vars.push_back(t);
+ }
+ return vars;
+}
+
+std::vector<int32_t> CLTile::supported_vector_lengths() const
+{
+ return std::vector<int32_t> {1, 2, 3, 4, 8, 16};
+}
+
+bool CLTile::is_assignable() const
+{
+ return true;
+}
+
+std::string CLTile::create_var_name(int32_t row) const
+{
+ std::string var_name = _basename;
+
+ // If a scalar variable, we do not append the row index
+ if(_info.height() == 1)
+ {
+ return var_name;
+
+ }
+ else
+ {
+ var_name += "_";
+ var_name += std::to_string(row);
+ }
+
+ return var_name;
+}
+
+void CLTile::validate_tile_info(const TileInfo &info) const
+{
+ if(cl_validate_vector_length(info.width()))
+ {
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported TileInfo width");
+ }
+
+ if(info.data_type() == DataType::Unknown)
+ {
+ COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("DataType::Unknown is not supported");
+ }
+}
+} // namespace ckw \ No newline at end of file
diff --git a/compute_kernel_writer/src/cl/CLTile.h b/compute_kernel_writer/src/cl/CLTile.h
new file mode 100644
index 0000000000..50801675a7
--- /dev/null
+++ b/compute_kernel_writer/src/cl/CLTile.h
@@ -0,0 +1,61 @@
+/*
+ * 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_SRC_CL_CLTILE_H
+#define COMPUTE_KERNEL_WRITER_SRC_CL_CLTILE_H
+
+#include "src/ITile.h"
+
+#include <string>
+
+namespace ckw
+{
+// Forward declarations
+class TileInfo;
+
+/** OpenCL specific tile */
+class CLTile : protected IVectorTile
+{
+public:
+ /** Constructor
+ *
+ * @param[in] name Tile name
+ * @param[in] info Tile info
+ */
+ CLTile(const std::string& name, const TileInfo &info);
+
+ // Inherited method overridden
+ TileVariable scalar(int32_t col, int32_t row) const override;
+ TileVariable vector(int32_t row) const override;
+ TileVariable vector(int32_t col_start, int32_t width, int32_t row) const override;
+ std::vector<TileVariable> all() const override;
+ std::vector<int32_t> supported_vector_lengths() const override;
+ bool is_assignable() const override;
+
+private:
+ std::string create_var_name(int32_t row) const;
+ void validate_tile_info(const TileInfo &info) const;
+};
+} // namespace ckw
+
+#endif /* COMPUTE_KERNEL_WRITER_SRC_CL_CLTILE_H */
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 */
diff --git a/scripts/clang_tidy_rules.py b/scripts/clang_tidy_rules.py
index 2e0b32e6cc..3e98e85ad3 100755
--- a/scripts/clang_tidy_rules.py
+++ b/scripts/clang_tidy_rules.py
@@ -70,6 +70,9 @@ def filter_clang_tidy_lines( lines ):
if "/arm_gemm/" in line:
continue
+ if "compute_kernel_writer/" in line:
+ continue
+
if "/convolution/" in line:
continue