Deeploy.DeeployTypes.NetworkContext

class Deeploy.DeeployTypes.NetworkContext(variableBuffer: Type[VariableBuffer], constantBuffer: Type[ConstantBuffer], structBuffer: Type[StructBuffer], transientBuffer: Type[TransientBuffer], globalObjects={}, localObjects={}, name: str = 'DeeployNetwork')

Bases: object

The global context of the compiler. This object holds all the typing inferred in the type-checking passes within the respective buffers. It holds all hoisted transient buffers, struct buffers, and global definitions. The context is the source of truth for all code generation in the backend.

Methods

__init__(variableBuffer: Type[VariableBuffer], constantBuffer: Type[ConstantBuffer], structBuffer: Type[StructBuffer], transientBuffer: Type[TransientBuffer], globalObjects={}, localObjects={}, name: str = 'DeeployNetwork')

__init__(variableBuffer, constantBuffer, ...)

add(obj[, ctxt, _id])

Adds a VariableBuffer object to the NetworkContext

addUser(name, node)

Adds an operator's name to the _user list of a VariableBuffer in the context

annotateType(name, _type)

Annotates a Deeploy-type pointer on the _type field of a VariableBuffer

copy()

Return a shallow copy of this NetworkContext

dealiasBuffer(referenceName)

Function to unravel reference instantiated in _ReferenceBuffer objects until the underlying VariableBuffer's name is returned

exportNetworkContext(folderPath, fileName)

Exports the NetworkContext as a pickled dictionary

hoistConstant(node[, name, _type])

Register a ConstantBuffer extracted directly from a graphsurgeon Node

hoistConstantAndReference(constBuf, pointerType)

Helper function to hoist a new ConstantBuffer and a _ReferenceBuffer to it.

hoistGlobalDefinition(name, definition)

Registers a new GlobalDefinition in the global context

hoistReference(_reference, name)

Helper function to register a _ReferenceBuffer to preexisting VariableBuffer

hoistStruct(_struct, name, _type)

Register a Struct with the local context

hoistTransientBuffer(name, size)

Registers a new TransientBuffer in the local context

importNetworkContext(folderPath, fileName)

Imports a pickled NetworkContext that was saved using exportNetworkContext

is_global(name)

Checks whether a name is associated with a global buffer

is_local(name)

Checks whether a name is associated with a local buffer

lookup(name[, _id])

Returns the VariableBuffer or GlobalDefinition registered under a given name

dealiasBuffer(referenceName: str) str

Function to unravel reference instantiated in _ReferenceBuffer objects until the underlying VariableBuffer’s name is returned

Parameters:

referenceName (str) – Name of the _ReferenceBuffer to unravel

Returns:

Name of the original VariableBuffer that was referenced

Return type:

str

Raises:

Exception – Raises an Exception if references are circular, i.e. there is no underlying VariableBuffer

exportNetworkContext(folderPath: str, fileName: str)

Exports the NetworkContext as a pickled dictionary

Parameters:
  • folderPath (str) – Path to the location where this pickled context should be saved

  • fileName (str) – Name of the pickled context file

Raises:

OSError – Raises an OSError if the path is not valid

static importNetworkContext(folderPath, fileName)

Imports a pickled NetworkContext that was saved using exportNetworkContext

Parameters:
  • folderPath (str) – Path to the location where the pickled context is stored

  • fileName (str) – Name of the pickled context file

Raises:

OSError – Raises in OSError if the pickled context file does not exist

add(obj: VariableBuffer, ctxt: str = 'local', _id: str = '')

Adds a VariableBuffer object to the NetworkContext

Parameters:
  • obj (VariableBuffer) – The VariableBuffer object to be registered

  • ctxt (str) – Level of the NetworkContext to register the VariableBuffer in, either local or global

  • _id (str) – Override for the registration name of the VariableBuffer. Do not use unless you have a good reason!

