Class context

| Home | Libraries | People | FAQ | More

## Class context

boost::compute::context — A compute context.

## Synopsis

    // In header: <boost/compute/context.hpp>

    class context {
    public:
      // construct/copy/destruct
      context();
      explicit context(const device &, const cl_context_properties * = 0);
      explicit context(const std::vector< device > &,
                       const cl_context_properties * = 0);
      explicit context(cl_context, bool = true);
      context(const context &);
      context(context &&) noexcept;
      context & operator=(const context &);
      context & operator=(context &&) noexcept;
      ~context();

      // public member functions
      cl_context & get() const;
      device get_device() const;
      std::vector< device > get_devices() const;
      template<typename T> T get_info(cl_context_info) const;
      template<int Enum> unspecified get_info() const;
      bool operator==(const context &) const;
      bool operator!=(const context &) const;
    };

## Description

The context class represents a compute context.

A context object manages a set of OpenCL resources including memory buffers and program objects. Before allocating memory on the device or executing kernels you must set up a context object.

To create a context for the default device on the system:

    // get the default compute device
    boost::compute::device gpu = boost::compute::system::default_device();

    // create a context for the device
    boost::compute::context context(gpu);

Once a context is created, memory can be allocated using the buffer class and kernels can be executed using the command_queue class.

See Also:

device, command_queue

### `context` public construct/copy/destruct

1.     context();

   Create a null context object.

2.     explicit context(const device & device,
                        const cl_context_properties * properties = 0);

   Creates a new context for `device` with `properties`.

   See the documentation for clCreateContext() for more information.

3.     explicit context(const std::vector< device > & devices,
                        const cl_context_properties * properties = 0);

   Creates a new context for `devices` with `properties`.

   See the documentation for clCreateContext() for more information.

4.     explicit context(cl_context context, bool retain = true);

   Creates a new context object for `context`. If `retain` is `true`, the reference count for `context` will be incremented.

5.     context(const context & other);

   Creates a new context object as a copy of `other`.

6.     context(context && other) noexcept;

   Move-constructs a new context object from `other`.

7.     context & operator=(const context & other);

   Copies the context object from `other` to `*this`.

8.     context & operator=(context && other) noexcept;

   Move-assigns the context from `other` to `*this`.

9.     ~context();

   Destroys the context object.

### `context` public member functions

1.     cl_context & get() const;

   Returns the underlying OpenCL context.

2.     device get_device() const;

   Returns the device for the context. If the context contains multiple devices, the first is returned.

3.     std::vector< device > get_devices() const;

   Returns a vector of devices for the context.

4.     template<typename T> T get_info(cl_context_info info) const;

   Returns information about the context.

   See the documentation for clGetContextInfo() for more information.

5.     template<int Enum> unspecified get_info() const;

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

6.     bool operator==(const context & other) const;

   Returns `true` if the context is the same at `other`.

7.     bool operator!=(const context & other) const;

   Returns `true` if the context is different from `other`.