diff --git a/Project.toml b/Project.toml index 808c511..e64ce24 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CPUSummary" uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9" authors = ["chriselrod and contributors"] -version = "0.2.6" +version = "0.2.7" [deps] CpuId = "adafc99b-e345-5852-983c-f28acb93d879" diff --git a/src/CPUSummary.jl b/src/CPUSummary.jl index 4101c01..8ab8008 100644 --- a/src/CPUSummary.jl +++ b/src/CPUSummary.jl @@ -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 @@ -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 @@ -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()), @@ -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 diff --git a/src/generic_topology.jl b/src/generic_topology.jl index be93684..df9adf1 100644 --- a/src/generic_topology.jl +++ b/src/generic_topology.jl @@ -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}() diff --git a/src/x86.jl b/src/x86.jl index d87e621..1b41898 100644 --- a/src/x86.jl +++ b/src/x86.jl @@ -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) @@ -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() @@ -55,5 +112,3 @@ function _extra_init() ci !== PrecompiledCacheInclusive && _eval_cache_inclusive(ci) return nothing end - -