concept context in category opencl

appears as: context, context
OpenCL in Action: How to Accelerate Graphics and Computation

This is an excerpt from Manning's book OpenCL in Action: How to Accelerate Graphics and Computation.

In this analogy, the dealer represents an OpenCL host, each player represents a device, the card table represents a context, and each card represents a kernel. Each player’s hand represents a command queue. Table 1.2 clarifies how the steps of a card game resemble the operation of an OpenCL application.

Table 1.2. Comparison of OpenCL operation to a card game

Card game

OpenCL application

The dealer sits at a card table and determines who the players are. The host selects devices and places them in a context.
The dealer selects cards from a deck and deals them to each player. Each player’s cards form a hand. The host selects kernels from a program. It adds kernels to each device’s command queue.
Each player looks at their hand and decides what actions to take. Each device processes the kernels that are sent through the command queue.
The dealer responds to players’ requests during the game. The host receives events from the devices and invokes event-handling routines.
The game ends, and the dealer looks at each player’s hand to determine who won. Once the devices are finished, the host receives and processes the output data.

The following listing presents an abbreviated portion of the code in Ch2/context_count.c. This creates a context with a single device and updates its reference count with the clRetainContext and clReleaseContext functions. After each update, the code reads the new count with clGetContextInfo.

Listing 2.3. Checking a context’s reference count: context_count.c

Many OpenCL data structures can only be created if a context is available. For example, you need a valid context in order to construct a program, and you need a program if you’re going to send kernels to your devices (which, honestly, is the whole point of OpenCL programming). The next section explains how programs work.

Program(const Context& context, const Sources& sources, cl_int* err = NULL)

Program(const Context& context, const VECTOR_CLASS<Device>& devices,
   const Binaries& binaries, VECTOR_CLASS<cl_int>* binaryStatus = NULL,
   cl_int* err = NULL)