![]() |
Home | Libraries | People | FAQ | More |
boost::compute::device — A compute device.
// 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; };
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 functionsdevice();Creates a null device object.
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.
device(const device & other);Creates a new device object as a copy of
other
. device & operator=(const device & other);Copies the device from
other
to *this
. device(device && other) noexcept;Move-constructs a new device object from
other
. device & operator=(device && other) noexcept;Move-assigns the device from
other
to *this
. ~device();Destroys the device object.
cl_device_id id() const;Returns the ID of the device.
cl_device_id & get() const;Returns a reference to the underlying OpenCL device id.
cl_device_type type() const;Returns the type of the device.
platform platform() const;Returns the platform for the device.
std::string name() const;Returns the name of the device.
std::string vendor() const;Returns the name of the vendor for the device.
std::string profile() const;Returns the device profile string.
std::string version() const;Returns the device version string.
std::string driver_version() const;Returns the driver version string.
std::vector< std::string > extensions() const;Returns a list of extensions supported by the device.
bool supports_extension(const std::string & name) const;
Returns true
if the device supports the extension with name
.
uint_ address_bits() const;Returns the number of address bits.
ulong_ global_memory_size() const;Returns the global memory size in bytes.
ulong_ local_memory_size() const;Returns the local memory size in bytes.
uint_ clock_frequency() const;Returns the clock frequency for the device's compute units.
uint_ compute_units() const;Returns the number of compute units in the device.
template<typename T> uint_ preferred_vector_width() const;Returns the preferred vector width for type
T
. size_t profiling_timer_resolution() const;Returns the profiling timer resolution in nanoseconds.
bool is_subdevice() const;Returns
true
if the device is a sub-device. 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
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.
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. |
std::vector< device > partition_equally(size_t count) const;
![]() |
Warning |
---|---|
This method is only available if the OpenCL version is 1.2 or later. |
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. |
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. |
ulong_ get_host_timer() const;
Returns the current value of the host clock as seen by device in nanoseconds.
See the documentation for
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
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
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
bool operator==(const device & other) const;Returns
true
if the device is the same at other
. bool operator!=(const device & other) const;Returns
true
if the device is different from other
. bool check_version(int major, int minor) const;
Returns true
if the device OpenCL version is major.minor or newer; otherwise returns false
.