You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ib...@apache.org on 2019/02/12 12:21:39 UTC
[incubator-mxnet] branch ib/jl-runtime-features updated:
mx.isenabled
This is an automated email from the ASF dual-hosted git repository.
iblis pushed a commit to branch ib/jl-runtime-features
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/ib/jl-runtime-features by this push:
new 84aec6e mx.isenabled
84aec6e is described below
commit 84aec6e5087f6ef6ac60f5bd4dfe10c61410367a
Author: Iblis Lin <ib...@hs.ntnu.edu.tw>
AuthorDate: Tue Feb 12 12:20:55 2019 +0000
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 61779d1..6831464 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 bb8a81c..fcdadfb 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