diff options
author | Junyan He <junyan.he@intel.com> | 2016-04-27 10:20:09 +0800 |
---|---|---|
committer | Junyan He <junyan.he@intel.com> | 2016-04-27 10:20:09 +0800 |
commit | d038a5ce8a61606fb6092c5e84885165b7e33fbc (patch) | |
tree | a78e5cacee30e4128ced388aded4ef99a8e49ed4 | |
parent | 3b538c2a6896bc404451383b992b956058ee0d4d (diff) |
add
-rw-r--r-- | libclapi/cl_enqueue.c | 21 | ||||
-rw-r--r-- | libclapi/cl_internals.h | 3 | ||||
-rw-r--r-- | libclapi/cl_kernel.c | 40 | ||||
-rw-r--r-- | libclapi/cl_mem.c | 27 |
4 files changed, 52 insertions, 39 deletions
diff --git a/libclapi/cl_enqueue.c b/libclapi/cl_enqueue.c index 2cffa30c..bbfa5c79 100644 --- a/libclapi/cl_enqueue.c +++ b/libclapi/cl_enqueue.c @@ -147,7 +147,7 @@ static void *worker_thread_function(void *Arg) /* We execute it without lock. */ worker->in_exec = CL_TRUE; - pthread_mutex_unlock(&worker->mutex); + CL_MUTEX_UNLOCK(&worker->mutex); assert(is_ready != 0); if (is_ready < 0) // Error happend, just cancel. @@ -283,8 +283,19 @@ LOCAL cl_int cl_enqueue_queue_work_item(cl_command_queue queue, cl_command_queue return ret; } +/* This function will be called to set a newly created event, we do not protect the event. */ +LOCAL void cl_enqueue_set_work_item_event(cl_command_queue_work_item it, cl_event event) +{ + assert(it->event == NULL); + assert(event); + + cl_retain_event(event); + assert(cl_event_get_status(event) == CL_QUEUED); + event->status = it->status; +} + LOCAL cl_command_queue_work_item cl_enqueue_create_work_item(cl_command_queue queue, - cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event event) + cl_uint num_events_in_wait_list, const cl_event *event_wait_list) { cl_command_queue_work_item it; int i; @@ -315,12 +326,6 @@ LOCAL cl_command_queue_work_item cl_enqueue_create_work_item(cl_command_queue qu it->depend_event_num = num_events_in_wait_list; } - if (event) { - cl_retain_event(event); - it->event = event; - assert(cl_event_get_status(event) == CL_QUEUED); - } - it->status = CL_QUEUED; it->queued = CL_FALSE; return it; diff --git a/libclapi/cl_internals.h b/libclapi/cl_internals.h index fa6942b8..2f651183 100644 --- a/libclapi/cl_internals.h +++ b/libclapi/cl_internals.h @@ -493,7 +493,8 @@ extern cl_int cl_enqueue_submit_work_item(cl_command_queue queue, cl_command_que extern cl_int cl_enqueue_run_work_item(cl_command_queue queue, cl_command_queue_work_item item); extern cl_int cl_enqueue_complete_work_item(cl_command_queue queue, cl_command_queue_work_item item); extern cl_command_queue_work_item cl_enqueue_create_work_item(cl_command_queue queue, - cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event event); + cl_uint num_events_in_wait_list, const cl_event *event_wait_list); +extern void cl_enqueue_set_work_item_event(cl_command_queue_work_item it, cl_event event); extern void cl_enqueue_destroy_work_item(cl_command_queue queue, cl_command_queue_work_item item); extern cl_int cl_command_queue_worker_init(cl_command_queue queue); extern void cl_command_queue_worker_destroy(cl_command_queue queue); diff --git a/libclapi/cl_kernel.c b/libclapi/cl_kernel.c index b0853536..46b93fb8 100644 --- a/libclapi/cl_kernel.c +++ b/libclapi/cl_kernel.c @@ -776,19 +776,6 @@ static cl_int cl_command_queue_ND_range(cl_command_queue queue, cl_kernel kernel cl_command_queue_work_item it = NULL; cl_int err = CL_SUCCESS; uint32_t i; - cl_int ret_status; - - if (event_ret) { - event = cl_create_event(queue->ctx, queue, CL_FALSE, num_events_in_wait_list, event_wait_list, &err); - if (event == NULL) - goto error; - } - - it = cl_enqueue_create_work_item(queue, num_events_in_wait_list, event_wait_list, event); - if (it == NULL) { - err = CL_OUT_OF_HOST_MEMORY; - goto error; - } CL_MUTEX_LOCK(&kernel->lock); for (i = 0; i < kernel->arg_num; ++i) @@ -799,26 +786,27 @@ static cl_int cl_command_queue_ND_range(cl_command_queue queue, cl_kernel kernel } CL_MUTEX_UNLOCK(&kernel->lock); + it = cl_enqueue_create_work_item(queue, num_events_in_wait_list, event_wait_list); + if (it == NULL) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } + err = queue->device->driver->enqueue_nd_range_kernel(queue, kernel, work_dim, global_wk_off, global_wk_sz, local_wk_sz, it); if (err != CL_SUCCESS) { goto error; } - /* If no events depend, we submit it immediately. */ - if (event_wait_list == NULL) { - ret_status = cl_enqueue_submit_work_item(queue, it); - if (ret_status < 0) { - /* We consider it as a error and return fail. */ - err = CL_OUT_OF_RESOURCES; + if (event_ret) { + event = cl_create_event(queue->ctx, queue, CL_FALSE, num_events_in_wait_list, event_wait_list, &err); + if (event == NULL) goto error; - } - if (ret_status > CL_COMPLETE) { - err = cl_enqueue_insert_work_item(queue, it); - if (err != CL_SUCCESS) - goto error; - } - } else { + } + cl_enqueue_set_work_item_event(it, event); + + + if (it->status > CL_COMPLETE) { // Still something todo err = cl_enqueue_insert_work_item(queue, it); if (err != CL_SUCCESS) goto error; diff --git a/libclapi/cl_mem.c b/libclapi/cl_mem.c index 0eebf6e8..441a7c3c 100644 --- a/libclapi/cl_mem.c +++ b/libclapi/cl_mem.c @@ -530,11 +530,34 @@ static void* cl_enqueue_map_buffer(cl_command_queue queue, cl_mem buffer, cl_boo void *mem_ptr = NULL; cl_int index; + + if (blocking_map) { + /* According to spec, when in block mode, we need to ensure all the + commands in queue are flushed. */ + err = cl_enqueue_wait_for_flush(queue); + if (err != CL_SUCCESS) + goto error; + } + + it = cl_enqueue_create_work_item(queue, num_events, event_list); + if (it == NULL) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } + + err = queue->device->driver->enqueue_map_buffer(queue, buffer, &mem_ptr, blocking_map, map_flags, + offset, size, num_events, event_list, event); + if (err != CL_SUCCESS) + goto error; + if (event_ret) { event = cl_create_event(buffer->ctx, queue, CL_FALSE, num_events, event_list, &err); if (event == NULL) goto error; } + + cl_enqueue_set_work_item_event(it, event); + #if 0 if (blocking_map) { /* According to spec, when in block mode, we need to ensure all the @@ -558,10 +581,6 @@ static void* cl_enqueue_map_buffer(cl_command_queue queue, cl_mem buffer, cl_boo goto error; } - err = queue->device->driver->enqueue_map_buffer(queue, buffer, &mem_ptr, blocking_map, map_flags, - offset, size, num_events, event_list, event); - if (err != CL_SUCCESS) - goto error; |