Transfer API

This part of the documentation covers transfer function of OrchesPy.

orchespy.transfer.transfer_array(src, target)[source]

Transfer N-dimension array to a specified target device.

Parameters:
  • src (array_like) – N-dimension array on a device or host to be transferred.

  • target (devicetype) – Target device; device to be transferred x to. Specify the devicetype class that corresponds to the device. See orchespy.devicetype for what you can specify.

Returns:

N-dimension array of src on the target device.

Return type:

ndarray

See also

orchespy.devicetype

Supported device types.

Examples

Transfer ndarray on a host to CUDAGPU.

>>> import orchespy
>>> import orchespy.devicetype
>>> import numpy
>>> import cupy
>>> x = numpy.asarray([1, 2, 3])
>>> y = orchespy.transfer_array(x, orchespy.devicetype.CUDAGPU())
>>> y
array([1, 2, 3])
>>> isinstance(y, cupy.ndarray)
True

If there are multiple identical devices, they can be specified by writing as follows. Also, when processing the ndarray output by transfer_array, it is necessary to switch to the output device after transfer.

>>> from orchespy.devicetype import VE
>>> import orchespy
>>> import numpy as np
>>> import nlcpy as vp
>>>
>>> src = np.ones((2, 2))
>>> x = orchespy.transfer_array(src, VE(1))
>>> x.venode.id
1
>>> vp.venode.VE(1).use()
<VE node logical_id=1, physical_id=1>
>>> y = vp.ones((2, 2))
>>> mul = x * y
>>> mul.venode.id
1
>>> type(mul)
<class 'nlcpy.core.core.ndarray'>
orchespy.transfer.transfer_array_content(dst, src)[source]

Transfer N-dimension array to a specified N-dimension array.

Parameters:
  • dst (array_like) – N-dimension array on a device or host that receives the src value.

  • src (array_like) – N-dimension array on a device or host to be transferred.

Return type:

None

Examples

Transfer ndarray on a host to CUDAGPU.

>>> import orchespy
>>> import numpy
>>> import cupy
>>> x = numpy.asarray([1, 2, 3])
>>> y = cupy.asarray([-1, -1, -1])
>>> orchespy.transfer_array_content(y, x)
>>> y
array([1, 2, 3])
>>> isinstance(y, cupy.ndarray)
True

Below is an example of an environment with multiple identical devices.

>>> import orchespy
>>> import numpy as np
>>> import nlcpy as vp
>>>
>>> src = np.ones((2, 2), dtype='i8', order='C') * 3
>>> vp.venode.VE(1).use()
<VE node logical_id=1, physical_id=1>
>>> dst = vp.zeros((2, 2), dtype='i8', order='C')
>>> orchespy.transfer_array_content(dst, src)
>>> dst.venode.id
1
>>> type(dst)
<class 'nlcpy.core.core.ndarray'>
>>> dst
array([[3, 3],
       [3, 3]])