clover: Run the associated action before an event is signalled.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 9 Jun 2015 19:59:43 +0000 (22:59 +0300)
committerJan Vesely <jan.vesely@rutgers.edu>
Wed, 20 Sep 2017 22:48:41 +0000 (18:48 -0400)
And define a method for other threads to wait until the action
function associated with an event has been executed to completion.

For hard events, this will mean waiting until the corresponding
command has been submitted to the pipe driver, without necessarily
flushing the pipe_context and waiting for the actual command to be
processed by the GPU (which is what hard_event::wait() already does).

This weaker kind of event wait will allow implementing blocking memory
transfers efficiently.

Acked-by: Aaron Watry <awatry@gmail.com>
Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>
src/gallium/state_trackers/clover/core/event.cpp
src/gallium/state_trackers/clover/core/event.hpp

index 4f8531e407ee8b1aaec3c845f4a6dab8bc1373dc..cd5d786604d688ea2c428ce5ae4fbeba58ddad18 100644 (file)
@@ -44,19 +44,16 @@ event::trigger_self() {
    if (!--_wait_count)
       std::swap(_chain, evs);
 
+   cv.notify_all();
    return evs;
 }
 
 void
 event::trigger() {
-   auto evs = trigger_self();
-
-   if (signalled()) {
+   if (wait_count() == 1)
       action_ok(*this);
-      cv.notify_all();
-   }
 
-   for (event &ev : evs)
+   for (event &ev : trigger_self())
       ev.trigger();
 }
 
@@ -73,11 +70,9 @@ event::abort_self(cl_int status) {
 
 void
 event::abort(cl_int status) {
-   auto evs = abort_self(status);
-
    action_fail(*this);
 
-   for (event &ev : evs)
+   for (event &ev : abort_self(status))
       ev.abort(status);
 }
 
@@ -111,13 +106,18 @@ event::chain(event &ev) {
    ev.deps.push_back(*this);
 }
 
+void
+event::wait_signalled() const {
+   std::unique_lock<std::mutex> lock(mutex);
+   cv.wait(lock, [=]{ return !_wait_count; });
+}
+
 void
 event::wait() const {
    for (event &ev : deps)
       ev.wait();
 
-   std::unique_lock<std::mutex> lock(mutex);
-   cv.wait(lock, [=]{ return !_wait_count; });
+   wait_signalled();
 }
 
 hard_event::hard_event(command_queue &q, cl_command_type command,
index 53dac686f8e1eacc5c88f4c88b45abb96a551a1d..03c97bcf4da0669bd6f94add97e5550ef19ed6ac 100644 (file)
@@ -69,6 +69,7 @@ namespace clover {
       virtual cl_int status() const;
       virtual command_queue *queue() const = 0;
       virtual cl_command_type command() const = 0;
+      void wait_signalled() const;
       virtual void wait() const;
 
       virtual struct pipe_fence_handle *fence() const {