Context
#
MXNet.mx.Context
— Type.
Context(dev_type, dev_id)
A context describes the device type and id on which computation should be carried on.
#
MXNet.mx.context
— Method.
context(x::NDArray)
Get the context that this NDArray
lives on.
#
MXNet.mx.cpu
— Function.
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.
#
MXNet.mx.current_context
— Method.
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
#
MXNet.mx.empty_cache
— Function.
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.
#
MXNet.mx.gpu
— Function.
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.
#
MXNet.mx.gpu_memory_info
— Function.
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)
#
MXNet.mx.num_gpus
— Method.
num_gpus()
Query CUDA for the number of GPUs present.
#
MXNet.mx.@context
— Macro.
@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
#
MXNet.mx.@cpu
— Macro.
@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
#
MXNet.mx.@gpu
— Macro.
@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