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

Commit

Permalink
Julia: add binding for runtime feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Jan 25, 2019
1 parent 0a45e1a commit 44156b5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 3 deletions.
7 changes: 4 additions & 3 deletions julia/deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ elseif Sys.islinux()
end

if Sys.isunix()
try
push!(CUDAPATHS, replace(strip(read(`which nvcc`, String)), "bin/nvcc", "lib64"))
catch
nvcc_path = Sys.which("nvcc")
if nvcc_path nothing
@info "Found nvcc: $nvcc_path"
push!(CUDAPATHS, replace(nvcc_path, "bin/nvcc", "lib64"))
end
end

Expand Down
1 change: 1 addition & 0 deletions julia/src/MXNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export to_graphviz

include("base.jl")

include("mxfeatures.jl")
include("context.jl")
include("util.jl")

Expand Down
116 changes: 116 additions & 0 deletions julia/src/mxfeatures.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# License); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


# runtime detection of compile time features in the native library

module MXFeatures

using ..mx

export Feature
export has_feature, features_enabled

@enum Feature begin
CUDA
CUDNN
NCCL
CUDA_RTC
TENSORRT
CPU_SSE
CPU_SSE2
CPU_SSE3
CPU_SSE4_1
CPU_SSE4_2
CPU_SSE4A
CPU_AVX
CPU_AVX2
OPENMP
SSE
F16C
JEMALLOC
BLAS_OPEN
BLAS_ATLAS
BLAS_MKL
BLAS_APPLE
LAPACK
MKLDNN
OPENCV
CAFFE
PROFILER
DIST_KVSTORE
CXX14
SIGNAL_HANDLER
DEBUG
end

"""
features_enabled()
features_enabled(Symbol)
features_enabled(String; sep = ", ")
Returns a list of enabled features in the back-end
## Examples
```julia-repl
julia> mx.features_enabled()
8-element Array{MXNet.mx.MXFeatures.Feature,1}:
CPU_SSE::Feature = 5
CPU_SSE2::Feature = 6
CPU_SSE3::Feature = 7
CPU_SSE4_1::Feature = 8
CPU_SSE4_2::Feature = 9
CPU_AVX::Feature = 11
F16C::Feature = 15
LAPACK::Feature = 21
julia> mx.features_enabled(String)
"CPU_SSE, CPU_SSE2, CPU_SSE3, CPU_SSE4_1, CPU_SSE4_2, CPU_AVX, F16C, LAPACK"
julia> mx.features_enabled(Symbol)
8-element Array{Symbol,1}:
:CPU_SSE
:CPU_SSE2
:CPU_SSE3
:CPU_SSE4_1
:CPU_SSE4_2
:CPU_AVX
:F16C
:LAPACK
```
"""
features_enabled() = filter(f -> has_feature(f), collect(instances(Feature)))
features_enabled(::Type{String}; sep = ", ") = join(features_enabled(Symbol), sep)
features_enabled(::Type{Symbol}) = Symbol.(features_enabled())


"""
hasfeature(feature::Feature) -> Bool
Check the library for compile-time feature at runtime
"""
function has_feature(x::Feature)
y = Ref{Bool}(0)
@mx.mxcall(:MXHasFeature, (mx.MX_uint, Ref{Bool},), mx.MX_uint(x), y)
y[]
end

end # module MXFeatures

using .MXFeatures

0 comments on commit 44156b5

Please sign in to comment.