Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

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 };

  // public member functions
  device();
  explicit device(cl_device_id, bool = true);
  device(const device &);
  device & operator=(const device &);
  device(device &&) noexcept;
  device & operator=(device &&) noexcept;
  ~device();
  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;
  ulong_ get_host_timer() const;
  std::pair< ulong_, ulong_ > get_device_and_host_timer() const;
  template<typename Duration> Duration get_host_timer() const;
  template<typename Duration> 
    std::pair< Duration, Duration > get_device_and_host_timer() const;
  bool operator==(const device &) const;
  bool operator!=(const device &) const;
  bool check_version(int, int) 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:


See Also: platform, context, command_queue

device public member functions

  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 & operator=(const device & other);
    Copies the device from other to *this.
  5. device(device && other) noexcept;
    Move-constructs a new device object from other.
  6. device & operator=(device && other) noexcept;
    Move-assigns the device from other to *this.
  7. ~device();
    Destroys the device object.
  8. cl_device_id id() const;
    Returns the ID of the device.
  9. cl_device_id & get() const;
    Returns a reference to the underlying OpenCL device id.
  10. cl_device_type type() const;
    Returns the type of the device.
  11. platform platform() const;
    Returns the platform for the device.
  12. std::string name() const;
    Returns the name of the device.
  13. std::string vendor() const;
    Returns the name of the vendor for the device.
  14. std::string profile() const;
    Returns the device profile string.
  15. std::string version() const;
    Returns the device version string.
  16. std::string driver_version() const;
    Returns the driver version string.
  17. std::vector< std::string > extensions() const;
    Returns a list of extensions supported by the device.
  18. bool supports_extension(const std::string & name) const;

    Returns true if the device supports the extension with name.

  19. uint_ address_bits() const;
    Returns the number of address bits.
  20. ulong_ global_memory_size() const;
    Returns the global memory size in bytes.
  21. ulong_ local_memory_size() const;
    Returns the local memory size in bytes.
  22. uint_ clock_frequency() const;
    Returns the clock frequency for the device's compute units.
  23. uint_ compute_units() const;
    Returns the number of compute units in the device.
  24. template<typename T> uint_ preferred_vector_width() const;
    Returns the preferred vector width for type T.
  25. size_t profiling_timer_resolution() const;
    Returns the profiling timer resolution in nanoseconds.
  26. bool is_subdevice() const;
    Returns true if the device is a sub-device.
  27. 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

  28. 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.
  29. std::vector< device > 
    partition(const cl_device_partition_property * properties) const;

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

    [Warning] Warning

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

  30. std::vector< device > partition_equally(size_t count) const;
    [Warning] Warning

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

  31. std::vector< device > 
    partition_by_counts(const std::vector< size_t > & counts) const;
    [Warning] Warning

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

  32. std::vector< device > 
    partition_by_affinity_domain(cl_device_affinity_domain domain) const;
    [Warning] Warning

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

  33. ulong_ get_host_timer() const;

    Returns the current value of the host clock as seen by device in nanoseconds.

    See the documentation for

  34. std::pair< ulong_, ulong_ > get_device_and_host_timer() const;

    Returns a reasonably synchronized pair of timestamps from the device timer and the host timer as seen by device in nanoseconds. The first of returned std::pair is a device timer timestamp, the second is a host timer timestamp.

    See the documentation for

  35. template<typename Duration> Duration get_host_timer() const;

    Returns the current value of the host clock as seen by device as duration.

    For example, to print the current value of the host clock as seen by device in milliseconds:

    std::cout << device.get_host_timer<std::chrono::milliseconds>().count() << " ms";
    

    See the documentation for

  36. template<typename Duration> 
      std::pair< Duration, Duration > get_device_and_host_timer() const;

    Returns a reasonably synchronized pair of timestamps from the device timer and the host timer as seen by device as a std::pair<Duration, Duration> value. The first of returned std::pair is a device timer timestamp, the second is a host timer timestamp.

    See the documentation for

  37. bool operator==(const device & other) const;
    Returns true if the device is the same at other.
  38. bool operator!=(const device & other) const;
    Returns true if the device is different from other.
  39. bool check_version(int major, int minor) const;

    Returns true if the device OpenCL version is major.minor or newer; otherwise returns false.


PrevUpHomeNext