← Back

Module energy

struct Joules(pub f64);

Source: energy.joule:18

const ZERO: Joules

Source: energy.joule:21

fn from_millijoules(mj: f64) -> Self

Create from millijoules

Source: energy.joule:24

fn from_microjoules(uj: f64) -> Self

Create from microjoules

Source: energy.joule:29

fn from_watt_seconds(ws: f64) -> Self

Create from watt-seconds (equivalent to joules)

Source: energy.joule:34

fn as_millijoules(&self) -> f64

Convert to millijoules

Source: energy.joule:39

fn as_kwh(&self) -> f64

Convert to kilowatt-hours (for large-scale training)

Source: energy.joule:44

fn estimated_co2_kg(&self, carbon_intensity: f64) -> f64

Estimate CO2 emissions (kg) assuming average grid intensity Default: 0.5 kg CO2 per kWh (varies by region)

Source: energy.joule:50

fn add(self, other: Joules) -> Joules

Source: energy.joule:57

fn add_assign(&mut self, other: Joules)

Source: energy.joule:63

fn sub(self, other: Joules) -> Joules

Source: energy.joule:70

fn mul(self, scalar: f64) -> Joules

Source: energy.joule:77

fn div(self, scalar: f64) -> Joules

Source: energy.joule:84

struct Watts(pub f64);

Source: energy.joule:91

const ZERO: Watts

Source: energy.joule:94

fn as_milliwatts(&self) -> f64

Convert to milliwatts

Source: energy.joule:97

fn as_kilowatts(&self) -> f64

Convert to kilowatts

Source: energy.joule:102

fn energy_over(&self, duration: Duration) -> Joules

Energy consumed over duration

Source: energy.joule:107

struct EnergyMetrics

Source: energy.joule:118

fn new() -> Self

Create new metrics

Source: energy.joule:150

fn compute_efficiency(&mut self)

Compute derived efficiency metrics

Source: energy.joule:172

fn merge(&mut self, other: &EnergyMetrics)

Merge with another metrics instance (accumulate)

Source: energy.joule:192

fn summary(&self) -> String

Create summary string

Source: energy.joule:213

fn default() -> Self

Source: energy.joule:233

struct CostModel

Cost model for estimating energy consumption of operations

Source: energy.joule:243

struct DeviceCostParams

Source: energy.joule:256

fn cpu_default() -> Self

Parameters for CPU (approximate Intel/AMD desktop)

Source: energy.joule:290

fn gpu_a100() -> Self

Parameters for GPU (approximate NVIDIA A100)

Source: energy.joule:306

fn apple_npu() -> Self

Parameters for Apple M-series NPU

Source: energy.joule:322

fn tpu_v4() -> Self

Parameters for TPU v4

Source: energy.joule:338

struct OpCost

Source: energy.joule:356

fn new(device_params: DeviceCostParams) -> Self

Create cost model for device

Source: energy.joule:375

fn init_default_costs(&mut self)

Initialize default operation costs

Source: energy.joule:387

fn estimate(&self, op_name: &str, numel: usize, extra_dims: &[usize]) -> Joules

Estimate energy for operation

Source: energy.joule:475

fn estimate_matmul(&self, m: usize, n: usize, k: usize) -> Joules

Estimate energy for matmul specifically

Source: energy.joule:509

fn calibrate(&mut self, op_name: &str, predicted: Joules, measured: Joules)

Calibrate model against measured values

Source: energy.joule:526

fn roofline_analysis(&self, op_name: &str, numel: usize) -> RooflineResult

Get roofline analysis for operation

Source: energy.joule:532

struct RooflineResult

Source: energy.joule:565

struct EnergyTracker

Global energy tracker for monitoring ML workloads

Source: energy.joule:579

fn new(device: Device) -> Self

Create new energy tracker

Source: energy.joule:604

fn begin_scope(&self, name: &str)

Begin tracking a named scope

Source: energy.joule:624

fn end_scope(&self) -> Option<EnergyMetrics>

End current scope and record metrics

Source: energy.joule:636

fn record_power(&self, power: Watts)

Record power sample (called by power monitoring thread)

