[Beignet] [PATCH] Calculate appropriate timestamps for cl profile

Yang, Rong R rong.r.yang at intel.com
Tue Sep 22 00:31:57 PDT 2015


Some mirror inline comments, and some code's style don't consistent.

For example:
ret_val = event->queued_timestamp;
and
ret_val=end_timestamp-start_timestamp;

Hope could add the space around operation. Thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Midhun Kodiyath
> Sent: Friday, September 18, 2015 7:52
> To: beignet at lists.freedesktop.org
> Cc: Kodiyath, Midhunchandra
> Subject: [Beignet] [PATCH] Calculate appropriate timestamps for cl profile
> 
> Signed-off-by: Midhun Kodiyath <midhunchandra.kodiyath at intel.com>
> ---
>  src/cl_api.c   |  9 +++++----
>  src/cl_event.c | 57
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/cl_event.h | 11 +++++++++++
>  3 files changed, 73 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..3c8afcc 100644
> --- a/src/cl_event.c
> +++ b/src/cl_event.c
> @@ -613,6 +613,63 @@ 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;
> +
> +  cl_ulong
> + submit_time_delta=cl_event_get_timestamp_delta(event-
> >timestamp[0],eve
> + nt->timestamp[1]);  ret_val = submit_time_delta+
> + cl_event_get_timestamp_delta(event->timestamp[1],event-
> >timestamp[2]);
Because timestamp[0] is gpu's queue time, and timestamp[2] is start time.
I think you could use cl_event_get_timestamp_delta(event->timestamp[0],event->timestamp[2]) directly to calculate the start delta.




> +
> +  return ret_val;
> +}
> +
> +cl_ulong cl_event_get_end_timestamp(cl_event event) {  cl_ulong
> +ret_val;
> +
> + cl_ulong
> + end_time_delta=cl_event_get_timestamp_delta(event-
> >timestamp[2],event-
> + >timestamp[3]);
> + ret_val=end_time_delta+cl_event_get_start_timestamp(event);
> +

Also could use cl_event_get_timestamp_delta(event->timestamp[0],event->timestamp[3]) directly to calculate the start delta.
And indent is not correct, only one space.

> + 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
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list