Context

# MXNet.mx.ContextType.

Context(dev_type, dev_id)

A context describes the device type and id on which computation should be carried on.

source

# MXNet.mx.contextMethod.

context(x::NDArray)

Get the context that this NDArray lives on.

source

# MXNet.mx.cpuFunction.

cpu(dev_id)

Get a CPU context with a specific id. cpu() is usually the default context for many operations when no context is specified.

Arguments

  • dev_id::Integer = 0: the CPU id.

source

# MXNet.mx.current_contextMethod.

current_context()

Return the current context.

By default, mx.cpu() is used for all the computations and it can be overridden by using the @context macro.

Examples

julia> mx.current_context()
cpu0

julia> mx.@context mx.GPU 1 begin  # Context changed in the following code block
         mx.current_context()
       end
gpu1

julia> mx.current_context()
cpu0

source

# MXNet.mx.empty_cacheFunction.

empty_cache(ctx::Context = current_context())

Empties the memory cache for the current contexts device. MXNet utilizes a memory pool to avoid excessive allocations. Calling empty_cache will empty the memory pool of the contexts device. This will only free the memory of the unreferenced data.

source

# MXNet.mx.gpuFunction.

gpu(dev_id)

Get a GPU context with a specific id. The K GPUs on a node is typically numbered as 0,...,K-1.

Arguments

  • dev_id::Integer = 0 the GPU device id.

source

# MXNet.mx.gpu_memory_infoFunction.

gpu_memory_info(dev_id = 0)::Tuple{UInt64,UInt64}

Query CUDA for the free and total bytes of GPU global memory. It returns a tuple of (free memory, total memory).

julia> mx.gpu_memory_info()
(0x00000003af240000, 0x00000003f9440000)

source

# MXNet.mx.num_gpusMethod.

num_gpus()

Query CUDA for the number of GPUs present.

source

# MXNet.mx.@contextMacro.

@context device_type [device_id] expr

Change the default context in the following expression.

Examples

julia> mx.@context mx.GPU begin
         mx.zeros(2, 3)
       end
2×3 NDArray{Float32,2} @ gpu0:
 0.0f0  0.0f0  0.0f0
 0.0f0  0.0f0  0.0f0

julia> @context mx.GPU mx.zeros(3, 2)
3×2 NDArray{Float32,2} @ gpu0:
 0.0f0  0.0f0
 0.0f0  0.0f0
 0.0f0  0.0f0

source

# MXNet.mx.@cpuMacro.

@cpu [device_id] expr

A shorthand for @context mx.GPU.

Examples

julia> mx.@with_gpu mx.zeros(2, 3)
2×3 NDArray{Float32,2} @ gpu0:
 0.0f0  0.0f0  0.0f0
 0.0f0  0.0f0  0.0f0

source

# MXNet.mx.@gpuMacro.

@gpu [device_id] expr

A shorthand for @context mx.GPU.

Examples

julia> mx.@with_gpu mx.zeros(2, 3)
2×3 NDArray{Float32,2} @ gpu0:
 0.0f0  0.0f0  0.0f0
 0.0f0  0.0f0  0.0f0

source