:mod:`heat.devices` ======================== .. py:module:: heat.core.devices .. autoapi-nested-parse:: handle different devices. Current options: CPU (default), GPU Module Contents --------------- .. py:class:: Device(device_type: str, device_id: int, torch_device: str) Implements a compute device. Heat can run computations on different compute devices or backends. A device describes the device type and id on which said computation should be carried out. :param device_type: Represents Heat's device name :type device_type: str :param device_id: The device id :type device_id: int :param torch_device: The corresponding PyTorch device type :type torch_device: str .. rubric:: Examples >>> ht.Device("cpu", 0, "cpu:0") device(cpu:0) >>> ht.Device("gpu", 0, "cuda:0") device(gpu:0) >>> ht.Device("gpu", 0, "mps:0") # on Apple M1/M2 device(gpu:0) .. attribute:: __device_type .. attribute:: __device_id .. attribute:: __torch_device .. role:: raw-html(raw) :format: html .. method:: __repr__() -> str Return the unambiguous information of :class:`~heat.core.device.Device`. .. method:: __str__() -> str Return the descriptive information of :class:`~heat.core.device.Device`. .. method:: __eq__(other: Any) -> bool Overloads the `==` operator for local equal check. :param other: The object to compare with :type other: Any .. data:: cpu The standard CPU Device .. rubric:: Examples >>> ht.cpu device(cpu:0) >>> ht.ones((2, 3), device=ht.cpu) DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: get_device() -> Device Retrieves the currently globally set default :class:`~heat.core.device.Device`. .. function:: sanitize_device(device: Optional[Union[str, Device]] = None) -> Device Sanitizes a device or device identifier, i.e. checks whether it is already an instance of :class:`~heat.core.device.Device` or a string with known device identifier and maps it to a proper :class:`~heat.core.device.Device`. :param device: The device to be sanitized :type device: str or Device, optional :raises ValueError: If the given device id is not recognized .. function:: use_device(device: Optional[Union[str, Device]] = None) -> None Sets the globally used default :class:`~heat.core.device.Device`. :param device: The device to be set :type device: str or Device