@@ -68,24 +68,45 @@ function versioninfo(io::IO=stdout)
6868 return
6969end
7070
71+ const _iokitlib = Symbol (" /System/Library/Frameworks/IOKit.framework/Resources/BridgeSupport/IOKit.dylib" )
72+ const _cflib = Symbol (" /System/Library/Frameworks/CoreFoundation.framework/Resources/BridgeSupport/CoreFoundation.dylib" )
73+
7174@static if isdefined (Base, :OncePerProcess ) # VERSION >= v"1.12.0-DEV.1421"
7275 const num_gpu_cores = OncePerProcess {Int64} () do
73- _num_cpu_cores = 0
76+ _num_gpu_cores = Ref {Int64} ( 0 )
7477 try
75- system_prof = read (` system_profiler SPDisplaysDataType` , String)
76- _num_gpu_cores = parse (Int64, only (match (r" Total Number of Cores:\s *(\d +)" , system_prof). captures))
78+ serv_match = @ccall _iokitlib. IOServiceMatching (" AGXAccelerator" :: Cstring ):: Ptr{Cvoid}
79+ serv = @ccall _iokitlib. IOServiceGetMatchingService (C_NULL :: Ptr{Nothing} , serv_match:: Ptr{Cvoid} ):: UInt
80+
81+ gpuCoreCountNumber = @ccall _iokitlib. IORegistryEntrySearchCFProperty (serv:: UInt , " IOService" :: Ptr{Cchar} , " gpu-core-count" :: id{NSString} , C_NULL :: Ptr{Nothing} , UInt32 (0 ):: UInt32 ):: id{Object}
82+ gpuCoreCountNumber != nil || error ()
83+
84+ type = @ccall _cflib. CFNumberGetType (gpuCoreCountNumber:: id{Object} ):: Int64
85+ type == 4 || error ()
86+
87+ success = @ccall _cflib. CFNumberGetValue (gpuCoreCountNumber:: id{Object} , type:: Int64 , _num_gpu_cores:: Ptr{Int64} ):: Bool
88+ success || error ()
7789 catch
7890 @warn " Could not determine number of GPU cores; some algorithms may not run optimally."
7991 end
80- _num_cpu_cores
92+ _num_gpu_cores[]
8193 end
8294else
8395 const _num_gpu_cores = Ref {Int64} (- 1 )
8496 function num_gpu_cores ()
8597 if _num_gpu_cores[] == - 1
8698 try
87- system_prof = read (` system_profiler SPDisplaysDataType` , String)
88- _num_gpu_cores[] = parse (Int64, only (match (r" Total Number of Cores:\s *(\d +)" , system_prof). captures))
99+ serv_match = @ccall _iokitlib. IOServiceMatching (" AGXAccelerator" :: Cstring ):: Ptr{Cvoid}
100+ serv = @ccall _iokitlib. IOServiceGetMatchingService (C_NULL :: Ptr{Nothing} , serv_match:: Ptr{Cvoid} ):: UInt
101+
102+ gpuCoreCountNumber = @ccall _iokitlib. IORegistryEntrySearchCFProperty (serv:: UInt , " IOService" :: Ptr{Cchar} , " gpu-core-count" :: id{NSString} , C_NULL :: Ptr{Nothing} , UInt32 (0 ):: UInt32 ):: id{Object}
103+ gpuCoreCountNumber != nil || error ()
104+
105+ type = @ccall _cflib. CFNumberGetType (gpuCoreCountNumber:: id{Object} ):: Int64
106+ type == 4 || error ()
107+
108+ success = @ccall _cflib. CFNumberGetValue (gpuCoreCountNumber:: id{Object} , type:: Int64 , _num_gpu_cores:: Ptr{Int64} ):: Bool
109+ success || error ()
89110 catch
90111 @warn " Could not determine number of GPU cores; some algorithms may not run optimally."
91112 _num_gpu_cores[] = 0
0 commit comments