summaryrefslogtreecommitdiff
path: root/src/cl_api_mem.c
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2016-12-27 18:45:22 +0800
committerYang Rong <rong.r.yang@intel.com>2016-12-28 17:36:18 +0800
commit64b8b046f2f844d292a692e788201acecb586359 (patch)
tree371bad1642b5fb6a829fd69ec3d867f763b6911b /src/cl_api_mem.c
parent7ae1517cfc373847f168ffb3e41b635861af19c7 (diff)
Improve event execute function.
Modify the event exec function, make it as the uniformal entry for all event command execution. This will help the timestamp record and profiling feature a lot. V2: 1. Set event init state to bigger than CL_QUEUED. Event state should be set to CL_QUEUED exactly when it is to be queued. Profiling feature make this requirement clearer. We need to record the timestamp exactly when it it to be queued. So we need to add a additional state beyond CL_QUEUED. 2. Fix cl_event_update_timestamp_gen bugi, the CL_SUMITTED time may be less. GPU may record the timestamp of CL_RUNNING before CPU record timestamp of CL_SUMITTED. It is a async process and it is hard for us to control. According to SPEC, we need to record timestamp after some state is done. We can just now set CL_SUMITTED to CL_RUNNING timestamp if the CL_SUBMITTED timestamp is the bigger one. Signed-off-by: Junyan He <junyan.he@intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'src/cl_api_mem.c')
-rw-r--r--src/cl_api_mem.c190
1 files changed, 74 insertions, 116 deletions
diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c
index de186841..09f9a141 100644
--- a/src/cl_api_mem.c
+++ b/src/cl_api_mem.c
@@ -107,7 +107,7 @@ clGetMemObjectInfo(cl_mem memobj,
} else if (memobj->type == CL_MEM_IMAGE_TYPE) {
parent = memobj;
} else if (memobj->type == CL_MEM_BUFFER1D_IMAGE_TYPE) {
- struct _cl_mem_buffer1d_image* image_buffer = (struct _cl_mem_buffer1d_image*)memobj;
+ struct _cl_mem_buffer1d_image *image_buffer = (struct _cl_mem_buffer1d_image *)memobj;
parent = image_buffer->descbuffer;
} else
parent = NULL;
@@ -309,31 +309,21 @@ clEnqueueMapBuffer(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- ptr = data->ptr;
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
- err = cl_enqueue_handle(data, CL_SUBMITTED); // Submit to get the address.
+ err = cl_event_exec(e, CL_SUBMITTED, CL_TRUE); // Submit to get the address.
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
- e->status = CL_SUBMITTED;
- ptr = data->ptr;
- assert(ptr);
-
cl_command_queue_enqueue_event(command_queue, e);
}
+ ptr = data->ptr;
+ assert(ptr);
err = cl_mem_record_map_mem(buffer, ptr, &mem_ptr, offset, size, NULL, NULL);
assert(err == CL_SUCCESS);
} while (0);
@@ -403,16 +393,15 @@ clEnqueueUnmapMemObject(cl_command_queue command_queue,
data->ptr = mapped_ptr;
if (e_status == CL_COMPLETE) { // No need to wait
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE;
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else { // May need to wait some event to complete.
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -507,16 +496,15 @@ clEnqueueReadBuffer(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -611,16 +599,15 @@ clEnqueueWriteBuffer(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -761,16 +748,15 @@ clEnqueueReadBufferRect(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -913,16 +899,15 @@ clEnqueueWriteBufferRect(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -1029,13 +1014,11 @@ clEnqueueCopyBuffer(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -1224,12 +1207,10 @@ clEnqueueCopyBufferRect(cl_command_queue command_queue,
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
} else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
+ err = cl_event_exec(e, CL_SUBMITTED, CL_FALSE);
if (err != CL_SUCCESS) {
break;
}
-
- e->status = CL_SUBMITTED;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -1324,13 +1305,11 @@ clEnqueueFillBuffer(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -1413,13 +1392,11 @@ clEnqueueMigrateMemObjects(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -1598,31 +1575,22 @@ clEnqueueMapImage(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- ptr = data->ptr;
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
- err = cl_enqueue_handle(data, CL_SUBMITTED); // Submit to get the address.
+ err = cl_event_exec(e, CL_SUBMITTED, CL_TRUE); // Submit to get the address.
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
- e->status = CL_SUBMITTED;
- ptr = data->ptr;
- assert(ptr);
-
cl_command_queue_enqueue_event(command_queue, e);
}
+ ptr = data->ptr;
+ assert(ptr);
+
/* Store and write back map info. */
if (mem->flags & CL_MEM_USE_HOST_PTR) {
if (image_slice_pitch)
@@ -1797,16 +1765,15 @@ clEnqueueReadImage(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -1950,16 +1917,15 @@ clEnqueueWriteImage(cl_command_queue command_queue,
if (e_status == CL_COMPLETE) {
// Sync mode, no need to queue event.
- err = cl_enqueue_handle(data, CL_COMPLETE);
+ err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
if (err != CL_SUCCESS) {
- assert(err < 0);
- e->status = err;
break;
}
-
- e->status = CL_COMPLETE; // Just set the status, no notify. No one depend on us now.
- cl_event_update_timestamp(e, CL_QUEUED, CL_COMPLETE);
} else {
+ err = cl_event_exec(e, CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
+ }
cl_command_queue_enqueue_event(command_queue, e);
}
} while (0);
@@ -2093,13 +2059,11 @@ clEnqueueCopyImage(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -2206,13 +2170,11 @@ clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -2320,13 +2282,11 @@ clEnqueueCopyBufferToImage(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);
@@ -2432,13 +2392,11 @@ clEnqueueFillImage(cl_command_queue command_queue,
if (e_status < CL_COMPLETE) { // Error happend, cancel.
err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
break;
- } else if (e_status == CL_COMPLETE) {
- err = cl_enqueue_handle(&e->exec_data, CL_SUBMITTED);
- if (err != CL_SUCCESS) {
- break;
- }
+ }
- e->status = CL_SUBMITTED;
+ err = cl_event_exec(e, e_status == CL_COMPLETE ? CL_SUBMITTED : CL_QUEUED, CL_FALSE);
+ if (err != CL_SUCCESS) {
+ break;
}
cl_command_queue_enqueue_event(command_queue, e);