Line data Source code
1 : /**
2 : * @file ns_simd_backend.c
3 : * @brief SIMD Navier-Stokes backend availability (compile-time + runtime).
4 : *
5 : * This is the single place that decides whether a SIMD NS solver can run. The
6 : * registry's backend-availability query and every SIMD solver's init guard go
7 : * through it, so they cannot disagree.
8 : *
9 : * The compile-time guard lives here, in the backend file, rather than in the
10 : * registry dispatcher.
11 : */
12 :
13 : #include "../ns_simd_backend_internal.h"
14 :
15 : #include "cfd/core/cpu_features.h"
16 :
17 : /* CFD_HAS_AVX2 is set by CMake when -DCFD_ENABLE_AVX2=ON, consistently across
18 : * GCC, Clang and MSVC. There are no NEON NS kernels, so AVX2 is the only
19 : * compiled SIMD implementation. */
20 : #if defined(CFD_HAS_AVX2)
21 : #define NS_HAS_SIMD_IMPL 1
22 : #else
23 : #define NS_HAS_SIMD_IMPL 0
24 : #endif
25 :
26 94 : bool ns_simd_backend_available(void) {
27 : #if NS_HAS_SIMD_IMPL
28 : return cfd_detect_simd_arch() == CFD_SIMD_AVX2;
29 : #else
30 94 : return false;
31 : #endif
32 : }
33 :
34 77 : cfd_status_t ns_check_simd_backend(void) {
35 77 : if (ns_simd_backend_available()) {
36 : return CFD_SUCCESS;
37 : }
38 : #if NS_HAS_SIMD_IMPL
39 : cfd_set_error(CFD_ERROR_UNSUPPORTED,
40 : "SIMD Navier-Stokes backend unavailable: CPU does not support AVX2");
41 : #else
42 77 : cfd_set_error(CFD_ERROR_UNSUPPORTED,
43 : "SIMD Navier-Stokes backend unavailable: built without AVX2 "
44 : "(configure with -DCFD_ENABLE_AVX2=ON)");
45 : #endif
46 77 : return CFD_ERROR_UNSUPPORTED;
47 : }
|