From a20dcd5c47f8a179fb84b7b36943efe2b675593f Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Sat, 28 Sep 2019 05:49:23 +0000 Subject: [PATCH 1/2] julia: implement context.gpu_memory_info resolve MXNET-1430 --- julia/src/context.jl | 18 ++++++++++++++++++ python/mxnet/context.py | 2 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/julia/src/context.jl b/julia/src/context.jl index bce67a593414..68e69138e10e 100644 --- a/julia/src/context.jl +++ b/julia/src/context.jl @@ -68,3 +68,21 @@ function num_gpus() @mxcall :MXGetGPUCount (Ref{Cint},) n n[] end + +""" + 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-repl +julia> mx.gpu_memory_info() +(0x00000003af240000, 0x00000003f9440000) +``` +""" +function gpu_memory_info(dev_id = 0) + free = Ref{UInt64}() + n = Ref{UInt64}() + @mxcall :MXGetGPUMemoryInformation64 (Cint, Ref{UInt64}, Ref{UInt64}) dev_id free n + free[], n[] +end diff --git a/python/mxnet/context.py b/python/mxnet/context.py index decea71762f6..99998eaa28f2 100644 --- a/python/mxnet/context.py +++ b/python/mxnet/context.py @@ -292,8 +292,6 @@ def gpu_memory_info(device_id=0): Returns ------- (free, total) : (int, int) - The number of GPUs. - """ free = ctypes.c_uint64() total = ctypes.c_uint64() From 07207b17e6b18ee0269f7448438ee8029a78bc55 Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Sat, 28 Sep 2019 06:23:33 +0000 Subject: [PATCH 2/2] update export and NEWS --- julia/NEWS.md | 4 ++++ julia/src/MXNet.jl | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/julia/NEWS.md b/julia/NEWS.md index 7e3076a303d4..8f5efbb0edd5 100644 --- a/julia/NEWS.md +++ b/julia/NEWS.md @@ -20,6 +20,10 @@ * Add an abstract type `AbstractMXError` as the parent type for all MXNet-related API errors. (#16235) +* Porting more `context` functions from Python. + * `num_gpus()` (#16236) + * `gpu_memory_info()` (#16324) + # v1.5.0 diff --git a/julia/src/MXNet.jl b/julia/src/MXNet.jl index 69bbcf85180d..86d7d06806fc 100644 --- a/julia/src/MXNet.jl +++ b/julia/src/MXNet.jl @@ -79,7 +79,8 @@ export Executor, export Context, cpu, gpu, - num_gpus + num_gpus, + gpu_memory_info # model.jl export AbstractModel,