[Beignet] [PATCH] Improve the clGetMemObjectInfo API, add more info option
junyan.he at inbox.com
junyan.he at inbox.com
Fri Jul 12 02:52:59 PDT 2013
From: Junyan He <junyan.he at linux.intel.com>
Improve the clGetMemObjectInfo API, add more info option.
CL_MEM_ASSOCIATED_MEMOBJECT and CL_MEM_OFFSET need create
subbuffer implememted firstly.
Attach the test case in get_cl_info.cpp
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
src/cl_api.c | 15 +++++++----
src/cl_mem.c | 21 +++++++++++----
utests/get_cl_info.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 95 insertions(+), 10 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index 03cad52..146c010 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -559,11 +559,16 @@ clGetMemObjectInfo(cl_mem memobj,
void * param_value,
size_t * param_value_size_ret)
{
- return cl_get_mem_object_info(memobj,
- param_name,
- param_value_size,
- param_value,
- param_value_size_ret);
+ cl_int err = CL_SUCCESS;
+ CHECK_MEM(memobj);
+
+ err = cl_get_mem_object_info(memobj,
+ param_name,
+ param_value_size,
+ param_value,
+ param_value_size_ret);
+error:
+ return err;
}
cl_int
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 5af16e0..e694395 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -58,6 +58,8 @@ cl_get_mem_object_info(cl_mem mem,
FIELD_SIZE(MEM_MAP_COUNT, cl_uint);
FIELD_SIZE(MEM_REFERENCE_COUNT, cl_uint);
FIELD_SIZE(MEM_CONTEXT, cl_context);
+ FIELD_SIZE(MEM_ASSOCIATED_MEMOBJECT, cl_mem);
+ FIELD_SIZE(MEM_OFFSET, size_t);
default:
return CL_INVALID_VALUE;
}
@@ -71,18 +73,25 @@ cl_get_mem_object_info(cl_mem mem,
*((cl_mem_flags *)param_value) = mem->flags;
break;
case CL_MEM_SIZE:
- *((size_t *)param_value) = cl_buffer_get_size(mem->bo);
+ *((size_t *)param_value) = mem->size;
break;
case CL_MEM_HOST_PTR:
- NOT_IMPLEMENTED;
+ *((size_t *)param_value) = (size_t)mem->host_ptr;
break;
case CL_MEM_MAP_COUNT:
- NOT_IMPLEMENTED;
+ *((cl_uint *)param_value) = mem->map_ref;
break;
case CL_MEM_REFERENCE_COUNT:
- NOT_IMPLEMENTED;
+ *((cl_uint *)param_value) = mem->ref_n;
break;
case CL_MEM_CONTEXT:
+ *((cl_context *)param_value) = mem->ctx;
+ break;
+ // TODO: Need to implement sub buffer first.
+ case CL_MEM_ASSOCIATED_MEMOBJECT:
+ NOT_IMPLEMENTED;
+ break;
+ case CL_MEM_OFFSET:
NOT_IMPLEMENTED;
break;
}
@@ -257,11 +266,13 @@ cl_mem_new(cl_context ctx,
if (mem == NULL || err != CL_SUCCESS)
goto error;
+ mem->type = CL_MEM_OBJECT_BUFFER;
+
/* Copy the data if required */
if (flags & CL_MEM_COPY_HOST_PTR || flags & CL_MEM_USE_HOST_PTR)
cl_buffer_subdata(mem->bo, 0, sz, data);
- if (flags & CL_MEM_USE_HOST_PTR)
+ if (flags & CL_MEM_USE_HOST_PTR || flags & CL_MEM_COPY_HOST_PTR)
mem->host_ptr = data;
exit:
diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp
index fff8123..ec02ce9 100644
--- a/utests/get_cl_info.cpp
+++ b/utests/get_cl_info.cpp
@@ -30,6 +30,7 @@ struct Info_Result {
}
bool check_result (void) {
+ //printf("The refer is %d, we get result is %d\n", refer, ret);
if (ret != refer && refer != (T)NO_STANDARD_REF)
return false;
@@ -537,3 +538,71 @@ void get_image_info(void)
}
MAKE_UTEST_FROM_FUNCTION(get_image_info);
+
+/* ***************************************************** *
+ * clGetMemObjectInfo *
+ * ***************************************************** */
+#define CALL_GETMEMINFO_AND_RET(TYPE) CALL_INFO_AND_RET(TYPE, clGetMemObjectInfo, (buf[0]))
+
+void get_mem_info(void)
+{
+ map<cl_mem_info, void *> maps;
+ int expect_ref;
+
+ OCL_CREATE_BUFFER(buf[0], 0, 64, NULL);
+ void * map_ptr = clEnqueueMapBuffer(queue, buf[0], 1, CL_MAP_READ, 0, 64, 0, NULL, NULL, NULL);
+
+ expect_ref = CL_MEM_OBJECT_BUFFER;
+ maps.insert(make_pair(CL_MEM_TYPE,
+ (void *)(new Info_Result<cl_mem_object_type>((cl_mem_object_type)expect_ref))));
+ expect_ref = 0;
+ maps.insert(make_pair(CL_MEM_FLAGS,
+ (void *)(new Info_Result<cl_mem_flags>(expect_ref))));
+ expect_ref = 64;
+ maps.insert(make_pair(CL_MEM_SIZE,
+ (void *)(new Info_Result<size_t>(((size_t)expect_ref)))));
+ expect_ref = 0;
+ maps.insert(make_pair(CL_MEM_HOST_PTR,
+ (void *)(new Info_Result<size_t>(((size_t)expect_ref)))));
+ expect_ref = 1;
+ maps.insert(make_pair(CL_MEM_MAP_COUNT,
+ (void *)(new Info_Result<cl_uint>(((cl_uint)expect_ref)))));
+ expect_ref = 1;
+ maps.insert(make_pair(CL_MEM_REFERENCE_COUNT,
+ (void *)(new Info_Result<cl_uint>(((cl_uint)expect_ref)))));
+ maps.insert(make_pair(CL_MEM_CONTEXT,
+ (void *)(new Info_Result<cl_context>(((cl_context)ctx)))));
+
+ std::for_each(maps.begin(), maps.end(), [](pair<cl_mem_info, void *> x) {
+ switch (x.first) {
+ case CL_MEM_TYPE:
+ CALL_GETMEMINFO_AND_RET(cl_mem_object_type);
+ break;
+ case CL_MEM_FLAGS:
+ CALL_GETMEMINFO_AND_RET(cl_mem_flags);
+ break;
+ case CL_MEM_SIZE:
+ CALL_GETMEMINFO_AND_RET(size_t);
+ break;
+ case CL_MEM_HOST_PTR:
+ CALL_GETMEMINFO_AND_RET(size_t);
+ break;
+ case CL_MEM_MAP_COUNT:
+ CALL_GETMEMINFO_AND_RET(cl_uint);
+ break;
+ case CL_MEM_REFERENCE_COUNT:
+ CALL_GETMEMINFO_AND_RET(cl_uint);
+ break;
+ case CL_MEM_CONTEXT:
+ CALL_GETMEMINFO_AND_RET(cl_context);
+ break;
+
+ default:
+ break;
+ }
+ });
+
+ clEnqueueUnmapMemObject(queue, buf[0], map_ptr, 0, NULL, NULL);
+}
+
+MAKE_UTEST_FROM_FUNCTION(get_mem_info);
--
1.7.9.5
More information about the Beignet
mailing list