Skip to content

Commit

Permalink
windows/msvc: use high level processor feature detection API
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 authored and manyoso committed Jul 12, 2023
1 parent ad0e7fd commit 95b8fb3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions gpt4all-backend/llmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <cassert>
#include <cstdlib>
#include <sstream>
#ifdef _MSC_VER
#include <processthreadsapi.h>
#endif

std::string s_implementations_search_path = ".";

Expand All @@ -18,9 +21,7 @@ static bool has_at_least_minimal_hardware() {
#ifndef _MSC_VER
return __builtin_cpu_supports("avx");
#else
int cpuInfo[4];
__cpuid(cpuInfo, 1);
return cpuInfo[2] & (1 << 28);
return IsProcessorFeaturePresent(PF_AVX_INSTRUCTIONS_AVAILABLE);
#endif
#else
return true; // Don't know how to handle non-x86_64
Expand All @@ -32,9 +33,7 @@ static bool requires_avxonly() {
#ifndef _MSC_VER
return !__builtin_cpu_supports("avx2");
#else
int cpuInfo[4];
__cpuidex(cpuInfo, 7, 0);
return !(cpuInfo[1] & (1 << 5));
return !IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE);
#endif
#else
return false; // Don't know how to handle non-x86_64
Expand Down

0 comments on commit 95b8fb3

Please sign in to comment.