ISA Control via Environment Variables in NCNN #5690
inspireMeNow
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This patch introduces a new mechanism in NCNN to control the enabling or disabling of specific Instruction Set Architecture (ISA) features through environment variables. This change provides flexibility to users, allowing them to optimize according to particular requirements or limitations.
Environment Variable Format
-
to disable the corresponding instruction set.Supported Instruction Set Flags
Depending on the architecture, the following instruction set flags are available (partial list):
ARM
Architecture:-cpuid
,-asimdhp
,-asimddp
,-neon
,-bf16
,-sve
,-sve2
,-i8mm
x86
Architecture:-avx
,-fma
,-xop
,-f16c
,-avx2
,-avx512
,-avx_vnni
,-avx512_vnni
,-avx512_bf16
,-avx512_fp16
Loongarch
Architecture:-lsx
,-lasx
MIPS
Architecture:-msa
Loongson
Architecture:-mmi
RISC-V
Architecture:-rvv
,-zfh
Changes Introduced
get_isa_env
Function:get_isa_env
is introduced to parse the environment variableNCNN_ISA
. This function reads the ISA flags passed as a string and checks whether specific CPU features should be disabled.-
, such as-neon
, the feature is disabled, and a warning is printed.strdup()
to make a copy of theNCNN_ISA
string and processes it usingstrtok()
, breaking it down into tokens and comparing each against the provided ISA feature.is_cpu_x86_avx_disabled
a global variable, allowing thecpu_support_x86_avx
function to directly reference it to modify its return value. By doing this, it avoid repeatedly parsing the environment variable in every call to the function. The global variable is initialized once, based on the environment variable NCNN_ISA. Thus it ensures that the environment setting is only parsed once.__mips__
, to determine which global variables are relevant based on the target architecture. Thus we conditionally compile code that checks the appropriate global variables for features supported by that architecture. For example, if__mips__
is defined, the code will use theis_cpu_mips_msa_disabled
global variable to check whetherMSA
support is disabled.Usage Examples
Here is an example for
x86 linux
, you can also useNCNN_ISA
on other architectures, such as ARM, RISC-V.Install required build dependencies
On
Debian 10+
,Ubuntu 20.04
+On
Redhat
based distributionBuild and install the project
Here is an example program for reference
Compile the example program.
Test the example program.
Normal
Disable AVX512
Beta Was this translation helpful? Give feedback.
All reactions