summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYan Wang <yan.wang@linux.intel.com>2017-06-12 17:08:12 +0800
committerYang Rong <rong.r.yang@intel.com>2017-06-13 18:36:20 +0800
commit78e9c99349264b3e6635d1c9ef0a5f83b72286c3 (patch)
treecc6bb861dc50924fcc75bde00a43346e448b562b
parent0c624f57c44cfb1cd26f54e414e2033b9c8db817 (diff)
Add cl_mem_record_map_mem_for_kernel() for record map adress for TILE_Y image by kernel copying.
Signed-off-by: Yan Wang <yan.wang@linux.intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r--src/cl_mem.c109
-rw-r--r--src/cl_mem.h5
2 files changed, 88 insertions, 26 deletions
diff --git a/src/cl_mem.c b/src/cl_mem.c
index a8543c9e..3f41fd80 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -2650,38 +2650,17 @@ error:
goto exit;
}
-LOCAL cl_int
-cl_mem_record_map_mem(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
- size_t size, const size_t *origin, const size_t *region)
+static cl_int
+get_mapped_address(cl_mem mem)
{
- // TODO: Need to add MT safe logic.
-
cl_int slot = -1;
- int err = CL_SUCCESS;
- size_t sub_offset = 0;
-
- if(mem->type == CL_MEM_SUBBUFFER_TYPE) {
- struct _cl_mem_buffer* buffer = (struct _cl_mem_buffer*)mem;
- sub_offset = buffer->sub_offset;
- }
-
- ptr = (char*)ptr + offset + sub_offset;
- if(mem->flags & CL_MEM_USE_HOST_PTR) {
- assert(mem->host_ptr);
- //only calc ptr here, will do memcpy in enqueue
- *mem_ptr = (char *)mem->host_ptr + offset + sub_offset;
- } else {
- *mem_ptr = ptr;
- }
- /* Record the mapped address. */
if (!mem->mapped_ptr_sz) {
mem->mapped_ptr_sz = 16;
mem->mapped_ptr = (cl_mapped_ptr *)malloc(
sizeof(cl_mapped_ptr) * mem->mapped_ptr_sz);
if (!mem->mapped_ptr) {
cl_mem_unmap_auto(mem);
- err = CL_OUT_OF_HOST_MEMORY;
- goto error;
+ return slot;
}
memset(mem->mapped_ptr, 0, mem->mapped_ptr_sz * sizeof(cl_mapped_ptr));
slot = 0;
@@ -2698,8 +2677,7 @@ cl_mem_record_map_mem(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
sizeof(cl_mapped_ptr) * mem->mapped_ptr_sz * 2);
if (!new_ptr) {
cl_mem_unmap_auto(mem);
- err = CL_OUT_OF_HOST_MEMORY;
- goto error;
+ return slot;
}
memset(new_ptr, 0, 2 * mem->mapped_ptr_sz * sizeof(cl_mapped_ptr));
memcpy(new_ptr, mem->mapped_ptr,
@@ -2710,7 +2688,86 @@ cl_mem_record_map_mem(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
mem->mapped_ptr = new_ptr;
}
}
+
assert(slot != -1);
+ return slot;
+}
+
+LOCAL cl_int
+cl_mem_record_map_mem_for_kernel(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
+ size_t size, const size_t *origin, const size_t *region,
+ cl_mem tmp_ker_buf, uint8_t write_map)
+{
+ // TODO: Need to add MT safe logic.
+
+ cl_int slot = -1;
+ int err = CL_SUCCESS;
+ size_t sub_offset = 0;
+
+ //ptr = (char*)ptr + offset + sub_offset;
+ if(mem->flags & CL_MEM_USE_HOST_PTR) {
+ assert(mem->host_ptr);
+ //only calc ptr here, will do memcpy in enqueue
+ *mem_ptr = (char*)ptr + offset + sub_offset;
+ } else {
+ *mem_ptr = ptr;
+ }
+ /* Record the mapped address. */
+ slot = get_mapped_address(mem);
+ if (slot == -1) {
+ err = CL_OUT_OF_HOST_MEMORY;
+ goto error;
+ }
+ mem->mapped_ptr[slot].ptr = *mem_ptr;
+ mem->mapped_ptr[slot].v_ptr = ptr;
+ mem->mapped_ptr[slot].size = size;
+ mem->mapped_ptr[slot].ker_write_map = write_map;
+ mem->mapped_ptr[slot].tmp_ker_buf = tmp_ker_buf;
+ if(origin) {
+ assert(region);
+ mem->mapped_ptr[slot].origin[0] = origin[0];
+ mem->mapped_ptr[slot].origin[1] = origin[1];
+ mem->mapped_ptr[slot].origin[2] = origin[2];
+ mem->mapped_ptr[slot].region[0] = region[0];
+ mem->mapped_ptr[slot].region[1] = region[1];
+ mem->mapped_ptr[slot].region[2] = region[2];
+ }
+ mem->map_ref++;
+error:
+ if (err != CL_SUCCESS)
+ *mem_ptr = NULL;
+ return err;
+}
+
+LOCAL cl_int
+cl_mem_record_map_mem(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
+ size_t size, const size_t *origin, const size_t *region)
+{
+ // TODO: Need to add MT safe logic.
+
+ cl_int slot = -1;
+ int err = CL_SUCCESS;
+ size_t sub_offset = 0;
+
+ if(mem->type == CL_MEM_SUBBUFFER_TYPE) {
+ struct _cl_mem_buffer* buffer = (struct _cl_mem_buffer*)mem;
+ sub_offset = buffer->sub_offset;
+ }
+
+ ptr = (char*)ptr + offset + sub_offset;
+ if(mem->flags & CL_MEM_USE_HOST_PTR) {
+ assert(mem->host_ptr);
+ //only calc ptr here, will do memcpy in enqueue
+ *mem_ptr = (char *)mem->host_ptr + offset + sub_offset;
+ } else {
+ *mem_ptr = ptr;
+ }
+ /* Record the mapped address. */
+ slot = get_mapped_address(mem);
+ if (slot == -1) {
+ err = CL_OUT_OF_HOST_MEMORY;
+ goto error;
+ }
mem->mapped_ptr[slot].ptr = *mem_ptr;
mem->mapped_ptr[slot].v_ptr = ptr;
mem->mapped_ptr[slot].size = size;
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 0b33c317..ce1294dd 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -61,6 +61,8 @@ typedef struct _cl_mapped_ptr {
size_t size;
size_t origin[3]; /* mapped origin */
size_t region[3]; /* mapped region */
+ cl_mem tmp_ker_buf; /* this object is tmp buffer for OCL kernel copying */
+ uint8_t ker_write_map; /* this flag is used to indicate CL_MAP_WRITE for OCL kernel copying */
}cl_mapped_ptr;
typedef struct _cl_mem_dstr_cb {
@@ -368,6 +370,9 @@ extern cl_mem cl_mem_new_image_from_fd(cl_context ctx,
extern cl_int cl_mem_record_map_mem(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
size_t size, const size_t *origin, const size_t *region);
+extern cl_int cl_mem_record_map_mem_for_kernel(cl_mem mem, void *ptr, void **mem_ptr, size_t offset,
+ size_t size, const size_t *origin, const size_t *region, cl_mem tmp_ker_buf, uint8_t write_map);
+
extern cl_int cl_mem_set_destructor_callback(cl_mem memobj,
void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data);
#endif /* __CL_MEM_H__ */