Skip to content

Instantly share code, notes, and snippets.

@V0XNIHILI
Last active March 16, 2023 10:43
Show Gist options
  • Save V0XNIHILI/2b6fa61edd4c06d9ffce5551065124c1 to your computer and use it in GitHub Desktop.
Save V0XNIHILI/2b6fa61edd4c06d9ffce5551065124c1 to your computer and use it in GitHub Desktop.
Functions to compute energy per operation on a chip
"""Data taken from paper: Computing's Energy Problem (and what we can do about it) - Mark Horowitz
All output energies are in pJ (pico Joule)
"""
import math
E_INT_ADD_PER_BIT = (0.03 / 8 + 0.1 / 32) / 2
def int_add(n_bits: int):
if n_bits == 8:
return 0.03
if n_bits == 32:
return 0.1
return E_INT_ADD_PER_BIT * n_bits
E_INT_MUL_PER_BIT = (0.2 / 8**2 + 3.1 / 32**2) / 2
def int_mul(n_bits: int):
if n_bits == 8:
return 0.2
if n_bits == 32:
return 3.1
return E_INT_MUL_PER_BIT * n_bits**2
E_FP_ADD_PER_BIT = (0.4 / 16 + 0.9 / 32) / 2
def fp_add(n_bits: int):
if n_bits == 16:
return 0.4
if n_bits == 32:
return 0.9
return E_FP_ADD_PER_BIT * n_bits
E_FP_MUL_PER_BIT = (1.1 / 16**2 + 3.7 / 32**2) / 2
def fp_mul(n_bits: int):
if n_bits == 16:
return 1.1
if n_bits == 32:
return 3.7
return E_FP_MUL_PER_BIT * n_bits**2
E_DRAM = (1.3 + 2.6) / 2 * 1000
E_CACHE = (10 / math.sqrt(8) + 20 / math.sqrt(32) + 100 / math.sqrt(1000)) / 3
def memory_access(n_bytes: int, location: str):
"""Assuming 64-bit word size"""
if location == "cache":
return E_CACHE * math.sqrt(n_bytes / 1000)
if location == "DRAM":
return
else:
raise ValueError(f"Unknown location {location}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment