Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

Taking Advantage of the Accelerate Framework

If your application is computationally intensive, you need to know about the Accelerate framework. The Accelerate framework is a set of libraries containing high-performance vector-accelerated libraries that run on both PowerPC-based Macintosh computers and the upcoming Intel-based Macintosh computers. Using the framework can be very advantageous, in terms of code maintenance and reliability across the architectures.

The Accelerate framework is a natural fit if your application uses AltiVec or other vector-based code. The framework provides a layer of abstraction that lets you perform vector-based operations without needing to use low-level vector instructions yourself. With the Accelerate framework, you don't need to be concerned with the architecture of the user's machine because the routines in this framework abstract the low-level details. Your application will run on either PowerPC-based or Intel-based Macintoshes without processor-specific customization. The framework is written to automatically invoke the appropriate instruction set for the architecture that your code runs on. The Accelerate framework gives you reliable, predictable results, and portable, highly optimized code in one package.

This article looks at each library in the Accelerate framework, shows you how easy it is to import the framework into your existing projects, and gives you pointers to more detailed documentation on the ADC website.

Universal Binaries and Accelerate Framework

At the 2005 Worldwide Developers Conference, Apple announced a move to Intel-based Macintoshes. At the same time, Apple also provided a new version of the Xcode suite of tools to build univeral binaries.

A universal binary is a compiled application that is capable of running on both the PowerPC and Intel-based Macintosh computers. The amount of work needed to create a universal binary depends greatly on the level of your source code. High-level code typically contains no processor dependencies, and therefore will require few if any changes to create a universal binary. However, developers who have low-level code containing hardware dependencies, such as AltiVec or SSE instructions, will face the most challenges in creating a universal binary.

This is where system APIs such as those provided in the Accelerate framework come in. With a new hardware architecture to support, it makes sense to replace your own code with system APIs wherever possible. The Accelerate framework is the solution for computationally intensive universal binaries. The functions it provides eliminate the need for you to include hardware-dependent AltiVec or SSE code in your application.

The Libraries in the Accelerate Framework

First introduced on Mac OS X v10.3 Panther and expanded in Mac OSX v10.4 Tiger, the Accelerate framework includes the vImage image processing framework, the vDSP digital signal processing framework, and the LAPACK and BLAS libraries for Linear Algebra, among others. The vImage framework, also introduced in Panther, contains functions to perform image processing operations such as resizing, distortions, and rotations. The vDSP framework provides support for a wide range of applications, including signal processing (audio, digital image, and speech), physics, statistics, and cryptography just to name a few.

Image Processing: vImage

The vImage library contains routines to perform operations on raster graphics, or images. vImage routines transparently make the best use of the hardware available. For example, vImage uses AltiVec if it is available, but your code will also run on a PowerPC G3 processor. On the Intel platform, vImage will use SSE. Next you'll see the broad functional capabilities provided by vImage.

  • Format conversion
  • The vImage library has primary support for four pixel formats and contains functions to convert between them:

    1. Planar8
    2. PlanarF
    3. ARGB8888

    There are additional conversion functions that convert between over a dozen major pixel formats. These other formats are currently not supported by vImage for operations other than format conversions. vImage functions such as convolutions and geometry functions operate on the four pixel formats listed above.

  • Convolution
  • Convolution is a term used to describe an operation in which a result pixel is the weighted sum of the source pixels around it. Convolutions are used to cause blur, sharpening, and embossing effects. Other uses for convolutions include shifting the image horizontally and vertically with subpixel precision, or even to swap the order of pixels. vImage also supports deconvolution, which a process that approximately reverses a previous convolution. vImage provides an implementation of the Richardson-Lucy deconvolution algorithm, which can be used to remove lens distortion.

  • Morphological operations
  • vImage supports two morphological operations: dilation, and erosion. Two special cases, Max (for dilation) and Min (for erosion) are also provided.

  • Histograms
  • Histogram operations serve two purposes. The first is to give you a histogram for an image. The histogram contains information about the range of intensities of the pixels in the image. The second purpose is to transform an image so that it has approximately the same distribution of pixel intensities as a particular histogram. For example, if an image contains a large proportion of dark pixels, you can improve the contrast by transforming the image to a histogram with a more even distribution of pixel intensities.

  • Geometric operations
  • vImage provides functions to geometrically alter images. These functions include:

    • Rotation
    • Scaling
    • Affine Warp
    • Reflection
    • Shear
    • Rotate by 90 degrees
  • Alpha compositing
  • Each pixel in an image contains an associated alpha value that determines the opaqueness of the pixel. Alpha compositing is the process of taking two images, each with its own alpha information, and combining them to create the image that would appear if one image were placed over the other.

  • Transformation operations
  • Other pixel transformation functions, which do not depend on the values of other pixels are:

    • Matrix multiplication
    • Gamma correction
    • Application of one or more caller-supplied polynomials
    • Application of one or more caller-supplied rational functions
    • Mapping pixels using a caller-supplies lookup table

