PIPS
Timer.h
Go to the documentation of this file.
1 
2 /* ============================================================
3 
4 Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
5 
6 Redistribution and use of this material is permitted under the following
7 conditions:
8 
9 Redistributions must retain the above copyright notice and all terms of this
10 license.
11 
12 In no event shall anyone redistributing or accessing or using this material
13 commence or participate in any arbitration or legal action relating to this
14 material against Advanced Micro Devices, Inc. or any copyright holders or
15 contributors. The foregoing shall survive any expiration or termination of
16 this license or any agreement or access or use related to this material.
17 
18 ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE REVOCATION
19 OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
20 
21 THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY COPYRIGHT
22 HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION AND WITHOUT ANY
23 REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR IN ANY WAY RELATED TO
24 SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED OPERATION, OR THAT IT IS FREE
25 FROM DEFECTS OR VIRUSES. ALL OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER
26 EXPRESS, IMPLIED, OR STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED
27 WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
28 ACCURACY, COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT.
29 IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
32 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, REVENUE, DATA, OR PROFITS; OR
33 BUSINESS INTERRUPTION) HOWEVER CAUSED OR BASED ON ANY THEORY OF LIABILITY
34 ARISING IN ANY WAY RELATED TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY
35 OF SUCH DAMAGE. THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES,
36 INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
37 (US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL ACCEPTS
38 THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO DEVICES, INC. AND
39 ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND ALL LIABILITIES,
40 OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN DOLLARS (US $10.00). THE
41 FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE AND, IF ANY OF THESE TERMS ARE
42 CONSTRUED AS UNENFORCEABLE, FAIL IN ESSENTIAL PURPOSE, OR BECOME VOID OR
43 DETRIMENTAL TO ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
44 CONTRIBUTORS FOR ANY REASON, THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE
45 THIS MATERIAL SHALL TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL
46 SURVIVE ANY EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR
47 ACCESS OR USE RELATED TO THIS MATERIAL.
48 
49 NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING THIS
50 MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE SUBJECT TO
51 RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED STATES OR OTHER
52 COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S. EXPORT CONTROL LAWS SUCH
53 AS THE EXPORT ADMINISTRATION REGULATIONS AND NATIONAL SECURITY CONTROLS AS
54 DEFINED THEREUNDER, AS WELL AS STATE DEPARTMENT CONTROLS UNDER THE U.S.
55 MUNITIONS LIST. THIS MATERIAL MAY NOT BE USED, RELEASED, TRANSFERRED, IMPORTED,
56 EXPORTED AND/OR RE-EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS,
57 INCLUDING U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
58 COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY CONTROLS.
59 MOREOVER, THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
60 LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
61 
62 NOTICE REGARDING THE U.S. GOVERNMENT AND DOD AGENCIES: This material is
63 provided with "RESTRICTED RIGHTS" and/or "LIMITED RIGHTS" as applicable to
64 computer software and technical data, respectively. Use, duplication,
65 distribution or disclosure by the U.S. Government and/or DOD agencies is
66 subject to the full extent of restrictions in all applicable regulations,
67 including those found at FAR52.227 and DFARS252.227 et seq. and any successor
68 regulations thereof. Use of this material by the U.S. Government and/or DOD
69 agencies is acknowledgment of the proprietary rights of any copyright holders
70 and contributors, including those of Advanced Micro Devices, Inc., as well as
71 the provisions of FAR52.227-14 through 23 regarding privately developed and/or
72 commercial computer software.
73 
74 This license forms the entire agreement regarding the subject matter hereof and
75 supersedes all proposals and prior discussions and writings between the parties
76 with respect thereto. This license does not affect any ownership, rights, title,
77 or interest in, or relating to, this material. No terms of this license can be
78 modified or waived, and no breach of this license can be excused, unless done
79 so in a writing signed by all affected parties. Each term of this license is
80 separately enforceable. If any term of this license is determined to be or
81 becomes unenforceable or illegal, such term shall be reformed to the minimum
82 extent necessary in order for this license to remain in effect in accordance
83 with its terms as modified by such reformation. This license shall be governed
84 by and construed in accordance with the laws of the State of Texas without
85 regard to rules on conflicts of law of any state or jurisdiction or the United
86 Nations Convention on the International Sale of Goods. All disputes arising out
87 of this license shall be subject to the jurisdiction of the federal and state
88 courts in Austin, Texas, and all defenses are hereby waived concerning personal
89 jurisdiction and venue of these courts.
90 
91 ============================================================ */
92 
93 #ifndef _TIMER_H_
94 #define _TIMER_H_
95 /**
96  * \file Timer.h
97  * \brief A timer class that provides a cross platform timer for use
98  * in timing code progress with a high degree of accuracy.
99  */
100 #ifdef _WIN32
101 /**
102  * \typedef __int64 i64
103  * \brief Maps the windows 64 bit integer to a uniform name
104  */
105 typedef __int64 i64 ;
106 #else
107 /**
108  * \typedef long long i64
109  * \brief Maps the linux 64 bit integer to a uniform name
110  */
111 typedef long long i64;
112 #endif
113 
114 /**
115  * \class CPerfCounter
116  * \brief Counter that provides a fairly accurate timing mechanism for both
117  * windows and linux. This timer is used extensively in all the samples.
118  */
120 
121 public:
122  /**
123  * \fn CPerfCounter()
124  * \brief Constructor for CPerfCounter that initializes the class
125  */
127  /**
128  * \fn ~CPerfCounter()
129  * \brief Destructor for CPerfCounter that cleans up the class
130  */
132  /**
133  * \fn void Start(void)
134  * \brief Start the timer
135  * \sa Stop(), Reset()
136  */
137  void Start(void);
138  /**
139  * \fn void Stop(void)
140  * \brief Stop the timer
141  * \sa Start(), Reset()
142  */
143  void Stop(void);
144  /**
145  * \fn void Reset(void)
146  * \brief Reset the timer to 0
147  * \sa Start(), Stop()
148  */
149  void Reset(void);
150  /**
151  * \fn double GetElapsedTime(void)
152  * \return Amount of time that has accumulated between the \a Start()
153  * and \a Stop() function calls
154  */
155  double GetElapsedTime(void);
156 
157 private:
158 
162 };
163 
164 #endif // _TIMER_H_
165 
long long i64
Maps the linux 64 bit integer to a uniform name.
Definition: Timer.h:111
Counter that provides a fairly accurate timing mechanism for both windows and linux.
Definition: Timer.h:119
i64 _freq
Definition: Timer.h:159
void Start(void)
Start the timer.
i64 _start
Definition: Timer.h:161
i64 _clocks
Definition: Timer.h:160
void Stop(void)
Stop the timer.
CPerfCounter()
Constructor for CPerfCounter that initializes the class.
~CPerfCounter()
Destructor for CPerfCounter that cleans up the class.
double GetElapsedTime(void)
void Reset(void)
Reset the timer to 0.