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
name onto the thread-local error call-stack at construction; pops it on destruction. Declared first so it outlives op_.op_OpScopectx_ 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
1OpScopeFull
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_viewOpEvent::name field.deviceDevicedtypeDtypeshapeShapeOpScope.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
1Methods
2Attach 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_viewvaluecompile::AttributeValueNotes
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.
Forwards the FLOPs estimate to the underlying OpScope.
See Also
OpScope::set_flops — receiver of the forwarded value.
Parameters
fint64_tOpEvent for later aggregation.