Skip to content

Commit 11bb61d

Browse files
committed
added status flags to saf_externals, and SIMD intrinsics can now be enabled via CMake
1 parent b8e4839 commit 11bb61d

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option(SAF_BUILD_EXTRAS "Build SAF extras."
1111
option(SAF_ENABLE_SOFA_READER_MODULE "Enable the SAF SOFA READER module" OFF)
1212
option(SAF_ENABLE_TRACKER_MODULE "Enable the SAF TRACKER module" OFF)
1313
option(SAF_USE_INTEL_IPP "Use Intel IPP for the FFT, resampler, etc." OFF)
14+
option(SAF_ENABLE_SIMD "Enable the use of SSE3, AVX2, AVX512" OFF)
1415
if (NOT SAF_PERFORMANCE_LIB)
1516
set(SAF_PERFORMANCE_LIB "SAF_USE_INTEL_MKL_LP64" CACHE STRING "Performance library for SAF to use.")
1617
endif()

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ The available SAF-related CMake options (and their default values) are:
9595
-DSAF_BUILD_EXAMPLES=1 # build saf examples
9696
-DSAF_BUILD_EXTRAS=0 # build safmex etc.
9797
-DSAF_BUILD_TESTS=1 # build unit testing program
98-
-DSAF_USE_INTEL_IPP=0 # To link and use Intel IPP for the FFT, resampler, etc.
98+
-DSAF_USE_INTEL_IPP=0 # link and use Intel IPP for the FFT, resampler, etc.
99+
-DSAF_ENABLE_SIMD=0 # enable/disable SSE, AVX, and/or AVX-512 support
99100
```
100101

101102
If using e.g. **SAF_USE_INTEL_MKL_LP64** as the performance library, note that the default header and library search paths may be overridden [according to your setup](docs/PERFORMANCE_LIBRARY_INSTRUCTIONS.md) with:
@@ -116,6 +117,8 @@ If the **saf_sofa_reader** module is enabled, CMake will use the statically buil
116117
For Linux/MacOS users: the framework, examples, and unit testing program may be built as follows:
117118
```
118119
cmake -S . -B build
120+
# Or to also enable e.g. SSE3 and AVX2 intrinsics (for both C and C++ code)
121+
cmake -S . -B build -DSAF_ENABLE_SIMD=1 -DCMAKE_CXX_FLAGS="-msse3 -mavx2" -DCMAKE_C_FLAGS="-msse3 -mavx2"
119122
cd build
120123
make
121124
test/saf_test # To run the unit testing program

framework/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ if(SAF_USE_INTEL_IPP)
212212
target_link_libraries(${PROJECT_NAME} PUBLIC ${INTEL_IPP_LIB} )
213213
endif()
214214

215+
############################################################################
216+
# Enable SIMD intrinsics
217+
if(SAF_ENABLE_SIMD)
218+
# Note that you need to pass the appropriate compiler flags to actually
219+
# enable certain intrinsics, for example:
220+
# $ cmake -S . -B build -DCMAKE_CXX_FLAGS="-msse3 -mavx2" -DCMAKE_C_FLAGS="-msse3 -mavx2"
221+
message(STATUS "SIMD intrinsics support is enabled.")
222+
target_compile_definitions(${PROJECT_NAME} PUBLIC SAF_ENABLE_SIMD=1)
223+
endif()
215224

216225
############################################################################
217226
# Sofa reader module dependencies

framework/include/saf_externals.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,73 @@
270270
#endif
271271

272272

273+
/* ========================================================================== */
274+
/* Configuration and Status Flags/Strings */
275+
/* ========================================================================== */
276+
277+
/* Currently employed performance library: */
278+
#if defined(SAF_USE_INTEL_MKL_LP64)
279+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "Intel MKL (LP64)"
280+
#elif defined(SAF_USE_INTEL_MKL_ILP64)
281+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "Intel MKL (ILP64)"
282+
#elif defined(SAF_USE_OPEN_BLAS_AND_LAPACKE)
283+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "OpenBLAS with LAPACKE"
284+
#elif defined(SAF_USE_ATLAS)
285+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "ATLAS"
286+
#elif defined(__APPLE__) && defined(SAF_USE_APPLE_ACCELERATE)
287+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "Apple Accelerate"
288+
#else
289+
# define SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "NONE"
290+
#endif
291+
292+
/* Status of Intel IPP */
293+
#if defined(SAF_USE_INTEL_IPP)
294+
# define SAF_INTEL_IPP_STATUS_STRING "Enabled"
295+
#else
296+
# define SAF_INTEL_IPP_STATUS_STRING "Disabled"
297+
#endif
298+
299+
/* Status of FFTW */
300+
#if defined(SAF_USE_FFTW)
301+
# define SAF_FFTW_STATUS_STRING "Enabled"
302+
#else
303+
# define SAF_FFTW_STATUS_STRING "Disabled"
304+
#endif
305+
306+
/* Status of SIMD intrinsics */
307+
#if defined(SAF_ENABLE_SIMD)
308+
# define SAF_SIMD_STATUS_STRING "Enabled"
309+
/* Which SIMD intrinsics are currently enabled? */
310+
# if defined(__AVX512F__)
311+
# define SAF_ENABLED_SIMD_INTRINSICS_STRING "SSE, SSE2, SSE3, AVX, AVX2, AVX512F"
312+
# elif defined(__AVX__) && defined(__AVX2__)
313+
# define SAF_ENABLED_SIMD_INTRINSICS_STRING "SSE, SSE2, SSE3, AVX, AVX2"
314+
# elif defined(__SSE__) && defined(__SSE2__) && defined(__SSE3__)
315+
# define SAF_ENABLED_SIMD_INTRINSICS_STRING "SSE, SSE2, SSE3"
316+
# else
317+
# define SAF_ENABLED_SIMD_INTRINSICS_STRING "None"
318+
# endif
319+
#else
320+
# define SAF_SIMD_STATUS_STRING "Disabled"
321+
# define SAF_ENABLED_SIMD_INTRINSICS_STRING "None"
322+
#endif
323+
324+
/* Status of netCDF */
325+
#if defined(SAF_ENABLE_SOFA_READER_MODULE)
326+
# define SAF_NETCDF_STATUS_STRING "Enabled"
327+
#else
328+
# define SAF_NETCDF_STATUS_STRING "Disabled"
329+
#endif
330+
331+
/** Current configuration information */
332+
#define SAF_EXTERNALS_CONFIGURATION_STRING \
333+
"Current SAF externals configuration: " "\n" \
334+
" - Performance library: " SAF_CURRENT_PERFORMANCE_LIBRARY_STRING "\n" \
335+
" - Intel IPP status: " SAF_INTEL_IPP_STATUS_STRING "\n" \
336+
" - FFTW status: " SAF_FFTW_STATUS_STRING "\n" \
337+
" - SIMD status: " SAF_SIMD_STATUS_STRING "\n" \
338+
" - Enabled intrinsics: " SAF_ENABLED_SIMD_INTRINSICS_STRING "\n" \
339+
" - netCDF status: " SAF_NETCDF_STATUS_STRING "\n"
340+
341+
273342
#endif /* __SAF_EXTERNALS_H_INCLUDED__ */

test/saf_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int main_test(void) {
6666
#else
6767
printf(" (Debug):\n\n");
6868
#endif
69+
printf("%s\n", SAF_EXTERNALS_CONFIGURATION_STRING);
6970

7071
/* initialise */
7172
timer_lib_initialize();

0 commit comments

Comments
 (0)