Differences between revisions 2 and 3
Revision 2 as of 2015-06-08 14:29:24
Size: 3344
Comment:
Revision 3 as of 2015-06-08 14:47:56
Size: 3464
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 9: Line 8:
The library can be disabled with --disable-mathvec configure option. The library can be disabled with --disable-mathvec configure option. The library is linked in as needed when using -lm (no need to specify -lmvec explicitly).
Line 12: Line 11:
Line 23: Line 21:
a. Functions may not raise exceptions as required by C language standard. Functions may raise spurious exceptions. This is considered an artifact of SIMD processing and may be fixed in the future on the case-by-case basis.
b. Functions may not change errno in some of the required cases, e.g. if the SIMD friendly algorithm is done branch-free without a libm call for that value. This is done for performance reasons.
c. As the implementation is dependent on libm, some accuracy and special case problems may be inherent to this fact.
d. Functions do not guarantee fully correct results in computation modes different from round-to-nearest one.
 a. Functions may not raise exceptions as required by C language standard. Functions may raise spurious exceptions. This is considered an artifact of SIMD processing and may be fixed in the future on the case-by-case basis
 a. Functions may not change errno in some of the required cases, e.g. if the SIMD friendly algorithm is done branch-free without a libm call for that value. This is done for performance reasons
 a. As the implementation is dependent on libm, some accuracy and special case problems may be inherent to this fact
 a. Functions do not guarantee fully correct results in computation modes different from round-to-nearest one
Line 29: Line 27:

For x86_64 vector functions names are created based on #2.6. Vector Function Name Mangling from Vector ABI (attached) which has been discussed at X86-64 System V Application Binary Interface mail list.
For x86_64 vector functions names are created based on #2.6. Vector Function Name Mangling from Vector ABI (attached) which has been discussed at X86-64 System V Application Binary Interface mail list.
Line 33: Line 30:

Use of the vector math function could be enabled with -fopenmp -ffast-math -O1 (for GCC starting from version 4.9.0) and appropriate usage of OpenMP SIMD constructs.
Use of the vector math function could be enabled with -fopenmp -ffast-math starting from optimization l (for GCC starting from version 4.9.0) and appropriate usage of OpenMP SIMD constructs.
Line 39: Line 35:
Line 42: Line 37:
#pragma omp declare simd
extern double cos(double);
int N = 300;
double b[300];
double a[300];
{{{
#include <math.h>
Line 48: Line 40:
int main(void) { int N = 3200;
Line 50: Line 42:
int i;
#pragma omp simd
double b[3200];
Line 53: Line 44:
for (i = 0; i < N; i += 1) {
b[i] = cos (a[i]);
}
return (0);
double a[3200];

int main (void)

{

  int i;

  #pragma omp simd

  
for (i = 0; i < N; i += 1)

 
{

    
b[i] = cos (a[i]);

  
}

  
return (0);
Line 59: Line 65:
being built by gcc 4.9.0 with the following command: gcc ./cos.c -I/PATH_TO_GLIBC_INSTALL/include/ -L/PATH_TO_GLIBC_INSTALL/lib/ -O1 -fopenmp -lm -mavx2 produces binary with call to AVX2 vector version of cos. Output of command "nm a.out" contains the following: }}}
being built by gcc 4.9.0 with the following command: gcc ./cos.c -I/PATH_TO_GLIBC_INSTALL/include/ -L/PATH_TO_GLIBC_INSTALL/lib/ -O1 -fopenmp -lm -mavx2 produces binary with call to AVX2 vectorized version of cos. Output of command "nm a.out" contains the following:

Libmvec

Libmvec is vector math library added in Glibc 2.22.

Vector math library was added to support SIMD constructs of OpenMP4.0 (#2.8 in http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) by adding vector implementations of vector math functions.

Vector math functions are vector variants of corresponding scalar math operations implemented using SIMD ISA extensions (e.g. SSE or AVX for x86_64). They take packed vector arguments, perform the operation on each element of the packed vector argument, and return a packed vector result. Using vector math functions is faster than repeatedly calling the scalar math routines.

The library can be disabled with --disable-mathvec configure option. The library is linked in as needed when using -lm (no need to specify -lmvec explicitly).

Libmvec on x86_64

Build and testing enabled by default.

Vector versions differ from the scalar analogues in accuracy and behavior on special values.

Functions are optimized for performance in their respective domains if processing doesn’t incur special values like denormal values, over- and under-flow, and out of range. Special values processing is done in a scalar fashion via respective scalar routine calls. Additionally functions like trigonometric may resort to scalar processing of huge (or other) arguments that do not necessarily cause special values, but rather require different and less SIMD-friendly handling.

These functions were tested (via reasonable random sampling) to pass 4-ulp maximum relative error criterion on their domains in round-to-nearest computation mode. Known limitations:

C99 compliance in terms of special values, errno:

  1. Functions may not raise exceptions as required by C language standard. Functions may raise spurious exceptions. This is considered an artifact of SIMD processing and may be fixed in the future on the case-by-case basis
  2. Functions may not change errno in some of the required cases, e.g. if the SIMD friendly algorithm is done branch-free without a libm call for that value. This is done for performance reasons
  3. As the implementation is dependent on libm, some accuracy and special case problems may be inherent to this fact
  4. Functions do not guarantee fully correct results in computation modes different from round-to-nearest one

Vector ABI

For x86_64 vector functions names are created based on #2.6. Vector Function Name Mangling from Vector ABI (attached) which has been discussed at X86-64 System V Application Binary Interface mail list.

Usage model

Use of the vector math function could be enabled with -fopenmp -ffast-math starting from optimization l (for GCC starting from version 4.9.0) and appropriate usage of OpenMP SIMD constructs.

The library is linked in as needed when using -lm (no need to specify -lmvec explicitly).

Example

The next code in file cos.c:

#include <math.h>

int N = 3200;

double b[3200];

double a[3200];

int main (void)

{

  int i;

  #pragma omp simd

  for (i = 0; i < N; i += 1)

  {

    b[i] = cos (a[i]);

  }

  return (0);
}

being built by gcc 4.9.0 with the following command: gcc ./cos.c -I/PATH_TO_GLIBC_INSTALL/include/ -L/PATH_TO_GLIBC_INSTALL/lib/ -O1 -fopenmp -lm -mavx2 produces binary with call to AVX2 vectorized version of cos. Output of command "nm a.out" contains the following:

U _ZGVdN4v_cos@@GLIBC_2.22

None: libmvec (last edited 2016-02-24 11:45:50 by AndrewSenkevich)