Skip to content

Commit a3ac9d1

Browse files
committed
Make functional require a fully-supported GPU
1 parent f4ef7b5 commit a3ac9d1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/initialization.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
const _functional = Ref{Bool}(false)
2-
functional() = _functional[]
1+
# Starts at `nothing`. Only false when it's determined
2+
const _functional = Ref{Union{Nothing,Bool}}(false)
3+
4+
function functional()
5+
if isnothing(_functional[])
6+
dev = device()
7+
8+
_functional[] =
9+
supports_family(dev, MTL.MTLGPUFamilyApple7) &&
10+
supports_family(dev, MTL.MTLGPUFamilyMetal3)
11+
end
12+
_functional[]
13+
end
314

415
function __init__()
516
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
@@ -39,7 +50,10 @@ function __init__()
3950
load_framework("CoreGraphics")
4051
ver = MTL.MTLCompileOptions().languageVersion
4152
@debug "Successfully loaded Metal; targeting v$ver."
42-
_functional[] = true
53+
54+
# Successful loading of CoreGraphics means there's a
55+
# chance the graphics device is supported
56+
_functional[] = nothing
4357
catch err
4458
@error "Failed to load Metal" exception=(err,catch_backtrace())
4559
return

0 commit comments

Comments
 (0)