Skip to content
class

OutOfMemory

extendsLucidError
OutOfMemory

Thrown when an allocation request cannot be satisfied by the device allocator.

The exception captures the failed request size together with the current and peak usage counters tracked by MemoryTracker for the offending device, so callers (or end-users reading the Python traceback) can distinguish OOM caused by absolute size from OOM caused by fragmentation. Mapped to lucid._C.engine.OutOfMemory on the Python side.

Parameters

requested_bytesstd::size_t
Number of bytes the allocator was asked to provide.
current_bytesstd::size_t
Live (in-use) bytes on the device immediately before the failed request.
peak_bytesstd::size_t
High-water-mark of bytes ever observed in-use on the device since the tracker was last reset.
devicestd::string
Human-readable device label (e.g. "cpu", "metal:0").

Attributes

requested_bytes_std::size_t
Stored copy of the failed request size.
current_bytes_std::size_t
Stored copy of the live byte count.
peak_bytes_std::size_t
Stored copy of the peak byte count.
device_std::string
Stored copy of the device label.

Examples

```
throw OutOfMemory(1ull << 30, current, peak, "metal:0");
```

Constructors

1
ctor

OutOfMemory

void OutOfMemory(int requested_bytes, int current_bytes, int peak_bytes, int device)

Construct an OutOfMemory error from the failed allocation size, the tracker's current/peak usage at the moment of failure, and the offending device label. All four arguments are formatted into the human-readable what() message so end-users can distinguish absolute-size OOM from fragmentation-induced OOM.

Methods

4
fnconst

current_bytes

→std::size_t
int current_bytes()

Returns the live byte count at the time of failure.

Returns

std::size_t

Bytes already in-use on the device when the allocator failed.

fnconst

device

→const std::string&
const int & device()

Returns the device label where the allocation was attempted.

Returns

const std::string&

Reference to the stored device string. Lifetime is tied to *this.

fnconst

peak_bytes

→std::size_t
int peak_bytes()

Returns the peak byte count observed on the device.

Returns

std::size_t

The high-water mark recorded by the memory tracker.

fnconst

requested_bytes

→std::size_t
int requested_bytes()

Returns the number of bytes that the failed allocation requested.

Returns

std::size_t

The original requested_bytes argument.