Should building for different SIMD levels be supported using flavors?

Jan Beich jbeich at FreeBSD.org
Wed Dec 27 20:01:07 UTC 2017


(Resent to ports@ because, apparently, I wasn't subscribed to the list anymore)

Yuri <yuri at rawbw.com> writes:

> Some projects rely on SIMD to perform computations. Sometimes,
> utilizing specific SIMD instructions can result in 10 times better
> performance, so it is important for the ports system to properly
> support SIMD. There are some projects that do automatic run-time SIMD
> detection, like Embree, but there are many that do not.

"10x times better performance" usually requires more than just passing
-msse* or -march=native without underlying code doing anything to take
advantage of it. Do you expect auto-vectorization to be that good?
Projects that use SSE 4.1 or AVX without runtime detections are rare
because they'd risk to shun away users if binaries are prebuilt on
modern hardware.

> I proposed the solution for this using flavors, see the proposed port
> science/g2o: https://reviews.freebsd.org/D13610

What in there actually requires -msse*? I can't find any __SSE*__ blocks
or #include <*intrin.h> while CMakeLists.txt tries to mimic -march=native 
by parsing /proc/cpuinfo then passing -msse* individually. Looks like
a regular violation of

https://www.freebsd.org/doc/en/books/porters-handbook/dads-cflags.html

> It maps SIMD levels into port flavors. So that g2o-sse42 is for SSE42,
> and g2o-nosimd is not using SIMD.

This won't work for ports with consumers until pkg supports a way to
swap dependencies e.g., g2o -> g2o-sse41, ffmpeg -> libav. On Linux
systems this is usually handled by update-alternatives(8).

> Later, the user will to install the flavor corresponding to his
> machine's SIMD support.
>
> Further, ports framework and tools (pkg) should automatically detect
> machine's SIMD, and install the ports with the correct SIMD flavor for
> it.

ABI string is probably where SIMD should be advertised but pkg repo
format, currently, isn't even flexible for ports marked as NO_ARCH.

> How can FreeBSD support SSE then?

For one, Linux i686 assumes SSE2. To mimic on FreeBSD i386 try
adding the following to make.conf(5)

  CPUTYPE?=	pentium4

then in the port use MACHINE_CPU, port options or both e.g.,

  OPTIONS_DEFINE=	SSE2 SSE41 AVX AVX2
  OPTIONS_DEFAULT=	${MACHINE_CPU:tu}

  SSE2_CONFIGURE_ENABLE=	sse2
  ...
  AVX2_CONFIGURE_ENABLE=	avx2


More information about the freebsd-ports mailing list