Add helpers methods to CLHelpers in CKW

This patch adds some helper methods to perform
     - scalar and vector data type to string conversion
     - decompose a vector length to a superposition of OpenCL vector lengths

Partially Resolves: COMPMID-5791

Signed-off-by: Gunes Bayir <gunes.bayir@arm.com>
Change-Id: I14495773a6bb57bd3c3565a0d6e44b891159a948
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9995
Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
diff --git a/compute_kernel_writer/src/cl/CLHelpers.cpp b/compute_kernel_writer/src/cl/CLHelpers.cpp
index af8a8a0..08108e3 100644
--- a/compute_kernel_writer/src/cl/CLHelpers.cpp
+++ b/compute_kernel_writer/src/cl/CLHelpers.cpp
@@ -42,7 +42,7 @@
 {
     if(cl_validate_vector_length(len) == false)
     {
-        COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported vector length");
+        CKW_THROW_MSG("Unsupported vector length");
         return "";
     }
 
@@ -77,7 +77,7 @@
             res += "bool";
             break;
         default:
-            COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported datatype");
+            CKW_THROW_MSG("Unsupported datatype");
             return "";
     }
 
@@ -89,7 +89,7 @@
     return res;
 }
 
-int32_t width_to_cl_vector_size(int32_t width)
+int32_t cl_round_up_to_nearest_valid_vector_width(int32_t width)
 {
     switch(width)
     {
@@ -136,10 +136,88 @@
             res += "__write_only image2d_t";
             break;
         default:
-            COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported storage type");
+            CKW_THROW_MSG("Unsupported storage type");
     }
 
     return res;
 }
 
+std::string cl_data_type_rounded_up_to_valid_vector_width(DataType dt, int32_t width)
+{
+    std::string data_type;
+    const int32_t     w = cl_round_up_to_nearest_valid_vector_width(width);
+    data_type += cl_get_variable_datatype_as_string(dt, 1);
+    if(w != 1)
+    {
+        data_type += std::to_string(w);
+    }
+    return data_type;
+}
+
+std::vector<int32_t> cl_decompose_vector_width(int32_t vector_width)
+{
+    std::vector<int32_t> x;
+
+    switch(vector_width)
+    {
+        case 0:
+            break;
+        case 1:
+        case 2:
+        case 3:
+        case 4:
+        case 8:
+        case 16:
+            x.push_back(vector_width);
+            break;
+        case 5:
+            x.push_back(4);
+            x.push_back(1);
+            break;
+        case 6:
+            x.push_back(4);
+            x.push_back(2);
+            break;
+        case 7:
+            x.push_back(4);
+            x.push_back(3);
+            break;
+        case 9:
+            x.push_back(8);
+            x.push_back(1);
+            break;
+        case 10:
+            x.push_back(8);
+            x.push_back(2);
+            break;
+        case 11:
+            x.push_back(8);
+            x.push_back(3);
+            break;
+        case 12:
+            x.push_back(8);
+            x.push_back(4);
+            break;
+        case 13:
+            x.push_back(8);
+            x.push_back(4);
+            x.push_back(1);
+            break;
+        case 14:
+            x.push_back(8);
+            x.push_back(4);
+            x.push_back(2);
+            break;
+        case 15:
+            x.push_back(8);
+            x.push_back(4);
+            x.push_back(3);
+            break;
+
+        default:
+            CKW_THROW_MSG("Vector width is too large");
+    }
+    return x;
+}
+
 } // namespace ckw
diff --git a/compute_kernel_writer/src/cl/CLHelpers.h b/compute_kernel_writer/src/cl/CLHelpers.h
index d0ca488..6694240 100644
--- a/compute_kernel_writer/src/cl/CLHelpers.h
+++ b/compute_kernel_writer/src/cl/CLHelpers.h
@@ -26,6 +26,7 @@
 
 #include <cstdint>
 #include <string>
+#include <vector>
 
 /** OpenCL specific helper functions */
 namespace ckw
@@ -57,7 +58,7 @@
  *
  * @return the OpenCL vector size
 */
-int32_t width_to_cl_vector_size(int32_t width);
+int32_t cl_round_up_to_nearest_valid_vector_width(int32_t width);
 
 /** Helper function to return the OpenCL storage type as a string from a @ref TensorStorage
  *
@@ -66,6 +67,24 @@
  * @return the OpenCL storage type as a string
  */
 std::string cl_get_variable_storagetype_as_string(TensorStorageType storage);
+
+/** Helper function to decompose a vector width into a summation of valid OpenCL vector widths.
+ *
+ * @param[in] vector_width Vector width to be decomposed
+ *
+ * @return a vector of OpenCL vector widths
+ */
+std::vector<int32_t> cl_decompose_vector_width(int32_t vector_width);
+
+/** Helper function to get OpenCL data type from the data type enum and width
+ *  It'll round up the given vector width to the nearest valid OpenCL vector width.
+ *
+ *  @param[in] dt    data type enum
+ *  @param[in] width vector width
+ *
+ * @return a string representation of the data type
+ */
+std::string cl_data_type_rounded_up_to_valid_vector_width(DataType dt, int32_t width);
 } // namespace ckw
 
-#endif /* COMPUTE_KERNEL_WRITER_SRC_CL_CLHELPERS_H */
+#endif /* CKW_SRC_CL_CLHELPERS_H */