opencv on mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cuda.hpp Source File

cuda.hpp

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
00016 // Third party copyrights are property of their respective owners.
00017 //
00018 // Redistribution and use in source and binary forms, with or without modification,
00019 // are permitted provided that the following conditions are met:
00020 //
00021 //   * Redistribution's of source code must retain the above copyright notice,
00022 //     this list of conditions and the following disclaimer.
00023 //
00024 //   * Redistribution's in binary form must reproduce the above copyright notice,
00025 //     this list of conditions and the following disclaimer in the documentation
00026 //     and/or other materials provided with the distribution.
00027 //
00028 //   * The name of the copyright holders may not be used to endorse or promote products
00029 //     derived from this software without specific prior written permission.
00030 //
00031 // This software is provided by the copyright holders and contributors "as is" and
00032 // any express or implied warranties, including, but not limited to, the implied
00033 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00034 // In no event shall the Intel Corporation or contributors be liable for any direct,
00035 // indirect, incidental, special, exemplary, or consequential damages
00036 // (including, but not limited to, procurement of substitute goods or services;
00037 // loss of use, data, or profits; or business interruption) however caused
00038 // and on any theory of liability, whether in contract, strict liability,
00039 // or tort (including negligence or otherwise) arising in any way out of
00040 // the use of this software, even if advised of the possibility of such damage.
00041 //
00042 //M*/
00043 
00044 #ifndef __OPENCV_CORE_CUDA_HPP__
00045 #define __OPENCV_CORE_CUDA_HPP__
00046 
00047 #ifndef __cplusplus
00048 #  error cuda.hpp header must be compiled as C++
00049 #endif
00050 
00051 #include "opencv2/core.hpp"
00052 #include "opencv2/core/cuda_types.hpp "
00053 
00054 /**
00055   @defgroup cuda CUDA-accelerated Computer Vision
00056   @{
00057     @defgroup cudacore Core part
00058     @{
00059       @defgroup cudacore_init Initalization and Information
00060       @defgroup cudacore_struct Data Structures
00061     @}
00062   @}
00063  */
00064 
00065 namespace cv { namespace cuda {
00066 
00067 //! @addtogroup cudacore_struct
00068 //! @{
00069 
00070 //===================================================================================
00071 // GpuMat
00072 //===================================================================================
00073 
00074 /** @brief Base storage class for GPU memory with reference counting.
00075 
00076 Its interface matches the Mat interface with the following limitations:
00077 
00078 -   no arbitrary dimensions support (only 2D)
00079 -   no functions that return references to their data (because references on GPU are not valid for
00080     CPU)
00081 -   no expression templates technique support
00082 
00083 Beware that the latter limitation may lead to overloaded matrix operators that cause memory
00084 allocations. The GpuMat class is convertible to cuda::PtrStepSz and cuda::PtrStep so it can be
00085 passed directly to the kernel.
00086 
00087 @note In contrast with Mat, in most cases GpuMat::isContinuous() == false . This means that rows are
00088 aligned to a size depending on the hardware. Single-row GpuMat is always a continuous matrix.
00089 
00090 @note You are not recommended to leave static or global GpuMat variables allocated, that is, to rely
00091 on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory
00092 release function returns error if the CUDA context has been destroyed before.
00093 
00094 @sa Mat
00095  */
00096 class CV_EXPORTS GpuMat
00097 {
00098 public:
00099     class CV_EXPORTS Allocator
00100     {
00101     public:
00102         virtual ~Allocator() {}
00103 
00104         // allocator must fill data, step and refcount fields
00105         virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0;
00106         virtual void free(GpuMat* mat) = 0;
00107     };
00108 
00109     //! default allocator
00110     static Allocator* defaultAllocator();
00111     static void setDefaultAllocator(Allocator* allocator);
00112 
00113     //! default constructor
00114     explicit GpuMat(Allocator* allocator = defaultAllocator());
00115 
00116     //! constructs GpuMat of the specified size and type
00117     GpuMat(int rows, int cols, int type, Allocator* allocator = defaultAllocator());
00118     GpuMat(Size size, int type, Allocator* allocator = defaultAllocator());
00119 
00120     //! constucts GpuMat and fills it with the specified value _s
00121     GpuMat(int rows, int cols, int type, Scalar  s, Allocator* allocator = defaultAllocator());
00122     GpuMat(Size size, int type, Scalar  s, Allocator* allocator = defaultAllocator());
00123 
00124     //! copy constructor
00125     GpuMat(const GpuMat& m);
00126 
00127     //! constructor for GpuMat headers pointing to user-allocated data
00128     GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
00129     GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
00130 
00131     //! creates a GpuMat header for a part of the bigger matrix
00132     GpuMat(const GpuMat& m, Range rowRange, Range colRange);
00133     GpuMat(const GpuMat& m, Rect roi);
00134 
00135     //! builds GpuMat from host memory (Blocking call)
00136     explicit GpuMat(InputArray arr, Allocator* allocator = defaultAllocator());
00137 
00138     //! destructor - calls release()
00139     ~GpuMat();
00140 
00141     //! assignment operators
00142     GpuMat& operator =(const GpuMat& m);
00143 
00144     //! allocates new GpuMat data unless the GpuMat already has specified size and type
00145     void create(int rows, int cols, int type);
00146     void create(Size size, int type);
00147 
00148     //! decreases reference counter, deallocate the data when reference counter reaches 0
00149     void release();
00150 
00151     //! swaps with other smart pointer
00152     void swap(GpuMat& mat);
00153 
00154     //! pefroms upload data to GpuMat (Blocking call)
00155     void upload(InputArray arr);
00156 
00157     //! pefroms upload data to GpuMat (Non-Blocking call)
00158     void upload(InputArray arr, Stream& stream);
00159 
00160     //! pefroms download data from device to host memory (Blocking call)
00161     void download(OutputArray dst) const;
00162 
00163     //! pefroms download data from device to host memory (Non-Blocking call)
00164     void download(OutputArray dst, Stream& stream) const;
00165 
00166     //! returns deep copy of the GpuMat, i.e. the data is copied
00167     GpuMat clone() const;
00168 
00169     //! copies the GpuMat content to device memory (Blocking call)
00170     void copyTo(OutputArray dst) const;
00171 
00172     //! copies the GpuMat content to device memory (Non-Blocking call)
00173     void copyTo(OutputArray dst, Stream& stream) const;
00174 
00175     //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Blocking call)
00176     void copyTo(OutputArray dst, InputArray mask) const;
00177 
00178     //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Non-Blocking call)
00179     void copyTo(OutputArray dst, InputArray mask, Stream& stream) const;
00180 
00181     //! sets some of the GpuMat elements to s (Blocking call)
00182     GpuMat& setTo(Scalar  s);
00183 
00184     //! sets some of the GpuMat elements to s (Non-Blocking call)
00185     GpuMat& setTo(Scalar  s, Stream& stream);
00186 
00187     //! sets some of the GpuMat elements to s, according to the mask (Blocking call)
00188     GpuMat& setTo(Scalar  s, InputArray mask);
00189 
00190     //! sets some of the GpuMat elements to s, according to the mask (Non-Blocking call)
00191     GpuMat& setTo(Scalar  s, InputArray mask, Stream& stream);
00192 
00193     //! converts GpuMat to another datatype (Blocking call)
00194     void convertTo(OutputArray dst, int rtype) const;
00195 
00196     //! converts GpuMat to another datatype (Non-Blocking call)
00197     void convertTo(OutputArray dst, int rtype, Stream& stream) const;
00198 
00199     //! converts GpuMat to another datatype with scaling (Blocking call)
00200     void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const;
00201 
00202     //! converts GpuMat to another datatype with scaling (Non-Blocking call)
00203     void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const;
00204 
00205     //! converts GpuMat to another datatype with scaling (Non-Blocking call)
00206     void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const;
00207 
00208     void assignTo(GpuMat& m, int type=-1) const;
00209 
00210     //! returns pointer to y-th row
00211     uchar* ptr(int y = 0);
00212     const uchar* ptr(int y = 0) const;
00213 
00214     //! template version of the above method
00215     template<typename _Tp> _Tp* ptr(int y = 0);
00216     template<typename _Tp> const _Tp* ptr(int y = 0) const;
00217 
00218     template <typename _Tp> operator PtrStepSz<_Tp>() const;
00219     template <typename _Tp> operator PtrStep<_Tp>() const;
00220 
00221     //! returns a new GpuMat header for the specified row
00222     GpuMat row(int y) const;
00223 
00224     //! returns a new GpuMat header for the specified column
00225     GpuMat col(int x) const;
00226 
00227     //! ... for the specified row span
00228     GpuMat rowRange(int startrow, int endrow) const;
00229     GpuMat rowRange(Range r) const;
00230 
00231     //! ... for the specified column span
00232     GpuMat colRange(int startcol, int endcol) const;
00233     GpuMat colRange(Range r) const;
00234 
00235     //! extracts a rectangular sub-GpuMat (this is a generalized form of row, rowRange etc.)
00236     GpuMat operator ()(Range rowRange, Range colRange) const;
00237     GpuMat operator ()(Rect roi) const;
00238 
00239     //! creates alternative GpuMat header for the same data, with different
00240     //! number of channels and/or different number of rows
00241     GpuMat reshape(int cn, int rows = 0) const;
00242 
00243     //! locates GpuMat header within a parent GpuMat
00244     void locateROI(Size& wholeSize, Point& ofs) const;
00245 
00246     //! moves/resizes the current GpuMat ROI inside the parent GpuMat
00247     GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright);
00248 
00249     //! returns true iff the GpuMat data is continuous
00250     //! (i.e. when there are no gaps between successive rows)
00251     bool isContinuous() const;
00252 
00253     //! returns element size in bytes
00254     size_t elemSize() const;
00255 
00256     //! returns the size of element channel in bytes
00257     size_t elemSize1() const;
00258 
00259     //! returns element type
00260     int type() const;
00261 
00262     //! returns element type
00263     int depth() const;
00264 
00265     //! returns number of channels
00266     int channels() const;
00267 
00268     //! returns step/elemSize1()
00269     size_t step1() const;
00270 
00271     //! returns GpuMat size : width == number of columns, height == number of rows
00272     Size size() const;
00273 
00274     //! returns true if GpuMat data is NULL
00275     bool empty() const;
00276 
00277     /*! includes several bit-fields:
00278     - the magic signature
00279     - continuity flag
00280     - depth
00281     - number of channels
00282     */
00283     int flags ;
00284 
00285     //! the number of rows and columns
00286     int rows, cols;
00287 
00288     //! a distance between successive rows in bytes; includes the gap if any
00289     size_t step;
00290 
00291     //! pointer to the data
00292     uchar* data;
00293 
00294     //! pointer to the reference counter;
00295     //! when GpuMat points to user-allocated data, the pointer is NULL
00296     int* refcount;
00297 
00298     //! helper fields used in locateROI and adjustROI
00299     uchar* datastart;
00300     const uchar* dataend;
00301 
00302     //! allocator
00303     Allocator* allocator;
00304 };
00305 
00306 /** @brief Creates a continuous matrix.
00307 
00308 @param rows Row count.
00309 @param cols Column count.
00310 @param type Type of the matrix.
00311 @param arr Destination matrix. This parameter changes only if it has a proper type and area (
00312 \f$\texttt{rows} \times \texttt{cols}\f$ ).
00313 
00314 Matrix is called continuous if its elements are stored continuously, that is, without gaps at the
00315 end of each row.
00316  */
00317 CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr);
00318 
00319 /** @brief Ensures that the size of a matrix is big enough and the matrix has a proper type.
00320 
00321 @param rows Minimum desired number of rows.
00322 @param cols Minimum desired number of columns.
00323 @param type Desired matrix type.
00324 @param arr Destination matrix.
00325 
00326 The function does not reallocate memory if the matrix has proper attributes already.
00327  */
00328 CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr);
00329 
00330 //! BufferPool management (must be called before Stream creation)
00331 CV_EXPORTS void setBufferPoolUsage(bool on);
00332 CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount);
00333 
00334 //===================================================================================
00335 // HostMem
00336 //===================================================================================
00337 
00338 /** @brief Class with reference counting wrapping special memory type allocation functions from CUDA.
00339 
00340 Its interface is also Mat-like but with additional memory type parameters.
00341 
00342 -   **PAGE_LOCKED** sets a page locked memory type used commonly for fast and asynchronous
00343     uploading/downloading data from/to GPU.
00344 -   **SHARED** specifies a zero copy memory allocation that enables mapping the host memory to GPU
00345     address space, if supported.
00346 -   **WRITE_COMBINED** sets the write combined buffer that is not cached by CPU. Such buffers are
00347     used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache
00348     utilization.
00349 
00350 @note Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2
00351 Pinned Memory APIs* document or *CUDA C Programming Guide*.
00352  */
00353 class CV_EXPORTS HostMem
00354 {
00355 public:
00356     enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 };
00357 
00358     static MatAllocator* getAllocator(AllocType alloc_type = PAGE_LOCKED);
00359 
00360     explicit HostMem(AllocType alloc_type = PAGE_LOCKED);
00361 
00362     HostMem(const HostMem& m);
00363 
00364     HostMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED);
00365     HostMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED);
00366 
00367     //! creates from host memory with coping data
00368     explicit HostMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED);
00369 
00370     ~HostMem();
00371 
00372     HostMem& operator =(const HostMem& m);
00373 
00374     //! swaps with other smart pointer
00375     void swap(HostMem& b);
00376 
00377     //! returns deep copy of the matrix, i.e. the data is copied
00378     HostMem clone() const;
00379 
00380     //! allocates new matrix data unless the matrix already has specified size and type.
00381     void create(int rows, int cols, int type);
00382     void create(Size size, int type);
00383 
00384     //! creates alternative HostMem header for the same data, with different
00385     //! number of channels and/or different number of rows
00386     HostMem reshape(int cn, int rows = 0) const;
00387 
00388     //! decrements reference counter and released memory if needed.
00389     void release();
00390 
00391     //! returns matrix header with disabled reference counting for HostMem data.
00392     Mat createMatHeader() const;
00393 
00394     /** @brief Maps CPU memory to GPU address space and creates the cuda::GpuMat header without reference counting
00395     for it.
00396 
00397     This can be done only if memory was allocated with the SHARED flag and if it is supported by the
00398     hardware. Laptops often share video and CPU memory, so address spaces can be mapped, which
00399     eliminates an extra copy.
00400      */
00401     GpuMat createGpuMatHeader() const;
00402 
00403     // Please see cv::Mat for descriptions
00404     bool isContinuous() const;
00405     size_t elemSize() const;
00406     size_t elemSize1() const;
00407     int type() const;
00408     int depth() const;
00409     int channels() const;
00410     size_t step1() const;
00411     Size size() const;
00412     bool empty() const;
00413 
00414     // Please see cv::Mat for descriptions
00415     int flags;
00416     int rows, cols;
00417     size_t step;
00418 
00419     uchar* data;
00420     int* refcount;
00421 
00422     uchar* datastart;
00423     const uchar* dataend;
00424 
00425     AllocType alloc_type;
00426 };
00427 
00428 /** @brief Page-locks the memory of matrix and maps it for the device(s).
00429 
00430 @param m Input matrix.
00431  */
00432 CV_EXPORTS void registerPageLocked(Mat& m);
00433 
00434 /** @brief Unmaps the memory of matrix and makes it pageable again.
00435 
00436 @param m Input matrix.
00437  */
00438 CV_EXPORTS void unregisterPageLocked(Mat& m);
00439 
00440 //===================================================================================
00441 // Stream
00442 //===================================================================================
00443 
00444 /** @brief This class encapsulates a queue of asynchronous calls.
00445 
00446 @note Currently, you may face problems if an operation is enqueued twice with different data. Some
00447 functions use the constant GPU memory, and next call may update the memory before the previous one
00448 has been finished. But calling different operations asynchronously is safe because each operation
00449 has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are
00450 also safe. :
00451  */
00452 class CV_EXPORTS Stream
00453 {
00454     typedef void (Stream::*bool_type)() const;
00455     void this_type_does_not_support_comparisons() const {}
00456 
00457 public:
00458     typedef void (*StreamCallback)(int status, void* userData);
00459 
00460     //! creates a new asynchronous stream
00461     Stream();
00462 
00463     /** @brief Returns true if the current stream queue is finished. Otherwise, it returns false.
00464     */
00465     bool queryIfComplete() const;
00466 
00467     /** @brief Blocks the current CPU thread until all operations in the stream are complete.
00468     */
00469     void waitForCompletion();
00470 
00471     /** @brief Makes a compute stream wait on an event.
00472     */
00473     void waitEvent(const Event& event);
00474 
00475     /** @brief Adds a callback to be called on the host after all currently enqueued items in the stream have
00476     completed.
00477 
00478     @note Callbacks must not make any CUDA API calls. Callbacks must not perform any synchronization
00479     that may depend on outstanding device work or other callbacks that are not mandated to run earlier.
00480     Callbacks without a mandated order (in independent streams) execute in undefined order and may be
00481     serialized.
00482      */
00483     void enqueueHostCallback(StreamCallback callback, void* userData);
00484 
00485     //! return Stream object for default CUDA stream
00486     static Stream& Null();
00487 
00488     //! returns true if stream object is not default (!= 0)
00489     operator bool_type() const;
00490 
00491     class Impl;
00492 
00493 private:
00494     Ptr<Impl>  impl_;
00495     Stream(const Ptr<Impl> & impl);
00496 
00497     friend struct StreamAccessor;
00498     friend class BufferPool;
00499     friend class DefaultDeviceInitializer;
00500 };
00501 
00502 class CV_EXPORTS Event
00503 {
00504 public:
00505     enum CreateFlags
00506     {
00507         DEFAULT        = 0x00,  /**< Default event flag */
00508         BLOCKING_SYNC  = 0x01,  /**< Event uses blocking synchronization */
00509         DISABLE_TIMING = 0x02,  /**< Event will not record timing data */
00510         INTERPROCESS   = 0x04   /**< Event is suitable for interprocess use. DisableTiming must be set */
00511     };
00512 
00513     explicit Event(CreateFlags flags = DEFAULT);
00514 
00515     //! records an event
00516     void record(Stream& stream = Stream::Null());
00517 
00518     //! queries an event's status
00519     bool queryIfComplete() const;
00520 
00521     //! waits for an event to complete
00522     void waitForCompletion();
00523 
00524     //! computes the elapsed time between events
00525     static float elapsedTime(const Event& start, const Event& end);
00526 
00527     class Impl;
00528 
00529 private:
00530     Ptr<Impl>  impl_;
00531     Event(const Ptr<Impl> & impl);
00532 
00533     friend struct EventAccessor;
00534 };
00535 
00536 //! @} cudacore_struct
00537 
00538 //===================================================================================
00539 // Initialization & Info
00540 //===================================================================================
00541 
00542 //! @addtogroup cudacore_init
00543 //! @{
00544 
00545 /** @brief Returns the number of installed CUDA-enabled devices.
00546 
00547 Use this function before any other CUDA functions calls. If OpenCV is compiled without CUDA support,
00548 this function returns 0.
00549  */
00550 CV_EXPORTS int getCudaEnabledDeviceCount();
00551 
00552 /** @brief Sets a device and initializes it for the current thread.
00553 
00554 @param device System index of a CUDA device starting with 0.
00555 
00556 If the call of this function is omitted, a default device is initialized at the fist CUDA usage.
00557  */
00558 CV_EXPORTS void setDevice(int device);
00559 
00560 /** @brief Returns the current device index set by cuda::setDevice or initialized by default.
00561  */
00562 CV_EXPORTS int getDevice();
00563 
00564 /** @brief Explicitly destroys and cleans up all resources associated with the current device in the current
00565 process.
00566 
00567 Any subsequent API call to this device will reinitialize the device.
00568  */
00569 CV_EXPORTS void resetDevice();
00570 
00571 /** @brief Enumeration providing CUDA computing features.
00572  */
00573 enum FeatureSet
00574 {
00575     FEATURE_SET_COMPUTE_10 = 10,
00576     FEATURE_SET_COMPUTE_11 = 11,
00577     FEATURE_SET_COMPUTE_12 = 12,
00578     FEATURE_SET_COMPUTE_13 = 13,
00579     FEATURE_SET_COMPUTE_20 = 20,
00580     FEATURE_SET_COMPUTE_21 = 21,
00581     FEATURE_SET_COMPUTE_30 = 30,
00582     FEATURE_SET_COMPUTE_32 = 32,
00583     FEATURE_SET_COMPUTE_35 = 35,
00584     FEATURE_SET_COMPUTE_50 = 50,
00585 
00586     GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11,
00587     SHARED_ATOMICS = FEATURE_SET_COMPUTE_12,
00588     NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13,
00589     WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30,
00590     DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35
00591 };
00592 
00593 //! checks whether current device supports the given feature
00594 CV_EXPORTS bool deviceSupports(FeatureSet feature_set);
00595 
00596 /** @brief Class providing a set of static methods to check what NVIDIA\* card architecture the CUDA module was
00597 built for.
00598 
00599 According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute
00600 capability can always be compiled to binary code of greater or equal compute capability".
00601  */
00602 class CV_EXPORTS TargetArchs
00603 {
00604 public:
00605     /** @brief The following method checks whether the module was built with the support of the given feature:
00606 
00607     @param feature_set Features to be checked. See :ocvcuda::FeatureSet.
00608      */
00609     static bool builtWith(FeatureSet feature_set);
00610 
00611     /** @brief There is a set of methods to check whether the module contains intermediate (PTX) or binary CUDA
00612     code for the given architecture(s):
00613 
00614     @param major Major compute capability version.
00615     @param minor Minor compute capability version.
00616      */
00617     static bool has(int major, int minor);
00618     static bool hasPtx(int major, int minor);
00619     static bool hasBin(int major, int minor);
00620 
00621     static bool hasEqualOrLessPtx(int major, int minor);
00622     static bool hasEqualOrGreater(int major, int minor);
00623     static bool hasEqualOrGreaterPtx(int major, int minor);
00624     static bool hasEqualOrGreaterBin(int major, int minor);
00625 };
00626 
00627 /** @brief Class providing functionality for querying the specified GPU properties.
00628  */
00629 class CV_EXPORTS DeviceInfo
00630 {
00631 public:
00632     //! creates DeviceInfo object for the current GPU
00633     DeviceInfo();
00634 
00635     /** @brief The constructors.
00636 
00637     @param device_id System index of the CUDA device starting with 0.
00638 
00639     Constructs the DeviceInfo object for the specified device. If device_id parameter is missed, it
00640     constructs an object for the current device.
00641      */
00642     DeviceInfo(int device_id);
00643 
00644     /** @brief Returns system index of the CUDA device starting with 0.
00645     */
00646     int deviceID() const;
00647 
00648     //! ASCII string identifying device
00649     const char* name() const;
00650 
00651     //! global memory available on device in bytes
00652     size_t totalGlobalMem() const;
00653 
00654     //! shared memory available per block in bytes
00655     size_t sharedMemPerBlock() const;
00656 
00657     //! 32-bit registers available per block
00658     int regsPerBlock() const;
00659 
00660     //! warp size in threads
00661     int warpSize() const;
00662 
00663     //! maximum pitch in bytes allowed by memory copies
00664     size_t memPitch() const;
00665 
00666     //! maximum number of threads per block
00667     int maxThreadsPerBlock() const;
00668 
00669     //! maximum size of each dimension of a block
00670     Vec3i maxThreadsDim() const;
00671 
00672     //! maximum size of each dimension of a grid
00673     Vec3i maxGridSize() const;
00674 
00675     //! clock frequency in kilohertz
00676     int clockRate() const;
00677 
00678     //! constant memory available on device in bytes
00679     size_t totalConstMem() const;
00680 
00681     //! major compute capability
00682     int majorVersion() const;
00683 
00684     //! minor compute capability
00685     int minorVersion() const;
00686 
00687     //! alignment requirement for textures
00688     size_t textureAlignment() const;
00689 
00690     //! pitch alignment requirement for texture references bound to pitched memory
00691     size_t texturePitchAlignment() const;
00692 
00693     //! number of multiprocessors on device
00694     int multiProcessorCount() const;
00695 
00696     //! specified whether there is a run time limit on kernels
00697     bool kernelExecTimeoutEnabled() const;
00698 
00699     //! device is integrated as opposed to discrete
00700     bool integrated() const;
00701 
00702     //! device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer
00703     bool canMapHostMemory() const;
00704 
00705     enum ComputeMode 
00706     {
00707         ComputeModeDefault,         /**< default compute mode (Multiple threads can use cudaSetDevice with this device) */
00708         ComputeModeExclusive,       /**< compute-exclusive-thread mode (Only one thread in one process will be able to use cudaSetDevice with this device) */
00709         ComputeModeProhibited,      /**< compute-prohibited mode (No threads can use cudaSetDevice with this device) */
00710         ComputeModeExclusiveProcess /**< compute-exclusive-process mode (Many threads in one process will be able to use cudaSetDevice with this device) */
00711     };
00712 
00713     //! compute mode
00714     ComputeMode computeMode() const;
00715 
00716     //! maximum 1D texture size
00717     int maxTexture1D() const;
00718 
00719     //! maximum 1D mipmapped texture size
00720     int maxTexture1DMipmap() const;
00721 
00722     //! maximum size for 1D textures bound to linear memory
00723     int maxTexture1DLinear() const;
00724 
00725     //! maximum 2D texture dimensions
00726     Vec2i maxTexture2D() const;
00727 
00728     //! maximum 2D mipmapped texture dimensions
00729     Vec2i maxTexture2DMipmap() const;
00730 
00731     //! maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory
00732     Vec3i maxTexture2DLinear() const;
00733 
00734     //! maximum 2D texture dimensions if texture gather operations have to be performed
00735     Vec2i maxTexture2DGather() const;
00736 
00737     //! maximum 3D texture dimensions
00738     Vec3i maxTexture3D() const;
00739 
00740     //! maximum Cubemap texture dimensions
00741     int maxTextureCubemap() const;
00742 
00743     //! maximum 1D layered texture dimensions
00744     Vec2i maxTexture1DLayered() const;
00745 
00746     //! maximum 2D layered texture dimensions
00747     Vec3i maxTexture2DLayered() const;
00748 
00749     //! maximum Cubemap layered texture dimensions
00750     Vec2i maxTextureCubemapLayered() const;
00751 
00752     //! maximum 1D surface size
00753     int maxSurface1D() const;
00754 
00755     //! maximum 2D surface dimensions
00756     Vec2i maxSurface2D() const;
00757 
00758     //! maximum 3D surface dimensions
00759     Vec3i maxSurface3D() const;
00760 
00761     //! maximum 1D layered surface dimensions
00762     Vec2i maxSurface1DLayered() const;
00763 
00764     //! maximum 2D layered surface dimensions
00765     Vec3i maxSurface2DLayered() const;
00766 
00767     //! maximum Cubemap surface dimensions
00768     int maxSurfaceCubemap() const;
00769 
00770     //! maximum Cubemap layered surface dimensions
00771     Vec2i maxSurfaceCubemapLayered() const;
00772 
00773     //! alignment requirements for surfaces
00774     size_t surfaceAlignment() const;
00775 
00776     //! device can possibly execute multiple kernels concurrently
00777     bool concurrentKernels() const;
00778 
00779     //! device has ECC support enabled
00780     bool ECCEnabled() const;
00781 
00782     //! PCI bus ID of the device
00783     int pciBusID() const;
00784 
00785     //! PCI device ID of the device
00786     int pciDeviceID() const;
00787 
00788     //! PCI domain ID of the device
00789     int pciDomainID() const;
00790 
00791     //! true if device is a Tesla device using TCC driver, false otherwise
00792     bool tccDriver() const;
00793 
00794     //! number of asynchronous engines
00795     int asyncEngineCount() const;
00796 
00797     //! device shares a unified address space with the host
00798     bool unifiedAddressing() const;
00799 
00800     //! peak memory clock frequency in kilohertz
00801     int memoryClockRate() const;
00802 
00803     //! global memory bus width in bits
00804     int memoryBusWidth() const;
00805 
00806     //! size of L2 cache in bytes
00807     int l2CacheSize() const;
00808 
00809     //! maximum resident threads per multiprocessor
00810     int maxThreadsPerMultiProcessor() const;
00811 
00812     //! gets free and total device memory
00813     void queryMemory(size_t& totalMemory, size_t& freeMemory) const;
00814     size_t freeMemory() const;
00815     size_t totalMemory() const;
00816 
00817     /** @brief Provides information on CUDA feature support.
00818 
00819     @param feature_set Features to be checked. See cuda::FeatureSet.
00820 
00821     This function returns true if the device has the specified CUDA feature. Otherwise, it returns false
00822      */
00823     bool supports(FeatureSet feature_set) const;
00824 
00825     /** @brief Checks the CUDA module and device compatibility.
00826 
00827     This function returns true if the CUDA module can be run on the specified device. Otherwise, it
00828     returns false .
00829      */
00830     bool isCompatible() const;
00831 
00832 private:
00833     int device_id_;
00834 };
00835 
00836 CV_EXPORTS void printCudaDeviceInfo(int device);
00837 CV_EXPORTS void printShortCudaDeviceInfo(int device);
00838 
00839 //! @} cudacore_init
00840 
00841 }} // namespace cv { namespace cuda {
00842 
00843 
00844 #include "opencv2/core/cuda.inl.hpp"
00845 
00846 #endif /* __OPENCV_CORE_CUDA_HPP__ */
00847