Skip to content

Commit

Permalink
makegeneric
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Nov 14, 2022
1 parent 9cf6071 commit 2bdb3df
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HostCPUFeatures"
uuid = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0"
authors = ["Chris Elrod <[email protected]> and contributors"]
version = "0.1.10"
version = "0.1.11"

[deps]
BitTwiddlingConvenienceFunctions = "62783981-4cbd-42fc-bca8-16325de8dc4b"
Expand Down
4 changes: 4 additions & 0 deletions src/HostCPUFeatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ unwrap(::StaticSymbol{S}) where {S} = S
end
const BASELINE_CPU_NAME = get_cpu_name()
function __init__()
if Sys.ARCH === :x86_64
target = Base.unsafe_string(Base.JLOptions().cpu_target)
occursin("native", target) || return make_generic(target)
end
ccall(:jl_generating_output, Cint, ()) == 1 && return
BASELINE_CPU_NAME == Sys.CPU_NAME::String || redefine()
return nothing
Expand Down
76 changes: 76 additions & 0 deletions src/cpu_info_x86.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,79 @@ fast_int64_to_double() = has_feature(Val(:x86_64_avx512dq))

fast_half() = False()

@noinline function setfeaturefalse(s)
if has_feature(Val(s)) === True()
@eval has_feature(::Val{:x86_64_avx512ifma}) = False()
end
end
@noinline function setfeaturetrue(s)
if has_feature(Val(s)) === False()
@eval has_feature(::Val{:x86_64_avx512ifma}) = True()
end
end

function make_generic(target)
if occursin("tigerlake", target) || occursin("znver4", target)
# most feature-complete architectures we use
setfeaturetrue(:x86_64_avx512ifma)
setfeaturetrue(:x86_64_avx512vl)
setfeaturetrue(:x86_64_avx512bw)
setfeaturetrue(:x86_64_avx512dq)
setfeaturetrue(:x86_64_avx512f)
setfeaturetrue(:x86_64_avx2)
setfeaturetrue(:x86_64_bmi2)
setfeaturetrue(:x86_64_fma)
setfeaturetrue(:x86_64_avx)
elseif occursin("icelake", target) || occursin("skylake-avx512", target) || occursin("rocketlake", target) || occursin("cascadelake", target)
# no ifma, but avx512f and avx512dq
setfeaturefalse(:x86_64_avx512ifma)
setfeaturetrue(:x86_64_avx512vl)
setfeaturetrue(:x86_64_avx512bw)
setfeaturetrue(:x86_64_avx512dq)
setfeaturetrue(:x86_64_avx512f)
setfeaturetrue(:x86_64_avx2)
setfeaturetrue(:x86_64_bmi2)
setfeaturetrue(:x86_64_fma)
setfeaturetrue(:x86_64_avx)
return
elseif occursin("znver", target) || occursin("lake", target) || occursin("well", target)
# no avx512, but avx2, fma, and bmi2
# znver tries to capture all zen < 4
# lake tries to capture lakes we didn't single out above as having avx512
#
setfeaturefalse(:x86_64_avx512ifma)
setfeaturefalse(:x86_64_avx512vl)
setfeaturefalse(:x86_64_avx512bw)
setfeaturefalse(:x86_64_avx512dq)
setfeaturefalse(:x86_64_avx512f)
setfeaturetrue(:x86_64_avx2)
setfeaturetrue(:x86_64_bmi2)
setfeaturetrue(:x86_64_fma)
setfeaturetrue(:x86_64_avx)
return
elseif occursin("ivybridge", target) || occursin("sandybridge", target)
# has avx, and that is about it we care about
setfeaturefalse(:x86_64_avx512ifma)
setfeaturefalse(:x86_64_avx512vl)
setfeaturefalse(:x86_64_avx512bw)
setfeaturefalse(:x86_64_avx512dq)
setfeaturefalse(:x86_64_avx512f)
setfeaturefalse(:x86_64_avx2)
setfeaturefalse(:x86_64_bmi2)
setfeaturefalse(:x86_64_fma)
setfeaturetrue(:x86_64_avx)
else
# hopefully we didn't miss something
# TODO: sapphire rapids
setfeaturefalse(:x86_64_avx512ifma)
setfeaturefalse(:x86_64_avx512vl)
setfeaturefalse(:x86_64_avx512bw)
setfeaturefalse(:x86_64_avx512dq)
setfeaturefalse(:x86_64_avx512f)
setfeaturefalse(:x86_64_avx2)
setfeaturefalse(:x86_64_bmi2)
setfeaturefalse(:x86_64_fma)
setfeaturefalse(:x86_64_avx)
end
end

0 comments on commit 2bdb3df

Please sign in to comment.