Line data Source code
1 : /**
2 : * @file cfdnn_simd_dispatch.c
3 : * @brief Runtime SIMD backend selection for `.cfdnn` inference.
4 : *
5 : * Mirrors lib/src/solvers/linear/simd/linear_solver_simd_dispatch.c: this file
6 : * holds only the dispatch, while the AVX2 and NEON kernels live in their own
7 : * sibling directories and share ../simd_template/cfdnn_kernels_simd_template.h.
8 : *
9 : * Selection is by the CPU actually running, not only by what was compiled:
10 : * a binary built with AVX2 enabled but run on a CPU without it gets NULL here,
11 : * so an explicit CFD_NN_BACKEND_SIMD request returns CFD_ERROR_UNSUPPORTED and
12 : * AUTO resolves to OMP or scalar -- the project's no-silent-fallback rule.
13 : * cfd_detect_simd_arch() caches its answer and is thread-safe, so this is
14 : * cheap enough to call at every context creation.
15 : */
16 :
17 : #include "../cfdnn_internal.h"
18 :
19 : #include "cfd/core/cpu_features.h"
20 :
21 3 : const cfd_nn_backend_impl_t* cfd_nn_simd_impl(void) {
22 3 : switch (cfd_detect_simd_arch()) {
23 3 : case CFD_SIMD_AVX2:
24 3 : return cfd_nn_impl_avx2.dense ? &cfd_nn_impl_avx2 : NULL;
25 0 : case CFD_SIMD_NEON:
26 0 : return cfd_nn_impl_neon.dense ? &cfd_nn_impl_neon : NULL;
27 : default:
28 : return NULL;
29 : }
30 : }
|