Skip to content
class

OpScopeFull

OpScopeFull

Composite RAII guard activating both error-context annotation and profiler timing for the duration of an op's body.

Holds an ErrorContextGuard (constructed first, destroyed last) and an OpScope (constructed second, destroyed first) as members. Construction pushes the op name onto the error stack and starts the profiler timer; destruction first stops the profiler (recording the event) and then pops the error frame. This ordering ensures the error frame is still active if the profiler's record call itself throws.

See Also

OpScope — timing-only RAII (no error context). ErrorContextGuard — error-context-only RAII (no timing).

Attributes

Pushes name onto the thread-local error call-stack at construction; pops it on destruction. Declared first so it outlives op_.
Wall-clock and memory-tracking RAII recorder. Declared second so it is destroyed first, while ctx_ is still on the stack.

Notes

Non-copyable and non-movable — both member guards hold thread-local state whose correct LIFO nesting depends on stack-discipline construction and destruction. Copying or moving the composite would either duplicate the error frame or move it out from under the inner scope.

Examples

Declare once at op entry::
    auto matmul(TensorPtr a, TensorPtr b) {
        OpScopeFull scope("matmul", a->device(), a->dtype(),
                          {a->shape()[0], b->shape()[1]});
        scope.set_flops(2LL * M * N * K);
        // ... kernel body — any error here carries "matmul" in its
        // context; the OpEvent records the full body's time.
    }

Constructors

1
ctor

OpScopeFull

void OpScopeFull(int name, Device device, Dtype dtype, int shape)

Pushes name onto the error-context stack and starts an OpScope for (name, device, dtype, shape).

Parameters

namestd::string_view
Op name; used both as the error-context frame label and the OpEvent::name field.
deviceDevice
Device on which the op is executing.
dtypeDtype
Output element dtype.
shapeShape
Output shape; moved into the underlying OpScope.

Notes

Both guards are torn down when the composite object goes out of scope. The profiler-side teardown happens first; the error-context teardown second.

Operators

1
op

operator=

OpScopeFull & operator=(const OpScopeFull &)

Methods

2
fn

set_attr

void set_attr(int key, int value)

Attach a single attribute to the trace's most recently recorded OpNode when a Tracer is installed; a no-op otherwise.

Used by op forwards to thread emitter context (permutation, axis, stride, padding, eps, …) that the MPSGraph builder would be unable to recover from input + output shapes alone.

Parameters

keystd::string_view
Attribute name. Convention: snake_case, matches the reference-framework keyword argument when one exists.
valuecompile::AttributeValue
Payload (variant over int64/vector<int64>/double/bool/string). Moved into the attribute map.

Notes

Outside any _tracing() scope this is a single TLS load + null check; no allocations. Cheap enough to put unconditionally at every op forward that has shape-invisible parameters.

fn

set_flops

void set_flops(int f)

Forwards the FLOPs estimate to the underlying OpScope.

See Also

OpScope::set_flops — receiver of the forwarded value.

Parameters

fint64_t
Estimated floating-point operations performed by the op body. Stored on the pending OpEvent for later aggregation.