dgl.DGLGraph.device

property DGLGraph.device

Get the device of the graph.

Returns

The device of the graph, which should be a framework-specific device object (e.g., torch.device).

Return type

device context

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Create a homogeneous graph for demonstration.

>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
>>> print(g.device)
device(type='cpu')

The case of heterogeneous graphs is the same.