SMART-Dal / codegreen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Codegreen

Codegreen is a Python package and CLI tool for energy profiling of Python code. It allows measuring the energy consumption of Deep learning framework APIs like TensorFlow.

Prerequisites

Codegreen requires the following hardware:

  • Intel processor
  • NVIDIA GPU

The Intel processor is needed for accessing the RAPL power sensors. An NVIDIA GPU is required for profiling GPU usage via nvidia-smi.

Make sure to add your respective local paths to the following files after installation:

  • codegreen/fecom/patching/patching_config.py
  • codegreen/fecom/measurement/measurement_config.py

Installation

pip install codegreen

Or install from source:

git clone https://github.com/user/codegreen
cd codegreen
pip install .

Usage

As a CLI

Run codegreen --help to see the CLI options:

Usage: codegreen [OPTIONS] COMMAND [ARGS]...                              
                                                                          
๐Ÿƒ CodeGreen: Your Passport to a Greener Code! ๐Ÿƒ                         
                                                                          
โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --install-completion        [bash|zsh|fish|power    Install completion   โ”‚
โ”‚                              shell|pwsh]            for the specified    โ”‚  
โ”‚                                                      shell.             โ”‚
โ”‚ --show-completion           [bash|zsh|fish|power    Show completion for  โ”‚
โ”‚                              shell|pwsh]            the specified shell, โ”‚
โ”‚                                                      to copy it or       โ”‚
โ”‚                                                      customize the       โ”‚
โ”‚                                                      installation.       โ”‚
โ”‚ --help                                              Show this message andโ”‚
โ”‚                                                      exit.               โ”‚  
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ project-patcher            Patch scripts for measurement โ”‚
โ”‚ run-energy-profiler        Start measurement server โ”‚   
โ”‚ start-energy-measurement   Run patched scripts and collect data โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Basic usage:

codegreen project-patcher --project myscripts/

Patch all Python scripts in myscripts/ for instrumentation. Patched projects are saved with a _patched suffix.

codegreen run-energy-profiler

This will start the energy measurement server.

codegreen start-energy-measurement --project repo_dir --scripts script_to_run --iterations "5"

This will run the patched scripts for project repo_dir, scripts script_to_run and number of run iterations n and collect power usage data. Save the energy profiles and execution logs under experiments/.

As a Python package

import codegreen

codegreen.profile(my_function)

See the API documentation for more details.

Code Structure

  • codegreen/: Source code
    • main.py: Main CLI entry point
    • fecom/: Core measurement functionality
      • patching/: Code instrumentation
      • measurement/: Measurement and output
      • experiment/: Experimental configurations
    • utils/: utility functions

License

codegreen is licensed under the Apache 2.0. See LICENSE for more details.

About

License:Apache License 2.0


Languages

Language:Python 100.0%