• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.azure-pipelines/H30-Jul-2021-272249

benchmark/H03-May-2022-816735

docs/H30-Jul-2021-2,1581,575

examples/H03-May-2022-708500

include/xsimd/H30-Jul-2021-38,78028,465

test/H03-May-2022-7,0215,730

.appveyor.ymlH A D30-Jul-20211.6 KiB4538

.gitignoreH A D30-Jul-2021398 4333

LICENSEH A D30-Jul-20211.5 KiB2923

README.mdH A D30-Jul-20216.5 KiB219155

azure-pipelines.ymlH A D30-Jul-2021220 97

install_sde.shH A D30-Jul-20211.4 KiB113

readthedocs.ymlH A D30-Jul-202138 32

xsimd.pc.inH A D30-Jul-2021251 97

xsimdConfig.cmake.inH A D30-Jul-20211.1 KiB2420

README.md

1# ![xsimd](docs/source/xsimd.svg)
2
3[![Appveyor](https://ci.appveyor.com/api/projects/status/wori7my48os31nu0?svg=true)](https://ci.appveyor.com/project/xtensor-stack/xsimd)
4[![Azure](https://dev.azure.com/xtensor-stack/xtensor-stack/_apis/build/status/xtensor-stack.xsimd?branchName=master)](https://dev.azure.com/xtensor-stack/xtensor-stack/_build/latest?definitionId=3&branchName=master)
5[![Documentation Status](http://readthedocs.org/projects/xsimd/badge/?version=latest)](https://xsimd.readthedocs.io/en/latest/?badge=latest)
6[![Join the Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/QuantStack/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
8C++ wrappers for SIMD intrinsics
9
10## Introduction
11
12SIMD (Single Instruction, Multiple Data) is a feature of microprocessors that has been available for many years. SIMD instructions perform a single operation
13on a batch of values at once, and thus provide a way to significantly accelerate code execution. However, these instructions differ between microprocessor
14vendors and compilers.
15
16`xsimd` provides a unified means for using these features for library authors. Namely, it enables manipulation of batches of numbers with the same arithmetic
17operators as for single values. It also provides accelerated implementation of common mathematical functions operating on batches.
18
19You can find out more about this implementation of C++ wrappers for SIMD intrinsics at the [The C++ Scientist](http://johanmabille.github.io/blog/archives/).
20The mathematical functions are a lightweight implementation of the algorithms used in [boost.SIMD](https://github.com/NumScale/boost.simd).
21
22`xsimd` requires a C++11 compliant compiler. The following C++ compilers are supported:
23
24Compiler                | Version
25------------------------|-------------------------------
26Microsoft Visual Studio | MSVC 2015 update 2 and above
27g++                     | 4.9 and above
28clang                   | 4.0 and above
29
30The following SIMD instruction set extensions are supported:
31
32Architecture | Instruction set extensions
33-------------|-----------------------------------------------------
34x86          | SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, FMA3, AVX2
35x86          | AVX512 (gcc7 and higher)
36x86 AMD      | same as above + SSE4A, FMA4, XOP
37ARM          | ARMv7, ARMv8
38
39## Installation
40
41### Install from conda-forge
42
43A package for xsimd is available on the mamba (or conda) package manager.
44
45```bash
46mamba install -c conda-forge xsimd
47```
48
49### Install with Spack
50
51A package for xsimd is available on the Spack package manager.
52
53```bash
54spack install xsimd
55spack load xsimd
56```
57
58### Install from sources
59
60You can directly install it from the sources with cmake:
61
62```bash
63cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix
64make install
65```
66
67## Documentation
68
69To get started with using `xsimd`, check out the full documentation
70
71http://xsimd.readthedocs.io/
72
73## Usage
74
75### Explicit use of an instruction set extension
76
77Here is an example that computes the mean of two sets of 4 double floating point values, assuming AVX extension is supported:
78```cpp
79#include <iostream>
80#include "xsimd/xsimd.hpp"
81
82namespace xs = xsimd;
83
84int main(int argc, char* argv[])
85{
86    xs::batch<double, 4> a(1.5, 2.5, 3.5, 4.5);
87    xs::batch<double, 4> b(2.5, 3.5, 4.5, 5.5);
88    auto mean = (a + b) / 2;
89    std::cout << mean << std::endl;
90    return 0;
91}
92```
93
94Do not forget to enable AVX extension when building the example. With gcc or clang, this is done with the `-march=native` flag,
95on MSVC you have to pass the `/arch:AVX` option.
96
97This example outputs:
98
99```cpp
100(2.0, 3.0, 4.0, 5.0)
101```
102
103### Auto detection of the instruction set extension to be used
104
105The same computation operating on vectors and using the most performant instruction set available:
106
107```cpp
108#include <cstddef>
109#include <vector>
110#include "xsimd/xsimd.hpp"
111
112namespace xs = xsimd;
113using vector_type = std::vector<double, xsimd::aligned_allocator<double, XSIMD_DEFAULT_ALIGNMENT>>;
114
115void mean(const vector_type& a, const vector_type& b, vector_type& res)
116{
117    std::size_t size = a.size();
118    constexpr std::size_t simd_size = xsimd::simd_type<double>::size;
119    std::size_t vec_size = size - size % simd_size;
120
121    for(std::size_t i = 0; i < vec_size; i += simd_size)
122    {
123        auto ba = xs::load_aligned(&a[i]);
124        auto bb = xs::load_aligned(&b[i]);
125        auto bres = (ba + bb) / 2.;
126        bres.store_aligned(&res[i]);
127    }
128    for(std::size_t i = vec_size; i < size; ++i)
129    {
130        res[i] = (a[i] + b[i]) / 2.;
131    }
132}
133```
134
135We also implement STL algorithms to work optimally on batches. Using `xsimd::transform`
136the loop from the example becomes:
137
138```cpp
139#include <cstddef>
140#include <vector>
141#include "xsimd/xsimd.hpp"
142#include "xsimd/stl/algorithms.hpp"
143
144namespace xs = xsimd;
145using vector_type = std::vector<double, xsimd::aligned_allocator<double, XSIMD_DEFAULT_ALIGNMENT>>;
146
147void mean(const vector_type& a, const vector_type& b, vector_type& res)
148{
149    xsimd::transform(a.begin(), a.end(), b.begin(), res.begin(),
150                     [](const auto& x, const auto& y) { (x + y) / 2.; });
151}
152```
153
154
155## Building and Running the Tests
156
157Building the tests requires the [GTest](https://github.com/google/googletest) testing framework and [cmake](https://cmake.org).
158
159gtest and cmake are available as a packages for most linux distributions. Besides, they can also be installed with the `conda` package manager (even on windows):
160
161```bash
162conda install -c conda-forge gtest cmake
163```
164
165Once `gtest` and `cmake` are installed, you can build and run the tests:
166
167```bash
168mkdir build
169cd build
170cmake ../ -DBUILD_TESTS=ON
171make xtest
172```
173
174In the context of continuous integration with Travis CI, tests are run in a `conda` environment, which can be activated with
175
176```bash
177cd test
178conda env create -f ./test-environment.yml
179source activate test-xsimd
180cd ..
181cmake . -DBUILD_TESTS=ON
182make xtest
183```
184
185## Building the HTML Documentation
186
187xsimd's documentation is built with three tools
188
189 - [doxygen](http://www.doxygen.org)
190 - [sphinx](http://www.sphinx-doc.org)
191 - [breathe](https://breathe.readthedocs.io)
192
193While doxygen must be installed separately, you can install breathe by typing
194
195```bash
196pip install breathe
197```
198
199Breathe can also be installed with `conda`
200
201```bash
202conda install -c conda-forge breathe
203```
204
205Finally, build the documentation with
206
207```bash
208make html
209```
210
211from the `docs` subdirectory.
212
213## License
214
215We use a shared copyright model that enables all contributors to maintain the
216copyright on their contributions.
217
218This software is licensed under the BSD-3-Clause license. See the [LICENSE](LICENSE) file for details.
219