Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/no cuda timer #43

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ endif()
set(interface_SRCS
carlsim/interface/src/callback_core.cpp
carlsim/interface/src/carlsim.cpp
carlsim/interface/src/execution_stopwatch.cpp
carlsim/interface/src/linear_algebra.cpp
carlsim/interface/src/poisson_rate.cpp
carlsim/interface/src/user_errors.cpp
Expand All @@ -119,6 +120,7 @@ set(interface_HDRS
carlsim/interface/inc/carlsim_api.h
carlsim/interface/inc/carlsim_conf_api.h
carlsim/interface/inc/carlsim_log_definitions.h
carlsim/interface/inc/execution_stopwatch.h
carlsim/interface/inc/linear_algebra.h
carlsim/interface/inc/poisson_rate.h
carlsim/interface/inc/user_errors.h
Expand Down
2 changes: 2 additions & 0 deletions carlsim/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
add_library(carlsim-interface
src/callback_core.cpp
src/carlsim.cpp
src/execution_stopwatch.cpp
src/linear_algebra.cpp
src/poisson_rate.cpp
src/user_errors.cpp
Expand Down Expand Up @@ -53,6 +54,7 @@
inc/carlsim_definitions.h
inc/carlsim.h
inc/carlsim_log_definitions.h
inc/execution_stopwatch.h
inc/linear_algebra.h
inc/poisson_rate.h
inc/user_errors.h
Expand Down
103 changes: 103 additions & 0 deletions carlsim/interface/inc/execution_stopwatch.h
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_
97 changes: 97 additions & 0 deletions carlsim/interface/src/execution_stopwatch.cpp
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();
}
}
5 changes: 4 additions & 1 deletion carlsim/kernel/inc/snn.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@

#include <carlsim.h>
#include <callback_core.h>
#include <execution_stopwatch.h>

#include <snn_definitions.h>
#include <snn_datastructures.h>
Expand Down Expand Up @@ -1226,7 +1227,7 @@ class SNN {
void printEntrails_GPU(int netId, int lGrpIdPre, int lGrpIdPost);
void printEntrails_GPU(char* buffer, unsigned length, int netId, int lGrpIdPre, int lGrpIdPost);
#else
bool updateDelays_GPU(int netId, int lGrpIdPre, int lGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays) { assert(false); }
bool updateDelays_GPU(int netId, int lGrpIdPre, int lGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays) { assert(false); return false; }
void printEntrails_GPU(int netId, int lGrpIdPre, int lGrpIdPost) { assert(false); }
void printEntrails_GPU(char* buffer, unsigned length, int netId, int lGrpIdPre, int lGrpIdPost) { assert(false); }
#endif
Expand Down Expand Up @@ -1317,6 +1318,8 @@ class SNN {
//! vairables for tracking performance
#ifndef __NO_CUDA__
StopWatchInterface* timer;
#else
ExecutionStopwatch* timer;
#endif
float cumExecutionTime;
float lastExecutionTime;
Expand Down
12 changes: 10 additions & 2 deletions carlsim/kernel/src/snn_cpu_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
*/

#include <snn.h>
#include <sstream>
#include <error_code.h>

#include <spike_buffer.h>
Expand Down Expand Up @@ -997,10 +998,18 @@ void SNN::copyExtFiringTable(int netId) {
else {


#if defined(WIN32) && defined(__NO_CUDA__)
#ifdef LN_MOST_RECENT
j_max = std::max(j_max, j_fired);
j_max = std::max<int>(j_max, j_fired);
#else
j_min = std::min<int>(j_min, j_fired);
#endif
#else
#ifdef LN_MOST_RECENT
j_max = std::max(j_max, j_fired);
#else
j_min = std::min(j_min, j_fired);
#endif
#endif
}
}
Expand Down Expand Up @@ -1028,7 +1037,6 @@ void SNN::copyExtFiringTable(int netId) {
string_stream << ",";
string_stream << *iter;
}

KERNEL_INFO("path: %s", string_stream.str().c_str());


Expand Down
35 changes: 32 additions & 3 deletions carlsim/kernel/src/snn_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ int SNN::runNetwork(int _nsec, int _nmsec, bool printRunSummary) {
#ifndef __NO_CUDA__
CUDA_RESET_TIMER(timer);
CUDA_START_TIMER(timer);
#else
timer->reset();
timer->start();
#endif

//KERNEL_INFO("Reached the advSimStep loop!");
Expand Down Expand Up @@ -1213,8 +1216,13 @@ int SNN::runNetwork(int _nsec, int _nmsec, bool printRunSummary) {
#ifndef __NO_CUDA__
CUDA_STOP_TIMER(timer);
lastExecutionTime = CUDA_GET_TIMER_VALUE(timer);
cumExecutionTime += lastExecutionTime;
#else
timer->stop();
lastExecutionTime = timer->get_time();
#endif

cumExecutionTime += lastExecutionTime;

return 0;
}

Expand Down Expand Up @@ -2609,6 +2617,9 @@ void SNN::SNNinit() {
#ifndef __NO_CUDA__
CUDA_CREATE_TIMER(timer);
CUDA_RESET_TIMER(timer);
#else
timer = new ExecutionStopwatch{};
timer->reset();
#endif
}

Expand Down Expand Up @@ -5252,6 +5263,8 @@ void SNN::deleteRuntimeData() {

#ifndef __NO_CUDA__
CUDA_DELETE_TIMER(timer);
#else
delete timer;
#endif
}

Expand Down Expand Up @@ -8333,7 +8346,12 @@ void SNN::updateNeuronMonitor(int gGrpId) {
int grpNumNeurons = groupConfigs[netId][lGrpId].lEndN - groupConfigs[netId][lGrpId].lStartN + 1;
//printf("The lStartN is: %i; and lEndN is: %i\n", groupConfigs[netId][lGrpId].lStartN, groupConfigs[netId][lGrpId].lEndN);
// for (int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].lEndN; lNId++) {

#if defined(WIN32) && defined(__NO_CUDA__)
for (int tmpNId = 0; tmpNId < std::min<int>(MAX_NEURON_MON_GRP_SZIE, grpNumNeurons); tmpNId++) {
#else
for (int tmpNId = 0; tmpNId < std::min(MAX_NEURON_MON_GRP_SZIE, grpNumNeurons); tmpNId++) {
#endif
int lNId = groupConfigs[netId][lGrpId].lStartN + tmpNId;
float v, u, I;

Expand Down Expand Up @@ -8391,6 +8409,10 @@ void SNN::printSimSummary() {
stopTiming();
etime = executionTime;

#ifndef __NO_CUDA__
etime /= 1000.0f;
#endif

fetchNetworkSpikeCount();

KERNEL_INFO("\n");
Expand All @@ -8403,8 +8425,15 @@ void SNN::printSimSummary() {
KERNEL_INFO("Simulation Mode:\t%s",sim_with_conductances?"COBA":"CUBA");
KERNEL_INFO("Random Seed:\t\t%d", randSeed_);
KERNEL_INFO("Timing:\t\t\tModel Simulation Time = %lld sec", (unsigned long long)simTimeSec);
KERNEL_INFO("\t\t\tActual Execution Time = %4.2f sec", etime/1000.0f);
float speed = float(simTimeSec) / std::max(.001f, etime / 1000.0f);
KERNEL_INFO("\t\t\tActual Execution Time = %4.2f sec", etime);

#if defined(WIN32) && defined(__NO_CUDA__)
float speed = float(simTimeSec) / std::max<float>(.001f, etime);
#else
float speed = float(simTimeSec) / std::max(.001f, etime);
#endif


#ifdef _DEBUG
const char* build = "(Debug)";
#else
Expand Down
6 changes: 5 additions & 1 deletion carlsim/monitor/neuron_monitor_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ NeuronMonitorCore::NeuronMonitorCore(SNN* snn, int monitorId, int grpId) {
}

void NeuronMonitorCore::init() {
nNeurons_ = std::min(MAX_NEURON_MON_GRP_SZIE, snn_->getGroupNumNeurons(grpId_));
#if defined(WIN32) && defined(__NO_CUDA__)
nNeurons_ = std::min<int>(MAX_NEURON_MON_GRP_SZIE, snn_->getGroupNumNeurons(grpId_));
#else
nNeurons_ = std::min(MAX_NEURON_MON_GRP_SZIE, snn_->getGroupNumNeurons(grpId_));
#endif
assert(nNeurons_>0);

// so the first dimension is neuron ID
Expand Down
Loading
Loading