Specifiying if the CPU or the GPU should be used for rendering.

Q: Which processor will Core Image use for rendering, and how can I specify it?

A: Core Image can either use the system's CPU or an ARB fragment-capable GPU for rendering. Unless specified, Core Image will use a simple set of rules to determine the best processor for rendering on the current system. Table 1 lists the rules and the order in which they are evaluated.

Table 1: Rules, in order, that Core Image uses to determine the best processor for rendering

If the GPU isDefault Processor
GeForce 5200 seriesCPU (See note)
ARB fragment capable HW (except for the GeForce 5200 series)GPU
non-ARB fragment capable HWCPU

Note: By default, Core Image uses the CPU for rendering on systems with a GeForce 5200 series card because, for most benchmarks, the 5200 can be slower than the CPU on currently shipping hardware.

Developers may want to use a processing unit other then the default for a number of reasons, such as to:

  • Free up the CPU to perform other processing in parallel. The GeForce 5200 may be fast enough for the specific application.

  • Get reproducible accuracy. CPUs are IEEE accurate, whereas GPUs are implementation specific.

  • Use fragment programs that have more than 64 instructions. Some GPUs are limited 64 instructions. Larger fragment programs can instead request that Core Image to use the CPU for processing.

To tell Core Image which processor to use for rendering, use the kCIContextUseSoftwareRenderer flag in the options parameter when creating the CIContext. If kCIContextUseSoftwareRenderer is equal to YES, Core Image will always render using the CPU. If kCIContextUseSoftwareRenderer equals NO, Core Image will use the GPU if possible. See Listing 1

Listing 1: Creates a Core Image context that will always use the CPU for rendering.

CIContext * CPUonlyCIContextFromCGContext(CGContextRef cgContext) {

  NSDictionary * contextOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithBool: YES],kCIContextUseSoftwareRenderer,nil];

  return [CIContext contextWithCGContext:cgContext options: contextOptions];
}

Document Revision History

DateNotes
2005-08-16Changed code sample to use kCIContextUseSoftwareRenderer constant.
2005-05-19Which processor will be used for rendering in Core Image and how to affect it.

Posted: 2005-08-16


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.