stormlog.utils

Utility functions for GPU memory profiling.

Functions

check_memory_fragmentation([device])

Check GPU memory fragmentation.

convert_bytes(value, from_unit, to_unit)

Convert between different byte units.

format_bytes(bytes_value[, precision])

Format bytes into human-readable format.

get_gpu_info([device])

Get comprehensive GPU information.

get_system_info()

Get system information relevant to GPU profiling.

memory_summary([device])

Generate a comprehensive memory summary.

suggest_memory_optimization(fragmentation_info)

Suggest memory optimization strategies.

Classes

MemoryContext([name, device])

Context manager for tracking memory usage in a block of code.

stormlog.utils.format_bytes(bytes_value, precision=2)[source]

Format bytes into human-readable format.

Parameters:
  • bytes_value (int) – Number of bytes

  • precision (int) – Decimal precision

Returns:

Formatted string (e.g., “1.25 GB”)

Return type:

str

stormlog.utils.convert_bytes(value, from_unit, to_unit)[source]

Convert between different byte units.

Parameters:
  • value (int | float) – Value to convert

  • from_unit (str) – Source unit (B, KB, MB, GB, TB)

  • to_unit (str) – Target unit (B, KB, MB, GB, TB)

Returns:

Converted value

Return type:

float

stormlog.utils.get_gpu_info(device=None)[source]

Get comprehensive GPU information.

Parameters:

device (str | int | torch.device | None) – GPU device to query (None for current device)

Returns:

Dictionary with GPU information

Return type:

Dict[str, Any]

stormlog.utils.get_system_info()[source]

Get system information relevant to GPU profiling.

Return type:

Dict[str, Any]

stormlog.utils.check_memory_fragmentation(device=None)[source]

Check GPU memory fragmentation.

Parameters:

device (str | int | torch.device | None) – GPU device to check

Returns:

Fragmentation analysis

Return type:

Dict[str, Any]

stormlog.utils.suggest_memory_optimization(fragmentation_info)[source]

Suggest memory optimization strategies.

Parameters:

fragmentation_info (Dict[str, Any]) – Output from check_memory_fragmentation

Returns:

List of optimization suggestions

Return type:

List[str]

stormlog.utils.memory_summary(device=None)[source]

Generate a comprehensive memory summary.

Parameters:

device (str | int | torch.device | None) – GPU device to summarize

Returns:

Formatted memory summary string

Return type:

str

class stormlog.utils.MemoryContext(name='memory_context', device=None)[source]

Bases: object

Context manager for tracking memory usage in a block of code.

Parameters:
  • name (str)

  • device (Optional[Union[str, int, torch.device]])

get_summary()[source]

Get memory usage summary for this context.

Return type:

Dict[str, Any]