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
  • Loading branch information
inspireMeNow committed Jul 12, 2024
1 parent 6211838 commit 3f0aab6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif // __wasi__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifdef _OPENMP
#if NCNN_SIMPLEOMP
Expand Down Expand Up @@ -620,6 +621,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 = getenv(ncnn_x86_avx512);

if (value)
if (strcmp(value, "0") == 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 +643,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 +676,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 +709,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 +738,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 3f0aab6

Please sign in to comment.