From 1df9f6ed4245489b74875893c695367bd0d6e3d8 Mon Sep 17 00:00:00 2001 From: Viet-Hoa Do Date: Mon, 24 Jul 2023 17:57:12 +0100 Subject: Add kernel argument emitting Resolves: COMPMID-6391 Signed-off-by: Viet-Hoa Do Change-Id: I0d54d99ffad275400c6da7fe16deb544553060eb Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10004 Reviewed-by: Anitha Raj Reviewed-by: Gunes Bayir Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Benchmark: Arm Jenkins --- compute_kernel_writer/include/ckw/Kernel.h | 16 ++-- compute_kernel_writer/include/ckw/KernelArgument.h | 98 ++++++++++++++++++++++ 2 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 compute_kernel_writer/include/ckw/KernelArgument.h (limited to 'compute_kernel_writer/include/ckw') diff --git a/compute_kernel_writer/include/ckw/Kernel.h b/compute_kernel_writer/include/ckw/Kernel.h index d93ed6f1d3..dc0cad5503 100644 --- a/compute_kernel_writer/include/ckw/Kernel.h +++ b/compute_kernel_writer/include/ckw/Kernel.h @@ -25,7 +25,9 @@ #ifndef CKW_INCLUDE_CKW_KERNEL_H #define CKW_INCLUDE_CKW_KERNEL_H +#include "ckw/KernelArgument.h" #include +#include namespace ckw { @@ -48,22 +50,24 @@ public: /** Initialize a new instance of @ref Kernel class with all emitted kernel information. * * @param[in] language The target language of the kernel. + * @param[in] arguments The list of kernel arguments. * @param[in] source_code The source code of the kernel. */ - Kernel(TargetLanguage language, const std::string &source_code); + Kernel(TargetLanguage language, const std::vector &arguments, const std::string &source_code); /** Get the target language. */ TargetLanguage target_language() const; + /** Get the list of arguments. */ + const std::vector &arguments() const; + /** Get the source code. */ const std::string &source_code() const; - /** Add a tile operand */ - virtual TileOperand &add_operand(const std::string &name, const TileInfo &tile_info) = 0; - private: - TargetLanguage _language; - std::string _source_code; + TargetLanguage _language; + std::vector _arguments; + std::string _source_code; }; } // namespace ckw diff --git a/compute_kernel_writer/include/ckw/KernelArgument.h b/compute_kernel_writer/include/ckw/KernelArgument.h new file mode 100644 index 0000000000..530e2920eb --- /dev/null +++ b/compute_kernel_writer/include/ckw/KernelArgument.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CKW_INCLUDE_CKW_KERNELARGUMENT_H +#define CKW_INCLUDE_CKW_KERNELARGUMENT_H + +#include "ckw/types/TensorComponentType.h" +#include "ckw/types/TensorStorageType.h" +#include + +namespace ckw +{ + +/** A kernel argument which can be either a tensor storage or a tensor component. */ +class KernelArgument +{ +public: + /** The type of kernel argument. */ + enum class Type : int32_t + { + /** The argument that provides the read and/or write access to the tensor data. + * + * See @ref ckw::TensorStorageType to see the list of supported storage type. + */ + TensorStorage, + + /** The argument that provides extra information about the tensor. + * + * See @ref ckw::TensorComponentType to see the list of supported component. + */ + TensorComponent, + }; + + /** Initialize a new instance of kernel argument class for a tensor storage argument. */ + KernelArgument(int32_t tensor_id, TensorStorageType storage_type); + + /** Initialize a new instance of kernel argument class for a tensor component argument. */ + KernelArgument(int32_t tensor_id, TensorComponentType component_type); + + /** Get the type of kernel argument. */ + Type type() const; + + /** Get the argument ID. + * + * This method can be used to get the tensor info ID of both tensor storage and tensor component arguments. + */ + int32_t id() const; + + /** Get the type of tensor storage. + * + * This method can only be used for tensor storage argument. + */ + TensorStorageType tensor_storage_type() const; + + /** Get the tensor component type. + * + * This method can only be used for tensor component argument. + */ + TensorComponentType tensor_component_type() const; + +private: + Type _type; + int32_t _id; + + union SubId + { + int32_t unknown; + TensorStorageType tensor_storage_type; + TensorComponentType tensor_component_type; + }; + + SubId _sub_id{ 0 }; +}; + +} // namespace ckw + +#endif // CKW_INCLUDE_CKW_KERNELARGUMENT_H -- cgit v1.2.1