Skip to content

Commit

Permalink
add VOLK (JuliaPackaging#3718)
Browse files Browse the repository at this point in the history
* initial commit adding VOLK

* disable avx512 on x86_64-mingw

* switch ORC to a HostBuildDependency
  • Loading branch information
Crghilardi authored and simeonschaub committed Feb 23, 2022
1 parent 97d9fe4 commit ad3aadf
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
71 changes: 71 additions & 0 deletions V/VOLK/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

name = "VOLK"
version = v"2.5.0"

# Collection of sources required to complete build
sources = [
ArchiveSource("https://github.com/gnuradio/volk/releases/download/v$(version)/volk-$(version).tar.gz", "d9183b9f86a32cdbb8698cbbeb15de574962c05200ccf445c1058629073521f8"),
DirectorySource("./bundled")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/volk-*
if [[ ${target} == *-freebsd* ]]; then
#this is not in 0.6.0 release, but has been added on master, can probably remove after next release
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/add-freebsd-macros.patch"
elif [[ ${target} == x86_64-w64-mingw* ]]; then
#disable avx512 on x86_64-mingw to avoid "Error: invalid register for .seh_savexmm". This is not needed on i686-mingw for some reason?
#copied from https://github.com/xianyi/OpenBLAS/issues/1801
export CFLAGS="${CFLAGS} -fno-asynchronous-unwind-tables"
fi
mkdir build
cd build/
pip install mako
cmake .. \
-DCMAKE_INSTALL_PREFIX=${prefix} \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DCMAKE_BUILD_TYPE=Release \
-DCROSSCOMPILE_MULTILIB=true \
-DENABLE_TESTING=OFF \
-DENABLE_MODTOOL=OFF
make -j${nproc}
make install
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = expand_cxxstring_abis(supported_platforms())


#volk by default builds with -D_GLIBCXX_USE_CXX11_ABI=1 see: https://github.com/gnuradio/volk/blob/2ff7b768a4b2174379a1f2e9214051677082f14b/CMakeLists.txt#L53
filter!(x -> cxxstring_abi(x) != "cxx03", platforms)


# The products that we will ensure are always built
products = [
LibraryProduct("libvolk", :libvolk),
ExecutableProduct("volk-config-info", :volk_config_info),
ExecutableProduct("volk_profile", :volk_profile),
ExecutableProduct("list_cpu_features", :list_cpu_features)
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency(PackageSpec(name="boost_jll", uuid="28df3c45-c428-5900-9ff8-a3135698ca75"))
HostBuildDependency(PackageSpec(name="ORC_jll", uuid="fb41591b-4dee-5dae-bf56-d83afd04fbc0"))
]

# Build the tarballs, and possibly a `build.jl` as well.
#need at least gcc5 for Wincompatible-pointer-type flag for cpu_features, needs at least gcc6 to avoid std::inf errors on musl see: https://github.com/gnuradio/volk/issues/375
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version = v"6")
74 changes: 74 additions & 0 deletions V/VOLK/bundled/patches/add-freebsd-macros.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
diff --git a/cpu_features/include/cpu_features_macros.h b/cpu_features/include/cpu_features_macros.h
index 4b231a1..59649b2 100644
--- a/cpu_features/include/cpu_features_macros.h
+++ b/cpu_features/include/cpu_features_macros.h
@@ -83,6 +83,10 @@
#define CPU_FEATURES_OS_DARWIN
#endif

+#if (defined(__freebsd__) || defined(__FreeBSD__))
+#define CPU_FEATURES_OS_FREEBSD
+#endif
+
////////////////////////////////////////////////////////////////////////////////
// Compilers
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/cpuinfo_x86.c b/src/cpuinfo_x86.c
index 378ed05..33ddb63 100644
--- a/cpu_features/src/cpuinfo_x86.c
+++ b/cpu_features/src/cpuinfo_x86.c
@@ -97,7 +97,7 @@
// microarchitectures.
#if defined(CPU_FEATURES_OS_WINDOWS)
#include <windows.h> // IsProcessorFeaturePresent
-#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID)
+#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) || defined(CPU_FEATURES_OS_FREEBSD)
#include "internal/filesystem.h" // Needed to parse /proc/cpuinfo
#include "internal/stack_line_reader.h" // Needed to parse /proc/cpuinfo
#include "internal/string_view.h" // Needed to parse /proc/cpuinfo
@@ -1239,6 +1239,45 @@ static void DetectSseViaOs(X86Features* features) {
features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3");
features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1");
features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2");
+ #elif defined(CPU_FEATURES_OS_FREEBSD)
+ // Handling FreeBSD platform through parsing /var/run/dmesg.boot.
+ const int fd = CpuFeatures_OpenFile("/var/run/dmesg.boot");
+ if (fd >= 0) {
+ StackLineReader reader;
+ StackLineReader_Initialize(&reader, fd);
+ for (;;) {
+ const LineResult result = StackLineReader_NextLine(&reader);
+ const StringView line = result.line;
+ const bool is_feature =
+ CpuFeatures_StringView_StartsWith(line, str(" Features="));
+ const bool is_feature2 =
+ CpuFeatures_StringView_StartsWith(line, str(" Features2="));
+ if (is_feature || is_feature2) {
+ // Lines of interests are of the following form:
+ // " Features=0x1783fbff<PSE36,MMX,FXSR,SSE,SSE2,HTT>"
+ // We replace '<', '>' and ',' with space so we can search by
+ // whitespace separated word.
+ // TODO: Fix CpuFeatures_StringView_HasWord to allow for different
+ // separators.
+ for (size_t i = 0; i < line.size; ++i) {
+ char* c = (char*)(&(line.ptr[i]));
+ if (*c == '<' || *c == '>' || *c == ',') *c = ' ';
+ }
+ if (is_feature) {
+ features->sse = CpuFeatures_StringView_HasWord(line, "SSE");
+ features->sse2 = CpuFeatures_StringView_HasWord(line, "SSE2");
+ }
+ if (is_feature2) {
+ features->sse3 = CpuFeatures_StringView_HasWord(line, "SSE3");
+ features->ssse3 = CpuFeatures_StringView_HasWord(line, "SSSE3");
+ features->sse4_1 = CpuFeatures_StringView_HasWord(line, "SSE4.1");
+ features->sse4_2 = CpuFeatures_StringView_HasWord(line, "SSE4.2");
+ }
+ }
+ if (result.eof) break;
+ }
+ CpuFeatures_CloseFile(fd);
+ }
#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID)
// Handling Linux platform through /proc/cpuinfo.
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");

0 comments on commit ad3aadf

Please sign in to comment.