Python API Reference#
Python API is used to control & access SPU, for example, to do data infeed/outfeed, to compile an XLA program to PPHlo, or to fire a PPHlo on an SPU runtime.
Runtime Setup#
- class spu.Runtime(link: Context, config: RuntimeConfig)[source]#
The SPU Virtual Machine Slice.
- get_var(name: str) bytes [source]#
Get an SPU value.
- Args:
name (str): Id of value.
- Returns:
spu_pb2.ValueProto: Data data.
- get_var_meta(name: str) ValueMeta [source]#
Get an SPU value without content.
- Args:
name (str): Id of value.
- Returns:
spu_pb2.ValueProto: Data with out content.
Runtime IO#
- class spu.Io(world_size: int, config: RuntimeConfig)[source]#
The SPU IO interface.
Convert from NumPy array to list of SPU value(s).
- Args:
x (np.ndarray): input. vtype (spu_pb2.Visibility): visibility. owner_rank (int): the index of the trusted piece. if >= 0, colocation optimization may be applied.
- Returns:
[spu_pb2.ValueProto]: output.
Compiler#
- spu.compile(ir_text: str, ir_type: str, vis: List[spu_pb2.Visibility]) str [source]#
Compile from textual HLO/MHLO IR to SPU bytecode.
- Args:
ir_text (str): textual HLO/MHLO IR protobuf binary format. ir_type (str): “hlo” or “mhlo”. vtype (spu_pb2.Visibility): Visbilities .
- Returns:
[spu_pb2.ValueProto]: output.