fpm icon indicating copy to clipboard operation
fpm copied to clipboard

OpenMP SIMD meta-option

Open ivan-pi opened this issue 9 months ago • 3 comments

Description

Some fpm packages may like to use OpenMP SIMD directives for vectorization.

Most compilers have specific flags to enable these separately from the multi-threading and target offloading.

OpenMP SIMD Flags

Compiler SIMD Flag
GNU (gfortran) -fopenmp-simd
Intel (ifx) -qopenmp-simd
Flang -fopenmp-simd (not sure if implemented yet)
Cray (crayftn) -h omp_simd or -fopenmp-simd
NVIDIA (nvfortran) No specific flag available
LFortran ?

Possible Solution

Could this be added to the meta-package dependencies?

name = "my_openmp_package"
[dependencies]
openmp = "*"
openmp-simd = "*"

Additional Information

  • SIMD Directives: https://www.openmp.org/spec-html/5.1/openmpsu49.html
  • SIMD Vectorization with OpenMP: https://blog.rwth-aachen.de/hpc_import_20210107/attachments/28344675/30867475.pdf
  • Explicit Vector Programming in Fortran: https://www.intel.com/content/www/us/en/developer/articles/technical/explicit-vector-programming-in-fortran.html
  • OpenMP SIMD in Visual C++: https://learn.microsoft.com/de-de/cpp/parallel/openmp/openmp-simd?view=msvc-170#openmp-simd-in-visual-c

ivan-pi avatar Mar 19 '25 15:03 ivan-pi

Are simd directives part of the standard? In other words, should we add them when versioning is available:

[dependencies]
openmp = ">=5.1" # if package uses SIMD

another option would be to use the recently introduced compiler introspection #1051 to just check if the current compiler supports them, and add them by default if so.

imho they should not be seen as a separate package (which they are not).

perazz avatar Mar 19 '25 15:03 perazz

SIMD directives are part of the standard since OpenMP 4.0. By default options like -fopenmp/-qopenmp will also turn on the SIMD directives.

The reason there are separate flags is if only the SIMD directives are needed, it isn't necessary to link against an OpenMP runtime library (i.e. libgomp, libomp, or libiomp). Typically when -fopenmp is used there may be some hidden initialization calls needed to initialize the ICVs (internal control variables) of the runtime library. At least that is how I understood it.

ivan-pi avatar Mar 19 '25 15:03 ivan-pi

I found the place where it is stated for GNU compilers,

The -fopenmp-simd flag can be used to enable a subset of OpenMP directives that do not require the linking of either the OpenMP runtime library or the POSIX threads library.

And for Intel Fortran Compiler,

You can use this option if you want to enable or disable the SIMD support with no impact on other OpenMP features. In this case, no OpenMP runtime library is needed to link and the compiler does not need to generate OpenMP runtime initialization code.

I guess the better idea would be to promote the key-value pair into an inline table (borrowing from the answer here):

openmp = "*"

to

openmp = { version=">=5.0", simd-only=true}

One could extend this to include offloading to accelerator devices:

openmp = { version=">=5.0", offload = true}

I would need to survey what other OpenMP features can be controlled individually using compiler flags.

ivan-pi avatar Mar 23 '25 15:03 ivan-pi