-
Notifications
You must be signed in to change notification settings - Fork 165
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
Simplify codepath selection #130
Comments
Good question, you'd think we could just use those macros at compile time and all would be good. But unfortunately it's a case of Chesterton's Fence. On x86, this library supports runtime dispatch for multiple architectures, so that the same library can run unmodified on everything from an Atom to the latest AVX512 machine. This simplifies the life of a distro packager because they can ship one binary library that works everywhere. Let's take a concrete example and focus on the Because what happens when you compile the For that reason, this library has to have full control over the architecture arguments to the compiler. It has to ensure that the I hope it now becomes clear that the |
I actually asked about this to simplify packaging. While I do understand your concern about safeguarding for incorrect compiler flags I would argue that it causes more issues than it solves. If you define lets say -march=tigerlake (11th gen with AVX512) and expect the final binary to run on a Haswell based Pentium (no AVX instructions at all) that's hardly the project at fault. That would also cause the majority of packages by far to be unusable since they'll be optimized for the target hardware defined by compiler flags. Some projects do however provide a "baseline" option which disables all optimization (ffmpeg for example) but that's usually for debugging rather than safeguarding. fwiw, I started hacking on this mostly as an exercise but also to see if it were possible to simplify packaging. |
You're advocating for a library that selects a single codepath at compile time. That's a reasonable position to take, but it's not the current design intent of this library. This library is positioned as a multi-arch, runtime-dispatched library that can run on all sorts of hardware without recompilation. It's also intended to provide the best possible performance by dispatching based on the capabilities of the actual hardware, rather than whatever baseline the packager chose. You are free to question these assumptions (and I'm not too happy with them after many years of maintaining this library), but they are quite fundamental. Changing them would mean a major break in compatibility. Full disclosure: I am unhappy about the runtime dispatching and would like to get rid of it (or rather make it optional) at some point in the future. I also agree with you that the compilation and configuration system is complex and messy. To fix this, I have some not-very-concrete plans about rebranding this project and doing a large rewrite at some point. I'd like to have standalone codecs which are exported as first-class symbols and are callable directly by the user, so that the user can do their own runtime dispatch. The internal runtime dispatcher needs to be optional, or maybe needs to disappear entirely, because I don't want to maintain platform selection code any more. The tree of If you have any good suggestions in this area after hacking on the library, I'm certainly interested. |
This would introduce strong coupling between compiler flags and source files which I really dislike. And while I concur that the buildsystem can be simplified, I find it surprising that you'd want to move details about the build process from the buildsystem into the source files. I've rewritten the BLAKE3 buildsystem within the last year--a library which faces similar build challenges--and I've arrived at a simpler design by dropping most of the compiler introspection support and fine grained codec (SSE/AVX/...) selection.
Sure this is fine for simple cases, but as soon as you have more than one independent component/library which takes a dependency on this library you will get multiple runtime dispatch implementations (each has to include their own) or have to make the optional component... uh... non-optional 😅 |
Is there a reason why codepath selection logic seems to be trying to work around compilers? Wouldn't it be easier and cleaner to just rely on what gets passed to the compiler?
Drop all
HAVE_EXTENSION
and just check for__EXTENSION__
instead?https://stackoverflow.com/questions/28939652/how-to-detect-sse-sse2-avx-avx2-avx-512-avx-128-fma-kcvi-availability-at-compile
The text was updated successfully, but these errors were encountered: