Skip to content

Setup

This page sets up a development environment: generate the headers, build and run the unit tests, build this documentation, and test other targets than your machine.


1. Prerequisites

Tool Version Used for
Python 3 (the CI uses 3.12 on GitLab and 3.14 on GitHub) the generators
Jinja2, jsonschema, colorama see generator/requirements.txt the generators
A C++20 compiler GCC 14 (GCC 15 for SVE) and Clang 20 in the CI the unit tests (the headers themselves only need C11 or C++11)
CMake 3.5 or later (3.16 or later for precompiled headers) the unit tests
Catch2 v3 the unit tests

On Ubuntu 24.04:

sudo apt install python3 python3-venv python3-pip cmake g++ catch2

On macOS with Homebrew:

brew install python cmake catch2

2. Python Environment

The generators are run from the generator/ directory: they read and write paths relative to it (../include/, ../tests/src/, ../docs/). Create the virtual environment there once:

cd generator
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

All the commands of this guide assume that you are in generator/ with this environment activated, and call the scripts directly (./gen_mipp_headers.py).


3. Generate

3.1. Headers

./gen_mipp_headers.py                        # all ISAs, coarse headers
./gen_mipp_headers.py --granularity fine     # also the fine-grained headers (as in the CI)
./gen_mipp_headers.py --simd-ext neon        # only NEON (plus the scalar fallback)

The script deletes and rewrites ../include/ (--no-clean keeps it, to regenerate only some --layers). It prints the validation results, the audit warnings, then a summary table with the number of functions per implementation level and per ISA. Restricting the ISAs with --simd-ext makes the generation faster during development. The options are described in the Command-Line Reference.

3.2. Unit Tests

./gen_mipp_tests.py                          # C, C++ Functional and C++ Object tests
./gen_mipp_tests.py obj                      # C++ Object tests only (as in the CI)

The sources are written to ../tests/src/{c,cpp,obj}/, one file per function (and per LMUL and mask variant for the C API). The options are described in the Command-Line Reference.

The other files of tests/src/ are written by hand, and gen_mipp_tests.py keeps them: main.cpp, the helpers of utils/ (random inputs, number of iterations, overflow checks, comparisons within a tolerance) and the tests of manual/. A manual test covers what a generated test cannot compare with the scalar reference: special values that the generated tests do not draw (the generated tests mix in the special_values of tests_specs.json, when a function has some), the C++ templates and overloads (scalar forms, immediate versions, permute<P>), the transpositions and the utilities. The comment at the top of each file says what it covers. Add a file there, or a test case to an existing file, when a new feature is not a function of the registry.

Generating one API leaves the others in place

./gen_mipp_tests.py obj only cleans and rewrites tests/src/obj/. The c/ and cpp/ directories of a previous run stay, and CMake compiles every file under tests/src/. Delete them if you only want the Object tests: rm -rf ../tests/src/c ../tests/src/cpp.

3.3. Documentation Pages

./gen_mipp_docs.py                                    # every generated page
./gen_mipp_docs.py --only dev_reference includes      # only what the hand-written pages need (about 30 s)

This writes the Function Support pages (docs/funcs_support/), the Hardware Support pages (docs/isas_support/), the API Explorer data (docs/assets/data/), the Command-Line and Registries reference of this guide, and the tables included in the hand-written pages (docs/includes/generated/). These files are ignored by Git. See Build the Documentation and Docs & API Explorer.


4. Build and Run the Unit Tests

The headers and the test sources must be generated first. From the repository root:

cd tests
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_UNITY_BUILD=ON \
      -DCMAKE_CXX_FLAGS="-march=native"
