# tf.contrib.tpu.Topology

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L43-L220) |

Describes a set of TPU devices.

    tf.contrib.tpu.Topology(
        serialized=None, mesh_shape=None, device_coordinates=None
    )

Represents both the shape of the physical mesh, and the mapping between
TensorFlow TPU devices to physical mesh coordinates.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `serialized` | A serialized `TopologyProto`, or `None`. If not `None`, the serialized proto is parsed to discover the topology. |
| `mesh_shape` | A sequence of 3 positive integers, or `None`. If not `None`, the shape of the TPU topology, in number of cores. Ignored if `serialized` is not `None`. |
| `device_coordinates` | A rank 3 numpy array that describes the mapping from TensorFlow TPU devices to TPU fabric coordinates, or `None`. Ignored if `serialized is not`None\`. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `serialized` does not describe a well-formed topology. |
| `ValueError` | If `serialized` is `None` and `mesh_shape` is not a sequence of 3 positive integers. |
| `ValueError` | If `serialized` is `None` and `device_coordinates` is not a rank 3 numpy int32 array that describes a valid coordinate mapping. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `device_coordinates` | Describes the mapping from TPU devices to topology coordinates. |
| `mesh_rank` | Returns the number of dimensions in the mesh. |
| `mesh_shape` | A rank 1 int32 array describing the shape of the TPU topology. |
| `num_tasks` | Returns the number of TensorFlow tasks in the TPU slice. |
| `num_tpus_per_task` | Returns the number of TPU devices per task in the TPU slice. |

<br />

## Methods

### `cpu_device_name_at_coordinates`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L189-L192)

    cpu_device_name_at_coordinates(
        device_coordinates, job=None
    )

Returns the CPU device attached to a logical core.

### `serialized`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L210-L220)

    serialized()

Returns the serialized form of the topology.

### `task_ordinal_at_coordinates`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L163-L174)

    task_ordinal_at_coordinates(
        device_coordinates
    )

Returns the TensorFlow task number attached to `device_coordinates`.

<br />

<br />

<br />

| Args ||
|---|---|
| `device_coordinates` | An integer sequence describing a device's physical coordinates in the TPU fabric. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Returns the TensorFlow task number that contains the TPU device with those physical coordinates. ||

<br />

### `tpu_device_name_at_coordinates`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L194-L198)

    tpu_device_name_at_coordinates(
        device_coordinates, job=None
    )

Returns the name of the TPU device assigned to a logical core.

### `tpu_device_ordinal_at_coordinates`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/tpu/topology.py#L176-L187)

    tpu_device_ordinal_at_coordinates(
        device_coordinates
    )

Returns the TensorFlow device number at `device_coordinates`.

<br />

<br />

<br />

| Args ||
|---|---|
| `device_coordinates` | An integer sequence describing a device's physical coordinates in the TPU fabric. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Returns the TensorFlow device number within the task corresponding to attached to the device with those physical coordinates. ||

<br />