File tree Expand file tree Collapse file tree 5 files changed +50
-14
lines changed
Expand file tree Collapse file tree 5 files changed +50
-14
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ version = "0.1.17"
77BitTwiddlingConvenienceFunctions = " 62783981-4cbd-42fc-bca8-16325de8dc4b"
88IfElse = " 615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
99Libdl = " 8f399da3-3557-5675-b5ff-fb832c97cbdb"
10+ Preferences = " 21216c6a-2e73-6563-6e65-726566657250"
1011Static = " aedffcd0-7271-4cad-89d0-dc628f76c6d3"
1112
1213[compat ]
Original file line number Diff line number Diff line change 77using Libdl, Static
88using Static: Zero, One, lt, gt
99using IfElse: ifelse
10+ using Preferences
1011
1112using BitTwiddlingConvenienceFunctions: prevpow2, nextpow2, intlog2
1213
@@ -37,19 +38,26 @@ unwrap(::StaticSymbol{S}) where {S} = S
3738
3839@noinline function redefine ()
3940 @debug " Defining CPU name."
40- define_cpu_name ()
41+ redefine_cpu_name ()
4142
4243 reset_features! ()
4344 reset_extra_features! ()
4445end
4546const BASELINE_CPU_NAME = get_cpu_name ()
47+ const allow_eval = @load_preference (" allow_runtime_invalidation" , false )
48+
4649function __init__ ()
4750 ccall (:jl_generating_output , Cint, ()) == 1 && return
4851 if Sys. ARCH === :x86_64 || Sys. ARCH === :i686
4952 target = Base. unsafe_string (Base. JLOptions (). cpu_target)
50- occursin (" native" , target) || return make_generic (target)
53+ if ! occursin (" native" , target)
54+ make_generic (target)
55+ return nothing
56+ end
57+ end
58+ if BASELINE_CPU_NAME != Sys. CPU_NAME:: String
59+ redefine ()
5160 end
52- BASELINE_CPU_NAME == Sys. CPU_NAME:: String || redefine ()
5361 return nothing
5462end
5563
Original file line number Diff line number Diff line change @@ -48,8 +48,12 @@ function reset_features!()
4848 for ext ∈ features
4949 feature, has = process_feature (ext)
5050 if _has_feature (feature) ≠ has
51- @debug " Defining $(has ? " presence" : " absense" ) of feature $feature ."
52- set_feature (feature, has)
51+ if allow_eval
52+ @debug " Defining $(has ? " presence" : " absense" ) of feature $feature ."
53+ set_feature (feature, has)
54+ else
55+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU feature flag: $ext ."
56+ end
5357 end
5458 end
5559 Libc. free (features_cstring)
5862register_size (:: Type{T} ) where {T} = register_size ()
5963register_size (:: Type{T} ) where {T<: Union{Signed,Unsigned} } = simd_integer_register_size ()
6064
61- function define_cpu_name ()
65+ function redefine_cpu_name ()
6266 cpu = QuoteNode (Symbol (get_cpu_name ()))
63- @eval cpu_name () = Val {$cpu} ()
67+ if allow_eval
68+ @eval cpu_name () = Val {$cpu} ()
69+ else
70+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU name (from build time)."
71+ end
6472end
65- define_cpu_name ()
73+ cpu = QuoteNode (Symbol (get_cpu_name ()))
74+ @eval cpu_name () = Val {$cpu} ()
Original file line number Diff line number Diff line change 3939
4040function reset_extra_features! ()
4141 drs = _dynamic_register_size ()
42- register_size () ≠ drs && _set_sve_vector_width! (drs)
42+ if register_size () ≠ drs
43+ if allow_eval
44+ _set_sve_vector_width! (drs)
45+ else
46+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU register size."
47+ end
48+ end
4349 hassve = _has_aarch64_sve ()
4450 if hassve ≠ has_feature (Val (:aarch64_sve_cpuid ))
45- @eval has_feature (:: Val{:aarch64_sve_cpuid} ) = $ (Expr (:call , hassve ? :True : :False ))
51+ if allow_eval
52+ @eval has_feature (:: Val{:aarch64_sve_cpuid} ) = $ (Expr (:call , hassve ? :True : :False ))
53+ else
54+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU feature flag: :aarch64_sve_cpuid."
55+ end
4656 end
4757end
4858
Original file line number Diff line number Diff line change @@ -32,14 +32,22 @@ fast_int64_to_double() = has_feature(Val(:x86_64_avx512dq))
3232
3333fast_half () = False ()
3434
35- @noinline function setfeaturefalse (s)
35+ @inline function setfeaturefalse (s)
3636 if has_feature (Val (s)) === True ()
37- @eval has_feature (:: Val{$(QuoteNode(s))} ) = False ()
37+ if allow_eval
38+ @eval has_feature (:: Val{$(QuoteNode(s))} ) = False ()
39+ else
40+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU feature flag: $s ."
41+ end
3842 end
3943end
40- @noinline function setfeaturetrue (s)
44+ @inline function setfeaturetrue (s)
4145 if has_feature (Val (s)) === False ()
42- @eval has_feature (:: Val{$(QuoteNode(s))} ) = True ()
46+ if allow_eval
47+ @eval has_feature (:: Val{$(QuoteNode(s))} ) = True ()
48+ else
49+ @warn " Runtime invalidation was disabled, but the CPU info is out-of-date.\n Will continue with incorrect CPU feature flag: $s ."
50+ end
4351 end
4452end
4553
You can’t perform that action at this time.
0 commit comments