SIMD Best Practice for Vectorisation #538
-
In attempt to accelerate my own custom sourcing, I have been referring to the use of SIMD vectorisation within Athena++ I have noted in multiple files the use of if statements within "#pragma omp simd" blocks, normally to include non barotropic effects .e.g with the NON_BAROTROPIC_EOS flag. From my own limited understanding of SIMD instructions, I would have assumed embedded if statements would prevent full SIMD vectorisation of these loops. Is the reason that this isn't an issue here because the NON_BAROTROPIC_EOS flag is implemented as a preprocessor instruction and therefore the proper if branch is identifiable at compile time? Similarly, there are also instances where functions such as std::sqrt and SQR are called within simd blocks. Are these functions already vectorised (declared as simd)? Otherwise I would assume that the compiler would struggle to properly vectorise these blocks. Instruction is appreciated, this is a very new area of computer science for me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
These days, compilers are generally smart enough to auto-vectorize even with runtime conditionals present (tons of caveats to this statement). Certainly if the conditional is a simple constant that has no way to switch from true to false or vice versa within the loop body, it is likely to vectorize without problems. Unfortunately, my impression is that the only ways to be sure are to 1) generate a compiler vectorization report 2) profile or instrument your compiled code. Everything is compiler/version/target architecture/option dependent. Use vectorized intrinsic functions if you need or want absolute control over the vectorization .
|
Beta Was this translation helpful? Give feedback.
These days, compilers are generally smart enough to auto-vectorize even with runtime conditionals present (tons of caveats to this statement). Certainly if the conditional is a simple constant that has no way to switch from true to false or vice versa within the loop body, it is likely to vectorize without problems. Unfortunately, my impression is that the only ways to be sure are to 1) generate a compiler vectorization report 2) profile or instrument your compiled code. Everything is compiler/version/target architecture/option dependent.
Use vectorized intrinsic functions if you need or want absolute control over the vectorization .
std::sqrt
should compile to AVX vectorized functions_m…