Skip to content

Commit e13ec2d

Browse files
committed
AUTO for SYMX_ENABLE_AVX2
1 parent 29253b3 commit e13ec2d

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

docs/source/compilation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Compiled<__m256d> compiled({f, df_dx}, "my_function_simd4d", codegen_dir, checks
120120
Compiled<__m256> compiled({f, df_dx}, "my_function_simd8f", codegen_dir, checksum);
121121
```
122122
Note that you will need to set values of type `FLOAT` and that the result will be returned as `View<FLOAT>`.
123-
If your system does not support these SIMD types, set SymX's the CMake flag `SYMX_ENABLE_AVX2` to `OFF`.
123+
If your system does not support these SIMD types, disable them with `-DSYMX_ENABLE_AVX2=OFF` (the default `AUTO` already does this on non-x86 targets).
124124
125125
### Parallel evaluation
126126
You can evaluate a `Compiled` expression in parallel in the following way:

docs/source/setup.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,19 @@ build/examples/examples # Examples
4141

4242
| Option | Default | Description |
4343
|---|---|---|
44-
| `SYMX_ENABLE_AVX2` | `ON` | Enable AVX2 + FMA SIMD paths |
44+
| `SYMX_ENABLE_AVX2` | `AUTO` | Enable AVX2 + FMA SIMD paths (`AUTO` / `ON` / `OFF`); `AUTO` enables on x86/x86_64/AMD64 |
4545
| `SYMX_COMPILER_PATH` | `AUTO` | Compiler used for JIT code generation at runtime |
4646
| `SYMX_CODEGEN_DIR` | *(empty)* | Output directory for generated files; defaults to `<build>/codegen` |
4747
| `SYMX_HESS_STORAGE_FLOAT` | `float` | Hessian storage precision (`float` or `double`) |
4848

4949

5050
### AVX2 support
5151
SymX uses AVX2 to speedup computations in several locations, such as evaluation and linear system solves.
52-
If your system does not support it (e.g. Apple Silicon) use `SYMX_ENABLE_AVX2=OFF` in CMake to disable such code paths.
52+
`SYMX_ENABLE_AVX2` accepts `AUTO` (default), `ON`, or `OFF`.
53+
`AUTO` enables AVX2 on x86/x86_64/AMD64 and disables it everywhere else (e.g. Apple Silicon).
54+
Override explicitly with `-DSYMX_ENABLE_AVX2=ON` or `-DSYMX_ENABLE_AVX2=OFF`.
5355

54-
If you try to compile SymX as-is, without support for AVX2 you will get something like:
56+
If you try to compile on a non-AVX2 system with `ON`, you will get something like:
5557

5658
```bash
5759
../immintrin.h:14 error "This header is only meant to be used on x86 and x64 architecture"

symx/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
cmake_minimum_required(VERSION 3.15)
22

33
# SymX options
4-
set(SYMX_ENABLE_AVX2 ON CACHE BOOL "Flag to enable AVX2 for symx")
4+
set(SYMX_ENABLE_AVX2 "AUTO" CACHE STRING "Enable AVX2+FMA SIMD: AUTO, ON, or OFF. AUTO enables on x86/x86_64/AMD64.")
5+
set_property(CACHE SYMX_ENABLE_AVX2 PROPERTY STRINGS "AUTO" "ON" "OFF")
6+
string(TOUPPER "${SYMX_ENABLE_AVX2}" _SYMX_AVX2)
7+
if(NOT _SYMX_AVX2 MATCHES "^(AUTO|ON|OFF)$")
8+
message(FATAL_ERROR "SYMX_ENABLE_AVX2 must be AUTO, ON, or OFF (got: ${SYMX_ENABLE_AVX2})")
9+
endif()
10+
if(_SYMX_AVX2 STREQUAL "AUTO")
11+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|X86_64|amd64|AMD64|i[3-6]86)$")
12+
set(_SYMX_AVX2 "ON")
13+
else()
14+
set(_SYMX_AVX2 "OFF")
15+
endif()
16+
endif()
17+
message(STATUS "SymX: AVX2 = ${_SYMX_AVX2} (SYMX_ENABLE_AVX2=${SYMX_ENABLE_AVX2}, processor=${CMAKE_SYSTEM_PROCESSOR})")
518
set(SYMX_COMPILER_PATH "AUTO" CACHE STRING "Path to the compiler to use for runtime compilation. Set to AUTO to auto-detect.")
619
set(SYMX_HESS_STORAGE_FLOAT "float" CACHE STRING "Storage type for Hessian matrices (float or double)")
720

@@ -113,7 +126,7 @@ if(OpenMP_CXX_FOUND)
113126
endif()
114127

115128
# SIMD: when AVX2 is enabled its intrinsics appear in public headers
116-
if(${SYMX_ENABLE_AVX2})
129+
if(_SYMX_AVX2 STREQUAL "ON")
117130
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
118131
target_compile_options(symx PUBLIC -mavx2 -mfma -Wno-ignored-attributes)
119132
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
@@ -130,7 +143,7 @@ if(MSVC)
130143
endif()
131144

132145
# Enable/disable the use of AVX2 instructions
133-
if(${SYMX_ENABLE_AVX2})
146+
if(_SYMX_AVX2 STREQUAL "ON")
134147
target_compile_definitions(symx PUBLIC SYMX_ENABLE_AVX2 BSM_ENABLE_AVX2)
135148
endif()
136149

0 commit comments

Comments
 (0)