Class device

| Home | Libraries | People | FAQ | More

## Class device

boost::compute::device — A compute device.

## Synopsis

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

    class device {
    public:

      enum type { cpu = = CL_DEVICE_TYPE_CPU, gpu = = CL_DEVICE_TYPE_GPU,
                  accelerator = = CL_DEVICE_TYPE_ACCELERATOR };
      // construct/copy/destruct
      device();
      explicit device(cl_device_id, bool = true);
      device(const device &);
      device(device &&) noexcept;
      device & operator=(const device &);
      device & operator=(device &&) noexcept;
      ~device();

      // public member functions
      cl_device_id id() const;
      cl_device_id & get() const;
      cl_device_type type() const;
      platform platform() const;
      std::string name() const;
      std::string vendor() const;
      std::string profile() const;
      std::string version() const;
      std::string driver_version() const;
      std::vector< std::string > extensions() const;
      bool supports_extension(const std::string &) const;
      uint_ address_bits() const;
      ulong_ global_memory_size() const;
      ulong_ local_memory_size() const;
      uint_ clock_frequency() const;
      uint_ compute_units() const;
      template<typename T> uint_ preferred_vector_width() const;
      size_t profiling_timer_resolution() const;
      bool is_subdevice() const;
      template<typename T> T get_info(cl_device_info) const;
      template<int Enum> unspecified get_info() const;
      std::vector< device > partition(const cl_device_partition_property *) const;
      std::vector< device > partition_equally(size_t) const;
      std::vector< device >
      partition_by_counts(const std::vector< size_t > &) const;
      std::vector< device >
      partition_by_affinity_domain(cl_device_affinity_domain) const;
      bool operator==(const device &) const;
      bool operator!=(const device &) const;
    };

## Description

Typical compute devices include GPUs and multi-core CPUs. A list of all compute devices available on a platform can be obtained via the platform::devices() method.

The default compute device for the system can be obtained with the system::default_device() method. For example:

    boost::compute::device gpu = boost::compute::system::default_device();

See Also:

platform, context, command_queue

### `device` public construct/copy/destruct

1.     device();

   Creates a null device object.

2.     explicit device(cl_device_id id, bool retain = true);

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

3.     device(const device & other);

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

4.     device(device && other) noexcept;

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

5.     device & operator=(const device & other);

   Copies the device from `other` to `*this`.

6.     device & operator=(device && other) noexcept;

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

7.     ~device();

   Destroys the device object.

### `device` public member functions

1.     cl_device_id id() const;

   Returns the ID of the device.

2.     cl_device_id & get() const;

   Returns a reference to the underlying OpenCL device id.

3.     cl_device_type type() const;

   Returns the type of the device.

4.     platform platform() const;

   Returns the platform for the device.

5.     std::string name() const;

   Returns the name of the device.

6.     std::string vendor() const;

   Returns the name of the vendor for the device.

7.     std::string profile() const;

   Returns the device profile string.

8.     std::string version() const;

   Returns the device version string.

9.     std::string driver_version() const;

   Returns the driver version string.

10.     std::vector< std::string > extensions() const;

    Returns a list of extensions supported by the device.

11.     bool supports_extension(const std::string & name) const;

    Returns `true` if the device supports the extension with `name`.

12.     uint_ address_bits() const;

    Returns the number of address bits.

13.     ulong_ global_memory_size() const;

    Returns the global memory size in bytes.

14.     ulong_ local_memory_size() const;

    Returns the local memory size in bytes.

15.     uint_ clock_frequency() const;

    Returns the clock frequency for the device's compute units.

16.     uint_ compute_units() const;

    Returns the number of compute units in the device.

17.     template<typename T> uint_ preferred_vector_width() const;

    Returns the preferred vector width for type `T`.

18.     size_t profiling_timer_resolution() const;

    Returns the profiling timer resolution in nanoseconds.

19.     bool is_subdevice() const;

    Returns `true` if the device is a sub-device.

20.     template<typename T> T get_info(cl_device_info info) const;

    Returns information about the device.

    For example, to get the number of compute units:

        device.get_info<cl_uint>(CL_DEVICE_MAX_COMPUTE_UNITS);

    Alternatively, the template-specialized version can be used which automatically determines the result type:

        device.get_info<CL_DEVICE_MAX_COMPUTE_UNITS>();

    See the documentation for clGetDeviceInfo() for more information.

21.     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.

22.     std::vector< device >
        partition(const cl_device_partition_property * properties) const;

    Partitions the device into multiple sub-devices according to `properties`.

    | Warning
    This method is only available if the OpenCL version is 1.2 or later.

23.     std::vector< device > partition_equally(size_t count) const;

    | Warning
    This method is only available if the OpenCL version is 1.2 or later.

24.     std::vector< device >
        partition_by_counts(const std::vector< size_t > & counts) const;

    | Warning
    This method is only available if the OpenCL version is 1.2 or later.

25.     std::vector< device >
        partition_by_affinity_domain(cl_device_affinity_domain domain) const;

    | Warning
    This method is only available if the OpenCL version is 1.2 or later.

26.     bool operator==(const device & other) const;

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

27.     bool operator!=(const device & other) const;

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