Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CPUSummary"
uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
authors = ["chriselrod <[email protected]> and contributors"]
version = "0.2.6"
version = "0.2.7"

[deps]
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
Expand Down
45 changes: 22 additions & 23 deletions src/CPUSummary.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module CPUSummary
if isdefined(Base, :Experimental) &&
isdefined(Base.Experimental, Symbol("@max_methods"))
@eval Base.Experimental.@max_methods 1
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
@eval Base.Experimental.@max_methods 1
end

using Static
Expand Down Expand Up @@ -52,22 +51,22 @@ if (Sys.ARCH === :x86_64)
else
include("generic_topology.jl")
end
function __init__()
ccall(:jl_generating_output, Cint, ()) == 1 && return
nc = _get_num_cores()
syst = Sys.CPU_THREADS::Int
if nc != num_l1cache()
@eval num_l1cache() = static($nc)
end
if nc != num_cores()
@eval num_cores() = static($nc)
end
if syst != sys_threads()
@eval sys_threads() = static($syst)
end
_extra_init()
return nothing
end
# function __init__()
# ccall(:jl_generating_output, Cint, ()) == 1 && return
# nc = _get_num_cores()
# syst = Sys.CPU_THREADS::Int
# if nc != num_l1cache()
# @eval num_l1cache() = static($nc)
# end
# if nc != num_cores()
# @eval num_cores() = static($nc)
# end
# if syst != sys_threads()
# @eval sys_threads() = static($syst)
# end
# # _extra_init()
# return nothing
# end


# end
Expand All @@ -80,7 +79,7 @@ cache_linesize() = cache_linesize(Val(1))
function num_cache_levels()
numl4 = num_l4cache()
numl4 === nothing && return nothing
ifelse(
return ifelse(
eq(numl4, Zero()),
ifelse(
eq(num_l3cache(), Zero()),
Expand All @@ -96,8 +95,8 @@ function num_cache_levels()
end

# explicit precompilation only on Julia v1.9 and newer
if VERSION >= v"1.9"
include("precompile.jl")
end
# if VERSION >= v"1.9"
# include("precompile.jl")
# end

end
6 changes: 4 additions & 2 deletions src/generic_topology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ end
cache_associativity(::Union{Val{2},StaticInt{2}}) = StaticInt{0}()
cache_type(::Union{Val{2},StaticInt{2}}) = Val{:Unified}()
cache_inclusive(_) = False()
@static if Sys.ARCH === :aarch64 && (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
@static if Sys.ARCH === :aarch64 &&
(Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
cache_linesize(_) = StaticInt{128}() # assume...
else
cache_linesize(_) = StaticInt{64}() # assume...
end
cache_size(_) = StaticInt{0}()

@static if Sys.ARCH === :aarch64 && (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
@static if Sys.ARCH === :aarch64 &&
(Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
else
cache_type(::Union{Val{3},StaticInt{3}}) = Val{:Unified}()
cache_size(::Union{Val{3},StaticInt{3}}) = StaticInt{1441792}()
Expand Down
79 changes: 67 additions & 12 deletions src/x86.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,76 @@ const PrecompiledCacheSize = let cs = CpuId.cachesize()
ntuple(i -> i == 3 ? cs[3] ÷ _get_num_cores() : cs[i], length(cs))
end
const PrecompiledCacheInclusive = CpuId.cacheinclusive()
cache_inclusive(_) = False()
@noinline function _eval_cache_size(cachesize)
for (i, csi) in enumerate(cachesize)
@eval cache_size(::Union{Val{$i},StaticInt{$i}}) = $(static(csi))
# cache_inclusive(_) = False()
# @noinline function _eval_cache_size(cachesize)
# for (i, csi) in enumerate(cachesize)
# @eval cache_size(::Union{Val{$i},StaticInt{$i}}) = $(static(csi))
# end
# end
# @noinline function _eval_cache_inclusive(cacheinclusive)
# for (i, cii) in enumerate(cacheinclusive)
# @eval cache_inclusive(::Union{Val{$i},StaticInt{$i}}) = $(static(cii != 0))
# end
# end
# _eval_cache_size(PrecompiledCacheSize)
# _eval_cache_inclusive(PrecompiledCacheInclusive)


cache_size(::Val{S}) where {S} = cache_size(S)
cache_size(::StaticInt{S}) where {S} = cache_size(S)

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

cache_sizes = map(enumerate(cs)) do (i, csi)

return :(
if cachesize == $i
return static($csi)
end
)
end

return quote
begin
$(cache_sizes...)
end
end

end
@noinline function _eval_cache_inclusive(cacheinclusive)
for (i, cii) in enumerate(cacheinclusive)
@eval cache_inclusive(::Union{Val{$i},StaticInt{$i}}) = $(static(cii != 0))
cache_inclusive(::Val{S}) where {S} = cache_inclusive(S)
cache_inclusive(::StaticInt{S}) where {S} = cache_inclusive(S)

@inline @generated function cache_inclusive(cacheinclusive)
ci = CpuId.cacheinclusive()

cache_inclusives = map(enumerate(ci)) do (i, cii)
val = cii != 0
return :(
if cacheinclusive == $i
return static($val)
end
)
end

if !isempty(cache_inclusives)
push!(cache_inclusives, :(return False()))
else
cache_inclusives = [:(return False())]
end

return quote
begin
$(cache_inclusives...)
end
end


end
_eval_cache_size(PrecompiledCacheSize)
_eval_cache_inclusive(PrecompiledCacheInclusive)


# TODO: implement
cache_associativity(_) = static(0)

Expand All @@ -43,7 +100,7 @@ cache_type(_) = Val{:Unified}()
let lnsize = static(CpuId.cachelinesize())
global cache_linesize(_) = lnsize
end
cache_size(_) = StaticInt{0}()
# cache_size(_) = StaticInt{0}()

# cache_size(::Union{Val{3},StaticInt{3}}) = num_cores() * StaticInt{1441792}()
function _extra_init()
Expand All @@ -55,5 +112,3 @@ function _extra_init()
ci !== PrecompiledCacheInclusive && _eval_cache_inclusive(ci)
return nothing
end


Loading