Ufo.Buffer

g GObject.Object GObject.Object Ufo.Buffer Ufo.Buffer GObject.Object->Ufo.Buffer

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (requisition, context)

class

new_with_data (requisition, data, context)

class

new_with_size (dims, context)

cmp_dimensions (requisition)

convert (depth)

convert_from_data (data, depth)

copy (dst)

copy_host_array (array)

copy_metadata (dst)

discard_location ()

dup ()

get_device_array (cmd_queue)

get_device_array_view (cmd_queue, region)

get_device_array_with_offset (cmd_queue, offset)

get_device_image (cmd_queue)

get_host_array (cmd_queue)

get_layout ()

get_location ()

get_metadata (name)

get_metadata_keys ()

get_requisition ()

get_size ()

max (cmd_queue)

min (cmd_queue)

resize (requisition)

set_device_array (array, free_data)

set_host_array (array, free_data)

set_layout (layout)

set_metadata (name, value)

swap_data (dst)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Ufo.Buffer(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Ufo.BufferClass

Represents n-dimensional data. The contents of the Ufo.Buffer structure are private and should only be accessed via the provided API.

classmethod new(requisition, context)
Parameters:
  • requisition (Ufo.Requisition) – size requisition

  • context (object or None) – cl_context to use for creating the device array

Returns:

A new Ufo.Buffer with the given dimensions.

Return type:

Ufo.Buffer

Create a new Ufo.Buffer.

classmethod new_with_data(requisition, data, context)
Parameters:
  • requisition (Ufo.Requisition) – size requisition

  • data (object or None) – Pointer to host memory that will be used by

  • context (object or None) – OpenCL context for this buffer

Return type:

Ufo.Buffer

Create a new buffer using existing host memory.

classmethod new_with_size(dims, context)
Parameters:
  • dims ([int]) – size requisition

  • context (object or None) – cl_context to use for creating the device array

Returns:

A new Ufo.Buffer with the given dimensions.

Return type:

Ufo.Buffer

Create a new Ufo.Buffer with a list of dimensions.

cmp_dimensions(requisition)
Parameters:

requisition (Ufo.Requisition) – Ufo.Requisition

Returns:

value < 0, 0 or > 0 if requisition is smaller, equal or larger.

Return type:

int

Compare the size of self with a given requisition.

convert(depth)
Parameters:

depth (Ufo.BufferDepth) – Source bit depth of host data

Convert host data according to its depth to the internal 32-bit floating point representation.

convert_from_data(data, depth)
Parameters:
  • data (object or None) – Pointer to data that should be converted

  • depth (Ufo.BufferDepth) – Source bit depth of host data

Convert data according from depth to the internal 32-bit floating point representation.

Note: data must provide as many bytes as the buffer was initialized with.

copy(dst)
Parameters:

dst (Ufo.Buffer) – Destination Ufo.Buffer

Copy contents of self to dst. The final memory location is determined by the destination buffer.

copy_host_array(array)
Parameters:

array (int) – A pointer to a float array with suitable size.

Copy data into the buffer.

copy_metadata(dst)
Parameters:

dst (Ufo.Buffer) – Destination buffer

Copies meta data content from self to dst.

discard_location()

Discard the current and use the last location without copying to it first.

dup()
Returns:

A Ufo.Buffer with the same size as self.

Return type:

Ufo.Buffer

Create a new buffer with the same requisition as self. Note, that this is not a copy of self!

get_device_array(cmd_queue)
Parameters:

cmd_queue (object or None) – A cl_command_queue object or None.

Returns:

A cl_mem object associated with self.

Return type:

object or None

Return the current cl_mem object of self. If the data is not yet in device memory, it is transfered via cmd_queue to the object. If cmd_queue is None cmd_queue, the last used command queue is used.

get_device_array_view(cmd_queue, region)
Parameters:
Returns:

A newly allocated cl_mem that the user must release himself with clReleaseMemObject().

Return type:

object or None

This method creates a new memory buffer that must be freed by the user. Moreover, the original self is kept intact.

get_device_array_with_offset(cmd_queue, offset)
Parameters:
  • cmd_queue (object or None) – A cl_command_queue object or None

  • offset (int) – Offset in bytes from the original buffer

Returns:

A cl_mem sub buffer of the original data.

Return type:

object or None

Creates a new cl_mem object with the given offset and a size that is the original size minus the offset.

get_device_image(cmd_queue)
Parameters:

cmd_queue (object or None) – A cl_command_queue object or None.

Returns:

A cl_mem image object associated with self.

Return type:

object or None

Return the current cl_mem image object of self. If the data is not yet in device memory, it is transfered via cmd_queue to the object. If cmd_queue is None cmd_queue, the last used command queue is used.

get_host_array(cmd_queue)
Parameters:

cmd_queue (object or None) – A cl_command_queue object or None.

Returns:

Float array.

Return type:

float

Returns a flat C-array containing the raw float data.

get_layout()
Return type:

Ufo.BufferLayout

Return current layout of self.

get_location()
Return type:

Ufo.BufferLocation

Return current location of data backed by self.

get_metadata(name)
Parameters:

name (str) – Name of the associated meta data

Returns:

previously defined metadata GObject.Value for this buffer.

Return type:

GObject.Value

Retrieve meta data.

get_metadata_keys()
Returns:

A GLib.List with C strings. The content of the list owned by the buffer and should not be modified or freed. Use #g_list_free() when done using the list.

Return type:

[str]

Get all meta data keys associated with self.

get_requisition()
Returns:

A location to store the requisition of self

Return type:

requisition: Ufo.Requisition

Return the size of self.

get_size()
Returns:

The size of self's data.

Return type:

int

Get the number of bytes of raw data that is managed by the self.

max(cmd_queue)
Parameters:

cmd_queue (object or None) – An OpenCL command queue or None

Returns:

The maximum found.

Return type:

float

Return the maximum value of self.

min(cmd_queue)
Parameters:

cmd_queue (object or None) – An OpenCL command queue or None

Returns:

The minimum found.

Return type:

float

Return the minimum value of self.

resize(requisition)
Parameters:

requisition (Ufo.Requisition) – A Ufo.Requisition structure

Resize an existing buffer. If the new requisition has the same size as before, resizing is a no-op.

New in version 0.2.

set_device_array(array, free_data)
Parameters:
  • array (object or None) – A cl_mem object.

  • free_data (bool) – True if self is supposed to call clReleaseMemObject on the existing device array.

Set the current cl_mem object.

set_host_array(array, free_data)
Parameters:
  • array (int) – A pointer to a float array with suitable size.

  • free_data (bool) – True if self is supposed to clean up the host array.

Use this function to set a host array with a user-provided memory buffer. This is useful to expose private data of a generator filter to a subsequent consumer. Note, that the buffer *must* have an appropriate size.

set_layout(layout)
Parameters:

layout (Ufo.BufferLayout) – Layout of the currently residing data

Set layout of the buffer.

set_metadata(name, value)
Parameters:

Associates a key-value pair with self.

swap_data(dst)
Parameters:

dst (Ufo.Buffer) – Buffer to receive data from self

Swap the *content* of the two buffers if possible (i.e. data resides on the same memory type) or copy from self to dst otherwise.

New in version 0.16.