Skip to content

Commit

Permalink
[finufft] Augment platforms by setting the microarchitecture
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Mar 22, 2022
1 parent 8c3c38c commit 66ff7e6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
39 changes: 27 additions & 12 deletions F/finufft/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using BinaryBuilder, Pkg
using BinaryBuilderBase

include(joinpath(@__DIR__, "..", "..", "platforms", "microarchitectures.jl"))

name = "finufft"
version = v"2.0.4"
julia_compat = "1.6"
Expand All @@ -17,30 +19,43 @@ script = raw"""
cd $WORKSPACE/srcdir/finufft*/
# Overwrite LIBSFFT such that we do not require fftw3_threads or fftw3_omp for OMP support. Since the libraries in FFTW_jll already provide for threading, we do not loose anything.
# Make use of the -DFFTW_PLAN_SAFE flag to allow for multiple threads using finufft at the same time.
make lib CFLAGS="-fopenmp -fPIC -O3 -funroll-loops -fcx-limited-range -Iinclude" CXXFLAGS="-fopenmp -fPIC -O3 -funroll-loops -fcx-limited-range -Iinclude -std=c++14 -DFFTW_PLAN_SAFE" LIBSFFT="-lfftw3 -lfftw3f -lm"
mv lib/libfinufft.so "${libdir}/libfinufft.${dlext}"
make lib \
CFLAGS="-fopenmp -fPIC -O3 -funroll-loops -fcx-limited-range -Iinclude" \
CXXFLAGS="-fopenmp -fPIC -O3 -funroll-loops -fcx-limited-range -Iinclude -std=c++14 -DFFTW_PLAN_SAFE" \
LIBSFFT="-lfftw3 -lfftw3f -lm"
install -Dvm 0755 lib/libfinufft.so "${libdir}/libfinufft.${dlext}"
"""

# Build for all supported platforms
platforms_x86_64 = filter(p -> p.tags["arch"]=="x86_64", supported_platforms())
platforms_other = filter(p -> p.tags["arch"]!="x86_64", supported_platforms())

# Expand for microarchitectures on x86_64 (library doesn't have CPU dispatching)
# Tests on Linux/x86_64 yielded a slow binary with avx512 for some reason, so disable that
platforms_x86_64 = expand_microarchitectures(platforms_x86_64)
platforms_x86_64 = filter(p -> p.tags["march"] != "avx512", platforms_x86_64)
platforms = expand_cxxstring_abis(expand_microarchitectures(supported_platforms(), ["x86_64", "avx", "avx2"]); skip=!Sys.iswindows)

augment_platform_block = """
$(MicroArchitectures.augment)
function augment_platform!(platform::Platform)
# We augment only x86_64
@static if Sys.ARCH === :x86_64
augment_microarchitecture!(platform)
else
platform
end
end
"""

platforms = vcat(platforms_x86_64, platforms_other)
# The products that we will ensure are always built
products = [
LibraryProduct("libfinufft", :libfinufft)
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency(PackageSpec(name="FFTW_jll", uuid="f5851436-0d7a-5f13-b9de-f02708fd171a"))
Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"))
Dependency(PackageSpec(name="FFTW_jll", uuid="f5851436-0d7a-5f13-b9de-f02708fd171a")),
# TODO: we should use clang as compiler on BSD systems and use
# `LLVMOpenMP_jll` to provide the OpenMP implementation.
Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae")),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version = v"8", julia_compat=julia_compat)
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
preferred_gcc_version = v"8", julia_compat, augment_platform_block)
17 changes: 17 additions & 0 deletions platforms/microarchitectures.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module MicroArchitectures

const augment = """
using Base.BinaryPlatforms: arch, arch_march_isa_mapping, CPUID, HostPlatform, Platform
function augment_microarchitecture!(platform::Platform)
haskey(platform, "march") && return platform
host_arch = arch(HostPlatform())
host_isas = arch_march_isa_mapping[host_arch]
idx = findlast(((name, isa),) -> isa <= CPUID.cpu_isa(), host_isas)
platform["march"] = first(host_isas[idx])
return platform
end
"""

end

0 comments on commit 66ff7e6

Please sign in to comment.