Skip to content
class

SchemaGuard

SchemaGuard

Combined determinism + AMP dtype-resolution guard.

Constructed once at the top of an op's dispatch routine. The constructor performs both checks; subsequent code reads the resolved dtype via effective_dtype.

Inside an autocast scope the guard is an RAII scope: autocast stays off on the op's device until the guard is destroyed, so it must live as long as the op's body. Outside one it owns nothing.

See Also

check_schema_determinism — determinism-only variant.

Examples

.. code-block:: cpp
    // Inside a forward op
    SchemaGuard guard(MyOp::schema_v1, input->dtype(), input->device());
    const Dtype dt = guard.effective_dtype();
    auto out = backend->allocate(out_shape, dt);
    dispatch_kernel(input, out, dt);

Constructors

1
ctor

SchemaGuard

void SchemaGuard(const OpSchema & schema, Dtype input_dtype, Device device)

Constructs the guard and runs both gates.

Parameters

schemaconst OpSchema&
Static metadata for the op being dispatched.
input_dtypeDtype
The dtype of the op's primary input — the starting point for AMP dtype resolution.
deviceDevice, default= Device::CPU
The device on which the op will execute. Selects the table's column, and applies the CPU-F16 → F32 demotion rule under AmpPolicy::Promote, since Accelerate has no native F16 path.

Raises

LucidError
Thrown when the op is non-deterministic and the global deterministic mode is active. See check_schema_determinism for the exact message format.

Operators

1
op

operator=

SchemaGuard & operator=(const SchemaGuard &)

Methods

1
fnconst

effective_dtype

→Dtype
Dtype effective_dtype()

Returns the dtype that the op should use for its computation.

May differ from the input_dtype passed at construction when AMP is active and the op's policy on the device is Promote (returns the autocast dtype, possibly demoted on CPU) or ForceFP32 (returns Dtype::F32). Equals input_dtype for KeepInput / PromoteWidest and when AMP is not active.

Returns

Dtype

The effective compute dtype for the op.

Notes

Marked noexcept — purely a field read, no allocations or exceptions.