Skip to content

Commit 0f8058d

Browse files
authored
Small improvements to discovery of local toolkits. (#1134)
1 parent 6e057e7 commit 0f8058d

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

deps/bindeps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro initialize_ref(ref, ex, hook=:())
2222
if val === nothing && !(eltype($ref) <: Union{Nothing,<:Any})
2323
error($"Could not find a required library")
2424
end
25-
$ref[] = $ex
25+
$ref[] = val
2626
if val !== nothing
2727
$hook
2828
end

deps/compatibility.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const lowest = v"0"
44
const highest = v"999"
55

6-
verlist(vers) = join(map(ver->"$(ver.major).$(ver.minor)", sort(collect(vers))), ", ", " and ")
6+
join_capabilities(vers) = join(map(ver->"$(ver.major).$(ver.minor)", sort(collect(vers))), ", ", " and ")
77

88

99
## version range
@@ -174,7 +174,7 @@ end
174174

175175
## high-level functions that return target and isa support
176176

177-
export llvm_compat, cuda_compat, supported_toolchain, supported_capability
177+
export llvm_compat, cuda_compat, supported_toolchain
178178

179179
function llvm_compat(version=LLVM.version())
180180
LLVM.InitializeNVPTXTarget()
@@ -207,16 +207,7 @@ function supported_toolchain()
207207
ptx_support = sort(collect(llvm_support.ptx cuda_support.ptx))
208208
isempty(ptx_support) && error("Your toolchain does not support any PTX ISA")
209209

210-
@debug("Toolchain with LLVM $(LLVM.version()), CUDA driver $(CUDA.release().major).$(CUDA.release().minor) and toolkit $(toolkit_release().major).$(toolkit_release().minor) supports devices $(verlist(target_support)); PTX $(verlist(ptx_support))")
210+
@debug("Toolchain with LLVM $(LLVM.version()), CUDA driver $(CUDA.release().major).$(CUDA.release().minor) and toolkit $(toolkit_release().major).$(toolkit_release().minor) supports devices $(join_capabilities(target_support)); PTX $(join_capabilities(ptx_support))")
211211

212212
return (cap=target_support, ptx=ptx_support)
213213
end
214-
215-
# select the highest capability that is supported by both the toolchain and device
216-
function supported_capability(dev_cap::VersionNumber)
217-
compat_caps = filter(cap -> cap <= dev_cap, supported_toolchain().cap)
218-
isempty(compat_caps) &&
219-
error("Device capability v$dev_cap not supported by available toolchain")
220-
221-
return maximum(compat_caps)
222-
end

deps/discovery.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@ function valid_dirs(dirs)
1313
filter(isdir, unique(dirs))
1414
end
1515

16+
function join_versions(versions)
17+
isempty(versions) && return "no specific version"
18+
"version " * join(versions, " or ")
19+
end
20+
21+
function join_locations(locations)
22+
isempty(locations) && return "in no specific location"
23+
"in " * join(locations, " or ")
24+
end
25+
1626

1727
## generic discovery routines
1828

1929
function library_versioned_names(name::String, versions::Vector=[])
2030
names = String[]
2131

22-
# always look for an unversion library first
32+
# always look for an unversioned library first
2333
if Sys.iswindows()
2434
push!(names, "$(name)$(Sys.WORD_SIZE).$(Libdl.dlext)")
2535

@@ -88,8 +98,6 @@ Returns the full path to the library.
8898
"""
8999
function find_library(name::String, versions::Vector=[];
90100
locations::Vector{String}=String[])
91-
@debug "Request to look for library $name $version" locations
92-
93101
# figure out names
94102
all_names = library_versioned_names(name, versions)
95103

@@ -108,15 +116,16 @@ function find_library(name::String, versions::Vector=[];
108116
end
109117
end
110118

111-
@debug "Looking for library $(join(all_names, ", "))" locations=all_locations
119+
@debug "Looking for library $name, $(join_versions(versions)), $(join_locations(locations))" all_names all_locations
112120
name_found = Libdl.find_library(all_names, all_locations)
113121
if isempty(name_found)
122+
@debug "Did not find $name"
114123
return nothing
115124
end
116125

117126
# find the full path of the library (which Libdl.find_library doesn't guarantee to return)
118127
path = Libdl.dlpath(name_found)
119-
@debug "Found library $(basename(path)) at $(dirname(path))"
128+
@debug "Found $(basename(path)) at $(dirname(path))"
120129
return path
121130
end
122131

@@ -127,8 +136,6 @@ Similar to `find_library`, performs an exhaustive search for a binary in various
127136
subdirectories of `locations`, and finally PATH by using `Sys.which`.
128137
"""
129138
function find_binary(name::String; locations::Vector{String}=String[])
130-
@debug "Request to look for binary $name" locations
131-
132139
# figure out locations
133140
all_locations = String[]
134141
for location in locations
@@ -137,20 +144,21 @@ function find_binary(name::String; locations::Vector{String}=String[])
137144
end
138145
# we look in PATH too by using `Sys.which` with unadorned names
139146

140-
@debug "Looking for binary $name" locations=all_locations
147+
@debug "Looking for binary $name $(join_locations(locations))" all_locations
141148
all_paths = [name; [joinpath(location, name) for location in all_locations]]
142149
for path in all_paths
143150
try
144151
program_path = Sys.which(path)
145152
if program_path !== nothing
146-
@debug "Found binary $path at $program_path"
153+
@debug "Found $path at $program_path"
147154
return program_path
148155
end
149156
catch
150157
# some system disallow `stat` on certain paths
151158
end
152159
end
153160

161+
@debug "Did not find $path"
154162
return nothing
155163
end
156164

src/compiler/gpucompiler.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ const DeviceProperties = @NamedTuple{cap::VersionNumber, ptx::VersionNumber,
55
const __device_properties = LazyInitialized{Vector{DeviceProperties}}()
66
function device_properties(dev)
77
props = get!(__device_properties) do
8+
toolchain = supported_toolchain()
9+
810
# NOTE: this doesn't initialize any context, so we can pre-compute for all devices
911
val = Vector{DeviceProperties}(undef, ndevices())
1012
for dev in devices()
11-
cap = supported_capability(capability(dev))
12-
ptx = v"6.3" # we only need 6.2, but NVPTX doesn't support that
13+
# select the highest capability that is supported by both the toolchain and device
14+
caps = filter(toolchain_cap -> toolchain_cap <= capability(dev), toolchain.cap)
15+
isempty(caps) &&
16+
error("Your $(name(dev)) GPU with capability v$(capability(dev)) is not supported by the available toolchain")
17+
cap = maximum(caps)
18+
19+
# select the PTX ISA we assume to be available
20+
# (we actually only need 6.2, but NVPTX doesn't support that)
21+
ptx = v"6.3"
1322

1423
# we need to take care emitting LLVM instructions like `unreachable`, which
1524
# may result in thread-divergent control flow that older `ptxas` doesn't like.

0 commit comments

Comments
 (0)