MCPcopy
hub / github.com/dmlc/dgl / device

Method device

python/dgl/heterograph.py:5632–5656  ·  view source on GitHub ↗

Get the device of the graph. Returns ------- device context The device of the graph, which should be a framework-specific device object (e.g., ``torch.device``). Examples -------- The following example uses PyTorch backend.

(self)

Source from the content-addressed store, hash-verified

5630
5631 @property
5632 def device(self):
5633 """Get the device of the graph.
5634
5635 Returns
5636 -------
5637 device context
5638 The device of the graph, which should be a framework-specific device object
5639 (e.g., ``torch.device``).
5640
5641 Examples
5642 --------
5643 The following example uses PyTorch backend.
5644
5645 >>> import dgl
5646 >>> import torch
5647
5648 Create a homogeneous graph for demonstration.
5649
5650 >>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
5651 >>> print(g.device)
5652 device(type='cpu')
5653
5654 The case of heterogeneous graphs is the same.
5655 """
5656 return F.to_backend_ctx(self._graph.ctx)
5657
5658 def to(self, device, **kwargs): # pylint: disable=invalid-name
5659 """Move ndata, edata and graph structure to the targeted device (cpu/gpu).

Calls

no outgoing calls