123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- #ifndef OPENCV_CORE_CUDA_HPP
- #define OPENCV_CORE_CUDA_HPP
- #ifndef __cplusplus
- # error cuda.hpp header must be compiled as C++
- #endif
- #include "opencv2/core.hpp"
- #include "opencv2/core/cuda_types.hpp"
- namespace cv { namespace cuda {
- class CV_EXPORTS GpuMat
- {
- public:
- class CV_EXPORTS Allocator
- {
- public:
- virtual ~Allocator() {}
-
- virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0;
- virtual void free(GpuMat* mat) = 0;
- };
-
- static Allocator* defaultAllocator();
- static void setDefaultAllocator(Allocator* allocator);
-
- explicit GpuMat(Allocator* allocator = defaultAllocator());
-
- GpuMat(int rows, int cols, int type, Allocator* allocator = defaultAllocator());
- GpuMat(Size size, int type, Allocator* allocator = defaultAllocator());
-
- GpuMat(int rows, int cols, int type, Scalar s, Allocator* allocator = defaultAllocator());
- GpuMat(Size size, int type, Scalar s, Allocator* allocator = defaultAllocator());
-
- GpuMat(const GpuMat& m);
-
- GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
- GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
-
- GpuMat(const GpuMat& m, Range rowRange, Range colRange);
- GpuMat(const GpuMat& m, Rect roi);
-
- explicit GpuMat(InputArray arr, Allocator* allocator = defaultAllocator());
-
- ~GpuMat();
-
- GpuMat& operator =(const GpuMat& m);
-
- void create(int rows, int cols, int type);
- void create(Size size, int type);
-
- void release();
-
- void swap(GpuMat& mat);
-
- void upload(InputArray arr);
-
- void upload(InputArray arr, Stream& stream);
-
- void download(OutputArray dst) const;
-
- void download(OutputArray dst, Stream& stream) const;
-
- GpuMat clone() const;
-
- void copyTo(OutputArray dst) const;
-
- void copyTo(OutputArray dst, Stream& stream) const;
-
- void copyTo(OutputArray dst, InputArray mask) const;
-
- void copyTo(OutputArray dst, InputArray mask, Stream& stream) const;
-
- GpuMat& setTo(Scalar s);
-
- GpuMat& setTo(Scalar s, Stream& stream);
-
- GpuMat& setTo(Scalar s, InputArray mask);
-
- GpuMat& setTo(Scalar s, InputArray mask, Stream& stream);
-
- void convertTo(OutputArray dst, int rtype) const;
-
- void convertTo(OutputArray dst, int rtype, Stream& stream) const;
-
- void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const;
-
- void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const;
-
- void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const;
- void assignTo(GpuMat& m, int type=-1) const;
-
- uchar* ptr(int y = 0);
- const uchar* ptr(int y = 0) const;
-
- template<typename _Tp> _Tp* ptr(int y = 0);
- template<typename _Tp> const _Tp* ptr(int y = 0) const;
- template <typename _Tp> operator PtrStepSz<_Tp>() const;
- template <typename _Tp> operator PtrStep<_Tp>() const;
-
- GpuMat row(int y) const;
-
- GpuMat col(int x) const;
-
- GpuMat rowRange(int startrow, int endrow) const;
- GpuMat rowRange(Range r) const;
-
- GpuMat colRange(int startcol, int endcol) const;
- GpuMat colRange(Range r) const;
-
- GpuMat operator ()(Range rowRange, Range colRange) const;
- GpuMat operator ()(Rect roi) const;
-
-
- GpuMat reshape(int cn, int rows = 0) const;
-
- void locateROI(Size& wholeSize, Point& ofs) const;
-
- GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright);
-
-
- bool isContinuous() const;
-
- size_t elemSize() const;
-
- size_t elemSize1() const;
-
- int type() const;
-
- int depth() const;
-
- int channels() const;
-
- size_t step1() const;
-
- Size size() const;
-
- bool empty() const;
-
- int flags;
-
- int rows, cols;
-
- size_t step;
-
- uchar* data;
-
-
- int* refcount;
-
- uchar* datastart;
- const uchar* dataend;
-
- Allocator* allocator;
- };
- CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr);
- CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr);
- class CV_EXPORTS BufferPool
- {
- public:
-
- explicit BufferPool(Stream& stream);
-
- GpuMat getBuffer(int rows, int cols, int type);
-
- GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
-
- Ptr<GpuMat::Allocator> getAllocator() const { return allocator_; }
- private:
- Ptr<GpuMat::Allocator> allocator_;
- };
- CV_EXPORTS void setBufferPoolUsage(bool on);
- CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount);
- class CV_EXPORTS HostMem
- {
- public:
- enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 };
- static MatAllocator* getAllocator(AllocType alloc_type = PAGE_LOCKED);
- explicit HostMem(AllocType alloc_type = PAGE_LOCKED);
- HostMem(const HostMem& m);
- HostMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED);
- HostMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED);
-
- explicit HostMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED);
- ~HostMem();
- HostMem& operator =(const HostMem& m);
-
- void swap(HostMem& b);
-
- HostMem clone() const;
-
- void create(int rows, int cols, int type);
- void create(Size size, int type);
-
-
- HostMem reshape(int cn, int rows = 0) const;
-
- void release();
-
- Mat createMatHeader() const;
-
- GpuMat createGpuMatHeader() const;
-
- bool isContinuous() const;
- size_t elemSize() const;
- size_t elemSize1() const;
- int type() const;
- int depth() const;
- int channels() const;
- size_t step1() const;
- Size size() const;
- bool empty() const;
-
- int flags;
- int rows, cols;
- size_t step;
- uchar* data;
- int* refcount;
- uchar* datastart;
- const uchar* dataend;
- AllocType alloc_type;
- };
- CV_EXPORTS void registerPageLocked(Mat& m);
- CV_EXPORTS void unregisterPageLocked(Mat& m);
- class CV_EXPORTS Stream
- {
- typedef void (Stream::*bool_type)() const;
- void this_type_does_not_support_comparisons() const {}
- public:
- typedef void (*StreamCallback)(int status, void* userData);
-
- Stream();
-
- Stream(const Ptr<GpuMat::Allocator>& allocator);
-
- bool queryIfComplete() const;
-
- void waitForCompletion();
-
- void waitEvent(const Event& event);
-
- void enqueueHostCallback(StreamCallback callback, void* userData);
-
- static Stream& Null();
-
- operator bool_type() const;
- class Impl;
- private:
- Ptr<Impl> impl_;
- Stream(const Ptr<Impl>& impl);
- friend struct StreamAccessor;
- friend class BufferPool;
- friend class DefaultDeviceInitializer;
- };
- class CV_EXPORTS Event
- {
- public:
- enum CreateFlags
- {
- DEFAULT = 0x00,
- BLOCKING_SYNC = 0x01,
- DISABLE_TIMING = 0x02,
- INTERPROCESS = 0x04
- };
- explicit Event(CreateFlags flags = DEFAULT);
-
- void record(Stream& stream = Stream::Null());
-
- bool queryIfComplete() const;
-
- void waitForCompletion();
-
- static float elapsedTime(const Event& start, const Event& end);
- class Impl;
- private:
- Ptr<Impl> impl_;
- Event(const Ptr<Impl>& impl);
- friend struct EventAccessor;
- };
- CV_EXPORTS int getCudaEnabledDeviceCount();
- CV_EXPORTS void setDevice(int device);
- CV_EXPORTS int getDevice();
- CV_EXPORTS void resetDevice();
- enum FeatureSet
- {
- FEATURE_SET_COMPUTE_10 = 10,
- FEATURE_SET_COMPUTE_11 = 11,
- FEATURE_SET_COMPUTE_12 = 12,
- FEATURE_SET_COMPUTE_13 = 13,
- FEATURE_SET_COMPUTE_20 = 20,
- FEATURE_SET_COMPUTE_21 = 21,
- FEATURE_SET_COMPUTE_30 = 30,
- FEATURE_SET_COMPUTE_32 = 32,
- FEATURE_SET_COMPUTE_35 = 35,
- FEATURE_SET_COMPUTE_50 = 50,
- GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11,
- SHARED_ATOMICS = FEATURE_SET_COMPUTE_12,
- NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13,
- WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30,
- DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35
- };
- CV_EXPORTS bool deviceSupports(FeatureSet feature_set);
- class CV_EXPORTS TargetArchs
- {
- public:
-
- static bool builtWith(FeatureSet feature_set);
-
- static bool has(int major, int minor);
- static bool hasPtx(int major, int minor);
- static bool hasBin(int major, int minor);
- static bool hasEqualOrLessPtx(int major, int minor);
- static bool hasEqualOrGreater(int major, int minor);
- static bool hasEqualOrGreaterPtx(int major, int minor);
- static bool hasEqualOrGreaterBin(int major, int minor);
- };
- class CV_EXPORTS DeviceInfo
- {
- public:
-
- DeviceInfo();
-
- DeviceInfo(int device_id);
-
- int deviceID() const;
-
- const char* name() const;
-
- size_t totalGlobalMem() const;
-
- size_t sharedMemPerBlock() const;
-
- int regsPerBlock() const;
-
- int warpSize() const;
-
- size_t memPitch() const;
-
- int maxThreadsPerBlock() const;
-
- Vec3i maxThreadsDim() const;
-
- Vec3i maxGridSize() const;
-
- int clockRate() const;
-
- size_t totalConstMem() const;
-
- int majorVersion() const;
-
- int minorVersion() const;
-
- size_t textureAlignment() const;
-
- size_t texturePitchAlignment() const;
-
- int multiProcessorCount() const;
-
- bool kernelExecTimeoutEnabled() const;
-
- bool integrated() const;
-
- bool canMapHostMemory() const;
- enum ComputeMode
- {
- ComputeModeDefault,
- ComputeModeExclusive,
- ComputeModeProhibited,
- ComputeModeExclusiveProcess
- };
-
- ComputeMode computeMode() const;
-
- int maxTexture1D() const;
-
- int maxTexture1DMipmap() const;
-
- int maxTexture1DLinear() const;
-
- Vec2i maxTexture2D() const;
-
- Vec2i maxTexture2DMipmap() const;
-
- Vec3i maxTexture2DLinear() const;
-
- Vec2i maxTexture2DGather() const;
-
- Vec3i maxTexture3D() const;
-
- int maxTextureCubemap() const;
-
- Vec2i maxTexture1DLayered() const;
-
- Vec3i maxTexture2DLayered() const;
-
- Vec2i maxTextureCubemapLayered() const;
-
- int maxSurface1D() const;
-
- Vec2i maxSurface2D() const;
-
- Vec3i maxSurface3D() const;
-
- Vec2i maxSurface1DLayered() const;
-
- Vec3i maxSurface2DLayered() const;
-
- int maxSurfaceCubemap() const;
-
- Vec2i maxSurfaceCubemapLayered() const;
-
- size_t surfaceAlignment() const;
-
- bool concurrentKernels() const;
-
- bool ECCEnabled() const;
-
- int pciBusID() const;
-
- int pciDeviceID() const;
-
- int pciDomainID() const;
-
- bool tccDriver() const;
-
- int asyncEngineCount() const;
-
- bool unifiedAddressing() const;
-
- int memoryClockRate() const;
-
- int memoryBusWidth() const;
-
- int l2CacheSize() const;
-
- int maxThreadsPerMultiProcessor() const;
-
- void queryMemory(size_t& totalMemory, size_t& freeMemory) const;
- size_t freeMemory() const;
- size_t totalMemory() const;
-
- bool supports(FeatureSet feature_set) const;
-
- bool isCompatible() const;
- private:
- int device_id_;
- };
- CV_EXPORTS void printCudaDeviceInfo(int device);
- CV_EXPORTS void printShortCudaDeviceInfo(int device);
- CV_EXPORTS void convertFp16(InputArray _src, OutputArray _dst, Stream& stream = Stream::Null());
- }}
- #include "opencv2/core/cuda.inl.hpp"
- #endif
|