Advanced avxonly autodetection (#744)

* Advanced avxonly requirement detection
This commit is contained in:
niansa/tuxifan 2023-06-01 03:26:18 +02:00 committed by GitHub
parent cae757aacd
commit 92407438c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,24 @@
#include <fstream>
#include <filesystem>
static
bool requires_avxonly() {
#ifdef __x86_64__
#ifndef _MSC_VER
return !__builtin_cpu_supports("avx2");
#else
int cpuInfo[4];
__cpuidex(cpuInfo, 7, 0);
return !(cpuInfo[1] & (1 << 5));
#endif
#else
return false; // Don't know how to handle non-x86_64
#endif
}
static Dlhandle *get_implementation(std::ifstream& f, const std::string& buildVariant) {
// Collect all model implementation libraries
// NOTE: allocated on heap so we leak intentionally on exit so we have a chance to clean up the
@ -56,14 +74,6 @@ static Dlhandle *get_implementation(std::ifstream& f, const std::string& buildVa
return nullptr;
}
static bool requires_avxonly() {
#ifdef __x86_64__
return !__builtin_cpu_supports("avx2") && !__builtin_cpu_supports("fma");
#else
return false; // Don't know how to handle ARM
#endif
}
LLModel *LLModel::construct(const std::string &modelPath, std::string buildVariant) {
//TODO: Auto-detect
if (buildVariant == "auto") {