项目文件夹

文件
zhjwy9343 808a3676c2 [Doc] Chinese User Guide chapter1 (#2240)
* [Feature] Add full graph training with dgl built-in dataset.

* [Feature] Add full graph training with dgl built-in dataset.

* [Feature] Add full graph training with dgl built-in dataset.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Bug] fix model to cuda.

* [Feature] Add test loss and accuracy

* [Feature] Add test loss and accuracy

* [Feature] Add test loss and accuracy

* [Feature] Add test loss and accuracy

* [Feature] Add test loss and accuracy

* [Feature] Add test loss and accuracy

* [Fix] Add random

* [Bug] Fix batch norm error

* [Doc] Test with CN in Sphinx

* [Doc] Test with CN in Sphinx

* [Doc] Remove the test CN docs.

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Feature] Add input embedding layer

* [Doc] fill readme with new performance results

* [Doc] Add Chinese User Guide, graph and 1.5

* [Doc] Add Chinese User Guide, graph and 1.5

* [Doc] Add Chines User Guide

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* Update README.md

* [Doc] Finalize CN user guide chapter 1

* [Doc] Finalize CN user guide chapter 1

* [Doc] Finalize CN user guide chapter 1

* [Doc] Add CN link in user guide chapter 1

* [Doc] Add CN link in user guide chapter 1

* [Fix] Temporary remove compgcn

* [Doc] Add Chines User Guide

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] user guide cn chapter 1

* [Doc] Finalize CN user guide chapter 1

* [Doc] Finalize CN user guide chapter 1

* [Doc] Finalize CN user guide chapter 1

* [Doc] Add CN link in user guide chapter 1

* update hash in 3rd party

* [Fix] copyedit some errors

* [Fix] copyedit some errors

* [Fix] copyedit some errors

* [Fix] copyedit some errors

* [Fix] copyedit some errors

* Update

Co-authored-by: Mufei Li <mufeili1996@gmail.com>
2020-09-30 18:16:10 +08:00

48 行
1.9 KiB
ReStructuredText

.. _guide-graph-gpu:
1.6 Using DGLGraph on a GPU
---------------------------
:ref:`(中文版)<guide_cn-graph-gpu>`
One can create a :class:`~dgl.DGLGraph` on a GPU by passing two GPU tensors during construction.
Another approach is to use the :func:`~dgl.DGLGraph.to` API to copy a :class:`~dgl.DGLGraph` to a GPU, which
copies the graph structure as well as the feature data to the given device.
.. code::
>>> import dgl
>>> import torch as th
>>> u, v = th.tensor([0, 1, 2]), th.tensor([2, 3, 4])
>>> g = dgl.graph((u, v))
>>> g.ndata['x'] = th.randn(5, 3) # original feature is on CPU
>>> g.device
device(type='cpu')
>>> cuda_g = g.to('cuda:0') # accepts any device objects from backend framework
>>> cuda_g.device
device(type='cuda', index=0)
>>> cuda_g.ndata['x'].device # feature data is copied to GPU too
device(type='cuda', index=0)
>>> # A graph constructed from GPU tensors is also on GPU
>>> u, v = u.to('cuda:0'), v.to('cuda:0')
>>> g = dgl.graph((u, v))
>>> g.device
device(type='cuda', index=0)
Any operations involving a GPU graph are performed on a GPU. Thus, they require all
tensor arguments to be placed on GPU already and the results (graph or tensor) will be on
GPU too. Furthermore, a GPU graph only accepts feature data on a GPU.
.. code::
>>> cuda_g.in_degrees()
tensor([0, 0, 1, 1, 1], device='cuda:0')
>>> cuda_g.in_edges([2, 3, 4]) # ok for non-tensor type arguments
(tensor([0, 1, 2], device='cuda:0'), tensor([2, 3, 4], device='cuda:0'))
>>> cuda_g.in_edges(th.tensor([2, 3, 4]).to('cuda:0')) # tensor type must be on GPU
(tensor([0, 1, 2], device='cuda:0'), tensor([2, 3, 4], device='cuda:0'))
>>> cuda_g.ndata['h'] = th.randn(5, 4) # ERROR! feature must be on GPU too!
DGLError: Cannot assign node feature "h" on device cpu to a graph on device
cuda:0. Call DGLGraph.to() to copy the graph to the same device.