cerebras.elf.cs_elf_runner.cs_elf_runner module¶
Methods and classes needed for cs_elf_runner.
- class cerebras.elf.cs_elf_runner.cs_elf_runner.CSELFRunner(elf_list, cmaddr=None, need_teardown=False, debug_mode=False, rpc_protocol: Optional[str] = 'http', rpc_hostname: Optional[str] = None, rpc_port: Optional[int] = None)¶
Bases:
objectLoads and runs ELFs on the Cerebras system and obtain core file.
Can also run on simfabric locally. Requires CM IP address and port for the Cerebras system runs.
Tensors can be fed into and collected along the kernel edges. The bounding box around all the ELFs represents the kernel.
- Parameters
elf_list – List of ELF filenames.
cmaddr –
'IP_ADDRESS:PORT'string of CM This argument is not needed if running on simfabric.need_teardown – Tells whether the kernel to be run needs the teardown bits to be set on the rectangle of the kernel.
rpc_protocol (optional) – The protocol name as a string.
rpc_hostname (optional) – The hostname as a string.
rpc_port (optional) – The port number.
Example:
runner = CSELFRunner(["a.elf", "b.elf"]) runner.add_input_tensor(2, <iportmap>, my_np_tensor) runner.add_output_tensor(3, <oportmap>, np.uint32) runner.run_on_simfabric()
Here the
<iportmap>and<oportmap>are ISL style maps as strings.iport_map
iport_map : { A[i=0:31, j=0:31] -> [ PE[j//8, -1] -> index[i, j mod 8] ]; x[i=0:31] -> [ PE[i//8, -1] -> index[i mod 8] ]; }
The
iport_mapfor each input is a relation between three types of objects:The tensor elements.
The PE from which they arrive from.
The local index and order.
The extent of each index of the tensor is specified in the first entry, for example,
A[i=0:31, j=0:31].The next part of the relation specifies from which PEs the inputs originate. For example,
PE[j//8, -1]represents that the input is arriving from the row above the first row and the elements are divided up based on thejindex over the 4 PEs.Note
Note that negative indices or indices outside the PE rectangle can be used to denote external PEs from which inputs are being sourced.
The last part of the relation specifies the local index for that PE. For example,
index[i, j mod 8]is a map from global indicesiandjto the local indexiandj mod 8.Note
Note that since each element of the subtensor local to the PE arrives one at a time, this also dictates the order in which those elements arrive.
oport_map
oport_map : { y[i=0:31] -> [PE[4, i//8] -> index[i mod 8]] }
The oport map functions very similar to the iport map. The only difference is that the oport map specifies what PEs the output is sent to and in what order.
In this example the output
ywill arrive on the column after the last column (column index 4).- add_input_tensor(color, iportmap, np_arr, sentinel=None)¶
Add an input tensor.
- Parameters
color – The color on which to send array. Must be unused.
iportmap – The ISL style
iportmapon how to distribute the indices. Can also be a tuple, for example,("WEST", i)describing the default (uniform) distribution on thei-thdimension of the tensor.np_arr – The
numpyndarrayto send to the kernel.sentinel – If sparse, the task_id/color of sentinel task.
- add_output_tensor(color: int, oportmap: Union[str, Tuple[str, str, List[int], int]], dtype: numpy.dtype)¶
Add an output tensor.
- Parameters
oportmap – The ISL style
oportmap. Can also be a tuple(name, side, shape, axis)wherenameis a string name for the tensor,sideis “NORTH”, “SOUTH”, “EAST”, or “WEST” andaxisthe dimension of the tensor along which the output is split.color – The color on which to receive. Must be unused.
dtype – The datatype of the output tensor.
- connect_and_run(**kwargs)¶
- run_on_simfabric(core: Optional[str] = None)¶
Alias to connect_and_run. See documentation for that function.
- cerebras.elf.cs_elf_runner.cs_elf_runner.generate_default_portmap(name: str, shape: List[int], side: str, elf_w: int, elf_h: int, axis: int = 0) str¶
Generates the
defaultInteger Set Library (ISL) style i/o-portmap given a SIDE of the kernel or rectangle to target.The tensor is block-distributed across the SIDE in this
defaultportmap.- Parameters
name – The symbolic name of the tensor for which to generate the map.
shape – The shape of the tensor.
side – One of “NORTH”, “SOUTH”, “EAST”, or “WEST”, representing which edge of the rectangle to target.
elf_w – The width of the target rectangle.
elf_h – The height of the target rectangle.
axis – The dimension of the tensor along which to distribute it.
- Returns
A string representation of the portmap.
- cerebras.elf.cs_elf_runner.cs_elf_runner.get_npad(wlets)¶
Helper function to get number of elements to pad by. Pad receives up to nearest multiple of PAD_FACTOR.
- cerebras.elf.cs_elf_runner.cs_elf_runner.marshall(a: numpy.ndarray) Tuple[xmlrpc.client.Binary, List[int], str]¶
Convert a
numpy.ndarrayinto a format that can be transmitted over XML RPC.
- cerebras.elf.cs_elf_runner.cs_elf_runner.unmarshall(a: Tuple[xmlrpc.client.Binary, List[int], str]) numpy.ndarray¶
Convert a marshalled
numpytensor into anumpy.ndarray.