def to_chainerx(array): """Converts an array or arrays to ChainerX. Destination ChainerX devices are chosen according to the types of input arrays. """ return _backend._convert_arrays(array, _array_to_chainerx)
def to_gpu(array, device=None, stream=None): """Copies the given CPU array to the specified device. Args: array (*array*, None, list or tuple): Array or arrays to be sent to GPU. device: CUDA device specifier. If ``None`` or :data:`cuda.DummyDevice`, the arrays will be copied to the current CUDA device. stream (~cupy.cuda.Stream): *(deprecated since v3.0.0)* CUDA stream. If not ``None``, the copy runs asynchronously. Returns: cupy.ndarray, list or tuple: Array or arrays on GPU. If some of the arrays are already on GPU, then this function just returns those arrays without performing any copy. If input arrays include `None`, it is returned as `None` as is. """ if stream is not None: warnings.warn( 'The stream option is deprecated in chainer.backends.cuda.to_gpu. ' 'Please remove it.', DeprecationWarning) check_cuda_available() if device is DummyDevice: device = cuda.Device() else: device = _get_device_or_current(device) return _backend._convert_arrays( array, lambda arr: _array_to_gpu(arr, device, stream))
def to_gpu(array, device=None, stream=None): """Copies the given CPU array to the specified device. Args: array (*array*, None, list or tuple): Array or arrays to be sent to GPU. device: CUDA device specifier. If ``None`` or :data:`cuda.DummyDevice`, the arrays will be copied to the current CUDA device. stream (~cupy.cuda.Stream): *(deprecated since v3.0.0)* CUDA stream. If not ``None``, the copy runs asynchronously. Returns: cupy.ndarray, list or tuple: Array or arrays on GPU. If some of the arrays are already on GPU, then this function just returns those arrays without performing any copy. If input arrays include `None`, it is returned as `None` as is. """ if stream is not None: warnings.warn( 'The stream option is deprecated in chainer.backends.cuda.to_gpu. ' 'Please remove it.', DeprecationWarning) check_cuda_available() if device is DummyDevice: device = cuda.Device() else: device = _get_device_or_current(device) return _backend._convert_arrays( array, lambda arr: _array_to_gpu(arr, device, stream))
def to_chx(array): """Converts an array or arrays to ChainerX. Destination ChainerX devices are chosen according to the types of input arrays. """ return _backend._convert_arrays(array, _array_to_chainerx)
def to_cpu(array, stream=None): """Copies the given GPU array to host CPU. Args: array (*array*, None, list or tuple): Array or arrays to be sent to CPU. stream (cupy.cuda.Stream): CUDA stream. Returns: numpy.ndarray, list or tuple: Array on CPU. If some of the arrays are already on CPU, then this function just returns those arrays without performing any copy. If input arrays include `None`, it is returned as `None` as is. """ return _backend._convert_arrays( array, lambda arr: _array_to_cpu(arr, stream))
def to_cpu(array, stream=None): """Copies the given GPU array to host CPU. Args: array (*array*, None, list or tuple): Array or arrays to be sent to CPU. stream (cupy.cuda.Stream): CUDA stream. Returns: numpy.ndarray, list or tuple: Array on CPU. If some of the arrays are already on CPU, then this function just returns those arrays without performing any copy. If input arrays include `None`, it is returned as `None` as is. """ return _backend._convert_arrays( array, lambda arr: _array_to_cpu(arr, stream))
def from_chainerx(array): """Converts an array or arrays from ChainerX to NumPy or CuPy ones. Destination array types are chosen such that no copies occur. """ return _backend._convert_arrays(array, _array_from_chainerx)
def from_chx(array): """Converts an array or arrays from ChainerX to NumPy or CuPy ones. Destination array types are chosen such that no copies occur. """ return _backend._convert_arrays(array, _array_from_chainerx)
def _to_cpu(array): """Converts an array or arrays to NumPy.""" return _backend._convert_arrays(array, _array_to_cpu)
def _to_cpu(array): """Converts an array or arrays to NumPy.""" return _backend._convert_arrays(array, _array_to_cpu)