Skip to content

Commit

Permalink
add environment variable NCNN_X86_AVX512 detect
Browse files Browse the repository at this point in the history
Signed-off-by: Kaiyao Duan <[email protected]>
  • Loading branch information
inspireMeNow committed Jul 12, 2024
1 parent 6211838 commit a5146d7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,20 @@ static int get_cpu_support_x86_avx_vnni()
#endif
}

static int check_avx512_flag()
{
const char* ncnn_x86_avx512 = "NCNN_X86_AVX512";
const char* value = std::getenv(ncnn_x86_avx512);

if (value)
if (std::string(value) == "0")
{
fprintf(stderr, "Warning: AVX512 support is disabled by environment variable NCNN_X86_AVX512=0\n");
return 0;
}
return 1;
}

static int get_cpu_support_x86_avx512()
{
#if __APPLE__
Expand All @@ -628,6 +642,9 @@ static int get_cpu_support_x86_avx512()
unsigned int cpu_info[4] = {0};
x86_cpuid(0, cpu_info);

if (!check_avx512_flag())
return 0;

int nIds = cpu_info[0];
if (nIds < 7)
return 0;
Expand Down Expand Up @@ -658,6 +675,9 @@ static int get_cpu_support_x86_avx512_vnni()
unsigned int cpu_info[4] = {0};
x86_cpuid(0, cpu_info);

if (!check_avx512_flag())
return 0;

int nIds = cpu_info[0];
if (nIds < 7)
return 0;
Expand Down Expand Up @@ -688,6 +708,9 @@ static int get_cpu_support_x86_avx512_bf16()
unsigned int cpu_info[4] = {0};
x86_cpuid(0, cpu_info);

if (!check_avx512_flag())
return 0;

int nIds = cpu_info[0];
if (nIds < 7)
return 0;
Expand All @@ -714,6 +737,9 @@ static int get_cpu_support_x86_avx512_fp16()
unsigned int cpu_info[4] = {0};
x86_cpuid(0, cpu_info);

if (!check_avx512_flag())
return 0;

int nIds = cpu_info[0];
if (nIds < 7)
return 0;
Expand Down

0 comments on commit a5146d7

Please sign in to comment.