cmake --build build -j4
./build/bin/run-tests
  • Target ISA. As for any MIPP program, the ISA is selected by the compiler flags in CMAKE_CXX_FLAGS (-march=native tests the ISA of your machine). The CI flags of each target are listed in CI Targets and Flags.
  • Build time. -DCMAKE_UNITY_BUILD=ON groups the translation units, which makes the build up to 7× faster (55 s instead of 401 s in one measurement). Precompiled headers are enabled by default (-DMIPP_PRECOMPILED_HEADERS=OFF disables them).
  • Selecting tests. Each test case is tagged with its function name. ./build/bin/run-tests "[add]" runs the tests of add in all APIs, and ./build/bin/run-tests --list-tests lists them.
  • Iterations. Each test runs 10 random iterations by default. The N_ITER environment variable changes it at run time (N_ITER=100 ./build/bin/run-tests), and ./gen_mipp_tests.py -N <n> changes the default.

4.1. Faster Iterations

The complete test suite takes several minutes to build. While working on one function, generate fewer tests:

./gen_mipp_tests.py obj --lmul 1 --no-ldiv --mask-kind unmasked maskm

This generates the C++ Object tests for LMUL 1 only, without half-vectors, and for the unmasked and Merge-Masked variants only.

4.2. Examples

The examples/ directory contains small programs for each API, built and run by the CI on every target:

cd examples
g++ -std=c++11 -O3 -march=native -DMIPP_PRINT_INFO -I../include -o mipp_cpp mipp.cpp && ./mipp_cpp
gcc -std=c11   -O3 -march=native -DMIPP_PRINT_INFO -I../include -o mipp_c   mipp.c   && ./mipp_c

mipp_fine_grained.cpp requires headers generated with --granularity fine.


5. Testing Other Targets

5.1. CI Targets and Flags

