18.2. Contexts

popxl.context

alias of <module ‘popxl.context’ from ‘/home/docs/checkouts/readthedocs.org/user_builds/graphcore-popxl-user-guide/checkouts/3.1.0/python/popxl/context.py’>

popxl.context.gcg()

Get the current graph from the current context.

The function gcg() is available as an alias of get_current_graph().

Raises

RuntimeError – If the stack is empty.

Returns

The last graph that was used as a context scope.

Return type

Graph

popxl.context.get_current_graph()

Get the current graph from the current context.

The function gcg() is available as an alias of get_current_graph().

Raises

RuntimeError – If the stack is empty.

Returns

The last graph that was used as a context scope.

Return type

Graph

popxl.context.get_main_graph()

Get the main graph from the current context.

The function gmg() is available as an alias of get_main_graph().

Raises

RuntimeError – If the stack is empty.

Returns

The main graph.

Return type

Graph

popxl.context.gmg()

Get the main graph from the current context.

The function gmg() is available as an alias of get_main_graph().

Raises

RuntimeError – If the stack is empty.

Returns

The main graph.

Return type

Graph

popxl.context.in_sequence(mode=True)

Force ops created in this context to execute in the order that they are created.

This is achieved by adding topological constraints to the scheduling graph.

Parameters

mode (Union[bool, Literal['pass']]) –

  • True: Ensure each op within the context is executed in a linear schedule in the same order as created.

  • False: Do not apply linear schedule constraint. If nested within an outer in_sequence(True) context, the inner context as a whole will be scheduled linearly with respect to ops in the outer context. For example:

    with in_sequence(True):
        OpA()
        with in_sequence(False):
            OpB()
            OpC()
        OpD()
    

    OpA will be executed before OpB and OpC.

    OpD will be executed after OpB and OpC.

  • 'pass': Do nothing when an op is created. Useful for transforms that want to delay adding topological constraints to the graph.

Raises

TypeError – If None is passed to mode.

popxl.context.io_tiles()

Execute ops created in this context on IO tiles of the current IPU.

popxl.context.ipu(ipu)

Set the IPU for ops created in this context.

Parameters

ipu (int) –

popxl.context.name_scope(name)

Set the name scope for ops created in this context.

Parameters

name (str) –

popxl.context.op_debug_context(name: str) Callable[[Fn], Fn]
popxl.context.op_debug_context(name: Fn) Fn

Specify a new op debug context.

Commonly used as decorator.

Typical usage:

@op_debug_context
def add(lhs, rhs):
    ...

Or, to specify the context name:

@op_debug_context("op")
def my_op(x):
    ...