Digital Signal Processing: vDSP

The vDSP library is focused primarily in the realm of Fourier Transforms, vector-to-scalar, and vector-to-vector operations. The vDSP library has a wide range of applications, including signal processing (audio, digital image, and speech), physics, statistics, and cryptography. The vDSP library can perform both one and two dimensional Fourier transforms. vDSP functions operate on both real and complex data types.

vDSP uses vectorized code to implement functions that operate on single precision data. This code uses AltiVec extensions when a PowerPC G4 or G5 is present, or the SSE extensions when an Intel microprocessor is present. On the PowerPC G3 processor, vDSP uses scalar code.

vDSP functions operate on the basic C data types: float, double, integer, short integer, and character. There are two additional data types defined by the library to handle complex numbers and complex vectors.

Linear Algebra: LAPACK and BLAS

The Basic Linear Algebra Subprograms (BLAS) and Linear Algebra Package (LAPACK) libraries contain—as you would expect—functions to perform linear algebra computations such as solving simultaneous linear equations, least squares solutions of linear equations, and eigenvalue problems. The BLAS library serves as a building block for the LAPACK library. The BLAS and LAPACK libraries are widely distributed and industry standard computational libraries. They are available on a number of different platforms and architectures. So, if you are already using these libraries you should feel right at home, as the APIs are exactly the same on Mac OS X.

These two libraries are somewhat unique in that they have Fortran roots. The C version of LAPACK was actually built using a Fortran to C converter. Therefore, there are some caveats to calling LAPCACK routines from C, C++, and Objective-C. See the Vector Libraries page on the ADC website for more information./p>

Vector Accelerated libm: vMathLib and vForce

The vMathLib and vForce are vector-accelerated versions of the standard libm math libary. The difference between them is that vMathLib uses short, 128-bit hardware vectors to perform operations. It allows you to stay completely in the hardware vector domain.

The vForce library uses long vectors to perform libm functions. You can pass it very long arrays, which allows the library to keep the processor's pipelines saturated. This gives much better performance than libm, without using underlying hardware vectors in your code. vForce automatically selects between scalar and vector code to give the best performance.

vBasicOps and vBigNum

vBasicOps performs operations such as integer multiplication, addition and multiplication using 64- and 128-bit operands.

vBigNum is essentially the same as vBasicOps, except it uses up to 1024 bit integer operands.

Using the Accelerate Framework with Xcode

If you are used to using static libraries or individual shared libraries, you might not be familiar with the Mac OS X concept of a framework. The topic of Mac OS X frameworks is discussed in detail in the Framework Programming Guide.

Very briefly, a framework on Mac OS X encapsulates both code and resources. A framework might contain only compiled code, but typically a framework contains both header files, and compiled code. Any resource needed at runtime can be packaged with the framework howerver, and this includes images, resource strings, nib files, and documentation. Another big advantage of frameworks is that they allow multiple versions to be deployed side-by-side in the same resource bundle. This makes backwards compatibility with older versions of the framework possible.

Some frameworks act as containers for a set of smaller, related frameworks. These are called umbrella frameworks, and such is the case with the Accelerate framework. Knowledge of the framework's internal packaging is not required to use it in your project, however. It is merely an interesting implementation detail.

It is simple to incorporate the Accelerate framework into your Xcode project. There is only one header file you need to include:

#include <Accelerate/Accelerate.h>

Next, add the framework to your project. It resides in the system frameworks folder:


If you are using make or GCC directly, include the same header file and add the -framework switch to the command line:

-framework Accelerate

For More Information

Posted: 2005-10-03