Skip to content

Commit

Permalink
[MXNET-1430] julia: implement context.gpu_memory_info (apache#16324)
Browse files Browse the repository at this point in the history
* julia: implement context.gpu_memory_info

resolve MXNET-1430

* update export and NEWS
  • Loading branch information
iblislin authored and aaronmarkham committed Oct 16, 2019
1 parent d948256 commit 4547cc4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions julia/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion julia/src/MXNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export Executor,
export Context,
cpu,
gpu,
num_gpus
num_gpus,
gpu_memory_info

# model.jl
export AbstractModel,
Expand Down
18 changes: 18 additions & 0 deletions julia/src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions python/mxnet/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4547cc4

Please sign in to comment.