Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
mx.isenabled
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Feb 12, 2019
1 parent 38e08f9 commit 84aec6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 3 additions & 4 deletions julia/src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ function mx_get_last_error()
end

"Utility macro to call MXNet API functions"
macro mxcall(fv, argtypes, args...)
f = eval(fv)
macro mxcall(f, argtypes, args...)
args = map(esc, args)
quote
_mxret = ccall(($(QuoteNode(f)), $MXNET_LIB),
Cint, $argtypes, $(args...))
_mxret = ccall(($f, $MXNET_LIB),
Cint, $(esc(argtypes)), $(args...))
if _mxret != 0
err_msg = mx_get_last_error()
throw(MXError(err_msg))
Expand Down
27 changes: 23 additions & 4 deletions julia/src/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
# specific language governing permissions and limitations
# under the License.


# runtime detection of compile time features in the native library

module MXRuntime

using ..mx

export LibFeature
export libinfo_features
export libinfo_features, isenabled

# defined in include/mxnet/c_api.h
struct LibFeature
Expand All @@ -42,12 +41,32 @@ Check the library for compile-time features.
The list of features are maintained in libinfo.h and libinfo.cc
"""
function libinfo_features()
ref = Ref{Ptr{mx.MXRuntime.LibFeature}}(C_NULL)
ref = Ref{Ptr{LibFeature}}(C_NULL)
s = Ref{Csize_t}(C_NULL)
mx.@mxcall(:MXLibInfoFeatures, (Ref{Ptr{mx.MXRuntime.LibFeature}}, Ref{Csize_t}), ref, s)
@mx.mxcall(:MXLibInfoFeatures, (Ref{Ptr{LibFeature}}, Ref{Csize_t}), ref, s)
unsafe_wrap(Array, ref[], s[])
end

"""
isenabled(x::Symbol)::Bool
Returns the given runtime feature is enabled or not.
```julia-repl
julia> mx.isenabled(:CUDA)
false
julia> mx.isenabled(:CPU_SSE)
true
```
See also `mx.libinfo_features`.
"""
isenabled(x::Symbol) =
any(libinfo_features()) do i
Symbol(unsafe_string(i.name)) == x && i.enabled
end

end # module MXRuntime

using .MXRuntime

0 comments on commit 84aec6e

Please sign in to comment.