Aussie AI

AVX Operations

  • Book Excerpt from "Generative AI in C++"
  • by David Spuler, Ph.D.

AVX Operations

The main SIMD instructions are called “vertical” instructions, by convention. They take one vector and a second vector (e.g. both are 128-bit), apply an operation element-wise in parallel, and put the result into a third register. In other words, they return the result of a “pair-wise” or “element-wise” operation on two vectors into a third vector.

For example, vertical addition requires two input vectors and will output a third vector with the sums. AVX-512 SIMD addition will add two 512-bit registers full of float values on a paired element basis (i.e. adds 16 pairs of 32-bit float values), yielding a third 512-bit vector with the result (16 float values).

Binary operations. The full list of binary AVX operations is very long. Supported AVX operations include:

  • Multiplication
  • Addition
  • Subtraction
  • Division
  • Maximum
  • Minimum
  • Fused Multiply-Add (FMA)
  • Bitwise operations
  • ...and many more

Unary operations. AVX unary intrinsics apply a particular function to all elements of an AVX register in parallel, and return the resulting register. Supported AVX unary operations include:

  • Clear to zero
  • Set to a constant
  • Casts
  • Conversions
  • Popcount (POPCNT)
  • Leading-zero count (LZCNT)

Mathematical Functions. Simple float-to-float mathematical functions are effectively a type of unary operator. AVX supports a variety of functions with vector hardware instructions, such as:

  • Absolute value: abs
  • Error function: erf
  • Reciprocal
  • Rounding, ceiling, floor
  • Roots: sqrt (square root), cube root
  • Inverted roots (e.g. invsqrt)
  • Exponential: exp, exp10
  • Logarithm: log, log10
  • Trigonometric functions
  • Hyperbolic functions
  • Statistics (e.g. Cumulative Distribution Function)

 

Next:

Up: Table of Contents

Buy: Generative AI in C++: Coding Transformers and LLMs

Generative AI in C++ The new AI programming book by Aussie AI co-founders:
  • AI coding in C++
  • Transformer engine speedups
  • LLM models
  • Phone and desktop AI
  • Code examples
  • Research citations

Get your copy from Amazon: Generative AI in C++