[Beignet] [PATCH] Calculate appropriate timestamps for cl profile
Midhun Kodiyath
midhunchandra.kodiyath at intel.com
Tue Sep 22 17:19:25 PDT 2015
Fix to calculate the current cpu monotonic raw timestamp in nanoseconds
for enqueued,submitted,start and finshed and send this to application
based on the parameter queries.
Signed-off-by: Midhun Kodiyath <midhunchandra.kodiyath at intel.com>
---
src/cl_api.c | 9 +++++----
src/cl_event.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/cl_event.h | 11 +++++++++++
3 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index dbbcbb0..02c5791 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -77,6 +77,7 @@ handle_events(cl_command_queue queue, cl_int num, const cl_event *wait_list,
if (e->type != CL_COMMAND_USER &&
e->queue->props & CL_QUEUE_PROFILING_ENABLE) {
cl_event_get_timestamp(e, CL_PROFILING_COMMAND_QUEUED);
+ cl_event_get_queued_cpu_timestamp(e);
}
if(event != NULL)
@@ -1488,15 +1489,15 @@ clGetEventProfilingInfo(cl_event event,
}
if (param_name == CL_PROFILING_COMMAND_QUEUED) {
- ret_val = event->timestamp[0];
+ ret_val = event->queued_timestamp;
} else if (param_name == CL_PROFILING_COMMAND_SUBMIT) {
- ret_val = event->timestamp[1];
+ ret_val= event->queued_timestamp + cl_event_get_timestamp_delta(event->timestamp[0],event->timestamp[1]);
} else if (param_name == CL_PROFILING_COMMAND_START) {
err = cl_event_get_timestamp(event, CL_PROFILING_COMMAND_START);
- ret_val = event->timestamp[2];
+ ret_val = event->queued_timestamp + cl_event_get_start_timestamp(event);
} else if (param_name == CL_PROFILING_COMMAND_END) {
err = cl_event_get_timestamp(event, CL_PROFILING_COMMAND_END);
- ret_val = event->timestamp[3];
+ ret_val = event->queued_timestamp + cl_event_get_end_timestamp(event);
} else {
err = CL_INVALID_VALUE;
goto error;
diff --git a/src/cl_event.c b/src/cl_event.c
index bbc1776..bf44197 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -613,6 +613,61 @@ cl_int cl_event_barrier_with_wait_list(cl_command_queue queue,
return CL_SUCCESS;
}
+cl_ulong cl_event_get_cpu_timestamp(cl_ulong *cpu_time)
+{
+ struct timespec ts;
+
+ if(clock_gettime(CLOCK_MONOTONIC_RAW,&ts) != 0){
+ printf("CPU Timmer error\n");
+ return CL_FALSE;
+ }
+ *cpu_time = (1000000000.0) * (cl_ulong) ts.tv_sec + (cl_ulong) ts.tv_nsec;
+
+ return CL_SUCCESS;
+}
+
+cl_int cl_event_get_queued_cpu_timestamp(cl_event event)
+{
+ cl_int ret_val;
+
+ ret_val = cl_event_get_cpu_timestamp(&event->queued_timestamp);
+
+ return ret_val;
+}
+
+cl_ulong cl_event_get_timestamp_delta(cl_ulong start_timestamp,cl_ulong end_timestamp)
+{
+ cl_ulong ret_val;
+
+ if(end_timestamp > start_timestamp){
+ ret_val = end_timestamp - start_timestamp;
+ }
+ else {
+ /*if start time stamp is greater than end timstamp then set ret value to max*/
+ ret_val = ((cl_ulong) 1 << 32);
+ }
+
+ return ret_val;
+}
+
+cl_ulong cl_event_get_start_timestamp(cl_event event)
+{
+ cl_ulong ret_val;
+
+ ret_val = cl_event_get_timestamp_delta(event->timestamp[0],event->timestamp[2]);
+
+ return ret_val;
+}
+
+cl_ulong cl_event_get_end_timestamp(cl_event event)
+{
+ cl_ulong ret_val;
+
+ ret_val = cl_event_get_timestamp_delta(event->timestamp[0],event->timestamp[3]);
+
+ return ret_val;
+}
+
cl_int cl_event_get_timestamp(cl_event event, cl_profiling_info param_name)
{
cl_ulong ret_val = 0;
diff --git a/src/cl_event.h b/src/cl_event.h
index e3cd2b2..f7bf09f 100644
--- a/src/cl_event.h
+++ b/src/cl_event.h
@@ -70,6 +70,7 @@ struct _cl_event {
enqueue_callback* waits_head; /* The head of enqueues list wait on this event */
cl_bool emplict; /* Identify this event whether created by api emplict*/
cl_ulong timestamp[4];/* The time stamps for profiling. */
+ cl_ulong queued_timestamp;
};
/* Create a new event object */
@@ -96,6 +97,16 @@ void cl_event_update_status(cl_event, cl_int);
cl_int cl_event_marker_with_wait_list(cl_command_queue, cl_uint, const cl_event *, cl_event*);
/* Create the barrier event */
cl_int cl_event_barrier_with_wait_list(cl_command_queue, cl_uint, const cl_event *, cl_event*);
+/* Get the cpu time */
+cl_ulong cl_event_get_cpu_timestamp(cl_ulong *cpu_time);
+/*Get the cpu time for queued*/
+cl_int cl_event_get_queued_cpu_timestamp(cl_event event);
+/*get timestamp delate between end and start*/
+cl_ulong cl_event_get_timestamp_delta(cl_ulong start_timestamp,cl_ulong end_timestamp);
+/*Get start time stamp*/
+cl_ulong cl_event_get_start_timestamp(cl_event event);
+/*Get end time stamp*/
+cl_ulong cl_event_get_end_timestamp(cl_event event);
/* Do the event profiling */
cl_int cl_event_get_timestamp(cl_event event, cl_profiling_info param_name);
/* insert the user event */
--
2.5.0
More information about the Beignet
mailing list