diff options
52 files changed, 1358 insertions, 348 deletions
diff --git a/Android.bp b/Android.bp index ccf513a137..fd6ff3b4d3 100644 --- a/Android.bp +++ b/Android.bp @@ -178,8 +178,8 @@ cc_library_static { proprietary: true, local_include_dirs: ["build/android-arm64v8a/src/core", "build/android-arm64v8a/src/core/CL", - "compute_kernel_writer/include", - "compute_kernel_writer", + "compute_kernel_writer/prototype/include", + "compute_kernel_writer/prototype", "src/core/common", "src/core/helpers", "src/core/NEON/kernels/arm_gemm", @@ -189,24 +189,14 @@ cc_library_static { "src/cpu/kernels/assembly"], export_include_dirs: [".", "./include"], srcs: [ - "compute_kernel_writer/src/Error.cpp", - "compute_kernel_writer/src/Helpers.cpp", - "compute_kernel_writer/src/Kernel.cpp", - "compute_kernel_writer/src/KernelWriter.cpp", - "compute_kernel_writer/src/OperandBase.cpp", - "compute_kernel_writer/src/TensorInfo.cpp", - "compute_kernel_writer/src/TensorOperand.cpp", - "compute_kernel_writer/src/TensorTileSampler.cpp", - "compute_kernel_writer/src/TensorUtils.cpp", - "compute_kernel_writer/src/TileInfo.cpp", - "compute_kernel_writer/src/TileOperand.cpp", - "compute_kernel_writer/src/acl/AclComponentArgument.cpp", - "compute_kernel_writer/src/acl/AclKernelWriter.cpp", - "compute_kernel_writer/src/acl/AclScopedKernelWriter.cpp", - "compute_kernel_writer/src/cl/CLConstantTile.cpp", - "compute_kernel_writer/src/cl/CLHelpers.cpp", - "compute_kernel_writer/src/cl/CLTile.cpp", - "compute_kernel_writer/src/cl/ICLTile.cpp", + "compute_kernel_writer/prototype/src/Kernel.cpp", + "compute_kernel_writer/prototype/src/KernelWriter.cpp", + "compute_kernel_writer/prototype/src/OperandBase.cpp", + "compute_kernel_writer/prototype/src/TensorInfo.cpp", + "compute_kernel_writer/prototype/src/TensorOperand.cpp", + "compute_kernel_writer/prototype/src/TensorTileSampler.cpp", + "compute_kernel_writer/prototype/src/TileInfo.cpp", + "compute_kernel_writer/prototype/src/TileOperand.cpp", "src/c/AclContext.cpp", "src/c/AclOperator.cpp", "src/c/AclQueue.cpp", @@ -642,7 +632,10 @@ cc_library_static { "src/dynamic_fusion/sketch/gpu/GpuOperatorGroup.cpp", "src/dynamic_fusion/sketch/gpu/GpuWorkloadContext.cpp", "src/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp", diff --git a/SConscript b/SConscript index 9ddffc4273..5504d48e07 100644 --- a/SConscript +++ b/SConscript @@ -128,7 +128,7 @@ def build_library(name, build_env, sources, static=False, libs=[]): cloned_build_env["LINKFLAGS"].remove('-static-libstdc++') if env['experimental_dynamic_fusion']: - libs.append('libckw.a') + libs.append('libckw_prototype.a') if static: obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs) diff --git a/SConstruct b/SConstruct index 4994972172..4ab9fdd66a 100644 --- a/SConstruct +++ b/SConstruct @@ -160,7 +160,7 @@ install_path = env['install_dir'] if not env['install_dir'].startswith('/') and install_path != "": install_path = "%s/%s" % (build_path, install_path) -env.Append(LIBPATH = [build_path]) +env.Append(LIBPATH = [build_path, os.path.join(build_path, "prototype")]) Export('env') Export('vars') @@ -432,7 +432,7 @@ if env['experimental_dynamic_fusion']: CKW_ENABLE_ASSERTS = env['debug'] or env['asserts'] CKW_PROJECT_DIR = Dir('.').path + "/compute_kernel_writer" - CKW_INCLUDE_DIR = CKW_PROJECT_DIR + "/include" + CKW_INCLUDE_DIR = CKW_PROJECT_DIR + "/prototype/include" CKW_BUILD_DIR = build_path.replace("#", "") CKW_CMAKE_CMD = "CC={CKW_CC} CXX={CKW_CXX} cmake -G \"Unix Makefiles\" " \ @@ -440,6 +440,7 @@ if env['experimental_dynamic_fusion']: "-DCMAKE_BUILD_TYPE={CKW_BUILD_TYPE} " \ "-DCKW_ENABLE_OPENCL={CKW_ENABLE_OPENCL} " \ "-DCKW_ENABLE_ASSERTS={CKW_ENABLE_ASSERTS} " \ + "-DCKW_BUILD_PROTOTYPE=ON " \ "-DCKW_CCACHE={CKW_CCACHE} ".format(CKW_CC=CKW_CC, CKW_CXX=CKW_CXX, CKW_PROJECT_DIR=CKW_PROJECT_DIR, diff --git a/compute_kernel_writer/CMakeLists.txt b/compute_kernel_writer/CMakeLists.txt index 2c770e4efb..186ab328f5 100644 --- a/compute_kernel_writer/CMakeLists.txt +++ b/compute_kernel_writer/CMakeLists.txt @@ -43,7 +43,6 @@ message(STATUS "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}") option(CKW_ENABLE_OPENCL "Enable OpenCL code generation" OFF) option(CKW_ENABLE_ASSERTS "Enable assertions. Always enabled in Debug builds" OFF) option(CKW_BUILD_TESTING "Build the Compute Kernel Writer validation test suite" OFF) -option(CKW_BUILD_EXAMPLES "Build the Compute Kernel Writer examples" OFF) option(CKW_CCACHE "Use compiler cache for faster recompilation" OFF) #--------------------------------------------------------------------- @@ -122,17 +121,6 @@ target_sources(ckw PRIVATE src/TensorInfo.cpp src/TensorUtils.cpp src/TileInfo.cpp - - src/Kernel.cpp - src/KernelWriter.cpp - src/OperandBase.cpp - src/TileOperand.cpp - src/TensorOperand.cpp - src/TensorTileSampler.cpp - - src/acl/AclKernelWriter.cpp - src/acl/AclScopedKernelWriter.cpp - src/acl/AclComponentArgument.cpp ) if(CKW_ENABLE_OPENCL) @@ -147,7 +135,7 @@ endif() target_include_directories(ckw PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include PRIVATE ${CMAKE_CURRENT_LIST_DIR} - ) +) #--------------------------------------------------------------------- # Validation tests @@ -172,16 +160,10 @@ if(CKW_BUILD_TESTING) endif() #--------------------------------------------------------------------- -# Examples - -function(add_ckw_example name) - add_executable(${name} ${ARGN}) - target_link_libraries(${name} PUBLIC ckw) -endfunction(add_ckw_example) +# Prototype -if(CKW_BUILD_EXAMPLES) - add_ckw_example(ckw_example_add_exp_store - examples/add_exp_store.cpp) +if(CKW_BUILD_PROTOTYPE) + add_subdirectory(prototype) endif() #--------------------------------------------------------------------- diff --git a/compute_kernel_writer/README.md b/compute_kernel_writer/README.md index 650eae2b48..8a24fe20ec 100644 --- a/compute_kernel_writer/README.md +++ b/compute_kernel_writer/README.md @@ -82,6 +82,5 @@ This project can be configured with the following build options. Enable options | CKW_ENABLE_OPENCL | Enable OpenCL code generation. | | CKW_ENABLE_ASSERTS | Enable assertions. Always enabled for Debug builds. | | CKW_BUILD_TESTING | Build the validation test suite. | -| CKW_BUILD_EXAMPLES | Build the examples. | | CKW_CCACHE | Use compiler cache for faster recompilation. | | CMAKE_TOOLCHAIN_FILE | When cross-compiling, set this variable to the path of the CMake toolchain file. | diff --git a/compute_kernel_writer/include/ckw/Error.h b/compute_kernel_writer/include/ckw/Error.h index 8c4853722b..996893823e 100644 --- a/compute_kernel_writer/include/ckw/Error.h +++ b/compute_kernel_writer/include/ckw/Error.h @@ -21,12 +21,11 @@ * 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 -#ifndef CKW_INCLUDE_CKW_ERROR_H -#define CKW_INCLUDE_CKW_ERROR_H - -#include <stdexcept> #include <string> +#include <stdexcept> namespace ckw { @@ -45,59 +44,16 @@ std::string create_error_msg(const std::string &file, const std::string &func, c * * @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); \ +#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) -/** If the condition is not met, throw an std::runtime_error with the specified message. - * - * @param[in] cond The condition that is expected to be true. - * @param[in] msg The error message when the condition is not met. - */ -#define CKW_ASSERT_MSG(cond, msg) \ - do \ - { \ - if(!(cond)) \ - { \ - throw ::std::runtime_error(msg); \ - } \ - } while(false) - -/** If the condition is not met, throw an std::runtime_error. - * - * @param[in] cond The condition that is expected to be true. - */ -#define CKW_ASSERT(cond) CKW_ASSERT_MSG(cond, #cond) - -/** If the precondition is met but the consequence is not met, throw an std::runtime_error. - * - * @param[in] precond The condition if is met requires the consequence must also be met. - * @param[in] cond The condition that is expected to be true if the precondition is true. - */ -#define CKW_ASSERT_IF(precond, cond) \ - CKW_ASSERT_MSG(!(precond) || ((precond) && (cond)), #precond " |-> " #cond) - -/** Mark the variables as unused. - * - * @param[in] ... Variables which are unused. - */ -#define CKW_UNUSED(...) ::ckw::ignore_unused(__VA_ARGS__) // NOLINT - -/** Mark the variables as unused. - * - * @param[in] ... Variables which are unused. - */ -template <typename... T> -inline void ignore_unused(T &&...) -{ -} - } // namespace ckw -#endif // CKW_INCLUDE_CKW_ERROR_H +#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H */ diff --git a/compute_kernel_writer/include/ckw/Types.h b/compute_kernel_writer/include/ckw/Types.h index 5516718e54..c9f80b65e0 100644 --- a/compute_kernel_writer/include/ckw/Types.h +++ b/compute_kernel_writer/include/ckw/Types.h @@ -21,120 +21,25 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - -#ifndef CKW_INCLUDE_CKW_TYPES_H -#define CKW_INCLUDE_CKW_TYPES_H - -#include <array> -#include <cstdint> +#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 = 0x00, - Fp32 = 0x11, - Fp16 = 0x12, - Int32 = 0x21, - Int16 = 0x22, - Int8 = 0x24, - Uint32 = 0x31, - Uint16 = 0x32, - Uint8 = 0x34, - Bool = 0x41 -}; - -enum class GpuTargetLanguage -{ Unknown, - OpenCL -}; - -/* Binary operations -*/ -enum class BinaryOp : int32_t -{ - // Elementwise - Add = 0x0000, // + - Sub = 0x0001, // - - Mul = 0x0002, // * - Div = 0x0003, // / - Mod = 0x0004, // % - // Relational - Equal = 0x1000, // == - Less = 0x1001, // < - LessEqual = 0x1002, // <= - Greater = 0x1003, // > - GreaterEqual = 0x1004, // >= - // Algebra - MatMul_Nt_Nt = 0x2000, // X - MatMul_Nt_T = 0x2001, // X - MatMul_T_Nt = 0x2002, // X - MatMul_T_T = 0x2003, // X - Dot = 0x2004, // . - // Logical - LogicalAnd = 0x3000, // && - LogicalOr = 0x3001, // || - LogicalNot = 0x3002 // ! -}; - -enum class AssignmentOp : int32_t -{ - // Unary - Increment = 0x0000, // += - Decrement = 0x0001, // -= -}; - -enum class ScalarUnaryFunction : int32_t -{ - Exp, -}; - -enum class TensorSamplerFormat : int32_t -{ - Unknown = 0, - C_WH_1 = 1, - C_W_H = 2 -}; - -enum class TensorSamplerAddressModeX : int32_t -{ - Unknown = 0, - None = 1, // The user guarantees that the X coordinate is always in-bound - OverlappingMin = 2 // (FIXED shapes only) Reduce the load/store length when x == 0 (MIN). The load length will be width % original length - // Leftover elements can be handled using overlapping. This involves processing some of the elements in the array twice. + Fp32, + Fp16, + Int32, + Int16, + Int8, + Uint32, + Uint16, + Uint8, + Bool }; - -enum class TensorSamplerAddressModeY : int32_t -{ - Unknown = 0, - None = 1, // The user guarantees that the Y coordinate is always in-bound - OverlappingMin = 2, // (FIXED shapes only) Reduce the load/store length when x == 0 (MIN). The load length will be width % original length - Skip = 3, // Skip the read/write - SkipMinEdgeOnly = 4, // Skip greater than or equal to max only. The user guarantees that the Y coordinate is always >= 0 - SkipMaxEdgeOnly = 5, // Skip less than 0 only - ClampToNearest = 6, // Clamp the coordinate to nearest edge (0 or max value allowed on Y) - ClampToMinEdgeOnly = 7, // Clamp the negative coordinate to 0 only. Therefore, we expect Y to be always < MAX - ClampToMaxEdgeOnly = 8, // Clamp the coordinate to the max value allowed on Y only. We expect Y to be always >= 0 - ClampToBorder = 9, // Clamp to border which always has 0 value - ClampToBorderMinEdgeOnly = 10, - ClampToBorderMaxEdgeOnly = 11 -}; - -enum class TensorSamplerAddressModeZ : int32_t -{ - Unknown = 0, - None = 1, // The user guarantees that the Y coordinate is always in-bound - Skip = 3, // Skip the read/write - SkipMinEdgeOnly = 4, // Skip greater than or equal to max only. The user guarantees that the Y coordinate is always >= 0 - SkipMaxEdgeOnly = 5, // Skip less than 0 only - ClampToNearest = 6, // Clamp the coordinate to nearest edge (0 or max value allowed on Y) - ClampToMinEdgeOnly = 7, // Clamp the negative coordinate to 0 only. Therefore, we expect Y to be always < MAX - ClampToMaxEdgeOnly = 8, // Clamp the coordinate to the max value allowed on Y only. We expect Y to be always >= 0 -}; - } // namespace ckw -#endif // CKW_INCLUDE_CKW_TYPES_H +#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TYPES_H */ diff --git a/compute_kernel_writer/prototype/CMakeLists.txt b/compute_kernel_writer/prototype/CMakeLists.txt new file mode 100644 index 0000000000..84436a95d6 --- /dev/null +++ b/compute_kernel_writer/prototype/CMakeLists.txt @@ -0,0 +1,72 @@ +# 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. + +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +#--------------------------------------------------------------------- +# Prototype + +add_library(ckw_prototype + src/TileInfo.cpp + src/TensorInfo.cpp + src/Kernel.cpp + src/KernelWriter.cpp + src/OperandBase.cpp + src/TileOperand.cpp + src/TensorOperand.cpp + src/TensorTileSampler.cpp +) + +target_compile_options(ckw_prototype + PUBLIC + ${CKW_CXX_FLAGS} + "$<$<CXX_COMPILER_ID:GNU>:${GNU_WARNINGS}>" + "$<$<CONFIG:Debug>:${CKW_ASSERTS_OPTS}>" + "$<$<BOOL:${CKW_ASSERTS}>:${CKW_ASSERTS_OPTS}>" + ${CMAKE_CXX_FLAGS} +) + +target_compile_definitions(ckw_prototype PUBLIC + $<$<CONFIG:Debug>:COMPUTE_KERNEL_WRITER_DEBUG_ENABLED> + $<$<CONFIG:Debug>:COMPUTE_KERNEL_WRITER_ASSERTS_ENABLED> + $<$<BOOL:${CKW_ASSERTS}>:COMPUTE_KERNEL_WRITER_ASSERTS_ENABLED> + $<$<BOOL:${CKW_ENABLE_OPENCL}>:COMPUTE_KERNEL_WRITER_OPENCL_ENABLED> +) + +target_include_directories(ckw_prototype + PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include + PRIVATE ${CMAKE_CURRENT_LIST_DIR} +) + +#--------------------------------------------------------------------- +# Examples + +add_library(ckw_prototype_examples_common + examples/common/ExampleKernelWriter.cpp + examples/common/ExampleScopedKernelWriter.cpp + examples/common/ExampleComponentArgument.cpp +) + +target_link_libraries(ckw_prototype_examples_common PUBLIC ckw_prototype) + +add_executable(ckw_prototype_examples_add_exp_store examples/add_exp_store.cpp) +target_link_libraries(ckw_prototype_examples_add_exp_store PUBLIC ckw_prototype_examples_common) diff --git a/compute_kernel_writer/examples/add_exp_store.cpp b/compute_kernel_writer/prototype/examples/add_exp_store.cpp index ab2f3e15fb..9ee21957f1 100644 --- a/compute_kernel_writer/examples/add_exp_store.cpp +++ b/compute_kernel_writer/prototype/examples/add_exp_store.cpp @@ -29,16 +29,16 @@ #include "ckw/TileOperand.h" #include "ckw/Types.h" -#include "acl/AclComponentArgument.h" -#include "acl/AclKernelWriter.h" -#include "acl/AclScopedKernelWriter.h" +#include "common/ExampleComponentArgument.h" +#include "common/ExampleKernelWriter.h" +#include "common/ExampleScopedKernelWriter.h" #include <iostream> #include <vector> using namespace ckw; -TensorTileSampler create_simple_sampler(AclScopedKernelWriter writer) +TensorTileSampler create_simple_sampler(ExampleScopedKernelWriter writer) { TensorTileSampler sampler; @@ -57,8 +57,8 @@ TensorTileSampler create_simple_sampler(AclScopedKernelWriter writer) sampler.x(gid_0); sampler.y(gid_1); - sampler.z(gid_2); - sampler.b(const_0); + sampler.z(const_0); + sampler.b(gid_2); sampler.width(n0); sampler.height(m0); @@ -71,7 +71,7 @@ TensorTileSampler create_simple_sampler(AclScopedKernelWriter writer) return sampler; } -void op_binary_elementwise(AclScopedKernelWriter writer, std::vector<AclComponentArgument *> operands) +void op_binary_elementwise(ExampleScopedKernelWriter writer, std::vector<ExampleComponentArgument *> operands) { auto lhs = operands.at(0); auto rhs = operands.at(1); @@ -113,7 +113,7 @@ void op_binary_elementwise(AclScopedKernelWriter writer, std::vector<AclComponen writer->op_binary_expression(dst_tile, lhs_tile, rhs_tile, BinaryOp::Add); } -void op_exp(AclScopedKernelWriter writer, std::vector<AclComponentArgument *> operands) +void op_exp(ExampleScopedKernelWriter writer, std::vector<ExampleComponentArgument *> operands) { auto src = operands.at(0); auto dst = operands.at(1); @@ -141,7 +141,7 @@ void op_exp(AclScopedKernelWriter writer, std::vector<AclComponentArgument *> op writer->op_scalar_function(dst_tile, src_tile, ScalarUnaryFunction::Exp); } -void op_store(AclScopedKernelWriter writer, std::vector<AclComponentArgument *> operands) +void op_store(ExampleScopedKernelWriter writer, std::vector<ExampleComponentArgument *> operands) { auto src = operands.at(0); auto dst = operands.at(1); @@ -156,19 +156,19 @@ void op_store(AclScopedKernelWriter writer, std::vector<AclComponentArgument *> int main() { Kernel kernel("example", GpuTargetLanguage::OpenCL); - AclKernelWriter root_writer(kernel); + ExampleKernelWriter root_writer(kernel); - AclScopedKernelWriter writer(&root_writer); + ExampleScopedKernelWriter writer(&root_writer); const TensorInfo src0_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 0); const TensorInfo src1_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 1); const TensorInfo dst_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 2); - AclComponentArgument src0(writer->create_tensor_argument("src0", src0_info)); - AclComponentArgument src1(writer->create_tensor_argument("src1", src1_info)); - AclComponentArgument dst(writer->create_tensor_argument("dst", dst_info)); + ExampleComponentArgument src0(writer->create_tensor_argument("src0", src0_info)); + ExampleComponentArgument src1(writer->create_tensor_argument("src1", src1_info)); + ExampleComponentArgument dst(writer->create_tensor_argument("dst", dst_info)); - AclComponentArgument ans; + ExampleComponentArgument ans; op_binary_elementwise(writer, { &src0, &src1, &ans }); op_exp(writer, { &ans, &ans }); diff --git a/compute_kernel_writer/src/acl/AclComponentArgument.cpp b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp index 5cb909021e..da5156ca8c 100644 --- a/compute_kernel_writer/src/acl/AclComponentArgument.cpp +++ b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp @@ -22,19 +22,19 @@ * SOFTWARE. */ -#include "acl/AclComponentArgument.h" +#include "ExampleComponentArgument.h" #include "ckw/Error.h" -AclComponentArgument::AclComponentArgument() +ExampleComponentArgument::ExampleComponentArgument() { } -AclComponentArgument::AclComponentArgument(ckw::TensorOperand &tensor) +ExampleComponentArgument::ExampleComponentArgument(ckw::TensorOperand &tensor) : _tensor(&tensor) { } -AclComponentArgument &AclComponentArgument::init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &tile_sampler) +ExampleComponentArgument &ExampleComponentArgument::init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &tile_sampler) { CKW_ASSERT(_tile == nullptr); @@ -44,52 +44,52 @@ AclComponentArgument &AclComponentArgument::init_virtual_tensor(ckw::TileOperand return *this; } -bool AclComponentArgument::has_tensor() const +bool ExampleComponentArgument::has_tensor() const { return _tensor != nullptr; } -ckw::TensorOperand &AclComponentArgument::tensor() +ckw::TensorOperand &ExampleComponentArgument::tensor() { CKW_ASSERT(_tensor != nullptr); return *_tensor; } -const ckw::TensorOperand &AclComponentArgument::tensor() const +const ckw::TensorOperand &ExampleComponentArgument::tensor() const { CKW_ASSERT(_tensor != nullptr); return *_tensor; } -bool AclComponentArgument::has_tile() const +bool ExampleComponentArgument::has_tile() const { return _tile != nullptr; } -ckw::TileOperand &AclComponentArgument::tile() +ckw::TileOperand &ExampleComponentArgument::tile() { CKW_ASSERT(_tile != nullptr); return *_tile; } -const ckw::TileOperand &AclComponentArgument::tile() const +const ckw::TileOperand &ExampleComponentArgument::tile() const { CKW_ASSERT(_tile != nullptr); return *_tile; } -ckw::TensorTileSampler &AclComponentArgument::tile_sampler() +ckw::TensorTileSampler &ExampleComponentArgument::tile_sampler() { CKW_ASSERT(_tile != nullptr); return _tile_sampler; } -const ckw::TensorTileSampler &AclComponentArgument::tile_sampler() const +const ckw::TensorTileSampler &ExampleComponentArgument::tile_sampler() const { CKW_ASSERT(_tile != nullptr); diff --git a/compute_kernel_writer/include/acl/AclComponentArgument.h b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h index 485b7a30bc..2de9042691 100644 --- a/compute_kernel_writer/include/acl/AclComponentArgument.h +++ b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_ACL_ACLCOMPONENTARGUMENT_H -#define CKW_INCLUDE_ACL_ACLCOMPONENTARGUMENT_H +#ifndef CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H +#define CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H #include "ckw/TensorTileSampler.h" @@ -34,27 +34,27 @@ class TileOperand; } // namespace ckw /** The argument of a dynamic fusion component which can be either user tensor or virtual tensor. */ -class AclComponentArgument +class ExampleComponentArgument { public: - /** Initialize a new instance of @ref AclComponentArgument class for empty virtual tensor. */ - AclComponentArgument(); + /** Initialize a new instance of @ref ExampleComponentArgument class for empty virtual tensor. */ + ExampleComponentArgument(); - /** Initialize a new instance of @ref AclComponentArgument class for user tensor. + /** Initialize a new instance of @ref ExampleComponentArgument class for user tensor. * * @param[in] tensor The user tensor. */ - explicit AclComponentArgument(ckw::TensorOperand &tensor); + explicit ExampleComponentArgument(ckw::TensorOperand &tensor); /** Set virtual tensor information (tile, sampler) for the argument. * * If the component is a user tensor, it can be treated as virtual tensor as well - * and won't be loaded again using @ref AclKernelWriter::op_load_once method. + * and won't be loaded again using @ref ExampleKernelWriter::op_load_once method. * * @param[in] tile The tile that has been loaded. * @param[in] sampler The tensor sampling information that has been used to load the tile. */ - AclComponentArgument &init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &sampler); + ExampleComponentArgument &init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &sampler); /** Get whether the argument is a user tensor. */ bool has_tensor() const; @@ -108,4 +108,4 @@ private: ckw::TensorTileSampler _tile_sampler{}; }; -#endif // CKW_INCLUDE_ACL_ACLCOMPONENTARGUMENT_H +#endif // CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H diff --git a/compute_kernel_writer/src/acl/AclKernelWriter.cpp b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp index a44e798c61..2c11ae36e5 100644 --- a/compute_kernel_writer/src/acl/AclKernelWriter.cpp +++ b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp @@ -22,17 +22,17 @@ * SOFTWARE. */ -#include "acl/AclKernelWriter.h" -#include "acl/AclComponentArgument.h" +#include "ExampleKernelWriter.h" +#include "ExampleComponentArgument.h" #include "ckw/Error.h" #include "ckw/TileInfo.h" -AclKernelWriter::AclKernelWriter(ckw::Kernel &kernel) +ExampleKernelWriter::ExampleKernelWriter(ckw::Kernel &kernel) : KernelWriter(kernel) { } -void AclKernelWriter::op_load_once(AclComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler) +void ExampleKernelWriter::op_load_once(ExampleComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler) { if(!tensor_or_tile->has_tile()) { diff --git a/compute_kernel_writer/include/acl/AclKernelWriter.h b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.h index 27b7add6ef..1528c3d933 100644 --- a/compute_kernel_writer/include/acl/AclKernelWriter.h +++ b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.h @@ -22,13 +22,13 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_ACL_ACLKERNELWRITER_H -#define CKW_INCLUDE_ACL_ACLKERNELWRITER_H +#ifndef CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLEKERNELWRITER_H +#define CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLEKERNELWRITER_H #include "ckw/KernelWriter.h" #include "ckw/TensorTileSampler.h" -class AclComponentArgument; +class ExampleComponentArgument; namespace ckw { @@ -36,21 +36,21 @@ class Kernel; } // namespace ckw /** Extended implementation of kernel writer for dynamic fusion. */ -class AclKernelWriter : public ckw::KernelWriter +class ExampleKernelWriter : public ckw::KernelWriter { public: - /** Initialize a new instance of @ref AclKernelWriter class. + /** Initialize a new instance of @ref ExampleKernelWriter class. * * @param[in] kernel The kernel to be generated. */ - explicit AclKernelWriter(ckw::Kernel &kernel); + explicit ExampleKernelWriter(ckw::Kernel &kernel); /** Load the user tensor to the tile in the same component argument if it hasn't been loaded. * * @param[in] tensor_or_tile The component argument that is either a user tensor or a virtual tensor. * @param[in] sampler The tensor sampling information to load the tile. */ - void op_load_once(AclComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler); + void op_load_once(ExampleComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler); }; -#endif // CKW_INCLUDE_ACL_ACLKERNELWRITER_H +#endif // CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLEKERNELWRITER_H diff --git a/compute_kernel_writer/src/acl/AclScopedKernelWriter.cpp b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp index 2a73d47592..7c44fa8749 100644 --- a/compute_kernel_writer/src/acl/AclScopedKernelWriter.cpp +++ b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp @@ -22,37 +22,37 @@ * SOFTWARE. */ -#include "acl/AclScopedKernelWriter.h" -#include "acl/AclKernelWriter.h" +#include "ExampleScopedKernelWriter.h" +#include "ExampleKernelWriter.h" -AclScopedKernelWriter::AclScopedKernelWriter(AclKernelWriter *writer) +ExampleScopedKernelWriter::ExampleScopedKernelWriter(ExampleKernelWriter *writer) : _writer(writer), _parent_id_space(writer->id_space()) { _writer->next_id_space(); } -AclScopedKernelWriter::AclScopedKernelWriter(const AclScopedKernelWriter &other) +ExampleScopedKernelWriter::ExampleScopedKernelWriter(const ExampleScopedKernelWriter &other) : _writer(other._writer), _parent_id_space(other._writer->id_space()) { _writer->next_id_space(); } -AclKernelWriter *AclScopedKernelWriter::operator->() +ExampleKernelWriter *ExampleScopedKernelWriter::operator->() { return _writer; } -const AclKernelWriter *AclScopedKernelWriter::operator->() const +const ExampleKernelWriter *ExampleScopedKernelWriter::operator->() const { return _writer; } -AclKernelWriter *AclScopedKernelWriter::writer() +ExampleKernelWriter *ExampleScopedKernelWriter::writer() { return _writer; } -const AclKernelWriter *AclScopedKernelWriter::writer() const +const ExampleKernelWriter *ExampleScopedKernelWriter::writer() const { return _writer; } diff --git a/compute_kernel_writer/include/acl/AclScopedKernelWriter.h b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.h index 6cb957bfb5..1aa0242c51 100644 --- a/compute_kernel_writer/include/acl/AclScopedKernelWriter.h +++ b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.h @@ -22,41 +22,41 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_ACL_ACLSCOPEDKERNELWRITER_H -#define CKW_INCLUDE_ACL_ACLSCOPEDKERNELWRITER_H +#ifndef CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLESCOPEDKERNELWRITER_H +#define CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLESCOPEDKERNELWRITER_H #include <cstdint> -class AclKernelWriter; +class ExampleKernelWriter; /** Helper to automatically manage kernel writer ID space. */ -class AclScopedKernelWriter +class ExampleScopedKernelWriter { public: - /** Initialize a new instance of @ref AclScopedKernelWriter class. */ - explicit AclScopedKernelWriter(AclKernelWriter *writer); + /** Initialize a new instance of @ref ExampleScopedKernelWriter class. */ + explicit ExampleScopedKernelWriter(ExampleKernelWriter *writer); /** Create a new scope from the specified scoped kernel writer. */ - AclScopedKernelWriter(const AclScopedKernelWriter &other); + ExampleScopedKernelWriter(const ExampleScopedKernelWriter &other); /** Assignment is disallowed. */ - AclScopedKernelWriter &operator=(const AclScopedKernelWriter &) = delete; + ExampleScopedKernelWriter &operator=(const ExampleScopedKernelWriter &) = delete; /** Access the underlying kernel writer. */ - AclKernelWriter *operator->(); + ExampleKernelWriter *operator->(); /** Access the underlying kernel writer. */ - const AclKernelWriter *operator->() const; + const ExampleKernelWriter *operator->() const; /** Get the kernel writer. */ - AclKernelWriter *writer(); + ExampleKernelWriter *writer(); /** Get the kernel writer. */ - const AclKernelWriter *writer() const; + const ExampleKernelWriter *writer() const; private: - AclKernelWriter *_writer; + ExampleKernelWriter *_writer; int32_t _parent_id_space; }; -#endif // CKW_INCLUDE_ACL_ACLSCOPEDKERNELWRITER_H +#endif // CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLESCOPEDKERNELWRITER_H diff --git a/compute_kernel_writer/prototype/include/ckw/Error.h b/compute_kernel_writer/prototype/include/ckw/Error.h new file mode 100644 index 0000000000..b18944eac5 --- /dev/null +++ b/compute_kernel_writer/prototype/include/ckw/Error.h @@ -0,0 +1,79 @@ +/* + * 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_PROTOTYPE_INCLUDE_CKW_ERROR_H +#define CKW_PROTOTYPE_INCLUDE_CKW_ERROR_H + +#include <stdexcept> +#include <string> + +namespace ckw +{ + +/** If the condition is not met, throw an std::runtime_error with the specified message. + * + * @param[in] cond The condition that is expected to be true. + * @param[in] msg The error message when the condition is not met. + */ +#define CKW_ASSERT_MSG(cond, msg) \ + do \ + { \ + if(!(cond)) \ + { \ + throw ::std::runtime_error(msg); \ + } \ + } while(false) + +/** If the condition is not met, throw an std::runtime_error. + * + * @param[in] cond The condition that is expected to be true. + */ +#define CKW_ASSERT(cond) CKW_ASSERT_MSG(cond, #cond) + +/** If the precondition is met but the consequence is not met, throw an std::runtime_error. + * + * @param[in] precond The condition if is met requires the consequence must also be met. + * @param[in] cond The condition that is expected to be true if the precondition is true. + */ +#define CKW_ASSERT_IF(precond, cond) \ + CKW_ASSERT_MSG(!(precond) || ((precond) && (cond)), #precond " |-> " #cond) + +/** Mark the variables as unused. + * + * @param[in] ... Variables which are unused. + */ +#define CKW_UNUSED(...) ::ckw::ignore_unused(__VA_ARGS__) // NOLINT + +/** Mark the variables as unused. + * + * @param[in] ... Variables which are unused. + */ +template <typename... T> +inline void ignore_unused(T &&...) +{ +} + +} // namespace ckw + +#endif // CKW_INCLUDE_CKW_ERROR_H diff --git a/compute_kernel_writer/include/ckw/Kernel.h b/compute_kernel_writer/prototype/include/ckw/Kernel.h index cbc7700c22..57a8a40341 100644 --- a/compute_kernel_writer/include/ckw/Kernel.h +++ b/compute_kernel_writer/prototype/include/ckw/Kernel.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_KERNEL_H -#define CKW_INCLUDE_CKW_KERNEL_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H +#define CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H #include "ckw/OperandBase.h" #include "ckw/Types.h" @@ -74,4 +74,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_KERNEL_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H diff --git a/compute_kernel_writer/include/ckw/KernelWriter.h b/compute_kernel_writer/prototype/include/ckw/KernelWriter.h index 5dce62a14c..a2778a9485 100644 --- a/compute_kernel_writer/include/ckw/KernelWriter.h +++ b/compute_kernel_writer/prototype/include/ckw/KernelWriter.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_KERNELWRITER_H -#define CKW_INCLUDE_CKW_KERNELWRITER_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_KERNELWRITER_H +#define CKW_PROTOTYPE_INCLUDE_CKW_KERNELWRITER_H #include "ckw/Kernel.h" #include "ckw/TensorInfo.h" @@ -214,4 +214,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_KERNELWRITER_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_KERNELWRITER_H diff --git a/compute_kernel_writer/include/ckw/OperandBase.h b/compute_kernel_writer/prototype/include/ckw/OperandBase.h index 0ea5030968..f4825e16a7 100644 --- a/compute_kernel_writer/include/ckw/OperandBase.h +++ b/compute_kernel_writer/prototype/include/ckw/OperandBase.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_OPERANDBASE_H -#define CKW_INCLUDE_CKW_OPERANDBASE_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_OPERANDBASE_H +#define CKW_PROTOTYPE_INCLUDE_CKW_OPERANDBASE_H #include "ckw/Types.h" #include <string> @@ -73,4 +73,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_OPERANDBASE_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_OPERANDBASE_H diff --git a/compute_kernel_writer/include/ckw/ScalarValue.h b/compute_kernel_writer/prototype/include/ckw/ScalarValue.h index cf017d435f..16c3f6d441 100644 --- a/compute_kernel_writer/include/ckw/ScalarValue.h +++ b/compute_kernel_writer/prototype/include/ckw/ScalarValue.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_SCALARVALUE_H -#define CKW_INCLUDE_CKW_SCALARVALUE_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_SCALARVALUE_H +#define CKW_PROTOTYPE_INCLUDE_CKW_SCALARVALUE_H #include "ckw/Error.h" @@ -134,4 +134,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_SCALARVALUE_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_SCALARVALUE_H diff --git a/compute_kernel_writer/prototype/include/ckw/TensorInfo.h b/compute_kernel_writer/prototype/include/ckw/TensorInfo.h new file mode 100644 index 0000000000..00bb60a444 --- /dev/null +++ b/compute_kernel_writer/prototype/include/ckw/TensorInfo.h @@ -0,0 +1,145 @@ +/* + * 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_PROTOTYPE_INCLUDE_CKW_TENSORINFO_H +#define CKW_PROTOTYPE_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 storage. The tensor storage represents the type of tensor memory object. + */ +enum class TensorStorage : uint32_t +{ + Unknown = 0x00000000, + BufferUint8Ptr = 0x01000000, + Texture2dReadOnly = 0x02000001, + Texture2dWriteOnly = 0x02000010, +}; + +/** 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 bound user tensor. 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 /* CKW_PROTOTYPE_INCLUDE_CKW_TENSORINFO_H */ diff --git a/compute_kernel_writer/include/ckw/TensorOperand.h b/compute_kernel_writer/prototype/include/ckw/TensorOperand.h index 130ab596fb..2fc5044d1c 100644 --- a/compute_kernel_writer/include/ckw/TensorOperand.h +++ b/compute_kernel_writer/prototype/include/ckw/TensorOperand.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_TENSOROPERAND_H -#define CKW_INCLUDE_CKW_TENSOROPERAND_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_TENSOROPERAND_H +#define CKW_PROTOTYPE_INCLUDE_CKW_TENSOROPERAND_H #include "ckw/OperandBase.h" #include "ckw/TensorInfo.h" @@ -178,4 +178,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_TENSOROPERAND_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSOROPERAND_H diff --git a/compute_kernel_writer/include/ckw/TensorTileSampler.h b/compute_kernel_writer/prototype/include/ckw/TensorTileSampler.h index 5ef7bca647..2ea65bce9e 100644 --- a/compute_kernel_writer/include/ckw/TensorTileSampler.h +++ b/compute_kernel_writer/prototype/include/ckw/TensorTileSampler.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_TENSORTILESAMPLER_H -#define CKW_INCLUDE_CKW_TENSORTILESAMPLER_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H +#define CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H #include "ckw/Types.h" #include <functional> @@ -160,4 +160,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_TENSORTILESAMPLER_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H diff --git a/compute_kernel_writer/prototype/include/ckw/TileInfo.h b/compute_kernel_writer/prototype/include/ckw/TileInfo.h new file mode 100644 index 0000000000..8fba8bb827 --- /dev/null +++ b/compute_kernel_writer/prototype/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 CKW_PROTOTYPE_INCLUDE_CKW_TILEINFO_H +#define CKW_PROTOTYPE_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. It is used to define the shape of the tile */ +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] h Tile height + * @param[in] w Tile width + */ + TileInfo(DataType dt, int32_t h, int32_t w); + /** 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/TileOperand.h b/compute_kernel_writer/prototype/include/ckw/TileOperand.h index 1eee18589f..c071707a45 100644 --- a/compute_kernel_writer/include/ckw/TileOperand.h +++ b/compute_kernel_writer/prototype/include/ckw/TileOperand.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_INCLUDE_CKW_TILEOPERAND_H -#define CKW_INCLUDE_CKW_TILEOPERAND_H +#ifndef CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H +#define CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H #include "ckw/Error.h" #include "ckw/OperandBase.h" @@ -107,4 +107,4 @@ private: } // namespace ckw -#endif // CKW_INCLUDE_CKW_TILEOPERAND_H +#endif // CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H diff --git a/compute_kernel_writer/prototype/include/ckw/Types.h b/compute_kernel_writer/prototype/include/ckw/Types.h new file mode 100644 index 0000000000..bb5d7ce077 --- /dev/null +++ b/compute_kernel_writer/prototype/include/ckw/Types.h @@ -0,0 +1,140 @@ +/* + * 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_PROTOTYPE_INCLUDE_CKW_TYPES_H +#define CKW_PROTOTYPE_INCLUDE_CKW_TYPES_H + +#include <array> +#include <cstdint> + +namespace ckw +{ + +/** Compute Kernel Writer data types. This data type is used by the code variables and tensor arguments. */ +enum class DataType +{ + Unknown = 0x00, + Fp32 = 0x11, + Fp16 = 0x12, + Int32 = 0x21, + Int16 = 0x22, + Int8 = 0x24, + Uint32 = 0x31, + Uint16 = 0x32, + Uint8 = 0x34, + Bool = 0x41 +}; + +enum class GpuTargetLanguage +{ + Unknown, + OpenCL +}; + +/* Binary operations +*/ +enum class BinaryOp : int32_t +{ + // Elementwise + Add = 0x0000, // + + Sub = 0x0001, // - + Mul = 0x0002, // * + Div = 0x0003, // / + Mod = 0x0004, // % + // Relational + Equal = 0x1000, // == + Less = 0x1001, // < + LessEqual = 0x1002, // <= + Greater = 0x1003, // > + GreaterEqual = 0x1004, // >= + // Algebra + MatMul_Nt_Nt = 0x2000, // X + MatMul_Nt_T = 0x2001, // X + MatMul_T_Nt = 0x2002, // X + MatMul_T_T = 0x2003, // X + Dot = 0x2004, // . + // Logical + LogicalAnd = 0x3000, // && + LogicalOr = 0x3001, // || + LogicalNot = 0x3002 // ! +}; + +enum class AssignmentOp : int32_t +{ + // Unary + Increment = 0x0000, // += + Decrement = 0x0001, // -= +}; + +enum class ScalarUnaryFunction : int32_t +{ + Exp, +}; + +enum class TensorSamplerFormat : int32_t +{ + Unknown = 0, + C_WH_1 = 1, + C_W_H = 2 +}; + +enum class TensorSamplerAddressModeX : int32_t +{ + Unknown = 0, + None = 1, // The user guarantees that the X coordinate is always in-bound + OverlappingMin = 2 // (FIXED shapes only) Reduce the load/store length when x == 0 (MIN). The load length will be width % original length + // Leftover elements can be handled using overlapping. This involves processing some of the elements in the array twice. +}; + +enum class TensorSamplerAddressModeY : int32_t +{ + Unknown = 0, + None = 1, // The user guarantees that the Y coordinate is always in-bound + OverlappingMin = 2, // (FIXED shapes only) Reduce the load/store length when x == 0 (MIN). The load length will be width % original length + Skip = 3, // Skip the read/write + SkipMinEdgeOnly = 4, // Skip greater than or equal to max only. The user guarantees that the Y coordinate is always >= 0 + SkipMaxEdgeOnly = 5, // Skip less than 0 only + ClampToNearest = 6, // Clamp the coordinate to nearest edge (0 or max value allowed on Y) + ClampToMinEdgeOnly = 7, // Clamp the negative coordinate to 0 only. Therefore, we expect Y to be always < MAX + ClampToMaxEdgeOnly = 8, // Clamp the coordinate to the max value allowed on Y only. We expect Y to be always >= 0 + ClampToBorder = 9, // Clamp to border which always has 0 value + ClampToBorderMinEdgeOnly = 10, + ClampToBorderMaxEdgeOnly = 11 +}; + +enum class TensorSamplerAddressModeZ : int32_t +{ + Unknown = 0, + None = 1, // The user guarantees that the Y coordinate is always in-bound + Skip = 3, // Skip the read/write + SkipMinEdgeOnly = 4, // Skip greater than or equal to max only. The user guarantees that the Y coordinate is always >= 0 + SkipMaxEdgeOnly = 5, // Skip less than 0 only + ClampToNearest = 6, // Clamp the coordinate to nearest edge (0 or max value allowed on Y) + ClampToMinEdgeOnly = 7, // Clamp the negative coordinate to 0 only. Therefore, we expect Y to be always < MAX + ClampToMaxEdgeOnly = 8, // Clamp the coordinate to the max value allowed on Y only. We expect Y to be always >= 0 +}; + +} // namespace ckw + +#endif // CKW_PROTOTYPE_INCLUDE_CKW_TYPES_H diff --git a/compute_kernel_writer/src/Kernel.cpp b/compute_kernel_writer/prototype/src/Kernel.cpp index bbf5c440a7..bbf5c440a7 100644 --- a/compute_kernel_writer/src/Kernel.cpp +++ b/compute_kernel_writer/prototype/src/Kernel.cpp diff --git a/compute_kernel_writer/src/KernelWriter.cpp b/compute_kernel_writer/prototype/src/KernelWriter.cpp index 5d79985e87..5d79985e87 100644 --- a/compute_kernel_writer/src/KernelWriter.cpp +++ b/compute_kernel_writer/prototype/src/KernelWriter.cpp diff --git a/compute_kernel_writer/src/OperandBase.cpp b/compute_kernel_writer/prototype/src/OperandBase.cpp index 59cf846cc7..59cf846cc7 100644 --- a/compute_kernel_writer/src/OperandBase.cpp +++ b/compute_kernel_writer/prototype/src/OperandBase.cpp diff --git a/compute_kernel_writer/src/Prototype.h b/compute_kernel_writer/prototype/src/Prototype.h index 45f1b3d464..b17481537f 100644 --- a/compute_kernel_writer/src/Prototype.h +++ b/compute_kernel_writer/prototype/src/Prototype.h @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef CKW_SRC_PROTOTYPE_H -#define CKW_SRC_PROTOTYPE_H +#ifndef CKW_PROTOTYPE_SRC_PROTOTYPE_H +#define CKW_PROTOTYPE_SRC_PROTOTYPE_H #include <vector> #include <map> @@ -3764,4 +3764,4 @@ inline int32_t adjust_step(TensorSamplerFormat tensor_format, int32_t step, cons } // namespace prototype } // namespace ckw -#endif // CKW_SRC_PROTOTYPE_H +#endif // CKW_PROTOTYPE_SRC_PROTOTYPE_H diff --git a/compute_kernel_writer/prototype/src/TensorInfo.cpp b/compute_kernel_writer/prototype/src/TensorInfo.cpp new file mode 100644 index 0000000000..561c126469 --- /dev/null +++ b/compute_kernel_writer/prototype/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/TensorOperand.cpp b/compute_kernel_writer/prototype/src/TensorOperand.cpp index 00ecc3824e..00ecc3824e 100644 --- a/compute_kernel_writer/src/TensorOperand.cpp +++ b/compute_kernel_writer/prototype/src/TensorOperand.cpp diff --git a/compute_kernel_writer/src/TensorTileSampler.cpp b/compute_kernel_writer/prototype/src/TensorTileSampler.cpp index 143d550dec..143d550dec 100644 --- a/compute_kernel_writer/src/TensorTileSampler.cpp +++ b/compute_kernel_writer/prototype/src/TensorTileSampler.cpp diff --git a/compute_kernel_writer/prototype/src/TileInfo.cpp b/compute_kernel_writer/prototype/src/TileInfo.cpp new file mode 100644 index 0000000000..7d8b2654ef --- /dev/null +++ b/compute_kernel_writer/prototype/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 h, int32_t w) + : _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/TileOperand.cpp b/compute_kernel_writer/prototype/src/TileOperand.cpp index 091947628d..091947628d 100644 --- a/compute_kernel_writer/src/TileOperand.cpp +++ b/compute_kernel_writer/prototype/src/TileOperand.cpp diff --git a/filelist.json b/filelist.json index a8f6ffc19c..2214e47459 100644 --- a/filelist.json +++ b/filelist.json @@ -2338,9 +2338,12 @@ "src/dynamic_fusion/sketch/gpu/template_writer/cl/ClTemplateStore.cpp", "src/dynamic_fusion/sketch/gpu/template_writer/cl/ClTemplateWriter.cpp", "src/dynamic_fusion/sketch/gpu/template_writer/GpuKernelVariableTable.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.cpp", + "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.cpp", "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp", "src/dynamic_fusion/runtime/gpu/cl/ckw_driver/GpuCkwKernelArgumentsHelpers.cpp" ] diff --git a/scripts/clang_tidy_rules.py b/scripts/clang_tidy_rules.py index 56b33f3922..11ca6c45f5 100755 --- a/scripts/clang_tidy_rules.py +++ b/scripts/clang_tidy_rules.py @@ -28,7 +28,7 @@ import re import sys def get_list_includes(): - return "compute_kernel_writer/include " \ + return "compute_kernel_writer/prototype/include " \ "src/cpu/kernels/assembly " \ "src/core/NEON/kernels/assembly " \ "src/core/NEON/kernels/convolution/winograd " \ diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.cpp new file mode 100644 index 0000000000..4b4c22fa1d --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.cpp @@ -0,0 +1,108 @@ +/* + * 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 "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h" +#include "ckw/Error.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +GpuCkwComponentArgument::GpuCkwComponentArgument() +{ +} + +GpuCkwComponentArgument::GpuCkwComponentArgument(ckw::TensorOperand &tensor) + : _tensor(&tensor) +{ +} + +GpuCkwComponentArgument &GpuCkwComponentArgument::init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &tile_sampler) +{ + CKW_ASSERT(_tile == nullptr); + + _tile = &tile; + _tile_sampler = tile_sampler; + + return *this; +} + +bool GpuCkwComponentArgument::has_tensor() const +{ + return _tensor != nullptr; +} + +ckw::TensorOperand &GpuCkwComponentArgument::tensor() +{ + CKW_ASSERT(_tensor != nullptr); + + return *_tensor; +} + +const ckw::TensorOperand &GpuCkwComponentArgument::tensor() const +{ + CKW_ASSERT(_tensor != nullptr); + + return *_tensor; +} + +bool GpuCkwComponentArgument::has_tile() const +{ + return _tile != nullptr; +} + +ckw::TileOperand &GpuCkwComponentArgument::tile() +{ + CKW_ASSERT(_tile != nullptr); + + return *_tile; +} + +const ckw::TileOperand &GpuCkwComponentArgument::tile() const +{ + CKW_ASSERT(_tile != nullptr); + + return *_tile; +} + +ckw::TensorTileSampler &GpuCkwComponentArgument::tile_sampler() +{ + CKW_ASSERT(_tile != nullptr); + + return _tile_sampler; +} + +const ckw::TensorTileSampler &GpuCkwComponentArgument::tile_sampler() const +{ + CKW_ASSERT(_tile != nullptr); + + return _tile_sampler; +} + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h new file mode 100644 index 0000000000..80f91389a0 --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h @@ -0,0 +1,122 @@ +/* + * 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 ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWCOMPONENTARGUMENT_H +#define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWCOMPONENTARGUMENT_H + +#include "ckw/TensorTileSampler.h" + +namespace ckw +{ +class TensorOperand; +class TileOperand; +} // namespace ckw + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +/** The argument of a dynamic fusion component which can be either user tensor or virtual tensor. */ +class GpuCkwComponentArgument +{ +public: + /** Initialize a new instance of @ref GpuCkwComponentArgument class for empty virtual tensor. */ + GpuCkwComponentArgument(); + + /** Initialize a new instance of @ref GpuCkwComponentArgument class for user tensor. + * + * @param[in] tensor The user tensor. + */ + explicit GpuCkwComponentArgument(ckw::TensorOperand &tensor); + + /** Set virtual tensor information (tile, sampler) for the argument. + * + * If the component is a user tensor, it can be treated as virtual tensor as well + * and won't be loaded again using @ref GpuCkwKernelWriter::op_load_once method. + * + * @param[in] tile The tile that has been loaded. + * @param[in] sampler The tensor sampling information that has been used to load the tile. + */ + GpuCkwComponentArgument &init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &sampler); + + /** Get whether the argument is a user tensor. */ + bool has_tensor() const; + + /** Get the tensor operand. + * + * If the tensor is not available, throw an error. + */ + ckw::TensorOperand &tensor(); + + /** Get the tensor operand. + * + * If the tensor is not available, throw an error. + */ + const ckw::TensorOperand &tensor() const; + + /** Get whether the argument contains a tile. + * + * The argument can be either a user tensor that has been loaded, + * or a virtual tensor (i.e. a tile with tensor sampling information). + */ + bool has_tile() const; + + /** Get the tile operand. + * + * If the tile is not available, throw an error. + */ + ckw::TileOperand &tile(); + + /** Get the tile operand. + * + * If the tile is not available, throw an error. + */ + const ckw::TileOperand &tile() const; + + /** Get the tensor sampling information for the tile. + * + * If the tile is not available, throw an error. + */ + ckw::TensorTileSampler &tile_sampler(); + + /** Get the tensor sampling information for the tile. + * + * If the tile is not available, throw an error. + */ + const ckw::TensorTileSampler &tile_sampler() const; + +private: + ckw::TensorOperand *_tensor{ nullptr }; + ckw::TileOperand *_tile{ nullptr }; + ckw::TensorTileSampler _tile_sampler{}; +}; + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute + +#endif // ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWCOMPONENTARGUMENT_H diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp index 7c8ec8777d..d5c03c60c5 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.cpp @@ -31,8 +31,8 @@ #include "src/common/utils/Log.h" #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h" -#include "acl/AclKernelWriter.h" -#include "acl/AclScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" using namespace ckw; namespace arm_compute @@ -55,10 +55,10 @@ std::string GpuCkwDriver::get_name() std::string GpuCkwDriver::get_code() { ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); - ckw::Kernel kernel(get_name().c_str(), GpuTargetLanguage::OpenCL); - AclKernelWriter root_writer(kernel); - AclScopedKernelWriter writer(&root_writer); - GpuCkwVariableTable vtable{}; + ckw::Kernel kernel(get_name().c_str(), GpuTargetLanguage::OpenCL); + GpuCkwKernelWriter root_writer(kernel); + GpuCkwScopedKernelWriter writer(&root_writer); + GpuCkwVariableTable vtable{}; // Global Kernel Writer Driver code diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.cpp new file mode 100644 index 0000000000..ca4f121566 --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.cpp @@ -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. + */ + +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h" +#include "ckw/Error.h" +#include "ckw/TileInfo.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +GpuCkwKernelWriter::GpuCkwKernelWriter(ckw::Kernel &kernel) + : KernelWriter(kernel) +{ +} + +void GpuCkwKernelWriter::op_load_once(GpuCkwComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler) +{ + if(!tensor_or_tile->has_tile()) + { + CKW_ASSERT(tensor_or_tile->has_tensor()); + + auto &tensor = tensor_or_tile->tensor(); + + const auto tile_name = tensor.name() + "_tile"; + auto &tile = declare_tile(tile_name.c_str(), ckw::TileInfo(tensor.data_type(), sampler.height(), sampler.width())); + + op_load(tile, tensor, sampler); + + tensor_or_tile->init_virtual_tensor(tile, sampler); + } +} + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h new file mode 100644 index 0000000000..b916e6b28b --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h @@ -0,0 +1,67 @@ +/* + * 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 ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWKERNELWRITER_H +#define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWKERNELWRITER_H + +#include "ckw/KernelWriter.h" +#include "ckw/TensorTileSampler.h" + +namespace ckw +{ +class Kernel; +} // namespace ckw + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +class GpuCkwComponentArgument; + +/** Extended implementation of kernel writer for dynamic fusion. */ +class GpuCkwKernelWriter : public ckw::KernelWriter +{ +public: + /** Initialize a new instance of @ref GpuCkwKernelWriter class. + * + * @param[in] kernel The kernel to be generated. + */ + explicit GpuCkwKernelWriter(ckw::Kernel &kernel); + + /** Load the user tensor to the tile in the same component argument if it hasn't been loaded. + * + * @param[in] tensor_or_tile The component argument that is either a user tensor or a virtual tensor. + * @param[in] sampler The tensor sampling information to load the tile. + */ + void op_load_once(GpuCkwComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler); +}; + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute + +#endif // ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWKERNELWRITER_H diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.cpp new file mode 100644 index 0000000000..043fda9e6f --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.cpp @@ -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. + */ + +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +GpuCkwScopedKernelWriter::GpuCkwScopedKernelWriter(GpuCkwKernelWriter *writer) + : _writer(writer), _parent_id_space(writer->id_space()) +{ + _writer->next_id_space(); +} + +GpuCkwScopedKernelWriter::GpuCkwScopedKernelWriter(const GpuCkwScopedKernelWriter &other) + : _writer(other._writer), _parent_id_space(other._writer->id_space()) +{ + _writer->next_id_space(); +} + +GpuCkwKernelWriter *GpuCkwScopedKernelWriter::operator->() +{ + return _writer; +} + +const GpuCkwKernelWriter *GpuCkwScopedKernelWriter::operator->() const +{ + return _writer; +} + +GpuCkwKernelWriter *GpuCkwScopedKernelWriter::writer() +{ + return _writer; +} + +const GpuCkwKernelWriter *GpuCkwScopedKernelWriter::writer() const +{ + return _writer; +} + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h new file mode 100644 index 0000000000..4d11b5e3e4 --- /dev/null +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h @@ -0,0 +1,73 @@ +/* + * 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 ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWSCOPEDKERNELWRITER_H +#define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWSCOPEDKERNELWRITER_H + +#include <cstdint> + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ + +class GpuCkwKernelWriter; + +/** Helper to automatically manage kernel writer ID space. */ +class GpuCkwScopedKernelWriter +{ +public: + /** Initialize a new instance of @ref GpuCkwScopedKernelWriter class. */ + explicit GpuCkwScopedKernelWriter(GpuCkwKernelWriter *writer); + + /** Create a new scope from the specified scoped kernel writer. */ + GpuCkwScopedKernelWriter(const GpuCkwScopedKernelWriter &other); + + /** Assignment is disallowed. */ + GpuCkwScopedKernelWriter &operator=(const GpuCkwScopedKernelWriter &) = delete; + + /** Access the underlying kernel writer. */ + GpuCkwKernelWriter *operator->(); + + /** Access the underlying kernel writer. */ + const GpuCkwKernelWriter *operator->() const; + + /** Get the kernel writer. */ + GpuCkwKernelWriter *writer(); + + /** Get the kernel writer. */ + const GpuCkwKernelWriter *writer() const; + +private: + GpuCkwKernelWriter *_writer; + int32_t _parent_id_space; +}; + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute + +#endif // ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWSCOPEDKERNELWRITER_H diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp index 85aed282d1..4475586db8 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.cpp @@ -23,8 +23,8 @@ */ #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h" -#include "acl/AclKernelWriter.h" -#include "acl/AclScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" #include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGroup.h" #include "src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/TypeConverter.h" #include <sstream> @@ -35,7 +35,7 @@ namespace experimental { namespace dynamic_fusion { -AclComponentArgument *GpuCkwVariableTable::declare_variable(const GpuKernelComponentGroup &comp_group, AclScopedKernelWriter &writer, const ITensorInfo *tensor, const std::string &alias) +GpuCkwComponentArgument *GpuCkwVariableTable::declare_variable(const GpuKernelComponentGroup &comp_group, GpuCkwScopedKernelWriter &writer, const ITensorInfo *tensor, const std::string &alias) { ARM_COMPUTE_ERROR_ON_MSG(!tensor->has_valid_id(), "Tensor info with valid id expected"); @@ -49,8 +49,8 @@ AclComponentArgument *GpuCkwVariableTable::declare_variable(const GpuKernelCompo if(comp_group.is_intermediate_tensor(tensor)) { // Create a virtual tensor variable - AclComponentArgument var; - auto &&inserted = _vars.emplace(tensor->id(), var); + GpuCkwComponentArgument var; + auto &&inserted = _vars.emplace(tensor->id(), var); return &(inserted.first->second); } else @@ -58,9 +58,9 @@ AclComponentArgument *GpuCkwVariableTable::declare_variable(const GpuKernelCompo // Create a user tensor variable std::stringstream ss; ss << alias << "_t" << abs(tensor->id()); - const auto uniq_name = ss.str(); - AclComponentArgument var{ writer->create_tensor_argument(uniq_name.c_str(), to_ckw(*tensor)) }; - auto &&inserted = _vars.emplace(tensor->id(), var); + const auto uniq_name = ss.str(); + GpuCkwComponentArgument var{ writer->create_tensor_argument(uniq_name.c_str(), to_ckw(*tensor)) }; + auto &&inserted = _vars.emplace(tensor->id(), var); return &(inserted.first->second); } } diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h index 170fda451b..1c9cb083ea 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h @@ -24,13 +24,11 @@ #ifndef ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWVARIABLETABLE #define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_GPUCKWVARIABLETABLE -#include "acl/AclComponentArgument.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h" #include "arm_compute/core/ITensorInfo.h" #include <map> -class AclScopedKernelWriter; - namespace arm_compute { namespace experimental @@ -38,6 +36,7 @@ namespace experimental namespace dynamic_fusion { class GpuKernelComponentGroup; +class GpuCkwScopedKernelWriter; /** A table of all the variables used in the kernel. * @@ -55,12 +54,12 @@ public: * @param[in] tensor Tensor info with which the new variable is associated * @param[in] alias Alias for the variable. Will be used as part of the variable name * - * @return AclComponentArgument* + * @return GpuCkwComponentArgument* */ - AclComponentArgument *declare_variable(const GpuKernelComponentGroup &comp_group, AclScopedKernelWriter &writer, const ITensorInfo *tensor, const std::string &alias = "unnamed"); + GpuCkwComponentArgument *declare_variable(const GpuKernelComponentGroup &comp_group, GpuCkwScopedKernelWriter &writer, const ITensorInfo *tensor, const std::string &alias = "unnamed"); private: - std::map<ITensorInfo::Id, AclComponentArgument> _vars{}; + std::map<ITensorInfo::Id, GpuCkwComponentArgument> _vars{}; }; } // namespace dynamic_fusion diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/IGpuCkwComponentDriver.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/IGpuCkwComponentDriver.h index 15402bc330..62255f1cf6 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/IGpuCkwComponentDriver.h +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/IGpuCkwComponentDriver.h @@ -28,8 +28,6 @@ #include "src/dynamic_fusion/sketch/ArgumentPack.h" #include "src/dynamic_fusion/sketch/gpu/components/Types.h" -class AclScopedKernelWriter; - namespace arm_compute { class ITensorInfo; @@ -40,6 +38,7 @@ namespace dynamic_fusion /** Forward declaration */ class GpuKernelComponentGroup; class GpuCkwVariableTable; +class GpuCkwScopedKernelWriter; /** An interface used by @ref GpuCkwDriver to write source code for a kernel component * @@ -90,7 +89,7 @@ public: * * @note @p writer can only be passed via value since the new scope is created in the copy constructor */ - virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, AclScopedKernelWriter writer) const = 0; + virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, GpuCkwScopedKernelWriter writer) const = 0; /** Get tensor arguments */ ArgumentPack<ITensorInfo> tensors() const { diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp index 9895bbeb77..cba1cfbe40 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.cpp @@ -23,8 +23,8 @@ */ #include "GpuCkwElementwiseBinary.h" -#include "acl/AclKernelWriter.h" -#include "acl/AclScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" #include "arm_compute/core/Error.h" #include "arm_compute/core/Validate.h" #include "ckw/TensorTileSampler.h" @@ -40,11 +40,13 @@ namespace arm_compute { namespace experimental { +namespace dynamic_fusion +{ namespace { /** Create a simple sampler from tile of dimension [m0, n0] */ -inline TensorTileSampler create_simple_sampler(AclScopedKernelWriter &writer, int32_t m0, int32_t n0) +inline TensorTileSampler create_simple_sampler(GpuCkwScopedKernelWriter &writer, int32_t m0, int32_t n0) { TensorTileSampler sampler; @@ -75,32 +77,31 @@ inline TensorTileSampler create_simple_sampler(AclScopedKernelWriter &writer, in } } // namespace -namespace dynamic_fusion -{ GpuCkwElementwiseBinary::GpuCkwElementwiseBinary(ComponentId id, const ArgumentPack<ITensorInfo> &tensors, const Attributes &attributes) : IGpuCkwComponentDriver{ id, tensors }, _lhs{}, _rhs{}, - _dst{}, - _attributes{ attributes } + _dst{} { + ARM_COMPUTE_UNUSED(attributes); + _lhs = this->tensors().get_const_tensor(TensorType::ACL_SRC_0); _rhs = this->tensors().get_const_tensor(TensorType::ACL_SRC_1); _dst = this->tensors().get_const_tensor(TensorType::ACL_DST_0); ARM_COMPUTE_ERROR_ON_NULLPTR(_lhs, _rhs, _dst); } -void GpuCkwElementwiseBinary::write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, AclScopedKernelWriter writer) const +void GpuCkwElementwiseBinary::write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, GpuCkwScopedKernelWriter writer) const { const auto root_window = comp_group.get_root_component()->ckw_component_driver()->get_window(); const unsigned int n0 = root_window.x().step(); const unsigned int m0 = root_window.y().step(); - AclComponentArgument *lhs = vtable.declare_variable(comp_group, writer, _lhs, "lhs"); - AclComponentArgument *rhs = vtable.declare_variable(comp_group, writer, _rhs, "rhs"); - AclComponentArgument *dst = vtable.declare_variable(comp_group, writer, _dst, "dst"); + GpuCkwComponentArgument *lhs = vtable.declare_variable(comp_group, writer, _lhs, "lhs"); + GpuCkwComponentArgument *rhs = vtable.declare_variable(comp_group, writer, _rhs, "rhs"); + GpuCkwComponentArgument *dst = vtable.declare_variable(comp_group, writer, _dst, "dst"); // Load the LHS and RHS tiles and prepare the tensor sampler. load_lhs_rhs_tiles_and_prepare_sampler(writer, lhs, rhs, m0, n0, create_simple_sampler); diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.h index 1a79754d1d..963b92baf9 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.h +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwElementwiseBinary.h @@ -53,14 +53,13 @@ public: /** Destructor */ ~GpuCkwElementwiseBinary() override = default; // Inherited methods overriden: - virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, AclScopedKernelWriter writer) const override; + virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, GpuCkwScopedKernelWriter writer) const override; Window get_window() const override; private: const ITensorInfo *_lhs; const ITensorInfo *_rhs; const ITensorInfo *_dst; - Attributes _attributes; }; } // namespace dynamic_fusion } // namespace experimental diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp index 1a1dfc135a..63555e6064 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.cpp @@ -24,8 +24,8 @@ #include "GpuCkwStore.h" #include "arm_compute/core/Error.h" -#include "compute_kernel_writer/include/acl/AclKernelWriter.h" -#include "compute_kernel_writer/include/acl/AclScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h" #include <string> @@ -41,7 +41,7 @@ GpuCkwStore::GpuCkwStore(ComponentId id, const ArgumentPack<ITensorInfo> &tensor _src = this->tensors().get_const_tensor(TensorType::ACL_SRC_0); _dst = this->tensors().get_const_tensor(TensorType::ACL_DST_0); } -void GpuCkwStore::write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, AclScopedKernelWriter writer) const +void GpuCkwStore::write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, GpuCkwScopedKernelWriter writer) const { auto src = vtable.declare_variable(comp_group, writer, _src, "src"); auto dst = vtable.declare_variable(comp_group, writer, _dst, "dst"); diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.h index 45cc43fe62..5728ff9f49 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.h +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/GpuCkwStore.h @@ -48,7 +48,7 @@ public: /** Destructor */ ~GpuCkwStore() override = default; // Inherited methods overriden: - virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, AclScopedKernelWriter writer) const override; + virtual void write_component_code(const ComponentGroup &comp_group, GpuCkwVariableTable &vtable, GpuCkwScopedKernelWriter writer) const override; private: const ITensorInfo *_src; diff --git a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/WriterHelper.h b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/WriterHelper.h index d94ebd5ce9..ca13329335 100644 --- a/src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/WriterHelper.h +++ b/src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/WriterHelper.h @@ -24,8 +24,8 @@ #ifndef ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_COMPONENTS_UTILS_WRITERHELPER #define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_COMPONENTS_UTILS_WRITERHELPER -#include "acl/AclComponentArgument.h" -#include "acl/AclScopedKernelWriter.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h" +#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" #include "ckw/TensorTileSampler.h" #include <functional> @@ -37,11 +37,11 @@ namespace experimental { namespace dynamic_fusion { -using SamplerCreator = std::function<TensorTileSampler(AclScopedKernelWriter &, int32_t /* m0 */, int32_t /* n0 */)>; +using SamplerCreator = std::function<TensorTileSampler(GpuCkwScopedKernelWriter &, int32_t /* m0 */, int32_t /* n0 */)>; /** Load lhs and rhs tiles of dimension [m0, n0] only when not loaded and prepare the sampler */ -inline void load_lhs_rhs_tiles_and_prepare_sampler(AclScopedKernelWriter &writer, AclComponentArgument *lhs, AclComponentArgument *rhs, int32_t m0, int32_t n0, SamplerCreator create_sampler) +inline void load_lhs_rhs_tiles_and_prepare_sampler(GpuCkwScopedKernelWriter &writer, GpuCkwComponentArgument *lhs, GpuCkwComponentArgument *rhs, int32_t m0, int32_t n0, SamplerCreator create_sampler) { if(!lhs->has_tile() && !rhs->has_tile()) { |