[Beignet] [PATCH 2/4] Modify clGetMemObjectInfo using cl_get_info_helper.
junyan.he at inbox.com
junyan.he at inbox.com
Mon Oct 10 07:20:08 UTC 2016
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/cl_api.c | 19 -------------
src/cl_api_mem.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/cl_mem.c | 72 +-----------------------------------------------
src/cl_mem.h | 3 +-
4 files changed, 85 insertions(+), 92 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index d21cc69..2560b71 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -498,25 +498,6 @@ error:
}
cl_int
-clGetMemObjectInfo(cl_mem memobj,
- cl_mem_info param_name,
- size_t param_value_size,
- void * param_value,
- size_t * 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
clGetImageInfo(cl_mem mem,
cl_image_info param_name,
size_t param_value_size,
diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c
index 054c37a..ae0fb9f 100644
--- a/src/cl_api_mem.c
+++ b/src/cl_api_mem.c
@@ -22,6 +22,89 @@
#include "cl_event.h"
#include "CL/cl.h"
+cl_int
+clGetMemObjectInfo(cl_mem memobj,
+ cl_mem_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret)
+{
+ const void *src_ptr = NULL;
+ size_t src_size = 0;
+
+ if (!CL_OBJECT_IS_MEM(memobj)) {
+ return CL_INVALID_MEM_OBJECT;
+ }
+
+ switch (param_name) {
+ case CL_MEM_TYPE: {
+ cl_mem_object_type type = cl_get_mem_object_type(memobj);
+ src_ptr = &type;
+ src_size = sizeof(cl_mem_object_type);
+ break;
+ }
+ case CL_MEM_FLAGS:
+ src_ptr = &memobj->flags;
+ src_size = sizeof(cl_mem_flags);
+ break;
+ case CL_MEM_SIZE:
+ src_ptr = &memobj->size;
+ src_size = sizeof(size_t);
+ break;
+ case CL_MEM_HOST_PTR: {
+ size_t ptr = 0;
+ if (memobj->type == CL_MEM_IMAGE_TYPE) {
+ ptr = (size_t)memobj->host_ptr;
+ } else {
+ struct _cl_mem_buffer *buf = (struct _cl_mem_buffer *)memobj;
+ ptr = (size_t)memobj->host_ptr + buf->sub_offset;
+ }
+ src_ptr = &ptr;
+ src_size = sizeof(size_t);
+ break;
+ }
+ case CL_MEM_MAP_COUNT:
+ src_ptr = &memobj->map_ref;
+ src_size = sizeof(cl_uint);
+ break;
+ case CL_MEM_REFERENCE_COUNT: {
+ cl_int ref = CL_OBJECT_GET_REF(memobj);
+ src_ptr = &ref;
+ src_size = sizeof(cl_int);
+ break;
+ }
+ case CL_MEM_CONTEXT:
+ src_ptr = &memobj->ctx;
+ src_size = sizeof(cl_context);
+ break;
+ case CL_MEM_ASSOCIATED_MEMOBJECT: {
+ cl_mem parent = NULL;
+ if (memobj->type == CL_MEM_SUBBUFFER_TYPE) {
+ struct _cl_mem_buffer *buf = (struct _cl_mem_buffer *)memobj;
+ parent = (cl_mem)(buf->parent);
+ }
+ src_ptr = &parent;
+ src_size = sizeof(cl_mem);
+ break;
+ }
+ case CL_MEM_OFFSET: {
+ size_t offset = 0;
+ if (memobj->type == CL_MEM_SUBBUFFER_TYPE) {
+ struct _cl_mem_buffer *buf = (struct _cl_mem_buffer *)memobj;
+ offset = buf->sub_offset;
+ }
+ src_ptr = &offset;
+ src_size = sizeof(size_t);
+ break;
+ }
+ default:
+ return CL_INVALID_VALUE;
+ }
+
+ return cl_get_info_helper(src_ptr, src_size,
+ param_value, param_value_size, param_value_size_ret);
+}
+
void *
clEnqueueMapBuffer(cl_command_queue command_queue,
cl_mem buffer,
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 333ffc9..2b91515 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -49,7 +49,7 @@
#define MAX_TILING_SIZE 128 * MB
-static cl_mem_object_type
+LOCAL cl_mem_object_type
cl_get_mem_object_type(cl_mem mem)
{
switch (mem->type) {
@@ -67,76 +67,6 @@ cl_get_mem_object_type(cl_mem mem)
}
}
-LOCAL cl_int
-cl_get_mem_object_info(cl_mem mem,
- cl_mem_info param_name,
- size_t param_value_size,
- void *param_value,
- size_t *param_value_size_ret)
-{
- switch(param_name)
- {
- FIELD_SIZE(MEM_TYPE, cl_mem_object_type);
- FIELD_SIZE(MEM_FLAGS, cl_mem_flags);
- FIELD_SIZE(MEM_SIZE, size_t);
- FIELD_SIZE(MEM_HOST_PTR, void *);
- 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;
- }
-
- switch(param_name)
- {
- case CL_MEM_TYPE:
- *((cl_mem_object_type *)param_value) = cl_get_mem_object_type(mem);
- break;
- case CL_MEM_FLAGS:
- *((cl_mem_flags *)param_value) = mem->flags;
- break;
- case CL_MEM_SIZE:
- *((size_t *)param_value) = mem->size;
- break;
- case CL_MEM_HOST_PTR:
- if(mem->type == CL_MEM_IMAGE_TYPE) {
- *((size_t *)param_value) = (size_t)mem->host_ptr;
- } else {
- struct _cl_mem_buffer* buf = (struct _cl_mem_buffer*)mem;
- *((size_t *)param_value) = (size_t)mem->host_ptr + buf->sub_offset;
- }
- break;
- case CL_MEM_MAP_COUNT:
- *((cl_uint *)param_value) = mem->map_ref;
- break;
- case CL_MEM_REFERENCE_COUNT:
- *((cl_uint *)param_value) = CL_OBJECT_GET_REF(mem);
- break;
- case CL_MEM_CONTEXT:
- *((cl_context *)param_value) = mem->ctx;
- break;
- case CL_MEM_ASSOCIATED_MEMOBJECT:
- if(mem->type != CL_MEM_SUBBUFFER_TYPE) {
- *((cl_mem *)param_value) = NULL;
- } else {
- struct _cl_mem_buffer* buf = (struct _cl_mem_buffer*)mem;
- *((cl_mem *)param_value) = (cl_mem)(buf->parent);
- }
- break;
- case CL_MEM_OFFSET:
- if(mem->type != CL_MEM_SUBBUFFER_TYPE) {
- *((size_t *)param_value) = 0;
- } else {
- struct _cl_mem_buffer* buf = (struct _cl_mem_buffer*)mem;
- *((size_t *)param_value) = buf->sub_offset;
- }
- break;
- }
-
- return CL_SUCCESS;
-}
#define IS_1D(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D || \
image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || \
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 82f30f6..4026028 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -197,8 +197,7 @@ cl_mem_buffer(cl_mem mem)
return (struct _cl_mem_buffer *)mem;
}
-/* Query information about a memory object */
-extern cl_int cl_get_mem_object_info(cl_mem, cl_mem_info, size_t, void *, size_t *);
+extern cl_mem_object_type cl_get_mem_object_type(cl_mem mem);
/* Query information about an image */
extern cl_int cl_get_image_info(cl_mem, cl_image_info, size_t, void *, size_t *);
--
2.7.4
More information about the Beignet
mailing list