Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extended_platform_key_abi #6

Closed
Closed
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
10 changes: 8 additions & 2 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.0"

[[CpuId]]
deps = ["Markdown", "Test"]
git-tree-sha1 = "f0464e499ab9973b43c20f8216d088b61fda80c6"
uuid = "adafc99b-e345-5852-983c-f28acb93d879"
version = "0.2.2"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down Expand Up @@ -99,6 +105,6 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Zlib_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "a2e0d558f6031002e380a90613b199e37a8565bf"
git-tree-sha1 = "64b39656c75e67f85b4ac2b336c54674a39f599d"
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.11+10"
version = "1.2.11+11"
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.2.0"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand All @@ -17,6 +18,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
CodecZlib = "0.5, 0.6, 0.7"
CpuId = "0.2"
JSON = "0.21"
OutputCollectors = "0.1"
julia = "1.3"
Expand Down
38 changes: 37 additions & 1 deletion src/Platforms.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Pkg.Artifacts, Pkg.BinaryPlatforms, Logging
using CpuId

export AnyPlatform, ExtendedPlatform, base_platform
export AnyPlatform, ExtendedPlatform, base_platform, extended_platform_key_abi

"""
AnyPlatform()
Expand Down Expand Up @@ -207,3 +208,38 @@ function Pkg.Artifacts.pack_platform!(meta::Dict, p::ExtendedPlatform)
# override the default ones
Artifacts.pack_platform!(meta, base_platform(p))
end

# NOTE: the keyword arguments are *not* part of the public API, they're only
# used for testing purposes and they may change in the future.
"""
extended_platform_key_abi()

