Metrics to measure energy of a code
Measuring the carbon footprint of code will depend where and when it is run. For a given server (or cloud VM) we can determine the energy consumed and then compare to other implementations to see which uses the least energy. (And then run when the electricity is greenest.) The energy consumed by the hardware includes consumption by the CPU/GPU and RAM but also fans, disks etc and will relate to the efficiency of the software (on that hardware configuration).
To determine the energy consumption of a code, we need to bear in mind that it will not be running in isolation. For example, when a weather simulation is running on a Linux or Windows PC, the operating system (and perhaps are applications) are also active and potentially consuming energy. Many tools are available to measure the system energy but that includes all running processes. Therefore it is important to reduce as many running processes as possible and recommended to do a small number of measurements. You can then take the minimum of these as the best indicator of the energy consumed by the code you are interested in. (The other, higher, measurements will most likely be the energy consumed not just by your code but also by (e.g.) the operating system doing a background task.) There are several tools available to measure (or estimate) energy consumption
RAPL
RAPL (Running average power limit) is a power management tool developed by Intel. Key features include, power monitoring for individual parts, real time control and power capping. This allows users to manage their operational costs and environmental impact
9:13 – temp has impact on power consumption
coefficient between Haswell’s package reading and temperature is 0.93 and the same for Skylake is 0.34. The high correlation coefficient for Haswell suggests that in case of Haswell temperature can have a measurable impact on the package power consumption and thus it is important to take the temperature of the system into account while measuring power using RAPL.
CPU temperature can influence the CPU package power draw. To obtain accurate RAPL power readings it would be good to warm up the CPU before obtaining any RAPL measurements.
9:14 – metering device unable to capture measurements
metering device was unable to capture the distinct phases as the phases changed faster than the metering device’s frequency. RAPL could actually capture the phase changes at a 5ms sampling frequency (RAPL can be sampled in 1ms frequency).
Read more about RAPL...
https://www.green-coding.io/case-studies/rapl-and-sgx/
Tools and framework
By using a power meter between the device and supply, a complete amount of energy can be measured including additional resources like cooling. Issues arise from other applications that may be running on the system will also influence this number.
Intel power gadget is a software tool for measuring an intel processors power consumption, it can provide real-time data and the ability to log results making it easy for developers to track how much power their system is using. The downside to this is that it is limited to intel processors and will not measure any other hardware like memory or storage.
Intel PCM (Performance Counter Monitor). On top of other features, this toolset can measure power consumption of individual parts of the CPU and report the energy usage.
Nvidia-SMI (NVIDIA System Management Interface) is a command line utility that can measure power consumption, usage and temperature, with the added ability to control power usage and set power limits. Constraints include this only working with Nvidia products and it’s less user friendly command line interface.
Free applications available to measure if above are limited
Example calculation:
When running code for 2 hours with the device consumed 265w (measured with power meter).
Energy = 0.265kW × 2 hours = 0.53kWh
Assume the carbon intensity of the electricity is 500 g CO2/kWh.
Carbon Emissions = 0.53kWh x 500g CO2/kWh = 265g CO2
https://developer.nvidia.com/system-management-interface
Further research
Intel SoC watch
https://www.intel.com/content/www/us/en/developer/tools/oneapi/system-bring-up-toolkit.html
Intel advisor
https://www.intel.com/content/www/us/en/developer/tools/oneapi/advisor.html
------------------
- See overview in Bane et al (2023), with some updates in Bane and Kibats (2024), covering use of RAPL (including on AMD chips), nvidia-smi and AMD/Xilinx FPGA counters.
- LIWKID
- nvidia-smi: gives instantaneous power draw of NVIDIA GPUs. Integrate over time to get energy consumed. NB: should include host (CPU) energy too
- RAPL gives energy of CPU + RAM (since boot)
Ideally energy would be power source side of PSE (transformer) in order to fully capture energy consumed (CPU+RAM but also fans, disks, circuit boards etc)
References
Bane, M.K., Brown, O., Ali, T., Bhowmik, D., Quinn, J., and Stansby, D. "ENERGETIC: Final Report v1.1" (March 2023).
Available at:
https://e-space.mmu.ac.uk/631671/ [Accessed on 25th September 2024]
Bane, M.K, and Kibats, A. "Errata to ENERGETIC: Final Report". (Jan 2024)
Available at:
https://e-space.mmu.ac.uk/633614/ [Accessed on 25th September 2024]