NAME
AI::MXNet::Context - A device context.
DESCRIPTION
This class governs the device context of AI::MXNet::NDArray objects.
SYNOPSIS
use AI::MXNet qw(mx);
print nd->array([[1,2],[3,4]], ctx => mx->cpu)->aspdl;
my $arr_gpu = nd->random->uniform(shape => [10, 10], ctx => mx->gpu(0));
Constructing a context.
Parameters
----------
device_type : {'cpu', 'gpu'} or Context.
String representing the device type
device_id : int (default=0)
The device id of the device, needed for GPU
cpu
Returns a CPU context.
Parameters
----------
device_id : int, optional
The device id of the device. device_id is not needed for CPU.
This is included to make interface compatible with GPU.
Returns
-------
context : AI::MXNet::Context
The corresponding CPU context.
cpu_pinned
Returns a CPU pinned memory context. Copying from CPU pinned memory to GPU
is faster than from normal CPU memory.
Parameters
----------
device_id : int, optional
The device id of the device. `device_id` is not needed for CPU.
This is included to make interface compatible with GPU.
Returns
-------
context : Context
The corresponding CPU pinned memory context.
gpu
Returns a GPU context.
Parameters
----------
device_id : int, optional
Returns
-------
context : AI::MXNet::Context
The corresponding GPU context.
current_context
Returns the current context.
Returns
-------
$default_ctx : AI::MXNet::Context
num_gpus
Query CUDA for the number of GPUs present.
Raises
------
Will raise an exception on any CUDA error.
Returns
-------
count : int
The number of GPUs.