2011-02-22 21:43:26 +01:00
Initalization and Information
=============================
.. highlight :: cpp
.. index :: gpu::getCudaEnabledDeviceCount
2011-03-23 11:56:20 +01:00
gpu::getCudaEnabledDeviceCount
2011-02-22 21:43:26 +01:00
----------------------------------
2011-03-29 01:16:20 +02:00
.. cpp:function :: int getCudaEnabledDeviceCount()
2011-03-23 11:56:20 +01:00
2011-03-29 01:16:20 +02:00
Returns the number of installed CUDA-enabled devices. Use this function before any other GPU functions calls. If OpenCV is compiled without GPU support, this function returns 0.
2011-03-23 11:56:20 +01:00
2011-02-22 21:43:26 +01:00
.. index :: gpu::setDevice
2011-03-23 11:56:20 +01:00
gpu::setDevice
2011-02-22 21:43:26 +01:00
------------------
2011-03-29 01:16:20 +02:00
.. cpp:function :: void setDevice(int device)
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
Sets a device and initializes it for the current thread. If the call of this function is omitted, a default device is initialized at the fist GPU usage.
2011-03-23 11:56:20 +01:00
2011-03-29 01:16:20 +02:00
:param device: System index of a GPU device starting with 0.
2011-03-23 11:56:20 +01:00
2011-02-22 21:43:26 +01:00
.. index :: gpu::getDevice
2011-03-23 11:56:20 +01:00
gpu::getDevice
2011-02-22 21:43:26 +01:00
------------------
2011-03-29 01:16:20 +02:00
.. cpp:function :: int getDevice()
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
Returns the current device index that was set by `` {gpu::getDevice} `` or initialized by default.
2011-03-23 11:56:20 +01:00
.. index :: gpu::GpuFeature
2011-02-22 21:43:26 +01:00
gpu::GpuFeature
---------------
2011-03-30 14:27:31 +02:00
.. cpp:class :: gpu::GpuFeature
2011-03-29 01:16:20 +02:00
This class provides GPU computing features.
::
2011-02-22 21:43:26 +01:00
enum GpuFeature
{
COMPUTE_10, COMPUTE_11,
COMPUTE_12, COMPUTE_13,
COMPUTE_20, COMPUTE_21,
ATOMICS, NATIVE_DOUBLE
};
2011-02-28 22:26:43 +01:00
2011-02-22 21:43:26 +01:00
2011-03-23 11:56:20 +01:00
.. index :: gpu::DeviceInfo
2011-02-22 21:43:26 +01:00
gpu::DeviceInfo
---------------
2011-03-23 11:56:20 +01:00
.. cpp:class :: gpu::DeviceInfo
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
This class provides functionality for querying the specified GPU properties.
::
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
class CV_EXPORTS DeviceInfo
2011-02-22 21:43:26 +01:00
{
public:
DeviceInfo();
DeviceInfo(int device_id);
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
string name() const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
int majorVersion() const;
int minorVersion() const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
int multiProcessorCount() const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
size_t freeMemory() const;
size_t totalMemory() const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
bool supports(GpuFeature feature) const;
bool isCompatible() const;
};
2011-02-28 22:26:43 +01:00
2011-02-22 21:43:26 +01:00
.. index :: gpu::DeviceInfo::DeviceInfo
2011-03-29 01:16:20 +02:00
.. Comment: two lines below look like a bug
2011-02-22 21:43:26 +01:00
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::DeviceInfo
2011-04-01 00:07:17 +02:00
-------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: gpu::DeviceInfo::DeviceInfo()
2011-02-22 21:43:26 +01:00
2011-03-23 11:56:20 +01:00
.. cpp:function :: gpu::DeviceInfo::DeviceInfo(int device_id)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
Constructs the `` DeviceInfo `` object for the specified device. If `` device_id `` parameter is missed, it constructs an object for the current device.
2011-03-23 11:56:20 +01:00
2011-03-29 01:16:20 +02:00
:param device_id: System index of the GPU device starting with 0.
2011-03-23 11:56:20 +01:00
2011-02-22 21:43:26 +01:00
.. index :: gpu::DeviceInfo::name
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::name
2011-02-22 21:43:26 +01:00
-------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: string gpu::DeviceInfo::name()
2011-02-22 21:43:26 +01:00
Returns the device name.
.. index :: gpu::DeviceInfo::majorVersion
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::majorVersion
2011-02-22 21:43:26 +01:00
---------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: int gpu::DeviceInfo::majorVersion()
2011-02-22 21:43:26 +01:00
Returns the major compute capability version.
.. index :: gpu::DeviceInfo::minorVersion
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::minorVersion
2011-02-22 21:43:26 +01:00
---------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: int gpu::DeviceInfo::minorVersion()
2011-02-22 21:43:26 +01:00
Returns the minor compute capability version.
.. index :: gpu::DeviceInfo::multiProcessorCount
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::multiProcessorCount
2011-02-22 21:43:26 +01:00
----------------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: int gpu::DeviceInfo::multiProcessorCount()
2011-02-22 21:43:26 +01:00
Returns the number of streaming multiprocessors.
.. index :: gpu::DeviceInfo::freeMemory
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::freeMemory
2011-02-22 21:43:26 +01:00
-------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: size_t gpu::DeviceInfo::freeMemory()
2011-02-22 21:43:26 +01:00
Returns the amount of free memory in bytes.
.. index :: gpu::DeviceInfo::totalMemory
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::totalMemory
2011-02-22 21:43:26 +01:00
--------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: size_t gpu::DeviceInfo::totalMemory()
2011-02-22 21:43:26 +01:00
Returns the amount of total memory in bytes.
.. index :: gpu::DeviceInfo::supports
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::supports
2011-02-22 21:43:26 +01:00
-----------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: bool gpu::DeviceInfo::supports(GpuFeature feature)
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
Provides information on GPU feature support. This function returns true if the device has the specified GPU feature. Otherwise, it returns false.
2011-03-23 11:56:20 +01:00
2011-03-30 14:27:31 +02:00
:param feature: Feature to be checked. See :cpp:class:`gpu::GpuFeature`.
2011-02-22 21:43:26 +01:00
.. index :: gpu::DeviceInfo::isCompatible
2011-03-23 11:56:20 +01:00
gpu::DeviceInfo::isCompatible
2011-02-22 21:43:26 +01:00
---------------------------------
2011-03-23 11:56:20 +01:00
.. cpp:function :: bool gpu::DeviceInfo::isCompatible()
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
Checks the GPU module and device compatibility. This function returns `` true `` if the GPU module can be run on the specified device. Otherwise, it returns false.
2011-03-23 11:56:20 +01:00
.. index :: gpu::TargetArchs
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. _gpu :: TargetArchs:
2011-02-22 21:43:26 +01:00
gpu::TargetArchs
----------------
2011-03-28 12:34:44 +02:00
.. cpp:class :: gpu::TargetArchs
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
This class provides a set of static methods to check what NVIDIA* card architecture the GPU module was built for.
2011-02-22 21:43:26 +01:00
The following method checks whether the module was built with the support of the given feature:
2011-04-01 00:07:17 +02:00
.. cpp:function:: static bool gpu::TargetArchs::builtWith(GpuFeature feature)
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
:param feature: Feature to be checked. See :cpp:class: `gpu::GpuFeature` .
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
There is a set of methods to check whether the module contains intermediate (PTX) or binary GPU code for the given architecture(s):
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::has(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasPtx(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasBin(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasEqualOrLessPtx(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasEqualOrGreater(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasEqualOrGreaterPtx(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-29 01:16:20 +02:00
.. cpp:function :: static bool gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor)
2011-02-22 21:43:26 +01:00
2011-03-30 14:27:31 +02:00
:param major: Major compute capability version.
2011-02-22 21:43:26 +01:00
2011-03-30 14:27:31 +02:00
:param minor: Minor compute capability version.
2011-02-22 21:43:26 +01:00
2011-04-01 00:07:17 +02:00
According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute capability can always be compiled to binary code of greater or equal compute capability".
2011-03-23 11:56:20 +01:00
.. index :: gpu::MultiGpuManager
gpu::MultiGpuManager
--------------------
2011-03-28 12:34:44 +02:00
.. cpp:class :: gpu::MultiGpuManager
2011-03-23 11:56:20 +01:00
2011-04-01 00:07:17 +02:00
This class provides functionality for working with many GPUs. ::
2011-03-23 11:56:20 +01:00
class MultiGpuManager
{
public:
MultiGpuManager();
~MultiGpuManager();
// Must be called before any other GPU calls
void init();
// Makes the given GPU active
void gpuOn(int gpu_id);
// Finishes the piece of work on the current GPU
void gpuOff();
static const int BAD_GPU_ID;
};
.. index :: gpu::MultiGpuManager::MultiGpuManager
gpu::MultiGpuManager::MultiGpuManager
----------------------------------------
.. cpp:function :: gpu::MultiGpuManager::MultiGpuManager()
2011-04-01 00:07:17 +02:00
Creates a multi-GPU manager but does not initialize it.
2011-03-23 11:56:20 +01:00
.. index :: gpu::MultiGpuManager::~MultiGpuManager
gpu::MultiGpuManager::~MultiGpuManager
----------------------------------------
.. cpp:function :: gpu::MultiGpuManager::~MultiGpuManager()
2011-04-01 00:07:17 +02:00
Releases a multi-GPU manager.
2011-03-23 11:56:20 +01:00
.. index :: gpu::MultiGpuManager::init
gpu::MultiGpuManager::init
----------------------------------------
.. cpp:function :: void gpu::MultiGpuManager::init()
2011-04-01 00:07:17 +02:00
Initializes a multi-GPU manager.
2011-03-23 11:56:20 +01:00
.. index :: gpu::MultiGpuManager::gpuOn
gpu::MultiGpuManager::gpuOn
----------------------------------------
.. cpp:function :: void gpu::MultiGpuManager::gpuOn(int gpu_id)
2011-04-01 00:07:17 +02:00
Activates the given GPU.
2011-03-23 11:56:20 +01:00
2011-04-01 00:07:17 +02:00
:param gpu_id: System index of the GPU device starting with 0.
2011-03-23 11:56:20 +01:00
.. index :: gpu::MultiGpuManager::gpuOff
gpu::MultiGpuManager::gpuOff
----------------------------------------
.. cpp:function :: void gpu::MultiGpuManager::gpuOff()
2011-04-01 00:07:17 +02:00
Finishes a piece of work on the current GPU.
2011-03-29 01:16:20 +02:00