Skip to content
Snippets Groups Projects
Commit 848262b4 authored by Elizabeth's avatar Elizabeth
Browse files

Added check to see if code is run on Jetson board

parent 68632c71
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,11 @@ private: ...@@ -65,6 +65,11 @@ private:
const std::string ddr_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0041/iio_device/in_power2_input"; const std::string ddr_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0041/iio_device/in_power2_input";
const std::string soc_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0040/iio_device/in_power1_input"; const std::string soc_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0040/iio_device/in_power1_input";
const std::string sys_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0041/iio_device/in_power0_input"; const std::string sys_power_rail = "/sys/devices/3160000.i2c/i2c-0/0-0041/iio_device/in_power0_input";
// Critical assumption: If this file doesn't exist, then the board isn't a Jetson
const std::string jetson_chip_id = "/sys/module/tegra_fuse/parameters/tegra_chip_id";
// True if running on Jetson, else false
bool on_jetson_;
// An individual power reading // An individual power reading
struct PowerReading { struct PowerReading {
......
#include "profiler.h" #include "profiler.h"
Profiler::Profiler() : should_run_profiler_(false), should_stop_profiler_(false) { Profiler::Profiler() : should_run_profiler_(false), should_stop_profiler_(false) {
// Open all streams. Not done in start_profiler() function bc the streams // Open all streams. Not done in start_profiler() function bc the streams
...@@ -9,8 +9,14 @@ Profiler::Profiler() : should_run_profiler_(false), should_stop_profiler_(false) ...@@ -9,8 +9,14 @@ Profiler::Profiler() : should_run_profiler_(false), should_stop_profiler_(false)
soc_stream_.open(soc_power_rail, std::ifstream::in); soc_stream_.open(soc_power_rail, std::ifstream::in);
sys_stream_.open(sys_power_rail, std::ifstream::in); sys_stream_.open(sys_power_rail, std::ifstream::in);
if (!cpu_stream_.is_open() || !gpu_stream_.is_open() || !ddr_stream_.is_open() // Check if the jetson file id file exists to indirectly check architecture
|| !soc_stream_.is_open() || !sys_stream_.is_open()) { std::ifstream jetson_file(jetson_chip_id);
on_jetson_ = jetson_file.good();
if (on_jetson_ &&
(!cpu_stream_.is_open() || !gpu_stream_.is_open()
|| !ddr_stream_.is_open() || !soc_stream_.is_open()
|| !sys_stream_.is_open())) {
std::cout << "Failed to open one of the power rails for reading\n"; std::cout << "Failed to open one of the power rails for reading\n";
exit(1); exit(1);
} }
...@@ -68,16 +74,23 @@ void Profiler::pause_profiler() { ...@@ -68,16 +74,23 @@ void Profiler::pause_profiler() {
// Returns this as a pair of <delta time in milliseconds, energy> // Returns this as a pair of <delta time in milliseconds, energy>
std::pair<double, double> Profiler::get_time_energy() const { std::pair<double, double> Profiler::get_time_energy() const {
double total_energy = 0.0; double total_energy = 0.0;
double delta_time = 0.0;
std::chrono::time_point<std::chrono::high_resolution_clock> prev_time = start_time_;
for (auto reading : power_readings_) { if (on_jetson_) {
std::chrono::duration<double> duration = reading.time_ - prev_time; std::chrono::time_point<std::chrono::high_resolution_clock> prev_time = start_time_;
total_energy += reading.gpu_ * duration.count(); for (auto reading : power_readings_) {
total_energy += reading.ddr_ * duration.count(); std::chrono::duration<double> duration = reading.time_ - prev_time;
prev_time = reading.time_; total_energy += reading.gpu_ * duration.count();
total_energy += reading.ddr_ * duration.count();
prev_time = reading.time_;
}
delta_time = std::chrono::duration<double, std::milli>(prev_time
- start_time_).count();
} else {
auto last_reading_time = power_readings_[power_readings_.size() - 1].time_;
delta_time = std::chrono::duration<double, std::milli>(last_reading_time
- start_time_).count();
} }
double delta_time = std::chrono::duration<double, std::milli>(prev_time
- start_time_).count();
return std::make_pair(delta_time, total_energy); return std::make_pair(delta_time, total_energy);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment