GoclContext

GoclContext — Object that represents an OpenCL context

Stability Level

Unstable, unless otherwise indicated

Synopsis

struct              GoclContext;
struct              GoclContextClass;
GoclContext *       gocl_buffer_get_context             (GoclBuffer *buffer);
GoclBuffer *        gocl_context_create_buffer          (GoclContext *self,
                                                         guint flags,
                                                         gsize size,
                                                         gpointer host_ptr,
                                                         GError **error);
cl_context          gocl_context_get_context            (GoclContext *self);
GoclContext *       gocl_context_get_default_cpu        (GError **error);
GoclContext *       gocl_context_get_default_gpu        (GError **error);
GoclDevice *        gocl_context_get_device_by_index    (GoclContext *self,
                                                         guint device_index);
guint               gocl_context_get_num_devices        (GoclContext *self);
GoclContext *       gocl_context_new                    (GoclDeviceType device_type,
                                                         GError **error);
GoclContext *       gocl_device_get_context             (GoclDevice *device);

Object Hierarchy

  GObject
   +----GoclContext

Implemented Interfaces

GoclContext implements GInitable.

Properties

  "device-type"              guint                 : Read / Write / Construct Only

Description

A GoclContext enables access to OpenCL objects such as devices, command queues, buffers, programs, kernels, etc. Obtaining a GoclContext is always the first step an OpenCL application performs.

A GoclContext can be created with gocl_context_new(), providing the type of device which is a value from GoclDeviceType. For convenience, the methods gocl_context_get_default_cpu() and gocl_context_get_default_gpu() are provided to easily retrieve pre-created CPU and GPU contexts, respectively.

Once a context is successfully created, devices can be obtained by calling gocl_context_get_device_by_index(), where index must be a value between 0 and the maximum number of devices in the context, minus one. Number of devices can be obtained with gocl_context_get_num_devices().

Memory buffers can be created in context's memory to that kernels can access and share them during execution. To create a buffer, gocl_context_create_buffer() method is provided.

Details

struct GoclContext

struct GoclContext;


struct GoclContextClass

struct GoclContextClass {
  GObjectClass parent_class;
};

The class for GoclContext objects.

GObjectClass parent_class;

The parent class

gocl_buffer_get_context ()

GoclContext *       gocl_buffer_get_context             (GoclBuffer *buffer);

Retrieves the GoclContext the buffer belongs to.

buffer :

The GoclBuffer

Returns :

A GoclContext object. [transfer none]

gocl_context_create_buffer ()

GoclBuffer *        gocl_context_create_buffer          (GoclContext *self,
                                                         guint flags,
                                                         gsize size,
                                                         gpointer host_ptr,
                                                         GError **error);

Creates a new buffer on context's memory. Depending on flags, the host_ptr pointer can be used to initialize the contents of the buffer from a block of memory in the host.

self :

The GoclContext

flags :

An OR'ed combination of values from GoclBufferFlags

size :

The size of the buffer, in bytes

host_ptr :

A pointer to memory in the host system, or NULL. [allow-none][type guint64]

error :

A pointer to a GError, or NULL. [out][allow-none]

Returns :

A newly created GoclBuffer, or NULL on error. [transfer full]

gocl_context_get_context ()

cl_context          gocl_context_get_context            (GoclContext *self);

Retrieves the internal OpenCL cl_context object. This is not normally called by applications. It is rather a low-level, internal API.

self :

The GoclContext

Returns :

The internal cl_context object. [transfer none][type guint]

gocl_context_get_default_cpu ()

GoclContext *       gocl_context_get_default_cpu        (GError **error);

Returns platform's default CPU context. The first call to this method will attempt to create a new GoclContext using a device type of GOCL_DEVICE_TYPE_CPU. Upon success, the context is cached and subsequent calls will return the same object, increasing its reference count.

error :

A pointer to a GError, or NULL. [out][allow-none]

Returns :

A GoclContext object, or NULL on error. [transfer full]

gocl_context_get_default_gpu ()

GoclContext *       gocl_context_get_default_gpu        (GError **error);

Returns platform's default GPU context. The first call to this method will attempt to create a new GoclContext using a device type of GOCL_DEVICE_TYPE_GPU. Upon success, the context is cached and subsequent calls will return the same object, increasing its reference count.

error :

A pointer to a GError, or NULL. [out][allow-none]

Returns :

A GoclContext object, or NULL on error. [transfer full]

gocl_context_get_device_by_index ()

GoclDevice *        gocl_context_get_device_by_index    (GoclContext *self,
                                                         guint device_index);

Retrieves the device_index-th device from the list of context devices. Use gocl_context_get_num_devices() to get the number of devices in the context.

Notice that method creates a new GoclDevice instance every time is called.

self :

The GoclContext

device_index :

The index of the device to retrieve

Returns :

A newly created GoclDevice. [transfer full]

gocl_context_get_num_devices ()

guint               gocl_context_get_num_devices        (GoclContext *self);

Obtains the number of devices in this context. Calls to gocl_context_get_device_by_index() must provide a device index between 0 and the number of devices returned by this method, minus one.

self :

The GoclContext

Returns :

The number of devices

gocl_context_new ()

GoclContext *       gocl_context_new                    (GoclDeviceType device_type,
                                                         GError **error);

Attempts to create a GoclContext of the type specified in device_type. Upon error, NULL is returned and error is filled accordingly. On success, a new GoclContext object is returned.

device_type :

A value from GoclDeviceType

error :

A pointer to a GError, or NULL. [out][allow-none]

Returns :

A newly created GoclContext. [transfer full]

gocl_device_get_context ()

GoclContext *       gocl_device_get_context             (GoclDevice *device);

Obtains the GoclContext the device belongs to.

device :

The GoclDevice

Returns :

A GoclContext. The returned object is owned by the device, do not free. [transfer none]

Property Details

The "device-type" property

  "device-type"              guint                 : Read / Write / Construct Only

The device type for this context.

Allowed values: >= 1

Default value: 1