xsimd Documentation

repository·master·Indexed 25 days ago

https://github.com/xtensor-stack/xsimd

A C++17 library providing unified wrappers for SIMD (Single Instruction, Multiple Data) intrinsics. It enables high-performance vectorized code using standard arithmetic operators and accelerated mathematical functions across various microprocessor architectures, including x86 (SSE, AVX), ARM (NEON, SVE), WebAssembly, powerpc64, RISC-V, and IBM Z. Features include aligned memory allocation, batch manipulation, and support for binary, unary, saturated, and fused arithmetic operations.

Tokens
7.2K
Snippets
16
Records
78
Agent score
82%

What's inside xsimd

  1. Overview of xsimd

    master

    xsimd provides C++17 wrappers for SIMD (Single Instruction, Multiple Data) intrinsics. It offers a unified abstraction for different microprocessor vendors and compilers, allowing developers to write vectorized code that is portable across architectures.

    The library is built around:

    • Batch Types: Parameterized vector types.
    • Operations: A set of arithmetic, data transfer, and mathematical functions designed for batch processing.
  2. Use xsimd in a CMake project

    master

    To use xsimd in your own project, use find_package to locate the configuration files and link against the xsimd target. Linking to the xsimd target automatically handles include directories and requirements like the minimum C++ version.

    find_package(xsimd REQUIRED)
    target_link_libraries(myproject PRIVATE xsimd)
  3. Migrate from xsimd 7.x to 8.x

    master

    Version 8.x introduces significant API changes due to a redesign of batch types. The primary change is that xsimd::batch is now parameterized by a type (e.g., double) and an optional architecture (e.g., avx512).

    Key Changes:

    • Batch Parameterization: Use xsimd::batch<T, arch> to target specific architectures, or xsimd::batch<T> to let the library select the best available architecture.
    • Batch Loading: xsimd::batch<T>::load* methods are now static. You can no longer update an existing batch via load; use the assignment operator instead.
    • Indexing: operator[] has been replaced by .get(size_t). Note that .get() performs a register load on every call and should be avoided in performance-critical loops.
    • Complex Types: Loading a batch of xtl::xcomplex<T> now returns an xsimd::batch<std::complex<T>>.
  4. Enable Emulated Mode for testing and debugging

    master
    You can enable an emulated architecture mode by defining the macro XSIMD_WITH_EMULATED to 1 during compilation. This introduces the xsimd::emulated<N> architecture, which simulates a vector of N bits using scalar mode. This mode is intended for testing and debugging purposes.
  5. Build xsimd HTML documentation

    master

    The documentation is built using doxygen, sphinx, and breathe. You can install breathe via pip or conda.

    1. Install breathe: pip install breathe or conda install -c conda-forge breathe
    2. Navigate to the docs directory.
    3. Run make html.
    make html
  6. Handle aligned and unaligned memory with xsimd::batch

    master

    When loading or storing values from contiguous dynamically allocated memory into SIMD registers, use xsimd::batch::load_unaligned and xsimd::batch::store_unaligned.

    To improve performance, use xsimd::aligned_allocator with STL containers to ensure memory is aligned, allowing for faster memory transfer operations.