MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
timer.cpp
Go to the documentation of this file.
1 /*
2  -- MAGMA (version 1.4.0) --
3  Univ. of Tennessee, Knoxville
4  Univ. of California, Berkeley
5  Univ. of Colorado, Denver
6  August 2013
7 */
8 
9 #include "common_magma.h"
10 
11 #if defined( _WIN32 ) || defined( _WIN64 )
12 # include <time.h>
13 # include <sys/timeb.h>
14 # if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
15 # define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
16 # else
17 # define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
18 # endif
19 #else
20 # include <sys/time.h>
21 #endif
22 
23 #if defined(ADD_)
24 # define magma_wtime_f magma_wtime_f_
25 #elif defined(NOCHANGE)
26 #endif
27 
28 
29 /* ////////////////////////////////////////////////////////////////////////////
30  -- Emulate gettimeofday on Windows.
31 */
32 #if defined( _WIN32 ) || defined( _WIN64 )
33 struct timezone
34 {
35  int tz_minuteswest; /* minutes W of Greenwich */
36  int tz_dsttime; /* type of dst correction */
37 };
38 
39 extern "C"
40 int gettimeofday(struct timeval* tv, struct timezone* tz)
41 {
42  FILETIME ft;
43  unsigned __int64 tmpres = 0;
44  static int tzflag = 0;
45 
46  if (NULL != tv) {
47  GetSystemTimeAsFileTime(&ft);
48  tmpres |= ft.dwHighDateTime;
49  tmpres <<= 32;
50  tmpres |= ft.dwLowDateTime;
51 
52  /*converting file time to unix epoch*/
53  tmpres /= 10; /*convert into microseconds*/
54  tmpres -= DELTA_EPOCH_IN_MICROSECS;
55 
56  tv->tv_sec = (long)(tmpres / 1000000UL);
57  tv->tv_usec = (long)(tmpres % 1000000UL);
58  }
59  if (NULL != tz) {
60  if (!tzflag) {
61  _tzset();
62  tzflag = 1;
63  }
64  tz->tz_minuteswest = _timezone / 60;
65  tz->tz_dsttime = _daylight;
66  }
67  return 0;
68 }
69 #endif
70 
71 
72 /* ////////////////////////////////////////////////////////////////////////////
73  -- Get current time.
74 */
75 extern "C"
77 {
78  struct timeval time_val;
79  magma_timestr_t time;
80 
81  cudaDeviceSynchronize();
82  gettimeofday(&time_val, NULL);
83 
84  time.sec = time_val.tv_sec;
85  time.usec = time_val.tv_usec;
86  return (time);
87 }
88 
89 
90 /* ////////////////////////////////////////////////////////////////////////////
91  -- Returns elapsed time between start and end in milliseconds.
92 */
93 extern "C"
95 {
96  int sec, usec;
97 
98  sec = end.sec - start.sec;
99  usec = end.usec - start.usec;
100 
101  return (1000.*(double)(sec) + (double)(usec) * 0.001);
102 }
103 
104 
105 /* ////////////////////////////////////////////////////////////////////////////
106  -- Return time in seconds since arbitrary time in the past.
107  Use for elapsed wall clock time computation.
108 */
109 extern "C"
110 double magma_wtime( void )
111 {
112  struct timeval t;
113  gettimeofday( &t, NULL );
114  return t.tv_sec + t.tv_usec*1e-6;
115 }
116 
117 // synchronize before getting time, e.g., to time asynchronous cublas calls
118 extern "C"
119 double magma_sync_wtime( magma_queue_t queue )
120 {
121  magma_queue_sync( queue );
122  return magma_wtime();
123 }
124 
125 // version callable from Fortran stores seconds in time.
126 extern "C"
127 void magma_wtime_f(double *time)
128 {
129  *time = magma_wtime();
130 }
unsigned int usec
Definition: auxiliary.h:15
unsigned int sec
Definition: auxiliary.h:14
double magma_sync_wtime(magma_queue_t queue)
Definition: timer.cpp:119
double magma_wtime(void)
Definition: timer.cpp:110
void magma_wtime_f(double *time)
Definition: timer.cpp:127
double GetTimerValue(magma_timestr_t start, magma_timestr_t end)
Definition: timer.cpp:94
magma_timestr_t get_current_time(void)
Definition: timer.cpp:76
#define magma_queue_sync(queue)
Definition: magma.h:119