gpu_initialization.tex 5.77 KB
Newer Older
1 2 3 4
\section{Initalization and Information}


\cvCppFunc{gpu::getCudaEnabledDeviceCount}
5
Returns number of CUDA-enabled devices installed. It is to be used before any other GPU functions calls. If OpenCV is compiled without GPU support this function returns 0. 
6 7 8 9 10

\cvdefCpp{int getCudaEnabledDeviceCount();}


\cvCppFunc{gpu::setDevice}
11
Sets device and initializes it for the current thread. Call of this function can be omitted, but in this case a default device will be initialized on fist GPU usage.
12 13 14 15 16 17 18 19

\cvdefCpp{void setDevice(int device);}
\begin{description}
\cvarg{device}{index of GPU device in system starting with 0.}
\end{description}


\cvCppFunc{gpu::getDevice}
20
Returns the current device index, which was set by {gpu::getDevice} or initialized by default.
21 22 23 24

\cvdefCpp{int getDevice();}


25
\cvclass{gpu::FeatureSet}\label{cpp.gpu.FeatureSet}
26 27 28
GPU compute features.

\begin{lstlisting}
29
enum FeatureSet
30
{
Anatoly Baksheev's avatar
Anatoly Baksheev committed
31 32 33
    FEATURE_SET_COMPUTE_10, FEATURE_SET_COMPUTE_11,
    FEATURE_SET_COMPUTE_12, FEATURE_SET_COMPUTE_13,
    FEATURE_SET_COMPUTE_20, FEATURE_SET_COMPUTE_21,
Anatoly Baksheev's avatar
Anatoly Baksheev committed
34
    GLOBAL_ATOMICS, NATIVE_DOUBLE
35 36 37 38
};
\end{lstlisting}


39 40
\cvclass{gpu::DeviceInfo}
This class provides functionality for querying the specified GPU properties. 
41

42 43 44 45 46 47
\begin{lstlisting}
class CV_EXPORTS DeviceInfo
{
public:
    DeviceInfo();
    DeviceInfo(int device_id);
48

49
    string name() const;
50

Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
51 52
    int majorVersion() const;
    int minorVersion() const;
53 54

    int multiProcessorCount() const;
55

56 57
    size_t freeMemory() const;
    size_t totalMemory() const;
58

59
    bool supports(FeatureSet feature_set) const;
60 61 62
    bool isCompatible() const;
};
\end{lstlisting}
63

64 65 66 67 68 69

\cvCppFunc{gpu::DeviceInfo::DeviceInfo}
Constructs DeviceInfo object for the specified device. If \texttt{device\_id} parameter is missed it constructs object for the current device.

\cvdefCpp{DeviceInfo::DeviceInfo();\newline
DeviceInfo::DeviceInfo(int device\_id);}
70
\begin{description}
71
\cvarg{device\_id}{Index of the GPU device in system starting with 0.}
72 73 74
\end{description}


75 76 77 78 79 80
\cvCppFunc{gpu::DeviceInfo::name}
Returns the device name.

\cvdefCpp{string DeviceInfo::name();}


Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
81
\cvCppFunc{gpu::DeviceInfo::majorVersion}
82 83
Returns the major compute capability version.

Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
84
\cvdefCpp{int DeviceInfo::majorVersion();}
85 86


Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
87
\cvCppFunc{gpu::DeviceInfo::minorVersion}
88 89
Returns the minor compute capability version.

Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
90
\cvdefCpp{int DeviceInfo::minorVersion();}
91 92 93 94 95 96 97


\cvCppFunc{gpu::DeviceInfo::multiProcessorCount}
Returns the number of streaming multiprocessors.

\cvdefCpp{int DeviceInfo::multiProcessorCount();}

98

99 100 101 102 103 104 105 106 107 108 109 110
\cvCppFunc{gpu::DeviceInfo::freeMemory}
Returns the amount of free memory in bytes.

\cvdefCpp{size\_t DeviceInfo::freeMemory();}


\cvCppFunc{gpu::DeviceInfo::totalMemory}
Returns the amount of total memory in bytes.

\cvdefCpp{size\_t DeviceInfo::totalMemory();}


111
\cvCppFunc{gpu::DeviceInfo::supports}
112 113
Returns true if the device has the given GPU feature, otherwise false.

114
\cvdefCpp{bool DeviceInfo::supports(FeatureSet feature\_set);}
115
\begin{description}
116
\cvarg{feature}{Feature to be checked. See \hyperref[cpp.gpu.FeatureSet]{cv::gpu::FeatureSet}.}
117 118 119
\end{description}


120 121 122 123
\cvCppFunc{gpu::DeviceInfo::isCompatible}
Returns true if the GPU module can be run on the specified device, otherwise false.

\cvdefCpp{bool DeviceInfo::isCompatible();}
124

125

126 127
\cvclass{gpu::TargetArchs}
This class provides functionality (as set of static methods) for checking which NVIDIA card architectures the GPU module was built for.
128

129
\bigskip
130

131
The following method checks whether the module was built with the support of the given feature:
132
\cvdefCpp{static bool builtWith(FeatureSet feature\_set);}
133
\begin{description}
134
\cvarg{feature}{Feature to be checked. See \hyperref[cpp.gpu.FeatureSet]{cv::gpu::FeatureSet}.}
135 136
\end{description}

137
There are a set of methods for checking whether the module contains intermediate (PTX) or binary GPU code for the given architecture(s):
138 139 140 141 142 143 144 145
\cvdefCpp{
static bool has(int major, int minor);\newline
static bool hasPtx(int major, int minor);\newline
static bool hasBin(int major, int minor);\newline
static bool hasEqualOrLessPtx(int major, int minor);\newline
static bool hasEqualOrGreater(int major, int minor);\newline
static bool hasEqualOrGreaterPtx(int major, int minor);\newline
static bool hasEqualOrGreaterBin(int major, int minor);}
Alexey Spizhevoy's avatar
Alexey Spizhevoy committed
146 147 148
\begin{description}
\cvarg{major}{Major compute capability version.}
\cvarg{minor}{Minor compute capability version.}
149 150
\end{description}

151 152
% By default GPU module is no compiled for devices with compute capability equal to 1.0. So if you run

153 154
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". 

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

\cvclass{gpu::MultiGpuManager}
Provides functionality for working with many GPUs.

\begin{lstlisting}
class CV_EXPORTS 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;
};
\end{lstlisting}


\cvCppFunc{gpu::MultiGpuManager::MultiGpuManager}
Creates multi GPU manager, but doesn't initialize it.
\cvdefCpp{MultiGpuManager::MultiGpuManager}


\cvfunc{cv::gpu::MultiGpuManager::\~{}MultiGpuManager}
Releases multi GPU manager.
\cvdefCpp{MultuGpuManager::\~{}multiGpuManager}


\cvCppFunc{gpu::MultiGpuManager::init}
Initializes multi GPU manager.
\cvdefCpp{void MultiGpuManager::init();}


\cvCppFunc{gpu::MultiGpuManager:gpuOn}
Makes the given GPU active.
\cvdefCpp{void MultiGpuManager::gpuOn(int gpu\_id);}
\begin{description}
\cvarg{gpu\_id}{Index of the GPU device in system starting with 0.}
\end{description}


\cvCppFunc{gpu::MultiGpuManager::gpuOff}
Finishes the piece of work on the current GPU.
\cvdefCpp{void MultiGpuManager::gpuOff();}