Raises:
  • ValueError – Raises a ValueError if ctxt is not local or global

  • KeyError – Raises a KeyError if the VariableBuffer’s name is already registered within the NetworkContext

lookup(name: str, _id: str = '') VariableBuffer | GlobalDefinition

Returns the VariableBuffer or GlobalDefinition registered under a given name

Parameters:
  • name (str) – Name of the VariableBuffer to look up

  • _id (str) – Override for the registration name of the VariableBuffer. Do not use unless you have a good reason!

Returns:

Registered buffer object

Return type:

Union[VariableBuffer, GlobalDefinition]

Raises:

KeyError – Raises a KeyError if the name does not match with any registered object

is_global(name: str) bool

Checks whether a name is associated with a global buffer

Parameters:

name (str) – Name of the VariableBuffer to check for

Returns:

Returns true if the name matches with any global buffer

Return type:

bool

is_local(name: str) bool

Checks whether a name is associated with a local buffer

Parameters:

name (str) – Name of the VariableBuffer to check for

Returns:

Returns ture if the name matches with any local buffer

Return type:

bool

hoistTransientBuffer(name: str, size: int) str

Registers a new TransientBuffer in the local context

Parameters:
  • name (str) – Name of the TransientBuffer to register

  • size (int) – BYTE size of the TransientBuffer to register

Returns:

On success, return the name of the registered buffer

Return type:

str

hoistGlobalDefinition(name: str, definition: str) None

Registers a new GlobalDefinition in the global context

Parameters:
  • name (str) – Name of the GlobalDefinition to register

  • definition (str) – Program code of the GlobalDefinition

hoistStruct(_struct: Dict[str, BaseType] | Struct, name: str, _type: Type[Struct]) str

Register a Struct with the local context

Parameters:
  • _struct (Union[Dict[str, BaseType], Struct]) – Struct object or Struct object’s definition

  • name (str) – Name to register the struct under

  • _type (Type[Struct]) – Type definition of the Struct class to register

Returns:

On success, return the name of the registered buffer

Return type:

str

hoistConstantAndReference(constBuf: ConstantBuffer, pointerType: Type[Pointer]) str

Helper function to hoist a new ConstantBuffer and a _ReferenceBuffer to it. Mostly used in tiling to create boilerplate for tiled variables.

Parameters:
  • constBuf (ConstantBuffer) – ConstantBuffer to hoist

  • pointerType (Type[Pointer]) – Pointer class to assign to the constant buffer

Returns:

name of the registered _ReferenceBuffer

Return type:

str

hoistReference(_reference: str, name: str) str

Helper function to register a _ReferenceBuffer to preexisting VariableBuffer

Parameters:
  • _reference (str) – Name of the VariableBuffer that should be referenced

  • name (str) – Name of the _ReferenceBuffer that should be registered

Returns:

Returns the name of the newly registered _ReferenceBuffer

Return type:

str

hoistConstant(node: Node, name: str = '', _type: Type[Pointer] | None = None) str

Register a ConstantBuffer extracted directly from a graphsurgeon Node

Parameters:
  • node (gs.Node) – graphsurgeon.Node containing a single constant output

  • name (str) – Name of the ConstantBuffer to be registered

  • _type (Optional[Type[Pointer]]) – Optional type assignment of the registered ConstantBuffer

Returns:

Returns the name of the newly registed ConstantBuffer

Return type:

str

addUser(name: str, node: Node)

Adds an operator’s name to the _user list of a VariableBuffer in the context

Parameters:
  • name (str) – Name of the VariableBuffer that gets used by the node

  • node (gs.Node) – graphsurgeon Node of the operator

annotateType(name: str, _type: Type[Pointer])

Annotates a Deeploy-type pointer on the _type field of a VariableBuffer

Parameters:
  • name (str) – Name of the VariableBuffer to annotate

  • _type (Type[Pointer]) – Type of the Deeploy-type pointer to annotate the VariableBuffer with

copy() NetworkContext

Return a shallow copy of this NetworkContext