BSD 3-Clause "New" or "Revised" License

项目介绍

xtensor-stack/xsimd 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前获得 2.8k 个 Star、309 次 Fork。

仓库全名
xtensor-stack/xsimd
开源许可证
BSD 3-Clause "New" or "Revised" License
Star 数
2.8k
Fork 数
309
未关闭 Issue
40

README 摘要

C++ wrappers for SIMD intrinsics Introduction SIMD (Single Instruction, Multiple Data) is a feature of microprocessors that has been available for many years. SIMD instructions perform a single operation on a batch of values at once, and thus provide a way to significantly accelerate code execution. However, these instructions differ between microprocessor vendors and compilers. xsimd provides a unified means for…

完整内容见 GitHub 原始 README 或本页 。

常见问题

xsimd 用什么语言开发?

主要使用 C++ 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前有 2.8k 个 Star。

xsimd 可以免费商用吗?

仓库采用 BSD 3-Clause "New" or "Revised" License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 xsimd 的源码?

可以直接克隆仓库:git clone https://github.com/xtensor-stack/xsimd.git,默认分支为 master;安装与运行步骤见仓库 README。

xsimd 最近还在维护吗?

仓库最近一次更新为 3 天前,当前有 40 个未关闭 Issue;Star 数为 2.8k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, AVX512, NEON, SVE, WebAssembly, VSX, RISC-V))

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
3458
价值分
1760
活跃状态
活跃

语言占比

C++
CMake
HTML
Jupyter Notebook
Python
Shell

README

xsimd

Documentation Jupyterlite Zulip

C++ wrappers for SIMD intrinsics

Introduction

SIMD (Single Instruction, Multiple Data) is a feature of microprocessors that has been available for many years. SIMD instructions perform a single operation on a batch of values at once, and thus provide a way to significantly accelerate code execution. However, these instructions differ between microprocessor vendors and compilers.

xsimd provides a unified means for using these features for library authors. Namely, it enables manipulation of batches of numbers with the same arithmetic operators as for single values. It also provides accelerated implementation of common mathematical functions operating on batches.

CI status

Workflow Status
android GHA android
cross-rvv GHA cross-rvv
cross-sve GHA cross-sve
cross GHA cross
cxx-no-exceptions GHA cxx-no-exceptions
cxx-versions GHA cxx-versions
emscripten GHA emscripten
linux GHA linux
macos GHA macos
windows GHA windows

Adoption

Beyond Xtensor, Xsimd has been adopted by major open-source projects, such as:

  • Mozilla Firefox - web browser,
  • Apache Arrow - cross-language framework for tabular data management,
  • Pandas - Python data analysis library,
  • KDE Krita - digital painting and illustration application,
  • Meta Velox - a composable execution engine,
  • Milvus - vector database for AI applications,
  • Pythran - Python-to-C++ compiler for numerical computing.

History

The XSimd project started with a series of blog articles by Johan Mabille on how to implement wrappers for SIMD intrinsicts. The archives of the blog can be found here: The C++ Scientist. The design described in the articles remained close to the actual architecture of XSimd up until Version 8.0.

The mathematical functions are a lightweight implementation of the algorithms originally implemented in the now deprecated boost.SIMD project.

Requirements

xsimd builds with any C++17 compliant compiler. Official support covers the compilers tested in the CI:

Compiler Version
Microsoft Visual Studio MSVC 2022 and above
g++ 10 and above
clang 16 and above

The following SIMD instruction set extensions are supported:

Architecture Instruction set extensions
x86 SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, FMA3+SSE, FMA3+AVX, FMA3+AVX2
x86 AVX512BW, AVX512CD, AVX512DQ, AVX512F, AVX512VL
x86 AMD FMA4
ARM NEON, NEON64, SVE128/256/512 (fixed vector size)
WebAssembly WASM
powerpc64 VSX
RISC-V RISC-V128/256/512 (fixed vector size)
LoongArch64 LSX, LASX
IBM Z (s390x) VXE (IBM z14)

Installation

Install from conda-forge

A package for xsimd is available on the mamba (or conda) package manager.

mamba install -c conda-forge xsimd

Install with Spack

A package for xsimd is available on the Spack package manager.

spack install xsimd
spack load xsimd

Install from sources

You can directly install it from the sources with cmake:

cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix .
make install

Documentation

To get started with using xsimd, check out the full documentation

http://xsimd.readthedocs.io/

Dependencies

xsimd has an optional dependency on the xtl library:

xsimd xtl (optional)
master ^0.7.0
12.x ^0.7.0
11.x ^0.7.0
10.x ^0.7.0
9.x ^0.7.0
8.x ^0.7.0

The dependency on xtl is required if you want to support vectorization for xtl::xcomplex.

Usage

The version 8 of the library is a complete rewrite and there are some slight differences with 7.x versions. A migration guide will be available soon. In the meanwhile, the following examples show how to use both versions 7 and 8 of the library?

Explicit use of an instruction set extension

Here is an example that computes the mean of two sets of 4 double floating point values, assuming AVX extension is supported:

#include <iostream>
#include "xsimd/xsimd.hpp"

namespace xs = xsimd;

int main(int argc, char* argv[])
{
    xs::batch<double, xs::avx2> a = {1.5, 2.5, 3.5, 4.5};
    xs::batch<double, xs::avx2> b = {2.5, 3.5, 4.5, 5.5};
    auto mean = (a + b) / 2;
    std::cout << mean << std::endl;
    return 0;
}

Do not forget to enable AVX extension when building the example. With gcc or clang, this is done with the -mavx flag, on MSVC you have to pass the /arch:AVX option.

This example outputs:

(2.0, 3.0, 4.0, 5.0)

Auto detection of the instruction set extension to be used

The same computation operating on vectors and using the most performant instruction set available at compile time, based on the provided compiler flags (e.g. -mavx2 for GCC and Clang to target AVX2):

#include <cstddef>
#include <vector>
#include "xsimd/xsimd.hpp"

namespace xs = xsimd;
using vector_type = std::vector<double, xsimd::aligned_allocator<double>>;

void mean(const vector_type& a, const vector_type& b, vector_type& res)
{
    std::size_t size = a.size();
    constexpr std::size_t simd_size = xsimd::simd_type<double>::size;
    std::size_t vec_size = size - size % simd_size;

    for(std::size_t i = 0; i < vec_size; i += simd_size)
    {
        auto ba = xs::load_aligned(&a[i]);
        auto bb = xs::load_aligned(&b[i]);
        auto bres = (ba + bb) / 2.;
        bres.store_aligned(&res[i]);
    }
    for(std::size_t i = vec_size; i < size; ++i)
    {
        res[i] = (a[i] + b[i]) / 2.;
    }
}

Building and Running the Tests

Building the tests requires cmake.

cmake is available as a package for most linux distributions. Besides, they can also be installed with the conda package manager (even on windows):

conda install -c conda-forge cmake

Once cmake is installed, you can build and run the tests:

mkdir build
cd build
cmake ../ -DBUILD_TESTS=ON
make xtest

In the context of continuous integration with Travis CI, tests are run in a conda environment, which can be activated with

cd test
conda env create -f ./test-environment.yml
source activate test-xsimd
cd ..
cmake . -DBUILD_TESTS=ON
make xtest

Building the HTML Documentation

xsimd’s documentation is built with three tools

While doxygen must be installed separately, you can install breathe by typing

pip install breathe

Breathe can also be installed with conda

conda install -c conda-forge breathe

Finally, build the documentation with

make html

from the docs subdirectory.

License

We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.

评论

暂无评论