Add GpuKernelArgumentBinding for runtime argument setting

* Add flexible runtime argument setting that accept argument bindings
exported from ckw.

* Introduce internal build flag ACL_INTERNAL_TEST_CKW_IN_DF. If set to
true, ckw will be tested in dynamic fusion validation tests. Otherwise
it will not be tested and the dynamic fusion will keep using
ClTemplateWriter instead.

* Fix CKW sampler for elementwise binary to deal with tile sizes > 1
in both dimensions

Resolves: COMPMID-6282
Partially resolves: COMPMID-6260

Signed-off-by: SiCong Li <sicong.li@arm.com>
Change-Id: I0ab225a4484eb2119643d900a4e72806558626ee
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9917
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Jakub Sujak <jakub.sujak@arm.com>
Reviewed-by: Anitha Raj <Anitha.Raj@arm.com>
Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
diff --git a/src/dynamic_fusion/runtime/gpu/cl/ClKernelRuntime.cpp b/src/dynamic_fusion/runtime/gpu/cl/ClKernelRuntime.cpp
index 6a57482..92ca855 100644
--- a/src/dynamic_fusion/runtime/gpu/cl/ClKernelRuntime.cpp
+++ b/src/dynamic_fusion/runtime/gpu/cl/ClKernelRuntime.cpp
@@ -24,6 +24,9 @@
 #include "ClKernelRuntime.h"
 #include "arm_compute/core/CL/ICLTensor.h"
 #include "src/core/CL/CLUtils.h"
+#ifdef ACL_INTERNAL_TEST_CKW_IN_DF
+#include "src/dynamic_fusion/runtime/gpu/cl/ckw_driver/GpuCkwKernelArgumentsHelpers.h"
+#endif // ACL_INTERNAL_TEST_CKW_IN_DF
 #include "src/dynamic_fusion/sketch/gpu/GpuKernelSourceCode.h"
 #include "src/gpu/cl/ClKernelLibrary.h"
 
@@ -57,6 +60,8 @@
     _arguments = code.arguments();
 }
 
+#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
+
 inline void ClKernelRuntime::add_tensor_argument(unsigned int &idx, const GpuKernelArgumentInfo &arg, const ICLTensor *tensor, const Window &arg_slice, std::vector<cl::Image2D> &cl_images)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
@@ -163,21 +168,65 @@
     }
 }
 
+#else // ACL_INTERNAL_TEST_CKW_IN_DF
+inline void ClKernelRuntime::add_kernel_argument(unsigned int &idx, const GpuKernelArgumentBinding &arg, const ICLTensor *tensor, std::vector<cl::Image2D> &cl_images)
+{
+    switch(arg.type())
+    {
+        case GpuKernelArgumentBinding::Type::TensorStorage:
+        {
+            switch(arg.tensor_storage_type())
+            {
+                case TensorStorageType::ClBufferUint8Ptr:
+                {
+                    cl_add_buffer_argument(_kernel, idx, tensor->cl_buffer());
+                    break;
+                }
+                case TensorStorageType::ClImage2dReadOnly:
+                {
+                    cl::Image2D tensor_image2d = create_image2d_from_tensor(tensor, CLImage2DType::ReadOnly);
+                    cl_images.push_back(tensor_image2d);
+                    cl_add_texture_argument(_kernel, idx, tensor_image2d);
+                    break;
+                }
+                case TensorStorageType::ClImage2dWriteOnly:
+                {
+                    cl::Image2D tensor_image2d = create_image2d_from_tensor(tensor, CLImage2DType::WriteOnly);
+                    cl_images.push_back(tensor_image2d);
+                    cl_add_texture_argument(_kernel, idx, tensor_image2d);
+                    break;
+                }
+                default:
+                {
+                    ARM_COMPUTE_ERROR("Do not accept other TensorStorageType");
+                    break;
+                }
+            }
+            break;
+        }
+        case GpuKernelArgumentBinding::Type::TensorComponent:
+        {
+            cl_add_tensor_component_argument(_kernel, idx, tensor, arg.tensor_component_type());
+            break;
+        }
+        default:
+        {
+            ARM_COMPUTE_ERROR("Do not accept other types of kernel arguments");
+            break;
+        }
+    }
+}
+
+#endif // ACL_INTERNAL_TEST_CKW_IN_DF
 void ClKernelRuntime::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
 {
     ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
     ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
 
     Window slice = window.first_slice_window_3D();
-    // Don't slice matrix along the z dimension if matrix has just 2 dimensions and matrix A more than 2
-    // This scenario can happen when the matrix multiplication is used to perform a convolution operation
-    Window slice_fixed_z = slice;
-    slice_fixed_z.set(Window::DimX, Window::Dimension(0, 1, 1));
-    slice_fixed_z.set(Window::DimY, Window::Dimension(0, 1, 1));
 
     /// NOTE: Parameters extracted from old kernels. So far they seem to be constant
     /// but we may need to make them into another configuration passed from GpuWorkloadSourceCode if needed in the future
-    constexpr bool slide_along_dimz     = true;
     constexpr bool skip_sliding_window  = false;
     constexpr bool use_dummy_work_items = false;
 
@@ -185,24 +234,28 @@
     do
     {
         // Set kernel arguments
-        Window arg_slice = slice;
         // CLImages created from tensor arguments. Need to be retained until enqueue
         std::vector<cl::Image2D> cl_images;
+#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
         for(auto id_arg : _arguments)
         {
             const auto arg    = id_arg.second;
             auto       tensor = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(id_arg.first));
             ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
             ARM_COMPUTE_ERROR_ON_NULLPTR(tensor->info());
-            if(!slide_along_dimz)
-            {
-                // The stride_z for matrix must be zero if we do not slice
-                ARM_COMPUTE_ERROR_ON(tensor->info()->strides_in_bytes()[3] != 0);
-                arg_slice = slice_fixed_z;
-            }
-            add_tensor_argument(idx, *arg.kernel_argument_info(), tensor, arg_slice, cl_images);
+            add_tensor_argument(idx, *arg.kernel_argument_info(), tensor, slice, cl_images);
         }
 
+#else  // ACL_INTERNAL_TEST_CKW_IN_DF
+        for(const auto &arg : _arguments)
+        {
+            auto tensor = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(arg.id()));
+            ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
+            ARM_COMPUTE_ERROR_ON_NULLPTR(tensor->info());
+            add_kernel_argument(idx, arg, tensor, cl_images);
+        }
+#endif // ACL_INTERNAL_TEST_CKW_IN_DF
+
         // Dispatch kernel
         enqueue(queue, *this, slice, lws_hint(), use_dummy_work_items);
     }