Quick Start

Last updated: Oct 10th,2024

CPPJoules - An Energy Measurement Tool for CPP


Tool Description

CPPJoules is a energy measurement tool designed to measure the energy consumption during the execution of a piece of C++ code. CPPJoules leverages the Intel Running Average Power Limit (RAPL) interface, Intel Powergadget, Nvidia Management Library (NVML) for reporting energy consumption of different system-on-chip (SoC) power domains.

Installation & Usage

Requirements

  • Intel processors from the Celeron, Pentium, Core i3, i7, i9, and Xeon series, featuring the Sandy Bridge or newer architecture.
  • Linux distribution Debian based operating system. We have tested on Ubuntu 20.04.6 LTS
  • The g++ compiler version has to be above v11.0.0. Install from here
  • If on Windows, then PowerGadget v3.6 has to installed. Click here to install

Github Repo

Our entire codebase is in this Github repo : https://github.com/rishalab/CPPJoules.git, you can either clone or download it to check it.

git clone https://github.com/rishalab/CPPJoules.git

For installing the CPP Joules follow the below steps.

Direct Installer Link

For Linux

  1. Click here to download CPP Joules for Linux
  2. The file installer.sh will be downloaded.

  3. Now naviagte to the folder where the file installer.sh has been downloaded .Open that folder in you terminal run the command :
    ./installer.sh

    You will be prompted to enter your user password

  4. The library will be installed in /usr/bin
  5. You have to give read 'r' access to the rapl first ,run this code :
    sudo chmod +r -R /sys/class/powercap/
  6. Check g++ version by running this code:
    g++ --version
  7. If the version is less than v11.0 then run the below code :

    sudo apt update
    sudo apt install g++-13
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 60
    sudo update-alternatives --config g++
  8. Now create a test.cpp file and copy the below test code :
  9. //test.cpp
    #include<cppjoules>
    #include<iostream>

    int main(){
        EnergyTracker tracker;
        tracker.start();
        //API Call
        tracker.stop();
        tracker.calculate();
        tracker.print_energy();
        return 0;
    }
  10. Now compile the code with this code :
    g++ test.cpp -lCPP_Joules
  11. And run it
    ./a.exe
  12. You will get the output as :
    To be written

For Windows

  1. Click here to download CPP Joules for Windows
  2. The file installer.bat will be downloaded.

  3. Right click on the installer.bat file and click run as administrator.
  4. The folder cppJoules will be created.
  5. Now place this cppJoules folder in the same location where your cpp file is present.
  6. Example :
    • Create a folder testCPPJoules and place the above cppJoules folder within it.
    • Now create a test.cpp file within the folder testCPPJoules .
    • Now you can directly use the header in your cpp file
    //test.cpp
    #include"cppJoules/include/cppJoules.h"
    #include<iostream>

    int main(){
        EnergyTracker tracker;
        tracker.start();
        //API Call
        tracker.stop();
        tracker.calculate();
        tracker.print_energy();
        return 0;
    }
  7. Now compile the file with this command :
    g++ test.cpp -lCPP_Joules -L./cppJoules
  8. Then run the executable :
    ./a.exe
  9. The output
    GT
    IT
    DRAM
    Time consumed :

    Note : The g++ compiler version has to be above v11.0.0. Install from here
    Note : If PowerGadget v3.6 is not present, then install from here


Approach diagram

  • Measurement of Energy

    CPPJoules leverages Intel's RAPL and NVIDIA's NVML libraries to measure energy consumption for both the CPU and GPU components. For CPU energy measurement, the tool utilizes Intel's RAPL interface, which provides detailed energy traces data across various domains, including the CPU package, core, uncore, and DRAM. This is achieved through the Powercap interface on Linux and Intel Power Gadget on Windows.

    elegant icons

Code snippet screenshot

  1. Test code for array concatenation ( in linux )

    screenshot
  2. Test code for bubble sort ( in linux )

    elegant icons

Goal

Helping developers and practitioners to develope energy efficient code in C++ language.

Results

The evaluation experiments have been done on a linux machine to compare CPP Joules with Pyjoules Results

Demo Video

Contributors

Person 1, Person 2, Person 3