dgl.sparse.SparseMatrix.cuda

SparseMatrix.cuda()[source]

Moves the matrix to GPU. If the matrix is already on GPU, the original matrix will be returned. If multiple GPU devices exist, cuda:0 will be selected.

Returns

The matrix on GPU

Return type

SparseMatrix

Examples

>>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.cuda()
SparseMatrix(indices=tensor([[1, 1, 2],
                             [1, 2, 0]], device='cuda:0'),
             values=tensor([1., 1., 1.], device='cuda:0'),
             shape=(3, 4), nnz=3)