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: object

Loads 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_map for each input is a relation between three types of objects:

  1. The tensor elements.

  2. The PE from which they arrive from.

  3. 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 the j index 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 indices i and j to the local index i and j 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 y will 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 iportmap on how to distribute the indices. Can also be a tuple, for example, ("WEST", i) describing the default (uniform) distribution on the i-th dimension of the tensor.

  • np_arr – The numpy ndarray to 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) where name is a string name for the tensor, side is “NORTH”, “SOUTH”, “EAST”, or “WEST” and axis the 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 default Integer 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 default portmap.

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.ndarray into 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 numpy tensor into a numpy.ndarray.