Skip to content

Commit f571858

Browse files
committed
Format coded according to JuliaFormatter
1 parent 20f5bd1 commit f571858

File tree

3 files changed

+81
-80
lines changed

3 files changed

+81
-80
lines changed

src/CPUSummary.jl

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
module CPUSummary
2-
if isdefined(Base, :Experimental) &&
3-
isdefined(Base.Experimental, Symbol("@max_methods"))
4-
@eval Base.Experimental.@max_methods 1
2+
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
3+
@eval Base.Experimental.@max_methods 1
54
end
65

76
using Static
87
using Static: Zero, One, gt, lt
98
using IfElse: ifelse
109
export cache_size,
11-
cache_linesize, cache_associativity, cache_type, cache_inclusive, num_cache, num_cores
10+
cache_linesize, cache_associativity, cache_type, cache_inclusive, num_cache, num_cores
1211

1312
# const USE_HWLOC = @load_preference("hwloc", Sys.ARCH !== :aarch64 || !Sys.isapple())
1413
# use_hwloc(b) = @set_preferences!("hwloc" => b)
@@ -41,16 +40,16 @@ Returns the cache size per core of the `N`th cache
4140
function cache_size end
4241

4342
function get_cpu_threads()::Int
44-
if isdefined(Sys, :CPU_THREADS)
45-
return Sys.CPU_THREADS
46-
else
47-
return Int(ccall(:jl_cpu_threads, Int32, ()))::Int
48-
end
43+
if isdefined(Sys, :CPU_THREADS)
44+
return Sys.CPU_THREADS
45+
else
46+
return Int(ccall(:jl_cpu_threads, Int32, ()))::Int
47+
end
4948
end
5049
if (Sys.ARCH === :x86_64)
51-
include("x86.jl")
50+
include("x86.jl")
5251
else
53-
include("generic_topology.jl")
52+
include("generic_topology.jl")
5453
end
5554
# function __init__()
5655
# ccall(:jl_generating_output, Cint, ()) == 1 && return
@@ -71,28 +70,28 @@ end
7170

7271

7372
# end
74-
num_cache(::Union{Val{1}, StaticInt{1}}) = num_l1cache()
75-
num_cache(::Union{Val{2}, StaticInt{2}}) = num_l2cache()
76-
num_cache(::Union{Val{3}, StaticInt{3}}) = num_l3cache()
77-
num_cache(::Union{Val{4}, StaticInt{4}}) = num_l4cache()
73+
num_cache(::Union{Val{1},StaticInt{1}}) = num_l1cache()
74+
num_cache(::Union{Val{2},StaticInt{2}}) = num_l2cache()
75+
num_cache(::Union{Val{3},StaticInt{3}}) = num_l3cache()
76+
num_cache(::Union{Val{4},StaticInt{4}}) = num_l4cache()
7877
const BASELINE_CORES = Int(num_cores()) * ((Sys.ARCH === :aarch64) && Sys.isapple() ? 2 : 1)
7978
cache_linesize() = cache_linesize(Val(1))
8079
function num_cache_levels()
81-
numl4 = num_l4cache()
82-
numl4 === nothing && return nothing
83-
return ifelse(
84-
eq(numl4, Zero()),
85-
ifelse(
86-
eq(num_l3cache(), Zero()),
87-
ifelse(
88-
eq(num_l2cache(), Zero()),
89-
ifelse(eq(num_l1cache(), Zero()), Zero(), One()),
90-
StaticInt{2}(),
91-
),
92-
StaticInt{3}(),
93-
),
94-
StaticInt{4}(),
95-
)
80+
numl4 = num_l4cache()
81+
numl4 === nothing && return nothing
82+
return ifelse(
83+
eq(numl4, Zero()),
84+
ifelse(
85+
eq(num_l3cache(), Zero()),
86+
ifelse(
87+
eq(num_l2cache(), Zero()),
88+
ifelse(eq(num_l1cache(), Zero()), Zero(), One()),
89+
StaticInt{2}(),
90+
),
91+
StaticInt{3}(),
92+
),
93+
StaticInt{4}(),
94+
)
9695
end
9796

9897
# explicit precompilation only on Julia v1.9 and newer

