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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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):
ARMArchitecture:-cpuid,-asimdhp,-asimddp,-neon,-bf16,-sve,-sve2,-i8mmx86Architecture:-avx,-fma,-xop,-f16c,-avx2,-avx512,-avx_vnni,-avx512_vnni,-avx512_bf16,-avx512_fp16LoongarchArchitecture:-lsx,-lasxMIPSArchitecture:-msaLoongsonArchitecture:-mmiRISC-VArchitecture:-rvv,-zfhChanges Introduced
get_isa_envFunction:get_isa_envis 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_ISAstring and processes it usingstrtok(), breaking it down into tokens and comparing each against the provided ISA feature.is_cpu_x86_avx_disableda global variable, allowing thecpu_support_x86_avxfunction 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_disabledglobal variable to check whetherMSAsupport is disabled.Usage Examples
Here is an example for
x86 linux, you can also useNCNN_ISAon other architectures, such as ARM, RISC-V.Install required build dependencies
On
Debian 10+,Ubuntu 20.04+On
Redhatbased 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