From 84aec6e5087f6ef6ac60f5bd4dfe10c61410367a Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Tue, 12 Feb 2019 12:20:55 +0000 Subject: [PATCH] mx.isenabled --- julia/src/base.jl | 7 +++---- julia/src/runtime.jl | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/julia/src/base.jl b/julia/src/base.jl index 61779d194a94..683146402620 100644 --- a/julia/src/base.jl +++ b/julia/src/base.jl @@ -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)) diff --git a/julia/src/runtime.jl b/julia/src/runtime.jl index bb8a81cdf7d9..fcdadfb2fb3c 100644 --- a/julia/src/runtime.jl +++ b/julia/src/runtime.jl @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. - # runtime detection of compile time features in the native library module MXRuntime @@ -23,7 +22,7 @@ module MXRuntime using ..mx export LibFeature -export libinfo_features +export libinfo_features, isenabled # defined in include/mxnet/c_api.h struct LibFeature @@ -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