aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunes Bayir <gunes.bayir@arm.com>2023-07-27 22:50:22 +0100
committerGunes Bayir <gunes.bayir@arm.com>2023-08-02 18:56:12 +0000
commite98413e405015dec7e90946cc1e0c7b9921b0be3 (patch)
treeb2d55286cf134e418040b47c2efdfd1f441d385f
parent366514d54fd43321f440ebddc49fda28d40b8e49 (diff)
downloadComputeLibrary-e98413e405015dec7e90946cc1e0c7b9921b0be3.tar.gz
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>
-rw-r--r--compute_kernel_writer/src/cl/CLHelpers.cpp86
-rw-r--r--compute_kernel_writer/src/cl/CLHelpers.h23
2 files changed, 103 insertions, 6 deletions
diff --git a/compute_kernel_writer/src/cl/CLHelpers.cpp b/compute_kernel_writer/src/cl/CLHelpers.cpp
index af8a8a07ac..08108e383f 100644
--- a/compute_kernel_writer/src/cl/CLHelpers.cpp
+++ b/compute_kernel_writer/src/cl/CLHelpers.cpp
@@ -42,7 +42,7 @@ std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len)
{
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 @@ std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len)
res += "bool";
break;
default:
- COMPUTE_KERNEL_WRITER_ERROR_ON_MSG("Unsupported datatype");
+ CKW_THROW_MSG("Unsupported datatype");
return "";
}
@@ -89,7 +89,7 @@ std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len)
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 @@ std::string cl_get_variable_storagetype_as_string(TensorStorageType storage)
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 d0ca488617..669424088e 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 @@ std::string cl_get_variable_datatype_as_string(DataType dt, int32_t len);
*
* @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 @@ int32_t width_to_cl_vector_size(int32_t width);
* @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 */