CUDAGPU

class orchespy.devicetype.CUDAGPU(device_id=0)[source]

Device type class for CUDAGPU.

Specify as the target of the orchespy’s decorator or function.

Examples

Specify CUDAGPU as the target of decorator. The function exec_on_gpu() will be execute on CUDAGPU.

>>> from orchespy.devicetype import CUDAGPU
>>> from orchespy import device
>>> import numpy
>>>
>>> @device(CUDAGPU)
... def exec_on_gpu(x, y):
...     return x * y
>>>
>>> x = numpy.ones((2,2))
>>> y = numpy.ones((2,2))
>>> z = exec_on_gpu(x, y)

If you have multiple identical devices, you can specify any device for the decorator. Also, when operating within the device decorator function, It is necessary to switch the output device in advance.

>>> from orchespy.devicetype import CUDAGPU
>>> from orchespy import device
>>> import numpy
>>> import cupy as cp
>>>
>>> @device(CUDAGPU(1))
... def exec_on_gpu(x, y):
...     return x * y
...
>>> x = numpy.ones((2,2)) * 3
>>> y = numpy.ones((2,2)) * 2
>>> cp.cuda.runtime.setDevice(1)
>>> z = exec_on_gpu(x, y)
>>> z.device.id
1
>>> type(z)
<class 'cupy.ndarray'>
>>> z
array([[6., 6.],
       [6., 6.]])