Hi Andreas,
I think it would be more intuitive if you changed time_till and
time_since to Python's __sub__, so one could write "elapsed = end - begin"
for events. A patch is attached, with documentation (and corrected
documentation for record_in_stream --> record).
regards,
Nicholas
diff --git a/doc/source/driver.rst b/doc/source/driver.rst
index 53202e7..67bdcd6 100644
--- a/doc/source/driver.rst
+++ b/doc/source/driver.rst
@@ -246,7 +246,7 @@ Concurrency and Streams
Insert a recording point for *self* into the global device execution
stream.
- .. method:: record_in_stream(stream)
+ .. method:: record(stream)
Insert a recording point for *self* into the :class:`Stream` *stream*
@@ -258,14 +258,31 @@ Concurrency and Streams
Return *True* if the device execution stream has reached this event.
- .. method:: time_since(event)
-
- Return the time in milliseconds that has passed between *self* and *event*.
-
- .. method:: time_till(event)
-
- Return the time in milliseconds that has passed between *event* and *self*.
-
+ .. method:: __sub__(event)
+
+ Return the time in milliseconds between events; use as *end* - *begin*. As an example::
+
+ begin = drv.Event()
+ end = drv.Event()
+ begin.record(stream)
+ fcn(mem, block=(300, 1, 1), grid=(1, 1), stream=stream) # trivial kernel
+ time.sleep(1)
+ end.record(stream)
+ time.sleep(1)
+
+ begin_2 = drv.Event()
+ end_2 = drv.Event()
+ begin_2.record(stream)
+ slow_fcn(mem, block=(300, 1, 1), grid=(10000, 1), stream=stream) # more expensive kernel
+ end_2.record(stream)
+
+ # the event must be synchronized before querying event times
+ # this test shows that events take the current time if nothing
+ # is processing; otherwise, their times are set when the stream
+ # has finished all tasks enqueued before the record() call.
+ end_2.synchronize()
+ print(end - begin) # one second
+ print(end_2 - begin_2) # time of slow_fcn
Memory
------
diff --git a/src/cpp/cuda.hpp b/src/cpp/cuda.hpp
index 2904e71..72b35e9 100644
--- a/src/cpp/cuda.hpp
+++ b/src/cpp/cuda.hpp
@@ -1157,19 +1157,12 @@ namespace cuda
}
}
- float time_since(event const &start)
+ float __sub__(event const &start)
{
float result;
CUDAPP_CALL_GUARDED(cuEventElapsedTime, (&result, start.m_event, m_event));
return result;
}
-
- float time_till(event const &end)
- {
- float result;
- CUDAPP_CALL_GUARDED(cuEventElapsedTime, (&result, m_event, end.m_event));
- return result;
- }
};
}
diff --git a/src/wrapper/wrap_cudadrv.cpp b/src/wrapper/wrap_cudadrv.cpp
index df7f1c3..a31d798 100644
--- a/src/wrapper/wrap_cudadrv.cpp
+++ b/src/wrapper/wrap_cudadrv.cpp
@@ -566,8 +566,7 @@ BOOST_PYTHON_MODULE(_driver)
.def("record", &cl::record_in_stream)
.DEF_SIMPLE_METHOD(synchronize)
.DEF_SIMPLE_METHOD(query)
- .DEF_SIMPLE_METHOD(time_since)
- .DEF_SIMPLE_METHOD(time_till)
+ .DEF_SIMPLE_METHOD(__sub__)
;
}
_______________________________________________
PyCuda mailing list
[email protected]
http://tiker.net/mailman/listinfo/pycuda_tiker.net