From 3c776066a0195f2e99d3503f8b058e468d53b884 Mon Sep 17 00:00:00 2001 From: Gunes Bayir Date: Wed, 12 Jul 2023 14:50:56 +0100 Subject: Rename ITileOperand and introduce vector/scalar interfaces in CKW Partially Resolves: COMPMID-5788 This patch - renames ITileOperand to TileOperand, which seems to be a more intuitive name for the prospective users of Compute Kernel Writer - provides IScalarAccess and IVectorAccess interfaces to be used by Tile classes. It replaces the current IScalarTile and IVectorTile, and forms a more intuitive inheritance hierarchy where each subclass "is a" member of the parent class semantically. Signed-off-by: Gunes Bayir Change-Id: I2b5253b0595e63f8ff3047c608d593b3b364634d Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9910 Reviewed-by: Jakub Sujak Reviewed-by: Viet-Hoa Do Comments-Addressed: Arm Jenkins Benchmark: Arm Jenkins Tested-by: Arm Jenkins --- compute_kernel_writer/CMakeLists.txt | 6 ++-- compute_kernel_writer/include/ckw/ITileOperand.h | 41 ------------------------ compute_kernel_writer/include/ckw/Kernel.h | 4 +-- compute_kernel_writer/include/ckw/KernelWriter.h | 10 +++--- compute_kernel_writer/include/ckw/TileOperand.h | 41 ++++++++++++++++++++++++ compute_kernel_writer/src/ITile.h | 18 +++++------ compute_kernel_writer/src/ITileOperand.cpp | 30 ----------------- compute_kernel_writer/src/KernelWriter.cpp | 4 +-- compute_kernel_writer/src/TileOperand.cpp | 30 +++++++++++++++++ compute_kernel_writer/src/cl/CLKernelWriter.cpp | 6 ++-- compute_kernel_writer/src/cl/CLKernelWriter.h | 5 +-- compute_kernel_writer/src/cl/CLTile.h | 4 +-- compute_kernel_writer/src/cl/ICLTile.h | 3 +- 13 files changed, 102 insertions(+), 100 deletions(-) delete mode 100644 compute_kernel_writer/include/ckw/ITileOperand.h create mode 100644 compute_kernel_writer/include/ckw/TileOperand.h delete mode 100644 compute_kernel_writer/src/ITileOperand.cpp create mode 100644 compute_kernel_writer/src/TileOperand.cpp diff --git a/compute_kernel_writer/CMakeLists.txt b/compute_kernel_writer/CMakeLists.txt index d763bc6de5..9f372df585 100644 --- a/compute_kernel_writer/CMakeLists.txt +++ b/compute_kernel_writer/CMakeLists.txt @@ -120,12 +120,12 @@ target_compile_definitions(ckw PUBLIC target_sources(ckw PRIVATE src/Error.cpp src/Helpers.cpp + src/Kernel.cpp + src/KernelWriter.cpp src/TensorInfo.cpp src/TensorUtils.cpp src/TileInfo.cpp - src/ITileOperand.cpp - src/Kernel.cpp - src/KernelWriter.cpp + src/TileOperand.cpp ) if(CKW_ENABLE_OPENCL) diff --git a/compute_kernel_writer/include/ckw/ITileOperand.h b/compute_kernel_writer/include/ckw/ITileOperand.h deleted file mode 100644 index db39ea0262..0000000000 --- a/compute_kernel_writer/include/ckw/ITileOperand.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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_TILEOPERAND -#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TILEOPERAND - -namespace ckw -{ - -/** Tile operand which can be either scalar, vector or 2D tile. */ -class ITileOperand -{ -public: - /* Destructor */ - virtual ~ITileOperand(); -}; - -} // namespace ckw - -#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TILEOPERAND */ diff --git a/compute_kernel_writer/include/ckw/Kernel.h b/compute_kernel_writer/include/ckw/Kernel.h index 54e7ca33fd..d93ed6f1d3 100644 --- a/compute_kernel_writer/include/ckw/Kernel.h +++ b/compute_kernel_writer/include/ckw/Kernel.h @@ -32,7 +32,7 @@ namespace ckw // Forward Declerations class TileInfo; -class ITileOperand; +class TileOperand; enum class TargetLanguage; @@ -59,7 +59,7 @@ public: const std::string &source_code() const; /** Add a tile operand */ - virtual ITileOperand &add_operand(const std::string &name, const TileInfo &tile_info) = 0; + virtual TileOperand &add_operand(const std::string &name, const TileInfo &tile_info) = 0; private: TargetLanguage _language; diff --git a/compute_kernel_writer/include/ckw/KernelWriter.h b/compute_kernel_writer/include/ckw/KernelWriter.h index f1635c6449..85ae47f686 100644 --- a/compute_kernel_writer/include/ckw/KernelWriter.h +++ b/compute_kernel_writer/include/ckw/KernelWriter.h @@ -25,7 +25,7 @@ #ifndef CKW_INCLUDE_CKW_KERNELWRITER_H #define CKW_INCLUDE_CKW_KERNELWRITER_H -#include "ckw/ITileOperand.h" +#include "ckw/TileOperand.h" #include #include @@ -103,23 +103,23 @@ public: * * @returns The created tile operand */ - virtual ITileOperand &declare_tile(const std::string &name, const TileInfo &tile_info) = 0; + virtual TileOperand &declare_tile(const std::string &name, const TileInfo &tile_info) = 0; protected: int32_t id_space() const; /** Pure virtual function to be overridden by language specific subclasses to add a tile operand to the kernel */ - virtual ITileOperand &add_operand(const std::string &name, const TileInfo &tile_info) = 0; + virtual TileOperand &add_operand(const std::string &name, const TileInfo &tile_info) = 0; /** Add a tile operand to the operand list */ - ITileOperand &add_operand(std::unique_ptr &operand_ptr); + TileOperand &add_operand(std::unique_ptr &operand_ptr); /** Generate full variable name by prefixing it with id space */ std::string generate_full_name(const std::string &name) const; private: int32_t _id_space{ 0 }; - std::set> _operands {}; + std::set> _operands {}; }; } // namespace ckw diff --git a/compute_kernel_writer/include/ckw/TileOperand.h b/compute_kernel_writer/include/ckw/TileOperand.h new file mode 100644 index 0000000000..abd3e0ac97 --- /dev/null +++ b/compute_kernel_writer/include/ckw/TileOperand.h @@ -0,0 +1,41 @@ +/* + * 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_TILEOPERAND +#define CKW_INCLUDE_CKW_TILEOPERAND + +namespace ckw +{ + +/** Tile operand which can be either scalar, vector or 2D tile. */ +class TileOperand +{ +public: + /* Destructor */ + virtual ~TileOperand(); +}; + +} // namespace ckw + +#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TILEOPERAND */ diff --git a/compute_kernel_writer/src/ITile.h b/compute_kernel_writer/src/ITile.h index c036907561..bed4996607 100644 --- a/compute_kernel_writer/src/ITile.h +++ b/compute_kernel_writer/src/ITile.h @@ -92,12 +92,12 @@ protected: std::string _basename{ "" }; // Tile name }; -/** Tile base class to store scalar variables. +/** Interface to provide support for scalar access for a Tile. */ -class IScalarTile : public ITile +class IScalarAccess { public: - virtual ~IScalarTile() = default; + virtual ~IScalarAccess() = default; /** Method to get the scalar variable from a tile as a string * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge @@ -108,12 +108,12 @@ public: virtual TileVariable scalar(int32_t row, int32_t col) const = 0; }; -/** Tile base class to store vector variables. It derives from IScalarTile since we can still access the scalar variable +/** Interface to provide support for vector access for a tile. */ -class IVectorTile : public IScalarTile +class IVectorAccess { public: - virtual ~IVectorTile() = default; + virtual ~IVectorAccess() = 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. @@ -124,11 +124,11 @@ public: */ 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 + /** Method to get a sub-vector variable. The length of the sub-vector must be supported by the derived IVectorAccess class * * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge - * @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] col_start Tile starting column to get the sub-vector. If out-of-bound, the derived IVectorAccess class may throw an assert. + * @param[in] width The width of the sub-vector. The width must be supported by the derived IVectorAccess class and the last element must be in-bound. * * @return the vector variable as a @ref TileVariable */ diff --git a/compute_kernel_writer/src/ITileOperand.cpp b/compute_kernel_writer/src/ITileOperand.cpp deleted file mode 100644 index 2da7b7a5bf..0000000000 --- a/compute_kernel_writer/src/ITileOperand.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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/ITileOperand.h" - -namespace ckw -{ - ITileOperand::~ITileOperand() = default; -} \ No newline at end of file diff --git a/compute_kernel_writer/src/KernelWriter.cpp b/compute_kernel_writer/src/KernelWriter.cpp index ab5ede8c77..347ae5b545 100644 --- a/compute_kernel_writer/src/KernelWriter.cpp +++ b/compute_kernel_writer/src/KernelWriter.cpp @@ -23,7 +23,7 @@ */ #include "ckw/Error.h" -#include "ckw/ITileOperand.h" +#include "ckw/TileOperand.h" #include "ckw/KernelWriter.h" #include "ckw/types/TargetArchitecture.h" #include "ckw/types/TargetLanguage.h" @@ -55,7 +55,7 @@ int32_t KernelWriter::id_space() const return _id_space; } -ITileOperand &KernelWriter::add_operand(std::unique_ptr &operand_ptr) +TileOperand &KernelWriter::add_operand(std::unique_ptr &operand_ptr) { auto it = _operands.insert(std::move(operand_ptr)); return *it.first->get(); diff --git a/compute_kernel_writer/src/TileOperand.cpp b/compute_kernel_writer/src/TileOperand.cpp new file mode 100644 index 0000000000..83914b3216 --- /dev/null +++ b/compute_kernel_writer/src/TileOperand.cpp @@ -0,0 +1,30 @@ +/* + * 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/TileOperand.h" + +namespace ckw +{ + TileOperand::~TileOperand() = default; +} \ No newline at end of file diff --git a/compute_kernel_writer/src/cl/CLKernelWriter.cpp b/compute_kernel_writer/src/cl/CLKernelWriter.cpp index 7faf2e6d60..2f8b1c95ce 100644 --- a/compute_kernel_writer/src/cl/CLKernelWriter.cpp +++ b/compute_kernel_writer/src/cl/CLKernelWriter.cpp @@ -61,7 +61,7 @@ const std::string &CLKernelWriter::body_source_code() const return _body_source_code; } -ITileOperand &CLKernelWriter::declare_tile(const std::string &name, const TileInfo &tile_info) +TileOperand &CLKernelWriter::declare_tile(const std::string &name, const TileInfo &tile_info) { const std::string fullname = generate_full_name(name); @@ -78,9 +78,9 @@ ITileOperand &CLKernelWriter::declare_tile(const std::string &name, const TileIn return add_operand(fullname, tile_info); } -ITileOperand &CLKernelWriter::add_operand(const std::string &name, const TileInfo &tile_info) +TileOperand &CLKernelWriter::add_operand(const std::string &name, const TileInfo &tile_info) { - std::unique_ptr operand = std::make_unique(name, tile_info); + std::unique_ptr operand = std::make_unique(name, tile_info); return KernelWriter::add_operand(operand); } diff --git a/compute_kernel_writer/src/cl/CLKernelWriter.h b/compute_kernel_writer/src/cl/CLKernelWriter.h index d0c4b7c9d4..5bf7293ae2 100644 --- a/compute_kernel_writer/src/cl/CLKernelWriter.h +++ b/compute_kernel_writer/src/cl/CLKernelWriter.h @@ -26,6 +26,7 @@ #define CKW_SRC_CL_CLKERNELWRITER_H #include "ckw/KernelWriter.h" + #include namespace ckw @@ -61,7 +62,7 @@ public: * * Similar to @ref KernelWriter::declare_tile() */ - ITileOperand &declare_tile(const ::std::string &name, const TileInfo &tile_info) override; + TileOperand &declare_tile(const ::std::string &name, const TileInfo &tile_info) override; protected: @@ -84,7 +85,7 @@ protected: const std::string &body_source_code() const; /** Add a tile operand to the kernel and return it */ - ITileOperand &add_operand(const std::string &code, const TileInfo &tile_info) override; + TileOperand &add_operand(const std::string &code, const TileInfo &tile_info) override; private: /** This string contains the kernel body source code, not the full CL source code. diff --git a/compute_kernel_writer/src/cl/CLTile.h b/compute_kernel_writer/src/cl/CLTile.h index 7e69de847b..b9d4bbaf84 100644 --- a/compute_kernel_writer/src/cl/CLTile.h +++ b/compute_kernel_writer/src/cl/CLTile.h @@ -26,7 +26,7 @@ #include "src/ITile.h" #include "src/cl/ICLTile.h" -#include "ckw/ITileOperand.h" +#include "ckw/TileOperand.h" #include @@ -36,7 +36,7 @@ namespace ckw class TileInfo; /** OpenCL specific tile */ -class CLTile : public ICLTile, public ITileOperand +class CLTile : public ICLTile, public TileOperand { public: /** Constructor diff --git a/compute_kernel_writer/src/cl/ICLTile.h b/compute_kernel_writer/src/cl/ICLTile.h index b02bc037af..17c44d1d3e 100644 --- a/compute_kernel_writer/src/cl/ICLTile.h +++ b/compute_kernel_writer/src/cl/ICLTile.h @@ -32,7 +32,8 @@ namespace ckw class TileInfo; /** Interface for the OpenCL specific tile */ -class ICLTile : public IVectorTile +class ICLTile : public ITile, // classes inherited + public IVectorAccess, public IScalarAccess // interfaces implemented { public: // Inherited method overridden -- cgit v1.2.1