Source: energy.joule:688

fn record_op(&self, op_name: &str, numel: usize, extra_dims: &[usize])

Record operation with estimated energy

Source: energy.joule:699

fn record_measured(&self, energy: Joules)

Record operation with measured energy

Source: energy.joule:708

fn total_energy(&self) -> Joules

Get total energy consumed

Source: energy.joule:716

fn get_scope(&self, name: &str) -> Option<EnergyMetrics>

Get metrics for a scope

Source: energy.joule:721

fn all_scopes(&self) -> HashMap<String, EnergyMetrics>

Get all scope metrics

Source: energy.joule:726

fn reset(&self)

Reset all metrics

Source: energy.joule:731

fn report(&self) -> EnergyReport

Generate report

Source: energy.joule:737

fn check_hw_power_available(device: Device) -> bool

Check if hardware power monitoring is available

Source: energy.joule:756

struct EnergyReport

Source: energy.joule:780

fn print(&self)

Print report to stdout

Source: energy.joule:787

fn to_json(&self) -> String

Export to JSON

Source: energy.joule:802

struct EnergyBudget

Source: energy.joule:826

enum BudgetAction

Source: energy.joule:848

fn new(total: Joules) -> Self

Create new budget

Source: energy.joule:861

fn from_kwh(kwh: f64) -> Self

Create from kWh

Source: energy.joule:873

fn with_epoch_budget(mut self, budget: Joules) -> Self

Set per-epoch budget

Source: energy.joule:878

fn with_step_budget(mut self, budget: Joules) -> Self

Set per-step budget

Source: energy.joule:884

fn on_exceed(mut self, action: BudgetAction) -> Self

Set action on exceed

Source: energy.joule:890

fn consume(&mut self, energy: Joules) -> BudgetStatus

Consume energy from budget

Source: energy.joule:896

fn remaining(&self) -> Joules

Get remaining budget

Source: energy.joule:909

fn consumed_fraction(&self) -> f64

Get fraction of budget consumed

Source: energy.joule:914

fn check_step(&self, step_energy: Joules) -> bool

Check if step is within budget

Source: energy.joule:919

fn reset(&mut self)

Reset budget

Source: energy.joule:927

enum BudgetStatus

Source: energy.joule:934

fn set_energy_tracker(tracker: Arc<EnergyTracker>)

Set energy tracker for current thread

Source: energy.joule:951

fn get_energy_tracker() -> Option<Arc<EnergyTracker>>

Get energy tracker for current thread

Source: energy.joule:958

struct EnergyScope

RAII guard for energy scope

Source: energy.joule:963

fn begin(name: &str) -> Self

Begin new scope

Source: energy.joule:970

fn drop(&mut self)

Source: energy.joule:983

fn with_energy_tracking<F, T>(name: &str, f: F) -> (T, Option<EnergyMetrics>)

Track energy of a closure

Source: energy.joule:999

struct PowerMonitor

Power monitor that samples power in background

Source: energy.joule:1014

fn start(device: Device, tracker: Arc<EnergyTracker>, interval: Duration) -> Self

Start power monitoring for device

Source: energy.joule:1027

fn stop(&mut self)

Stop monitoring

Source: energy.joule:1048

fn drop(&mut self)

Source: energy.joule:1057

fn read_power(device: Device) -> Option<Watts>

Read current power draw for device

Source: energy.joule:1063

fn read_gpu_power(device_idx: u32) -> Option<Watts>

Source: energy.joule:1072

fn nvmlDeviceGetPowerUsage(device: *mut std::ffi::c_void, power: *mut u32) -> i32;

Source: energy.joule:1082

fn read_cpu_power() -> Option<Watts>

Source: energy.joule:1097

fn read_npu_power() -> Option<Watts>

Source: energy.joule:1129

fn read_tpu_power(_device_idx: u32) -> Option<Watts>

Source: energy.joule:1142

fn test_joules_arithmetic()

Source: energy.joule:1156

fn test_cost_model_estimation()

Source: energy.joule:1167

fn test_roofline_analysis()

Source: energy.joule:1178

fn test_energy_budget()

Source: energy.joule:1189