[Beignet] [PATCH 3/4 opencl 1.2] Add the clGetKernelArgInfo api and misc help functions
junyan.he at inbox.com
junyan.he at inbox.com
Sun Jun 8 23:39:00 PDT 2014
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/backend/program.cpp | 25 +++++++++++
backend/src/backend/program.h | 14 +++++++
backend/src/backend/program.hpp | 4 ++
backend/src/gbe_bin_interpreter.cpp | 1 +
src/cl_api.c | 27 ++++++++++++
src/cl_kernel.c | 83 +++++++++++++++++++++++++++++++++++++
src/cl_kernel.h | 6 +++
7 files changed, 160 insertions(+)
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 925f908..3cb755f 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -911,6 +911,29 @@ namespace gbe {
return kernel->getArgNum();
}
+ static void *kernelGetArgInfo(gbe_kernel genKernel, uint32_t argID, uint32_t value) {
+ if (genKernel == NULL) return NULL;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ ir::FunctionArgument::InfoFromLLVM* info = kernel->getArgInfo(argID);
+
+ switch (value) {
+ case GBE_GET_ARG_INFO_ADDRSPACE:
+ return (void*)((ulong)info->addrSpace);
+ case GBE_GET_ARG_INFO_TYPE:
+ return (void *)(info->typeName.c_str());
+ case GBE_GET_ARG_INFO_ACCESS:
+ return (void *)(info->accessQual.c_str());
+ case GBE_GET_ARG_INFO_TYPEQUAL:
+ return (void *)(info->typeQual.c_str());
+ case GBE_GET_ARG_INFO_NAME:
+ return (void *)(info->argName.c_str());
+ default:
+ assert(0);
+ }
+
+ return NULL;
+ }
+
static uint32_t kernelGetArgSize(gbe_kernel genKernel, uint32_t argID) {
if (genKernel == NULL) return 0u;
const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
@@ -1034,6 +1057,7 @@ GBE_EXPORT_SYMBOL gbe_kernel_get_name_cb *gbe_kernel_get_name = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_code_cb *gbe_kernel_get_code = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_code_size_cb *gbe_kernel_get_code_size = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_arg_num_cb *gbe_kernel_get_arg_num = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_arg_info_cb *gbe_kernel_get_arg_info = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_arg_size_cb *gbe_kernel_get_arg_size = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_arg_type_cb *gbe_kernel_get_arg_type = NULL;
GBE_EXPORT_SYMBOL gbe_kernel_get_arg_align_cb *gbe_kernel_get_arg_align = NULL;
@@ -1073,6 +1097,7 @@ namespace gbe
gbe_kernel_get_code = gbe::kernelGetCode;
gbe_kernel_get_code_size = gbe::kernelGetCodeSize;
gbe_kernel_get_arg_num = gbe::kernelGetArgNum;
+ gbe_kernel_get_arg_info = gbe::kernelGetArgInfo;
gbe_kernel_get_arg_size = gbe::kernelGetArgSize;
gbe_kernel_get_arg_type = gbe::kernelGetArgType;
gbe_kernel_get_arg_align = gbe::kernelGetArgAlign;
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index e23f4db..873e569 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -52,6 +52,16 @@ enum gbe_arg_type {
GBE_ARG_INVALID = 0xffffffff
};
+/*! Get argument info values */
+enum gbe_get_arg_info_value {
+ GBE_GET_ARG_INFO_ADDRSPACE = 0,
+ GBE_GET_ARG_INFO_ACCESS = 1,
+ GBE_GET_ARG_INFO_TYPE = 2,
+ GBE_GET_ARG_INFO_TYPEQUAL = 3,
+ GBE_GET_ARG_INFO_NAME = 4,
+ GBE_GET_ARG_INFO_INVALID = 0xffffffff
+};
+
/*! Constant buffer values (ie values to setup in the constant buffer) */
enum gbe_curbe_type {
GBE_CURBE_LOCAL_ID_X = 0,
@@ -191,6 +201,10 @@ extern gbe_kernel_get_code_size_cb *gbe_kernel_get_code_size;
typedef uint32_t (gbe_kernel_get_arg_num_cb)(gbe_kernel);
extern gbe_kernel_get_arg_num_cb *gbe_kernel_get_arg_num;
+/*! Get the argument info */
+typedef void* (gbe_kernel_get_arg_info_cb)(gbe_kernel, uint32_t argID, uint32_t value);
+extern gbe_kernel_get_arg_info_cb *gbe_kernel_get_arg_info;
+
/*! Get the size of the given argument */
typedef uint32_t (gbe_kernel_get_arg_size_cb)(gbe_kernel, uint32_t argID);
extern gbe_kernel_get_arg_size_cb *gbe_kernel_get_arg_size;
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 6bb1529..592f1fc 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -49,6 +49,7 @@ namespace gbe {
uint32_t size; //!< Size of the argument
uint32_t align; //!< addr alignment of the argument
uint32_t bufSize; //!< Contant buffer size
+ ir::FunctionArgument::InfoFromLLVM info;
};
/*! Stores the offset where to patch where to patch */
@@ -134,6 +135,9 @@ namespace gbe {
void setImageSet(ir::ImageSet * from) {
imageSet = from;
}
+
+ ir::FunctionArgument::InfoFromLLVM* getArgInfo(uint32_t id) const { return &args[id].info; }
+
/*! Set compile work group size */
void setCompileWorkGroupSize(const size_t wg_sz[3]) {
compileWgSize[0] = wg_sz[0];
diff --git a/backend/src/gbe_bin_interpreter.cpp b/backend/src/gbe_bin_interpreter.cpp
index bd160c3..c64b4be 100644
--- a/backend/src/gbe_bin_interpreter.cpp
+++ b/backend/src/gbe_bin_interpreter.cpp
@@ -40,6 +40,7 @@ struct BinInterpCallBackInitializer
gbe_kernel_get_code_size = gbe::kernelGetCodeSize;
gbe_kernel_get_code = gbe::kernelGetCode;
gbe_kernel_get_arg_num = gbe::kernelGetArgNum;
+ gbe_kernel_get_arg_info = gbe::kernelGetArgInfo;
gbe_kernel_get_curbe_size = gbe::kernelGetCurbeSize;
gbe_kernel_get_sampler_size = gbe::kernelGetSamplerSize;
gbe_kernel_get_compile_wg_size = gbe::kernelGetCompileWorkGroupSize;
diff --git a/src/cl_api.c b/src/cl_api.c
index 8598088..96f0b58 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1129,6 +1129,33 @@ error:
return err;
}
+cl_int clGetKernelArgInfo(cl_kernel kernel, cl_uint arg_index, cl_kernel_arg_info param_name,
+ size_t param_value_size, void *param_value, size_t *param_value_size_ret)
+{
+ cl_int err = CL_SUCCESS;
+ CHECK_KERNEL(kernel);
+
+ if (param_name != CL_KERNEL_ARG_ADDRESS_QUALIFIER
+ && param_name != CL_KERNEL_ARG_ACCESS_QUALIFIER
+ && param_name != CL_KERNEL_ARG_TYPE_NAME
+ && param_name != CL_KERNEL_ARG_TYPE_QUALIFIER
+ && param_name != CL_KERNEL_ARG_NAME) {
+ err = CL_INVALID_VALUE;
+ goto error;
+ }
+
+ if (arg_index >= kernel->arg_n) {
+ err = CL_INVALID_ARG_INDEX;
+ goto error;
+ }
+
+ err = cl_get_kernel_arg_info(kernel, arg_index, param_name, param_value_size,
+ param_value, param_value_size_ret);
+
+error:
+ return err;
+}
+
cl_int
clGetKernelInfo(cl_kernel kernel,
cl_kernel_info param_name,
diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index a45e281..09ed4da 100644
--- a/src/cl_kernel.c
+++ b/src/cl_kernel.c
@@ -208,6 +208,89 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
return CL_SUCCESS;
}
+LOCAL int
+cl_get_kernel_arg_info(cl_kernel k, cl_uint arg_index, cl_kernel_arg_info param_name,
+ size_t param_value_size, void *param_value, size_t *param_value_size_ret)
+{
+ assert(k != NULL);
+ void *ret_info = gbe_kernel_get_arg_info(k->opaque, arg_index,
+ param_name - CL_KERNEL_ARG_ADDRESS_QUALIFIER);
+ int str_len = 0;
+ cl_kernel_arg_type_qualifier type_qual = CL_KERNEL_ARG_TYPE_NONE;
+
+ switch (param_name) {
+ case CL_KERNEL_ARG_ADDRESS_QUALIFIER:
+ if (param_value_size < sizeof(cl_kernel_arg_address_qualifier))
+ return CL_INVALID_VALUE;
+ if (param_value_size_ret)
+ *param_value_size_ret = sizeof(cl_kernel_arg_address_qualifier);
+ if (!param_value) return CL_SUCCESS;
+ if ((ulong)ret_info == 0) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ADDRESS_PRIVATE;
+ } else if ((ulong)ret_info == 1) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ADDRESS_GLOBAL;
+ } else if ((ulong)ret_info == 2) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ADDRESS_CONSTANT;
+ } else if ((ulong)ret_info == 3) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ADDRESS_LOCAL;
+ } else {
+ /* If no address qualifier is specified, the default address qualifier
+ which is CL_KERNEL_ARG_ADDRESS_PRIVATE is returned. */
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ADDRESS_LOCAL;
+ }
+ return CL_SUCCESS;
+
+ case CL_KERNEL_ARG_ACCESS_QUALIFIER:
+ if (param_value_size < sizeof(cl_kernel_arg_access_qualifier))
+ return CL_INVALID_VALUE;
+ if (param_value_size_ret)
+ *param_value_size_ret = sizeof(cl_kernel_arg_access_qualifier);
+ if (!param_value) return CL_SUCCESS;
+ if (!strcmp((char*)ret_info, "write_only")) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ACCESS_WRITE_ONLY;
+ } else if (!strcmp((char*)ret_info, "read_only")) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ACCESS_READ_ONLY;
+ } else if (!strcmp((char*)ret_info, "read_write")) {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ACCESS_READ_WRITE;
+ } else {
+ *(cl_kernel_arg_address_qualifier *)param_value = CL_KERNEL_ARG_ACCESS_NONE;
+ }
+ return CL_SUCCESS;
+
+ case CL_KERNEL_ARG_TYPE_NAME:
+ case CL_KERNEL_ARG_NAME:
+ str_len = strlen(ret_info);
+ if (param_value_size < str_len + 1)
+ return CL_INVALID_VALUE;
+ if (param_value_size_ret)
+ *param_value_size_ret = str_len + 1;
+ if (!param_value) return CL_SUCCESS;
+ memcpy(param_value, ret_info, str_len);
+ ((char *)param_value)[str_len] = 0;
+ return CL_SUCCESS;
+
+ case CL_KERNEL_ARG_TYPE_QUALIFIER:
+ if (param_value_size < sizeof(cl_kernel_arg_type_qualifier))
+ return CL_INVALID_VALUE;
+ if (param_value_size_ret)
+ *param_value_size_ret = sizeof(cl_kernel_arg_type_qualifier);
+ if (!param_value) return CL_SUCCESS;
+ if (strstr((char*)ret_info, "const"))
+ type_qual = type_qual | CL_KERNEL_ARG_TYPE_CONST;
+ if (strstr((char*)ret_info, "volatile"))
+ type_qual = type_qual | CL_KERNEL_ARG_TYPE_VOLATILE;
+ if (strstr((char*)ret_info, "restrict"))
+ type_qual = type_qual | CL_KERNEL_ARG_TYPE_RESTRICT;
+ *(cl_kernel_arg_type_qualifier *)param_value = type_qual;
+ return CL_SUCCESS;
+
+ default:
+ assert(0);
+ }
+
+ return CL_SUCCESS;
+}
+
LOCAL uint32_t
cl_kernel_get_simd_width(cl_kernel k)
{
diff --git a/src/cl_kernel.h b/src/cl_kernel.h
index 8d0e566..09362b3 100644
--- a/src/cl_kernel.h
+++ b/src/cl_kernel.h
@@ -93,6 +93,12 @@ extern int cl_kernel_set_arg(cl_kernel,
size_t arg_size,
const void *arg_value);
+/* Get the argument information */
+extern int cl_get_kernel_arg_info(cl_kernel k, cl_uint arg_index,
+ cl_kernel_arg_info param_name,
+ size_t param_value_size, void *param_value,
+ size_t *param_value_size_ret);
+
/* Compute and check the work group size from the user provided local size */
extern cl_int
cl_kernel_work_group_sz(cl_kernel ker,
--
1.8.3.2
More information about the Beignet
mailing list