summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Steckelmacher <steckdenis@yahoo.fr>2011-08-08 14:03:45 +0200
committerDenis Steckelmacher <steckdenis@yahoo.fr>2011-08-08 14:03:45 +0200
commit1a80d876947c922873b93a03e2d3b73f57d3468a (patch)
treeaa4e0045104d9e723deb00e09b8152f07bf51e7e
parent6c3aec27e5a1f120432f5c0702c75f353d78302a (diff)
Call CommandQueue::flush() when the spec asks to do so.
-rw-r--r--src/api/api_command.cpp2
-rw-r--r--src/api/api_enqueue.cpp26
-rw-r--r--src/api/api_event.cpp4
3 files changed, 27 insertions, 5 deletions
diff --git a/src/api/api_command.cpp b/src/api/api_command.cpp
index 4d1bf20..a97d4a3 100644
--- a/src/api/api_command.cpp
+++ b/src/api/api_command.cpp
@@ -63,7 +63,7 @@ clReleaseCommandQueue(cl_command_queue command_queue)
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
- // TODO: Flush command queue
+ command_queue->flush();
if (command_queue->dereference())
delete command_queue;
diff --git a/src/api/api_enqueue.cpp b/src/api/api_enqueue.cpp
index 64574ce..589c3b6 100644
--- a/src/api/api_enqueue.cpp
+++ b/src/api/api_enqueue.cpp
@@ -432,10 +432,10 @@ clEnqueueMapBuffer(cl_command_queue command_queue,
cl_event * event,
cl_int * errcode_ret)
{
- cl_int rs;
+ cl_int dummy_errcode;
if (!errcode_ret)
- errcode_ret = &rs;
+ errcode_ret = &dummy_errcode;
*errcode_ret = CL_SUCCESS;
@@ -458,12 +458,24 @@ clEnqueueMapBuffer(cl_command_queue command_queue,
return 0;
}
+ // We need command to be valid after queueEvent, so don't let the command
+ // queue handle it like a fire-and-forget event. Fixes a crash when event
+ // is NULL : the event gets deleted by clReleaseEvent called from
+ // CPUDevice's worker() and we then try to read it in command->ptr();
+ command->reference();
+
*errcode_ret = queueEvent(command_queue, command, event, blocking_map);
if (*errcode_ret != CL_SUCCESS)
return 0;
else
- return command->ptr();
+ {
+ void *rs = command->ptr();
+
+ clReleaseEvent((cl_event)command);
+
+ return rs;
+ }
}
void *
@@ -514,10 +526,12 @@ clEnqueueMapImage(cl_command_queue command_queue,
return 0;
}
+ command->reference(); // See clEnqueueMapImage for explanation.
*errcode_ret = queueEvent(command_queue, command, event, blocking_map);
if (*errcode_ret != CL_SUCCESS)
{
+ delete command;
return 0;
}
else
@@ -527,7 +541,11 @@ clEnqueueMapImage(cl_command_queue command_queue,
if (image_slice_pitch)
*image_slice_pitch = command->slice_pitch();
- return command->ptr();
+ void *rs = command->ptr();
+
+ clReleaseEvent((cl_event)command);
+
+ return rs;
}
}
diff --git a/src/api/api_event.cpp b/src/api/api_event.cpp
index 6e114b2..fed8536 100644
--- a/src/api/api_event.cpp
+++ b/src/api/api_event.cpp
@@ -24,6 +24,10 @@ clWaitForEvents(cl_uint num_events,
return CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
cl_context evt_ctx = (cl_context)event_list[i]->parent()->parent();
+ cl_command_queue evt_queue = (cl_command_queue)event_list[i]->parent();
+
+ // Flush the queue
+ evt_queue->flush();
if (global_ctx == 0)
global_ctx = evt_ctx;