C++ Vector class library

News and research about CPU microarchitecture and software optimization
Post Reply
agner
Site Admin
Posts: 75
Joined: 2019-12-27, 18:56:25
Contact:

C++ Vector class library

Post by agner » 2019-12-30, 7:15:57

The C++ Vector Class Library (VCL) is a tool that makes it easy to do multiple calculations simultaneously.

Modern microprocessors have vector registers that allow you to do multiple operations in a single instruction. This principle is called SIMD (Single Instruction Multiple Data).

The vector registers can be 128, 256, or 512 bits long. Microprocessors with the AVX512 instruction set can pack sixteen floating point values (using 32 bits each) into a single 512-bit register. This allows you to do sixteen floating point operations in a single instruction. You can pack even more values into a single vector register if you are using integers of less than 32 bits each. The SIMD principle has the potential to give you a tremendous improvement in calculation speed.

The latest microprocessors have thousands of different SIMD instruction, and it is quite complicated to use them. The VCL library provides a simple and easy interface to the SIMD instructions. For example, if a and b are vectors containing sixteen floating point values each, then you can add them simply by writing c = a + b. This will generate a single machine instruction that does all sixteen additions at once, using the AVX512 instruction set. If the vector registers are shorter, then you will need more instructions. For example, the same code will generate two instructions if your computer has the AVX instruction set with 256-bit vector registers. VCL allows you to compile for different microprocessors with different instruction set extensions from the same C++ source code. All you have to do is to specify the instruction set on the compiler command line.

A library of mathematical functions is included. The latest version of VCL can be downloaded from Github at https://github.com/vectorclass/version2/releases

The code is free and open source.

agner
Site Admin
Posts: 75
Joined: 2019-12-27, 18:56:25
Contact:

Re: C++ Vector class library

Post by agner » 2020-05-12, 6:16:40

A video blogger in Australia has made a nice introduction video on how to get started with the Vector Class Library:

https://www.youtube.com/watch?v=TKjYdLIMTrI

He has also made a nice video showing some amazingly beautiful fractal patterns made with this library

https://www.youtube.com/watch?v=u6v_70opPsk

Here is an introduction showing how to use the AVX512 instruction set

https://www.youtube.com/watch?v=I3efQKLgsjM

agner
Site Admin
Posts: 75
Joined: 2019-12-27, 18:56:25
Contact:

Re: C++ Vector class library

Post by agner » 2020-05-12, 6:24:16

The Vector Class Library works on Godbolt. This is a nice tool to test how different compilers treat a piece of code.

https://godbolt.org/

dbyoung
Posts: 1
Joined: 2021-02-03, 23:57:32

Re: C++ Vector class library

Post by dbyoung » 2021-02-05, 8:25:16

If the machine has no avx2 instruction,but only AVX instruction, can VCL's AVX optimization not be used?

agner
Site Admin
Posts: 75
Joined: 2019-12-27, 18:56:25
Contact:

Re: C++ Vector class library

Post by agner » 2021-02-05, 9:57:10

@dbyoung

You can make 256 bit floating point vectors with AVX. Please see table 9.1 and 9.2 in the manual.

Please note that this is not a place to seek programming help. Programming questions may be asked at Stackoverflow.com using the tag vector-class-library.

agner
Site Admin
Posts: 75
Joined: 2019-12-27, 18:56:25
Contact:

New release supports half precision floating point vectors

Post by agner » 2022-08-07, 9:53:28

Version 2.02.00 of the Vector Class Library is now released. Link.

New in this version:
  • Half precision floating point vectors, using the new AVX512-FP16 instruction set (or emulated on lower instruction sets). Includes all general functions and operators, exponential function, trigonometric functions, and complex numbers in half precision.
  • New trigonometric functions sinpi, cospi, sincospi, tanpi
  • Floating point modulo and remainder functions
  • Works on Gnu, Clang, Microsoft, and Intel C++ compilers
  • New add-on package with container class and matrix class templates
  • Improvements in add-on package 'complex'
  • Minor updates and bug fixes

Post Reply