Skip to content
Open
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
18 changes: 7 additions & 11 deletions Speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void Speed::update(const unsigned int numPoints, const unsigned int indexDevice)
const auto ns = std::chrono::steady_clock::now().time_since_epoch().count();
const bool bPrint = ((ns - m_lastPrint) / 1000000) > m_intervalPrintMs;

updateList(numPoints, ns, m_lSamples);
updateList(numPoints, ns, m_mDeviceSamples[indexDevice]);

if (bPrint) {
Expand All @@ -44,10 +43,6 @@ void Speed::update(const unsigned int numPoints, const unsigned int indexDevice)
}
}

double Speed::getSpeed() const {
return this->getSpeed(m_lSamples);
}

double Speed::getSpeed(const unsigned int indexDevice) const {
return m_mDeviceSamples.count(indexDevice) == 0 ? 0 : this->getSpeed(m_mDeviceSamples.at(indexDevice));
}
Expand All @@ -70,20 +65,21 @@ void Speed::updateList(const unsigned int & numPoints, const long long & ns, sam
l.push_back(samplePair(ns, numPoints));

// Pop old samples until time difference between first and last element is less than or equal to m_sampleSeconds
// We don't need to check size of m_lSamples since it's always >= 1 at this point
while (l.size() > 2 && (l.back().first - l.front().first) / 1000000 > m_intervalSampleMs) {
l.pop_front();
}
}

void Speed::print() const {
const std::string strVT100ClearLine = "\33[2K\r";
std::cout << strVT100ClearLine << "Speed: " << formatSpeed(this->getSpeed());

double totalSpeed = 0.0;
std::ostringstream oss;
// std::map is sorted by key so we'll always have the devices in numerical order
for (auto it = m_mDeviceSamples.begin(); it != m_mDeviceSamples.end(); ++it) {
std::cout << " GPU" << it->first << ": " << formatSpeed(this->getSpeed(it->second));
const double speed = this->getSpeed(it->second);
totalSpeed += speed;
oss << " GPU" << it->first << ": " << formatSpeed(speed);
}

std::cout << "\r" << std::flush;
const std::string strVT100ClearLine = "\33[2K\r";
std::cout << strVT100ClearLine << "Speed: " << formatSpeed(totalSpeed) << oss.str() << "\r" << std::flush;
}
2 changes: 0 additions & 2 deletions Speed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Speed {
void update(const unsigned int numPoints, const unsigned int indexDevice);
void print() const;

double getSpeed() const;
double getSpeed(const unsigned int indexDevice) const;

private:
Expand All @@ -31,7 +30,6 @@ class Speed {

long long m_lastPrint;
mutable std::recursive_mutex m_mutex;
sampleList m_lSamples;
std::map<unsigned int, sampleList> m_mDeviceSamples;
};

Expand Down