Backends and Devices

Common Classes and Utilities

chainer.backend.Device

A base class of unified devices.

chainer.get_device

Returns a device object.

chainer.using_device

Context manager to apply the thread-local device state.

chainer.backend.get_device_from_array

Gets the device from arrays.

chainer.backend.get_array_module

Gets an appropriate NumPy-compatible module to process arguments

chainer.DeviceResident

A base class of objects with multi-device hierarchy.

chainer.device_resident.DeviceResidentsVisitor

Base class of visitors that visits device resident objects recursively.

chainer.backend.copyto

Copies the elements of an ndarray to those of another one.

Concrete Device Classes

chainer.backend.CpuDevice

Device for CPU (NumPy) backend

chainer.backend.GpuDevice

Device for GPU (CuPy) backend

chainer.backend.Intel64Device

Device for Intel64 (Intel Architecture) backend with iDeep

chainer.backend.ChainerxDevice

Device for ChainerX backend

GPU (CuPy)

Device, context and memory management on CuPy.

Note

The package chainer.cuda has been renamed to chainer.backends.cuda as of v4.0.0, but the previous module path chainer.cuda is also available.

Chainer uses CuPy (with very thin wrapper) to exploit the speed of GPU computation. Following modules and classes defined in CuPy are imported to chainer.backends.cuda module for convenience (refer to this table when reading chainer’s source codes).

imported name

original name

chainer.backends.cuda.cupy

cupy

chainer.backends.cuda.cupyx

cupyx

chainer.backends.cuda.ndarray

cupy.ndarray

chainer.backends.cuda.cupy.cuda

cupy.cuda

chainer.backends.cuda.Device

cupy.cuda.Device

chainer.backends.cuda.Event

cupy.cuda.Event

chainer.backends.cuda.Stream

cupy.cuda.Stream

Chainer replaces the default allocator of CuPy by its memory pool implementation. It enables us to reuse the device memory over multiple forward/backward computations, and temporary arrays for consecutive elementwise operations.

Devices

chainer.backends.cuda.get_device

Gets the device from a device object, an ID integer or an array object.

chainer.backends.cuda.get_device_from_id

Gets the device from an ID integer.

chainer.backends.cuda.get_device_from_array

Gets the device from a list of CuPy array or a single CuPy array.

CuPy array allocation and copy

chainer.backends.cuda.copy

Copies a cupy.ndarray object using the default stream.

chainer.backends.cuda.to_cpu

Copies the given GPU array to host CPU.

chainer.backends.cuda.to_gpu

Copies the given CPU array to the specified device.

Kernel definition utilities

chainer.backends.cuda.memoize

Makes a function memoizing the result for each argument and device.

chainer.backends.cuda.clear_memo

Clears the memoized results for all functions decorated by memoize.

chainer.backends.cuda.elementwise

Creates an elementwise kernel function.

chainer.backends.cuda.raw

Creates a raw kernel function.

chainer.backends.cuda.reduce

Creates a global reduction kernel function.

CPU/GPU generic code support

chainer.backends.cuda.get_array_module

Gets an appropriate one from numpy or cupy.

cuDNN support

chainer.backends.cuda.set_max_workspace_size

Sets the workspace size for cuDNN.

chainer.backends.cuda.get_max_workspace_size

Gets the workspace size for cuDNN.

Intel64 (iDeep)

iDeep is a module that provides NumPy-like API and DNN acceleration using MKL-DNN for Intel CPUs. See Tips and FAQs and Performance Best Practices for details.

chainer.backends.intel64.is_ideep_available

Returns if iDeep is available.

ChainerX

chainer.backend.from_chx

Converts an array or arrays from ChainerX to NumPy or CuPy ones.

chainer.backend.to_chx

Converts an array or arrays to ChainerX.