src/generic_topology.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ end
3535
cache_associativity(::Union{Val{2},StaticInt{2}}) = StaticInt{0}()
3636
cache_type(::Union{Val{2},StaticInt{2}}) = Val{:Unified}()
3737
cache_inclusive(_) = False()
38-
@static if Sys.ARCH === :aarch64 && (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
38+
@static if Sys.ARCH === :aarch64 &&
39+
(Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
3940
cache_linesize(_) = StaticInt{128}() # assume...
4041
else
4142
cache_linesize(_) = StaticInt{64}() # assume...
4243
end
4344
cache_size(_) = StaticInt{0}()
4445

45-
@static if Sys.ARCH === :aarch64 && (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
46+
@static if Sys.ARCH === :aarch64 &&
47+
(Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
4648
else
4749
cache_type(::Union{Val{3},StaticInt{3}}) = Val{:Unified}()
4850
cache_size(::Union{Val{3},StaticInt{3}}) = StaticInt{1441792}()

src/x86.jl

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ num_sockets() = static(1)
66
_get_num_cores()::Int = clamp(CpuId.cpucores(), 1, (get_cpu_threads())::Int)
77

88
let nc = static(_get_num_cores())
9-
global num_l1cache() = nc
10-
global num_cores() = nc
9+
global num_l1cache() = nc
10+
global num_cores() = nc
1111
end
1212
let syst = static((get_cpu_threads())::Int)
13-
global sys_threads() = syst
13+
global sys_threads() = syst
1414
end
1515
num_l2cache() = num_l1cache()
1616
num_l3cache() = static(1)
1717
num_l4cache() = static(0)
1818

1919
const PrecompiledCacheSize = let cs = CpuId.cachesize()
20-
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
20+
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
2121
end
2222
const PrecompiledCacheInclusive = CpuId.cacheinclusive()
2323
# cache_inclusive(_) = False()
@@ -39,52 +39,52 @@ cache_size(::Val{S}) where {S} = cache_size(S)
3939
cache_size(::StaticInt{S}) where {S} = cache_size(S)
4040

4141
@inline @generated function cache_size(cachesize)
42-
cs = let cs = CpuId.cachesize()
43-
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
44-
end
42+
cs = let cs = CpuId.cachesize()
43+
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
44+
end
4545

46-
cache_sizes = map(enumerate(cs)) do (i, csi)
46+
cache_sizes = map(enumerate(cs)) do (i, csi)
4747

48-
return :(
49-
if cachesize == $i
50-
return static($csi)
51-
end
52-
)
53-
end
48+
return :(
49+
if cachesize == $i
50+
return static($csi)
51+
end
52+
)
53+
end
5454

55-
return quote
56-
begin
57-
$(cache_sizes...)
58-
end
55+
return quote
56+
begin
57+
$(cache_sizes...)
5958
end
59+
end
6060

6161
end
6262
cache_inclusive(::Val{S}) where {S} = cache_inclusive(S)
6363
cache_inclusive(::StaticInt{S}) where {S} = cache_inclusive(S)
6464

6565
@inline @generated function cache_inclusive(cacheinclusive)
66-
ci = CpuId.cacheinclusive()
67-
68-
cache_inclusives = map(enumerate(ci)) do (i, cii)
69-
val = cii != 0
70-
return :(
71-
if cacheinclusive == $i
72-
return static($val)
73-
end
74-
)
75-
end
76-
77-
if !isempty(cache_inclusives)
78-
push!(cache_inclusives, :(return False()))
79-
else
80-
cache_inclusives = [:(return False())]
81-
end
82-
83-
return quote
84-
begin
85-
$(cache_inclusives...)
86-
end
66+
ci = CpuId.cacheinclusive()
67+
68+
cache_inclusives = map(enumerate(ci)) do (i, cii)
69+
val = cii != 0
70+
return :(
71+
if cacheinclusive == $i
72+
return static($val)
73+
end
74+
)
75+
end
76+
77+
if !isempty(cache_inclusives)
78+
push!(cache_inclusives, :(return False()))
79+
else
80+
cache_inclusives = [:(return False())]
81+
end
82+
83+
return quote
84+
begin
85+
$(cache_inclusives...)
8786
end
87+
end
8888

8989

9090
end
@@ -93,22 +93,22 @@ end
9393
# TODO: implement
9494
cache_associativity(_) = static(0)
9595

96-
cache_type(::Union{Val{1}, StaticInt{1}}) = Val{:Data}()
96+
cache_type(::Union{Val{1},StaticInt{1}}) = Val{:Data}()
9797
cache_type(_) = Val{:Unified}()
9898
# cache_type(::Union{Val{2},StaticInt{2}}) = Val{:Unified}()
9999
# cache_type(::Union{Val{3},StaticInt{3}}) = Val{:Unified}()
100100
let lnsize = static(CpuId.cachelinesize())
101-
global cache_linesize(_) = lnsize
101+
global cache_linesize(_) = lnsize
102102
end
103103
# cache_size(_) = StaticInt{0}()
104104

105105
# cache_size(::Union{Val{3},StaticInt{3}}) = num_cores() * StaticInt{1441792}()
106106
function _extra_init()
107-
cs = let cs = CpuId.cachesize()
108-
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
109-
end
110-
cs !== PrecompiledCacheSize && _eval_cache_size(cs)
111-
ci = CpuId.cacheinclusive()
112-
ci !== PrecompiledCacheInclusive && _eval_cache_inclusive(ci)
113-
return nothing
107+
cs = let cs = CpuId.cachesize()
108+
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
109+
end
110+
cs !== PrecompiledCacheSize && _eval_cache_size(cs)
111+
ci = CpuId.cacheinclusive()
112+
ci !== PrecompiledCacheInclusive && _eval_cache_inclusive(ci)
113+
return nothing
114114
end

0 commit comments

Comments
 (0)