-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to measure actual execution time when running on CPU
- Loading branch information
1 parent
239240a
commit 576fccc
Showing
8 changed files
with
332 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* * Copyright (c) 2016 Regents of the University of California. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* 3. The names of its contributors may not be used to endorse or promote | ||
* products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* *********************************************************************************************** * | ||
* CARLsim | ||
* created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran | ||
* maintained by: | ||
* (MA) Mike Avery <[email protected]> | ||
* (MB) Michael Beyeler <[email protected]>, | ||
* (KDC) Kristofor Carlson <[email protected]> | ||
* (TSC) Ting-Shuo Chou <[email protected]> | ||
* (HK) Hirak J Kashyap <[email protected]> | ||
* | ||
* CARLsim v1.0: JM, MDR | ||
* CARLsim v2.0/v2.1/v2.2: JM, MDR, MA, MB, KDC | ||
* CARLsim3: MB, KDC, TSC | ||
* CARLsim4: TSC, HK | ||
* CARLsim5: HK, JX, KC | ||
* CARLsim6: LN, JX, KC, KW | ||
* | ||
* CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/ | ||
* Ver 12/31/2016 | ||
*/ | ||
|
||
#ifndef _EXECUTION_STOPWATCH_H_ | ||
#define _EXECUTION_STOPWATCH_H_ | ||
|
||
#ifdef __NO_CUDA__ | ||
|
||
#include "carlsim_api.h" | ||
|
||
#include <chrono> // std::chrono::steady_clock::time_point | ||
|
||
/*! | ||
* \brief A stopwatch class for measuring program execution time | ||
* | ||
* This class implements a class for a stopwatch object that can be used to measure the runtime for | ||
* a program or a part of it when CARLsim is not run on the GPU. The stopwatch is started at the | ||
* beginning of the part of the program to be measured and stopped at the end. After a measurement, | ||
* the stopwatch can be used to get the time elapsed and reset for a new measurement. | ||
*/ | ||
class CARLSIM_API ExecutionStopwatch | ||
{ | ||
private: | ||
bool _timer_on; //!< true if the timer is on, false if off | ||
std::chrono::steady_clock::time_point _start_time; //!< time point when the stopwatch is started | ||
std::chrono::steady_clock::time_point _stop_time; //!< time point when the stopwatch is stopped | ||
|
||
public: | ||
/*! | ||
* \brief Starts the stopwatch by recording the time it was started | ||
*/ | ||
void start(); | ||
|
||
/*! | ||
* \brief Stops the stopwatch by recording the time it was stopped | ||
*/ | ||
void stop(); | ||
|
||
/*! | ||
* \brief Gets the time measured by the stopwatch (time between start and stop time) | ||
* | ||
* This function returns the time measured by the stopwatch, specifically the difference between | ||
* the start and stop time. If the timer has not been stopped, a time of 0 will be returned. | ||
* | ||
* \returns the time measured by the stopwatch (s) | ||
*/ | ||
float get_time(); | ||
|
||
/*! | ||
* \brief Resets the stopwatch by clearing the currently stored start and stop times | ||
*/ | ||
void reset(); | ||
}; | ||
#endif | ||
|
||
#endif // _EXECUTION_STOPWATCH_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* * Copyright (c) 2016 Regents of the University of California. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* 3. The names of its contributors may not be used to endorse or promote | ||
* products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* *********************************************************************************************** * | ||
* CARLsim | ||
* created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran | ||
* maintained by: | ||
* (MA) Mike Avery <[email protected]> | ||
* (MB) Michael Beyeler <[email protected]>, | ||
* (KDC) Kristofor Carlson <[email protected]> | ||
* (TSC) Ting-Shuo Chou <[email protected]> | ||
* (HK) Hirak J Kashyap <[email protected]> | ||
* | ||
* CARLsim v1.0: JM, MDR | ||
* CARLsim v2.0/v2.1/v2.2: JM, MDR, MA, MB, KDC | ||
* CARLsim3: MB, KDC, TSC | ||
* CARLsim4: TSC, HK | ||
* CARLsim5: HK, JX, KC | ||
* CARLsim6: LN, JX, KC, KW | ||
* | ||
* CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/ | ||
* Ver 12/31/2016 | ||
*/ | ||
#include "execution_stopwatch.h" | ||
|
||
#include <carlsim_log_definitions.h> // CARLSIM_WARN | ||
|
||
void ExecutionStopwatch::start() { | ||
if (_timer_on) { | ||
CARLSIM_WARN("ExecutionStopwatch::start", "Cannot start timer when timer is on."); | ||
} | ||
else { | ||
_start_time = std::chrono::steady_clock::now(); | ||
_timer_on = true; | ||
} | ||
} | ||
|
||
void ExecutionStopwatch::stop() { | ||
if (_timer_on) { | ||
_stop_time = std::chrono::steady_clock::now(); | ||
_timer_on = false; | ||
} | ||
else { | ||
CARLSIM_WARN("ExecutionStopwatch::stop", "Cannot stop timer when timer is off."); | ||
} | ||
} | ||
|
||
float ExecutionStopwatch::get_time() { | ||
if (_timer_on) { | ||
CARLSIM_WARN("ExecutionStopwatch::get_time", "Cannot get time when timer when timer is on."); | ||
|
||
return 0.0f; | ||
} | ||
else { | ||
// Return difference of start and stop times as a float | ||
std::chrono::duration<float> measured_time = _stop_time - _start_time; | ||
|
||
return measured_time.count(); | ||
} | ||
} | ||
|
||
void ExecutionStopwatch::reset() { | ||
if (_timer_on) { | ||
CARLSIM_WARN("ExecutionStopwatch::reset", "Cannot reset when timer when timer is on."); | ||
} | ||
else { | ||
// Set start and stop times to beginning of clock | ||
_start_time = std::chrono::steady_clock::time_point::min(); | ||
_stop_time = std::chrono::steady_clock::time_point::min(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ endif() | |
conn_mon.cpp | ||
core.cpp | ||
cuba.cpp | ||
exec_stopwatch.cpp | ||
group_mon.cpp | ||
interface.cpp | ||
main.cpp | ||
|
Oops, something went wrong.