class MXNet::Context
- MXNet::Context
- Reference
- Object
Overview
MXNet context.
Defined in:
mxnet/context.crConstructors
-
.new(device_type : ::Symbol | Int32, device_id : Int32 = 0)
Constructs a context.
Class Method Summary
-
.cpu(device_id : Int32 = 0)
Returns a CPU context.
-
.current
Returns the current context.
-
.gpu(device_id : Int32 = 0)
Returns a GPU context.
-
.gpu_memory_info(device_id : Int32 = 0)
Queries CUDA for the free and total bytes of GPU global memory.
-
.num_gpus
Queries CUDA for the number of GPUs present.
-
.with(context : self, &)
Sets the current context within the block.
Instance Method Summary
-
#==(other : self)
Compares contexts.
- #device : Tuple(Int32, Int32)
- #device_id : Int32
- #device_type
-
#to_s(io)
Writes this object to an
IO
.
Constructor Detail
Constructs a context.
MXNet can run operations on a CPU and different GPUs. A context describes the device on which computation should be carried out.
Use .cpu
and .gpu
as shortcuts.
Parameters
- device_type (
:cpu
,:gpu
orInt32
) Symbol representing the device type, or the device type. - device_id (
Int32
, default = 0) Device id of the device (for GPUs).
See also
Class Method Detail
Returns a CPU context.
This function is a shortcut for MXNet::Context.new(:cpu, device_id)
.
For most operations, when no context is specified, the default
context is MXNet::Context.cpu
.
Parameters
- device_id (
Int32
, default = 0) Device id of the device. Not required for the CPU context. Included to make the interface compatible with GPU contexts.
Returns a GPU context.
This function is a shortcut for MXNet::Context.new(:gpu, device_id)
.
The K GPUs on a node are typically numbered 0, ..., K-1.
Parameters
- device_id (
Int32
, default = 0) Device id of the device. Required for the GPU contexts.
Queries CUDA for the free and total bytes of GPU global memory.
Returns the free and total memory as a two-element tuple.
Parameters
- device_id (
Int32
, default = 0) Device id of the device.
Note: not supported on MXNet versions < 1.3.0.
Queries CUDA for the number of GPUs present.
Returns the number of GPUs.
Note: not supported on MXNet versions < 1.3.0.
Instance Method Detail
Compares contexts.
Two contexts are equal if they have the same device type and device id.