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

Function context

python/dgl/_ffi/ndarray.py:53–85  ·  view source on GitHub ↗

Construct a DGL context with given device type and id. Parameters ---------- dev_type: int or str The device type mask or name of the device. dev_id : int, optional The integer device id Returns ------- ctx: DGLContext The corresponding context.

(dev_type, dev_id=0)

Source from the content-addressed store, hash-verified

51
52
53def context(dev_type, dev_id=0):
54 """Construct a DGL context with given device type and id.
55
56 Parameters
57 ----------
58 dev_type: int or str
59 The device type mask or name of the device.
60
61 dev_id : int, optional
62 The integer device id
63
64 Returns
65 -------
66 ctx: DGLContext
67 The corresponding context.
68
69 Examples
70 --------
71 Context can be used to create reflection of context by
72 string representation of the device type.
73
74 .. code-block:: python
75
76 assert dgl.context("cpu", 1) == dgl.cpu(1)
77 assert dgl.context("gpu", 0) == dgl.gpu(0)
78 assert dgl.context("cuda", 0) == dgl.gpu(0)
79 """
80 if isinstance(dev_type, string_types):
81 dev_type = dev_type.split()[0]
82 if dev_type not in DGLContext.STR2MASK:
83 raise ValueError("Unknown device type %s" % dev_type)
84 dev_type = DGLContext.STR2MASK[dev_type]
85 return DGLContext(dev_type, dev_id)
86
87
88def numpyasarray(np_data):

Callers 2

numpyasarrayFunction · 0.70
emptyFunction · 0.70

Calls 1

DGLContextClass · 0.85

Tested by

no test coverage detected