Skip to content

Commit 6f7c35b

Browse files
committed
better apple silicon support
1 parent d7c3676 commit 6f7c35b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CPUSummary"
22
uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
33
authors = ["chriselrod <elrodc@gmail.com> and contributors"]
4-
version = "0.1.14"
4+
version = "0.1.15"
55

66
[deps]
77
Hwloc = "0e44f5e4-bd66-52a0-8798-143a42290a1d"

src/CPUSummary.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using IfElse: ifelse
66
export cache_size, cache_linesize, cache_associativity, cache_type,
77
cache_inclusive, num_cache, num_cores, num_threads
88

9-
const USE_HWLOC = @load_preference("hwloc", true)
9+
const USE_HWLOC = @load_preference("hwloc", Sys.ARCH !== :aarch64 || !Sys.isapple())
1010
use_hwloc(b) = @set_preferences!("hwloc" => b)
1111

1212
@static if USE_HWLOC

src/generic_topology.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22
num_machines() = static(1)
33
num_sockets() = static(1)
44

5-
let nc = static((Sys.CPU_THREADS)::Int>>1)
5+
function _get_num_threads()
6+
static((Sys.CPU_THREADS)::Int >> (Sys.ARCH !== :aarch64))
7+
end
8+
9+
let nc = _get_num_threads()
610
global num_l1cache() = nc
711
global num_cores() = nc
812
end
913
let syst = static((Sys.CPU_THREADS)::Int)
1014
global sys_threads() = syst
1115
global num_threads() = syst
1216
end
13-
17+
@static if Sys.ARCH === :aarch64
18+
num_l2cache() = static(1)
19+
num_l3cache() = static(0)
20+
else
1421
num_l2cache() = num_l1cache()
1522
num_l3cache() = static(1)
23+
end
1624
num_l4cache() = static(0)
1725

1826
if Sys.CPU_NAME === "tigerlake" || Sys.CPU_NAME === "icelake" || Sys.CPU_NAME === "icelake-server"
1927
cache_size(::Union{Val{1},StaticInt{1}}) = StaticInt{49152}()
28+
elseif Sys.ARCH === :aarch64 && Sys.isapple()
29+
cache_size(::Union{Val{1},StaticInt{1}}) = StaticInt{131072}()
2030
else
2131
cache_size(::Union{Val{1},StaticInt{1}}) = StaticInt{32768}()
2232
end
@@ -30,6 +40,8 @@ elseif Sys.CPU_NAME === "tigerlake" || Sys.CPU_NAME === "icelake-server"
3040
cache_size(::Union{Val{2},StaticInt{2}}) = StaticInt{1310720}()
3141
elseif occursin("zn", Sys.CPU_NAME) || occursin("icelake", Sys.CPU_NAME)
3242
cache_size(::Union{Val{2},StaticInt{2}}) = StaticInt{524288}()
43+
elseif Sys.ARCH === :aarch64 && Sys.isapple()
44+
cache_size(::Union{Val{2},StaticInt{2}}) = StaticInt{12582912}()
3345
else
3446
cache_size(::Union{Val{2},StaticInt{2}}) = StaticInt{262144}()
3547
end
@@ -48,7 +60,7 @@ cache_size(::Union{Val{3},StaticInt{3}}) = num_cores() * StaticInt{1441792}()
4860

4961
function __init__()
5062
ccall(:jl_generating_output, Cint, ()) == 1 && return
51-
nc = (Sys.CPU_THREADS)::Int>>1
63+
nc = _get_num_threads()
5264
syst = Sys.CPU_THREADS::Int
5365
nt = Threads.nthreads()
5466
if nc != num_l1cache()

0 commit comments

Comments
 (0)