|
15 | 15 | end
|
16 | 16 |
|
17 | 17 | module __CUDA
|
18 |
| - $(CUDA.augment::String) |
| 18 | + using Base.BinaryPlatforms |
| 19 | + |
| 20 | +try |
| 21 | + using CUDA_Runtime_jll |
| 22 | +catch |
| 23 | + # during initial package installation, CUDA_Runtime_jll may not be available. |
| 24 | + # in that case, we just won't select an artifact. |
| 25 | +end |
| 26 | + |
| 27 | +# can't use Preferences for the same reason |
| 28 | +const CUDA_Runtime_jll_uuid = Base.UUID("76a88914-d11a-5bdc-97e0-2f5a05c973a2") |
| 29 | +const preferences = Base.get_preferences(CUDA_Runtime_jll_uuid) |
| 30 | +Base.record_compiletime_preference(CUDA_Runtime_jll_uuid, "version") |
| 31 | +Base.record_compiletime_preference(CUDA_Runtime_jll_uuid, "local") |
| 32 | +const local_toolkit = something(tryparse(Bool, get(preferences, "local", "false")), false) |
| 33 | + |
| 34 | +function cuda_comparison_strategy(_a::String, _b::String, a_requested::Bool, b_requested::Bool) |
| 35 | + # if we're using a local toolkit, we can't use artifacts |
| 36 | + if local_toolkit |
| 37 | + return false |
| 38 | + end |
| 39 | + |
| 40 | + # if either isn't a version number (e.g. "none"), perform a simple equality check |
| 41 | + a = tryparse(VersionNumber, _a) |
| 42 | + b = tryparse(VersionNumber, _b) |
| 43 | + if a === nothing || b === nothing |
| 44 | + return _a == _b |
| 45 | + end |
| 46 | + |
| 47 | + # if both b and a requested, then we fall back to equality |
| 48 | + if a_requested && b_requested |
| 49 | + return Base.thisminor(a) == Base.thisminor(b) |
| 50 | + end |
| 51 | + |
| 52 | + # otherwise, do the comparison between the the single version cap and the single version: |
| 53 | + function is_compatible(artifact::VersionNumber, host::VersionNumber) |
| 54 | + if host >= v"11.0" |
| 55 | + # enhanced compatibility, semver-style |
| 56 | + artifact.major == host.major && |
| 57 | + Base.thisminor(artifact) <= Base.thisminor(host) |
| 58 | + else |
| 59 | + Base.thisminor(artifact) == Base.thisminor(host) |
| 60 | + end |
| 61 | + end |
| 62 | + if a_requested |
| 63 | + is_compatible(b, a) |
| 64 | + else |
| 65 | + is_compatible(a, b) |
| 66 | + end |
| 67 | +end |
| 68 | + |
| 69 | +function augment_platform!(platform::Platform) |
| 70 | + if !@isdefined(CUDA_Runtime_jll) |
| 71 | + # don't set to nothing or Pkg will download any artifact |
| 72 | + platform["cuda"] = "none" |
| 73 | + end |
| 74 | + |
| 75 | + if !haskey(platform, "cuda") |
| 76 | + CUDA_Runtime_jll.augment_platform!(platform) |
| 77 | + end |
| 78 | + BinaryPlatforms.set_compare_strategy!(platform, "cuda", cuda_comparison_strategy) |
| 79 | + |
| 80 | + return platform |
| 81 | +end |
19 | 82 | end
|
20 | 83 |
|
21 | 84 | function augment_platform!(platform::Platform)
|
|
0 commit comments