class MXNet::Context

Overview

MXNet context.

Defined in:

mxnet/context.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(device_type : ::Symbol | Int32, device_id : Int32 = 0) #

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 or Int32) Symbol representing the device type, or the device type.
  • device_id (Int32, default = 0) Device id of the device (for GPUs).

See also

How to run MXNet on multiple CPU/GPUs


[View source]

Class Method Detail

def self.cpu(device_id : Int32 = 0) #

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.

[View source]
def self.current #

Returns the current context.


[View source]
def self.gpu(device_id : Int32 = 0) #

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.

[View source]
def self.gpu_memory_info(device_id : Int32 = 0) #

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.


[View source]
def self.num_gpus #

Queries CUDA for the number of GPUs present.

Returns the number of GPUs.

Note: not supported on MXNet versions < 1.3.0.


[View source]
def self.with(context : self, &) #

Sets the current context within the block.


[View source]

Instance Method Detail

def ==(other : self) #

Compares contexts.

Two contexts are equal if they have the same device type and device id.


[View source]
def device : Tuple(Int32, Int32) #

[View source]
def device_id : Int32 #

[View source]
def device_type #

[View source]
def to_s(io) #

Writes this object to an IO.


[View source]