The GitLab CI builds and runs the tests with GCC 14 and Clang 20 on 16 targets (SSE, AVX, AVX-512, NEON, SVE, SVE2, RVV and scalar). The compiler flags of each target, and the build options specific to RVV and SVE, are listed in Continuous Integration. To reproduce a job, put the flags of the target in CMAKE_CXX_FLAGS, with the warning flags of the CI: -Wall -Wno-unused-function -Werror -funroll-loops -finline-functions. Without -Werror, a warning that fails the CI goes unnoticed. The CI also links the tests statically (-DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++"), which is only needed to run them in another container.

5.2. CI Docker Images

The CI images are public. They contain GCC 14, Clang 20, CMake, Python and Catch2, and are named registry.gitlab.com/aff3ct/aff3ct/mipp_linux:<compiler>_<target>, for instance gcc-14_avx2 or clang-20_riscv64-rvv1.0. Their Dockerfiles are in ci/docker/. To run the tests of a foreign architecture on your machine, Docker needs to emulate it (QEMU user-mode emulation, included in Docker Desktop):

docker run --rm --platform linux/riscv64 -v "$PWD":/mipp -w /mipp/tests \
  registry.gitlab.com/aff3ct/aff3ct/mipp_linux:gcc-14_riscv64-rvv1.0 \
  bash -c 'cmake -S . -B build_rvv -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_BUILD_TYPE=Release \
             -DCMAKE_CXX_FLAGS="-march=rv64gv1_zve32f_zvl256b -mrvv-vector-bits=zvl" \
             -DCMAKE_UNITY_BUILD=OFF -DMIPP_PRECOMPILED_HEADERS=OFF \
           && cmake --build build_rvv -j8 && ./build_rvv/bin/run-tests'

Emulated builds are slow: restrict the generated tests first (Faster Iterations).

5.3. x86 on Apple Silicon

On a Mac with Apple Silicon, Rosetta runs x86-64 binaries with SSE, AVX and AVX2 (not AVX-512). Compile with -target x86_64-apple-macos and the x86 flags:

clang++ -std=c++11 -O2 -target x86_64-apple-macos -mavx2 -mfma -I../include my_test.cpp -o my_test && ./my_test

Libraries such as Catch2 must then be available for x86-64 too: a Homebrew installation in /opt/homebrew only provides arm64 libraries, so this approach suits standalone programs better than the unit tests.


6. Build the Documentation

The site uses MkDocs with the Material theme. From the repository root, in a virtual environment:

pip install -r docs/requirements.txt      # also installs generator/requirements.txt
(cd generator && ./gen_mipp_headers.py --granularity fine && ./gen_mipp_docs.py)   # generated pages, needed by the site
mkdocs serve                              # live preview on http://127.0.0.1:8000
mkdocs build --strict                     # what the CI runs: warnings are errors

gen_mipp_docs.py reads the generated headers for the Algorithm modal of the API Explorer: without include/, it skips that part and prints a message. --strict turns broken links and missing pages into errors. Run it before submitting a change to the documentation.

The scalar simulator of the API Explorer compiles the scalar references for WebAssembly (Docs & API Explorer). It needs clang with the WebAssembly target, wasm-ld and wasi-libc: a wasi-sdk whose directory is in WASI_SDK_PATH (what the CI does), or the packages of the system (brew install llvm lld wasi-libc on macOS). Without them, gen_mipp_docs.py skips the simulator with a warning, and the Explorer says the simulator is not built.

6.1. Code Examples of the User Guide

The C and C++ code blocks of the User Guide are not written in the pages: they are sections of complete programs in examples/doc/<page>/, one file per API (c.c, fun.cpp, obj.cpp), included by pymdownx.snippets. A section is delimited by two comments in the program:

mipp::vd<float> a = mipp::load<float>(A);               // setup, not shown
// --8<-- [start:masked]
mipp::vd<float> c = mipp::add<mipp::M, float>(m, a, b);
// --8<-- [end:masked]
DOC_CHECK(...);                                         // check, not shown

and the page includes it inside a code block, with the path from the repository root:

```cpp
--8<-- "examples/doc/programming_model/fun.cpp:masked"
```

The section is dedented, and takes the indentation of the --8<-- line (code blocks in admonitions, tabs and lists). Without :section, the whole file is included. Several --8<-- lines in the same code block are concatenated. A missing file or section fails mkdocs build.

When an example exists in several APIs, each version goes in a content tab, with the labels C API, C++ Functional API and C++ Object API. These are the labels of the Function Support pages: with content.tabs.link, choosing an API in one tab set selects it everywhere on the site. A notion specific to one API (deduction in the Functional API, operators of the Object API) gets a single tab with the label of its API.

The tabs of a set do exactly the same thing: same variables, same order, same comments, same number of lines. Each API uses its own syntax (operators in the Object API: a + b, a < b, v[i]), but the Object API loads with load_obj / loadu_obj rather than with the constructor, which does not show the alignment. A remark specific to one API (what is deduced, what must be given) goes in the text, not in a comment of one tab. Types are written: no auto, except in the examples that present it (Programming Model §3.5).

=== "C API"

    ```c
    --8<-- "examples/doc/masking_semantics/c.c:select"
    ```

=== "C++ Functional API"
    ...

Each program prepares its inputs outside the sections, and checks the results announced by the snippet with DOC_CHECK (examples/doc/doc_check.h): a failed check makes the program return a non-zero exit code. scripts/check_doc_snippets.sh compiles every program with -Werror (C11 and C++11, or the standard given by a // doc-std: c++17 line), runs it, compiles and runs the C++ example of README.md, and fails if a C or C++ block of docs/user/ is written inline, if a tab label is not one of the three above, if a tab includes the file of another API, if the tabs of a set include sections of different lengths (non-blank lines of the named sections at the top level of each tab; complete programs are not compared), or if the included code uses auto (exceptions in AUTO_ALLOWED):

scripts/check_doc_snippets.sh                                    # native target
SIMD_EXT="-DMIPP_SCALAR -DMIPP_SCALAR_SIZE=1024" scripts/check_doc_snippets.sh
CC="clang -arch x86_64" CXX="clang++ -arch x86_64" SIMD_EXT="-mavx2 -mfma" \
  scripts/check_doc_snippets.sh --out /tmp/doc_avx2              # x86 on Apple Silicon

A block that cannot be compiled (a class synopsis, an excerpt of generated code) stays inline, preceded by <!-- not-compiled: reason -->. The GitLab CI runs the script on every target of the matrix (CI).