Returns the `Platform` representing the current platform. It is an
[`ExtendedPlatform`](@ref) if it possible to detect additional features, like
the microarchitecture.
"""
function extended_platform_key_abi(; p::Platform = platform_key_abi(),
cpu_features::Vector{Symbol} = cpufeatures())
function get_x86_64_march(cpu_features)
# List of CPU features from https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
if all(in(cpu_features), (:MMX, :SSE, :SSE2, :SSE3, :SSSE3, :SSE41, :SSE42, :POPCNT, :AVX, :AES, :PCLMUL))
# Some names are different: FSGSBASE -> FSGS, FMA -> FMA3, BMI -> BMI1
if all(in(cpu_features), (:MOVBE, :AVX2, :FSGS, :RDRND, :FMA3, :BMI1, :BMI2, :F16C))
# Some names are different: ADCX -> ADX, CLFLUSHOPT -> CLFLUSH, XSAVEC and XSAVES -> :XSAVE
if all(in(cpu_features), (:PKU, :RDSEED, :ADX, :PREFETCHW, :CLFLUSH, :XSAVE, :AVX512F, :CLWB, :AVX512VL, :AVX512BW, :AVX512DQ, :AVX512CD))
return "avx512"
end
return "avx2"
end
return "avx"
end
# Generic fallback
return "x86_64"
end

if arch(p) == :x86_64
return ExtendedPlatform(p; march=get_x86_64_march(cpu_features))
else
return p
end
end
45 changes: 45 additions & 0 deletions test/platforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,51 @@ end
# Extending different platforms
@test !platforms_match(ExtendedPlatform(Linux(:i686); cuda="10.1"), ExtendedPlatform(FreeBSD(:x86_64); cuda="11.1"))
end

@testset "extended_platform_key_abi" begin
p = Linux(:i686)
@test extended_platform_key_abi(; p=p) == p
# The following sets of CPU features are taken from real machines
p = Linux(:x86_64)
cpu_features = [
:AES, :AHF64, :APIC, :APIC_, :AVX, :CLFSH, :CMOV, :CMOV_, :CMPLEG,
:CR8D, :CX16, :CX8, :CX8_, :DE, :DE_, :FFXSR, :FMA4, :FPU, :FPU_,
:FXSR, :FXSR_, :HYPVS, :LM, :LZCNT, :MCA, :MCA_, :MCE, :MCE_, :MMX,
:MMXEXT_, :MMX_, :MSR, :MSR_, :MTRR, :MTRR_, :NX, :OSVW, :OSXSV,
:PAE, :PAE_, :PAT, :PAT_, :PCLMUL, :PG1G, :PGE, :PGE_, :POPCNT,
:PREFETCHW, :PSE, :PSE36, :PSE36_, :PSE_, :SEP, :SSE, :SSE2, :SSE3,
:SSE41, :SSE42, :SSE4A, :SSEMISALIGN, :SSSE3, :SYSCALL, :TSC, :TSC_,
:VME, :VME_, :X2APIC, :XOP, :XSAVE
]
@test extended_platform_key_abi(; p=p, cpu_features=cpu_features) == ExtendedPlatform(p; march="avx")
cpu_features = [
:ACPI, :AES, :AHF64, :APIC, :AVX, :AVX2, :BMI1, :BMI2, :CLFSH,
:CMOV, :CX16, :CX8, :DE, :DS, :DSCPL, :DTES64, :ERMS, :EST, :F16C,
:FMA3, :FP128, :FP256, :FPDPR, :FPU, :FSGS, :FXSR, :HTT, :INVPCID,
:LM, :LZCNT, :MCA, :MCE, :MMX, :MON, :MOVBE, :MOVU, :MSR, :MTRR,
:NX, :OSXSV, :PAE, :PAT, :PBE, :PCID, :PCLMUL, :PDCM, :PG1G, :PGE,
:POPCNT, :PSE, :PSE36, :RDRND, :RDTSCP, :SDBG, :SEP, :SMEP, :SMX,
:SS, :SSE, :SSE2, :SSE3, :SSE41, :SSE42, :SSSE3, :SYSCALL, :TM,
:TM2, :TSC, :TSCADJ, :TSCDL, :TSCINV, :VME, :VMX, :X2APIC, :XSAVE,
:XTPR
]
@test extended_platform_key_abi(; p=p, cpu_features=cpu_features) == ExtendedPlatform(p; march="avx2")
cpu_features = [
:ACPI, :ADX, :AES, :AHF64, :APIC, :AVX, :AVX2, :AVX512BW, :AVX512CD,
:AVX512DQ, :AVX512F, :AVX512VL, :BMI1, :BMI2, :CLFLUSH, :CLFSH,
:CLWB, :CMOV, :CX16, :CX8, :DCA, :DE, :DS, :DSCPL, :DTES64, :ERMS,
:EST, :F16C, :FMA3, :FP256, :FPDPR, :FPU, :FSGS, :FXSR, :HLE, :HTT,
:INVPCID, :IPT, :LM, :LZCNT, :MCA, :MCE, :MMX, :MON, :MOVBE, :MPX,
:MSR, :MTRR, :NX, :OSPKE, :OSXSV, :PAE, :PAT, :PBE, :PCID, :PCLMUL,
:PDCM, :PG1G, :PGE, :PKU, :POPCNT, :PQE, :PQM, :PREFETCHW, :PSE,
:PSE36, :RDRND, :RDSEED, :RDTSCP, :RTM, :SDBG, :SEP, :SMAP, :SMEP,
:SMX, :SS, :SSE, :SSE2, :SSE3, :SSE41, :SSE42, :SSSE3, :SYSCALL,
:TM, :TM2, :TSC, :TSCADJ, :TSCDL, :TSCINV, :VME, :VMX, :X2APIC,
:XSAVE, :XTPR
]
@test extended_platform_key_abi(; p=p, cpu_features=cpu_features) == ExtendedPlatform(p; march="avx512")
@test extended_platform_key_abi(; p=p, cpu_features=Symbol[]) == ExtendedPlatform(p; march="x86_64")
end
end

@testset "AnyPlatform" begin
Expand Down