Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
ocl.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) 2013, OpenCV Foundation, all rights reserved. 00014 // Third party copyrights are property of their respective owners. 00015 // 00016 // Redistribution and use in source and binary forms, with or without modification, 00017 // are permitted provided that the following conditions are met: 00018 // 00019 // * Redistribution's of source code must retain the above copyright notice, 00020 // this list of conditions and the following disclaimer. 00021 // 00022 // * Redistribution's in binary form must reproduce the above copyright notice, 00023 // this list of conditions and the following disclaimer in the documentation 00024 // and/or other materials provided with the distribution. 00025 // 00026 // * The name of the copyright holders may not be used to endorse or promote products 00027 // derived from this software without specific prior written permission. 00028 // 00029 // This software is provided by the copyright holders and contributors "as is" and 00030 // any express or implied warranties, including, but not limited to, the implied 00031 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00032 // In no event shall the OpenCV Foundation or contributors be liable for any direct, 00033 // indirect, incidental, special, exemplary, or consequential damages 00034 // (including, but not limited to, procurement of substitute goods or services; 00035 // loss of use, data, or profits; or business interruption) however caused 00036 // and on any theory of liability, whether in contract, strict liability, 00037 // or tort (including negligence or otherwise) arising in any way out of 00038 // the use of this software, even if advised of the possibility of such damage. 00039 // 00040 //M*/ 00041 00042 #ifndef OPENCV_OPENCL_HPP 00043 #define OPENCV_OPENCL_HPP 00044 00045 #include "opencv2/core.hpp" 00046 00047 namespace cv { namespace ocl { 00048 00049 //! @addtogroup core_opencl 00050 //! @{ 00051 00052 CV_EXPORTS_W bool haveOpenCL(); 00053 CV_EXPORTS_W bool useOpenCL(); 00054 CV_EXPORTS_W bool haveAmdBlas(); 00055 CV_EXPORTS_W bool haveAmdFft(); 00056 CV_EXPORTS_W void setUseOpenCL(bool flag); 00057 CV_EXPORTS_W void finish(); 00058 00059 CV_EXPORTS bool haveSVM(); 00060 00061 class CV_EXPORTS Context; 00062 class CV_EXPORTS Device; 00063 class CV_EXPORTS Kernel; 00064 class CV_EXPORTS Program; 00065 class CV_EXPORTS ProgramSource; 00066 class CV_EXPORTS Queue; 00067 class CV_EXPORTS PlatformInfo; 00068 class CV_EXPORTS Image2D; 00069 00070 class CV_EXPORTS Device 00071 { 00072 public: 00073 Device(); 00074 explicit Device(void* d); 00075 Device(const Device& d); 00076 Device& operator = (const Device& d); 00077 ~Device(); 00078 00079 void set(void* d); 00080 00081 enum 00082 { 00083 TYPE_DEFAULT = (1 << 0), 00084 TYPE_CPU = (1 << 1), 00085 TYPE_GPU = (1 << 2), 00086 TYPE_ACCELERATOR = (1 << 3), 00087 TYPE_DGPU = TYPE_GPU + (1 << 16), 00088 TYPE_IGPU = TYPE_GPU + (1 << 17), 00089 TYPE_ALL = 0xFFFFFFFF 00090 }; 00091 00092 String name() const; 00093 String extensions() const; 00094 String version() const; 00095 String vendorName() const; 00096 String OpenCL_C_Version() const; 00097 String OpenCLVersion() const; 00098 int deviceVersionMajor() const; 00099 int deviceVersionMinor() const; 00100 String driverVersion() const; 00101 void* ptr() const; 00102 00103 int type() const; 00104 00105 int addressBits() const; 00106 bool available() const; 00107 bool compilerAvailable() const; 00108 bool linkerAvailable() const; 00109 00110 enum 00111 { 00112 FP_DENORM=(1 << 0), 00113 FP_INF_NAN=(1 << 1), 00114 FP_ROUND_TO_NEAREST=(1 << 2), 00115 FP_ROUND_TO_ZERO=(1 << 3), 00116 FP_ROUND_TO_INF=(1 << 4), 00117 FP_FMA=(1 << 5), 00118 FP_SOFT_FLOAT=(1 << 6), 00119 FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7) 00120 }; 00121 int doubleFPConfig() const; 00122 int singleFPConfig() const; 00123 int halfFPConfig() const; 00124 00125 bool endianLittle() const; 00126 bool errorCorrectionSupport() const; 00127 00128 enum 00129 { 00130 EXEC_KERNEL=(1 << 0), 00131 EXEC_NATIVE_KERNEL=(1 << 1) 00132 }; 00133 int executionCapabilities() const; 00134 00135 size_t globalMemCacheSize() const; 00136 00137 enum 00138 { 00139 NO_CACHE=0, 00140 READ_ONLY_CACHE=1, 00141 READ_WRITE_CACHE=2 00142 }; 00143 int globalMemCacheType() const; 00144 int globalMemCacheLineSize() const; 00145 size_t globalMemSize() const; 00146 00147 size_t localMemSize() const; 00148 enum 00149 { 00150 NO_LOCAL_MEM=0, 00151 LOCAL_IS_LOCAL=1, 00152 LOCAL_IS_GLOBAL=2 00153 }; 00154 int localMemType() const; 00155 bool hostUnifiedMemory() const; 00156 00157 bool imageSupport() const; 00158 00159 bool imageFromBufferSupport() const; 00160 uint imagePitchAlignment() const; 00161 uint imageBaseAddressAlignment() const; 00162 00163 size_t image2DMaxWidth() const; 00164 size_t image2DMaxHeight() const; 00165 00166 size_t image3DMaxWidth() const; 00167 size_t image3DMaxHeight() const; 00168 size_t image3DMaxDepth() const; 00169 00170 size_t imageMaxBufferSize() const; 00171 size_t imageMaxArraySize() const; 00172 00173 enum 00174 { 00175 UNKNOWN_VENDOR=0, 00176 VENDOR_AMD=1, 00177 VENDOR_INTEL=2, 00178 VENDOR_NVIDIA=3 00179 }; 00180 int vendorID() const; 00181 // FIXIT 00182 // dev.isAMD() doesn't work for OpenCL CPU devices from AMD OpenCL platform. 00183 // This method should use platform name instead of vendor name. 00184 // After fix restore code in arithm.cpp: ocl_compare() 00185 inline bool isAMD() const { return vendorID() == VENDOR_AMD; } 00186 inline bool isIntel() const { return vendorID() == VENDOR_INTEL; } 00187 inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; } 00188 00189 int maxClockFrequency() const; 00190 int maxComputeUnits() const; 00191 int maxConstantArgs() const; 00192 size_t maxConstantBufferSize() const; 00193 00194 size_t maxMemAllocSize() const; 00195 size_t maxParameterSize() const; 00196 00197 int maxReadImageArgs() const; 00198 int maxWriteImageArgs() const; 00199 int maxSamplers() const; 00200 00201 size_t maxWorkGroupSize() const; 00202 int maxWorkItemDims() const; 00203 void maxWorkItemSizes(size_t*) const; 00204 00205 int memBaseAddrAlign() const; 00206 00207 int nativeVectorWidthChar() const; 00208 int nativeVectorWidthShort() const; 00209 int nativeVectorWidthInt() const; 00210 int nativeVectorWidthLong() const; 00211 int nativeVectorWidthFloat() const; 00212 int nativeVectorWidthDouble() const; 00213 int nativeVectorWidthHalf() const; 00214 00215 int preferredVectorWidthChar() const; 00216 int preferredVectorWidthShort() const; 00217 int preferredVectorWidthInt() const; 00218 int preferredVectorWidthLong() const; 00219 int preferredVectorWidthFloat() const; 00220 int preferredVectorWidthDouble() const; 00221 int preferredVectorWidthHalf() const; 00222 00223 size_t printfBufferSize() const; 00224 size_t profilingTimerResolution() const; 00225 00226 static const Device& getDefault(); 00227 00228 protected: 00229 struct Impl; 00230 Impl* p; 00231 }; 00232 00233 00234 class CV_EXPORTS Context 00235 { 00236 public: 00237 Context(); 00238 explicit Context(int dtype); 00239 ~Context(); 00240 Context(const Context& c); 00241 Context& operator = (const Context& c); 00242 00243 bool create(); 00244 bool create(int dtype); 00245 size_t ndevices() const; 00246 const Device& device(size_t idx) const; 00247 Program getProg(const ProgramSource& prog, 00248 const String& buildopt, String& errmsg); 00249 00250 static Context& getDefault(bool initialize = true); 00251 void* ptr() const; 00252 00253 friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); 00254 00255 bool useSVM() const; 00256 void setUseSVM(bool enabled); 00257 00258 struct Impl; 00259 Impl* p; 00260 }; 00261 00262 class CV_EXPORTS Platform 00263 { 00264 public: 00265 Platform(); 00266 ~Platform(); 00267 Platform(const Platform& p); 00268 Platform& operator = (const Platform& p); 00269 00270 void* ptr() const; 00271 static Platform& getDefault(); 00272 00273 friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); 00274 protected: 00275 struct Impl; 00276 Impl* p; 00277 }; 00278 00279 /* 00280 //! @brief Attaches OpenCL context to OpenCV 00281 // 00282 //! @note Note: 00283 // OpenCV will check if available OpenCL platform has platformName name, 00284 // then assign context to OpenCV and call clRetainContext function. 00285 // The deviceID device will be used as target device and new command queue 00286 // will be created. 00287 // 00288 // Params: 00289 //! @param platformName - name of OpenCL platform to attach, 00290 //! this string is used to check if platform is available 00291 //! to OpenCV at runtime 00292 //! @param platfromID - ID of platform attached context was created for 00293 //! @param context - OpenCL context to be attached to OpenCV 00294 //! @param deviceID - ID of device, must be created from attached context 00295 */ 00296 CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID); 00297 00298 /* 00299 //! @brief Convert OpenCL buffer to UMat 00300 // 00301 //! @note Note: 00302 // OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV. 00303 // Memory content is not copied from clBuffer to UMat. Instead, buffer handle assigned 00304 // to UMat and clRetainMemObject is called. 00305 // 00306 // Params: 00307 //! @param cl_mem_buffer - source clBuffer handle 00308 //! @param step - num of bytes in single row 00309 //! @param rows - number of rows 00310 //! @param cols - number of cols 00311 //! @param type - OpenCV type of image 00312 //! @param dst - destination UMat 00313 */ 00314 CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst); 00315 00316 /* 00317 //! @brief Convert OpenCL image2d_t to UMat 00318 // 00319 //! @note Note: 00320 // OpenCL image2d_t (cl_mem_image), should be compatible with OpenCV 00321 // UMat formats. 00322 // Memory content is copied from image to UMat with 00323 // clEnqueueCopyImageToBuffer function. 00324 // 00325 // Params: 00326 //! @param cl_mem_image - source image2d_t handle 00327 //! @param dst - destination UMat 00328 */ 00329 CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); 00330 00331 // TODO Move to internal header 00332 void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); 00333 00334 class CV_EXPORTS Queue 00335 { 00336 public: 00337 Queue(); 00338 explicit Queue(const Context& c, const Device& d=Device()); 00339 ~Queue(); 00340 Queue(const Queue& q); 00341 Queue& operator = (const Queue& q); 00342 00343 bool create(const Context& c=Context(), const Device& d=Device()); 00344 void finish(); 00345 void* ptr() const; 00346 static Queue& getDefault(); 00347 00348 protected: 00349 struct Impl; 00350 Impl* p; 00351 }; 00352 00353 00354 class CV_EXPORTS KernelArg 00355 { 00356 public: 00357 enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 }; 00358 KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0); 00359 KernelArg(); 00360 00361 static KernelArg Local() { return KernelArg(LOCAL, 0); } 00362 static KernelArg PtrWriteOnly(const UMat& m) 00363 { return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); } 00364 static KernelArg PtrReadOnly(const UMat& m) 00365 { return KernelArg(PTR_ONLY+READ_ONLY, (UMat*)&m); } 00366 static KernelArg PtrReadWrite(const UMat& m) 00367 { return KernelArg(PTR_ONLY+READ_WRITE, (UMat*)&m); } 00368 static KernelArg ReadWrite(const UMat& m, int wscale=1, int iwscale=1) 00369 { return KernelArg(READ_WRITE, (UMat*)&m, wscale, iwscale); } 00370 static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1, int iwscale=1) 00371 { return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale, iwscale); } 00372 static KernelArg ReadOnly(const UMat& m, int wscale=1, int iwscale=1) 00373 { return KernelArg(READ_ONLY, (UMat*)&m, wscale, iwscale); } 00374 static KernelArg WriteOnly(const UMat& m, int wscale=1, int iwscale=1) 00375 { return KernelArg(WRITE_ONLY, (UMat*)&m, wscale, iwscale); } 00376 static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) 00377 { return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } 00378 static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) 00379 { return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } 00380 static KernelArg Constant(const Mat& m); 00381 template<typename _Tp> static KernelArg Constant(const _Tp* arr, size_t n) 00382 { return KernelArg(CONSTANT, 0, 1, 1, (void*)arr, n); } 00383 00384 int flags; 00385 UMat* m; 00386 const void* obj; 00387 size_t sz; 00388 int wscale, iwscale; 00389 }; 00390 00391 00392 class CV_EXPORTS Kernel 00393 { 00394 public: 00395 Kernel(); 00396 Kernel(const char* kname, const Program& prog); 00397 Kernel(const char* kname, const ProgramSource& prog, 00398 const String& buildopts = String(), String* errmsg=0); 00399 ~Kernel(); 00400 Kernel(const Kernel& k); 00401 Kernel& operator = (const Kernel& k); 00402 00403 bool empty() const; 00404 bool create(const char* kname, const Program& prog); 00405 bool create(const char* kname, const ProgramSource& prog, 00406 const String& buildopts, String* errmsg=0); 00407 00408 int set(int i, const void* value, size_t sz); 00409 int set(int i, const Image2D& image2D); 00410 int set(int i, const UMat& m); 00411 int set(int i, const KernelArg& arg); 00412 template<typename _Tp> int set(int i, const _Tp& value) 00413 { return set(i, &value, sizeof(value)); } 00414 00415 template<typename _Tp0> 00416 Kernel& args(const _Tp0& a0) 00417 { 00418 set(0, a0); return *this; 00419 } 00420 00421 template<typename _Tp0, typename _Tp1> 00422 Kernel& args(const _Tp0& a0, const _Tp1& a1) 00423 { 00424 int i = set(0, a0); set(i, a1); return *this; 00425 } 00426 00427 template<typename _Tp0, typename _Tp1, typename _Tp2> 00428 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2) 00429 { 00430 int i = set(0, a0); i = set(i, a1); set(i, a2); return *this; 00431 } 00432 00433 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3> 00434 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3) 00435 { 00436 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this; 00437 } 00438 00439 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> 00440 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, 00441 const _Tp3& a3, const _Tp4& a4) 00442 { 00443 int i = set(0, a0); i = set(i, a1); i = set(i, a2); 00444 i = set(i, a3); set(i, a4); return *this; 00445 } 00446 00447 template<typename _Tp0, typename _Tp1, typename _Tp2, 00448 typename _Tp3, typename _Tp4, typename _Tp5> 00449 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, 00450 const _Tp3& a3, const _Tp4& a4, const _Tp5& a5) 00451 { 00452 int i = set(0, a0); i = set(i, a1); i = set(i, a2); 00453 i = set(i, a3); i = set(i, a4); set(i, a5); return *this; 00454 } 00455 00456 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00457 typename _Tp4, typename _Tp5, typename _Tp6> 00458 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00459 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6) 00460 { 00461 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); 00462 i = set(i, a4); i = set(i, a5); set(i, a6); return *this; 00463 } 00464 00465 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00466 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7> 00467 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00468 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7) 00469 { 00470 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); 00471 i = set(i, a4); i = set(i, a5); i = set(i, a6); set(i, a7); return *this; 00472 } 00473 00474 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4, 00475 typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8> 00476 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00477 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00478 const _Tp8& a8) 00479 { 00480 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); 00481 i = set(i, a5); i = set(i, a6); i = set(i, a7); set(i, a8); return *this; 00482 } 00483 00484 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4, 00485 typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8, typename _Tp9> 00486 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00487 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00488 const _Tp8& a8, const _Tp9& a9) 00489 { 00490 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00491 i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this; 00492 } 00493 00494 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00495 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00496 typename _Tp8, typename _Tp9, typename _Tp10> 00497 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00498 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00499 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10) 00500 { 00501 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00502 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this; 00503 } 00504 00505 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00506 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00507 typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11> 00508 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00509 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00510 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11) 00511 { 00512 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00513 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); set(i, a11); return *this; 00514 } 00515 00516 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00517 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00518 typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12> 00519 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00520 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00521 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, 00522 const _Tp12& a12) 00523 { 00524 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00525 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); 00526 set(i, a12); return *this; 00527 } 00528 00529 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00530 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00531 typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, 00532 typename _Tp13> 00533 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00534 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00535 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, 00536 const _Tp12& a12, const _Tp13& a13) 00537 { 00538 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00539 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); 00540 i = set(i, a12); set(i, a13); return *this; 00541 } 00542 00543 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00544 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00545 typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, 00546 typename _Tp13, typename _Tp14> 00547 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00548 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00549 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, 00550 const _Tp12& a12, const _Tp13& a13, const _Tp14& a14) 00551 { 00552 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00553 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); 00554 i = set(i, a12); i = set(i, a13); set(i, a14); return *this; 00555 } 00556 00557 template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, 00558 typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, 00559 typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, 00560 typename _Tp13, typename _Tp14, typename _Tp15> 00561 Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, 00562 const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, 00563 const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, 00564 const _Tp12& a12, const _Tp13& a13, const _Tp14& a14, const _Tp15& a15) 00565 { 00566 int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); 00567 i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); 00568 i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this; 00569 } 00570 /* 00571 Run the OpenCL kernel. 00572 @param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3. 00573 @param globalsize work items for each dimension. 00574 It is not the final globalsize passed to OpenCL. 00575 Each dimension will be adjusted to the nearest integer divisible by the corresponding value in localsize. 00576 If localsize is NULL, it will still be adjusted depending on dims. 00577 The adjusted values are greater than or equal to the original values. 00578 @param localsize work-group size for each dimension. 00579 @param sync specify whether to wait for OpenCL computation to finish before return. 00580 @param q command queue 00581 */ 00582 bool run(int dims, size_t globalsize[], 00583 size_t localsize[], bool sync, const Queue& q=Queue()); 00584 bool runTask(bool sync, const Queue& q=Queue()); 00585 00586 size_t workGroupSize() const; 00587 size_t preferedWorkGroupSizeMultiple() const; 00588 bool compileWorkGroupSize(size_t wsz[]) const; 00589 size_t localMemSize() const; 00590 00591 void* ptr() const; 00592 struct Impl; 00593 00594 protected: 00595 Impl* p; 00596 }; 00597 00598 class CV_EXPORTS Program 00599 { 00600 public: 00601 Program(); 00602 Program(const ProgramSource& src, 00603 const String& buildflags, String& errmsg); 00604 explicit Program(const String& buf); 00605 Program(const Program& prog); 00606 00607 Program& operator = (const Program& prog); 00608 ~Program(); 00609 00610 bool create(const ProgramSource& src, 00611 const String& buildflags, String& errmsg); 00612 bool read(const String& buf, const String& buildflags); 00613 bool write(String& buf) const; 00614 00615 const ProgramSource& source() const; 00616 void* ptr() const; 00617 00618 String getPrefix() const; 00619 static String getPrefix(const String& buildflags); 00620 00621 protected: 00622 struct Impl; 00623 Impl* p; 00624 }; 00625 00626 00627 class CV_EXPORTS ProgramSource 00628 { 00629 public: 00630 typedef uint64 hash_t; 00631 00632 ProgramSource(); 00633 explicit ProgramSource(const String& prog); 00634 explicit ProgramSource(const char* prog); 00635 ~ProgramSource(); 00636 ProgramSource(const ProgramSource& prog); 00637 ProgramSource& operator = (const ProgramSource& prog); 00638 00639 const String& source() const; 00640 hash_t hash() const; 00641 00642 protected: 00643 struct Impl; 00644 Impl* p; 00645 }; 00646 00647 class CV_EXPORTS PlatformInfo 00648 { 00649 public: 00650 PlatformInfo(); 00651 explicit PlatformInfo(void* id); 00652 ~PlatformInfo(); 00653 00654 PlatformInfo(const PlatformInfo& i); 00655 PlatformInfo& operator =(const PlatformInfo& i); 00656 00657 String name() const; 00658 String vendor() const; 00659 String version() const; 00660 int deviceNumber() const; 00661 void getDevice(Device& device, int d) const; 00662 00663 protected: 00664 struct Impl; 00665 Impl* p; 00666 }; 00667 00668 CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf); 00669 CV_EXPORTS const char* typeToStr(int t); 00670 CV_EXPORTS const char* memopTypeToStr(int t); 00671 CV_EXPORTS const char* vecopTypeToStr(int t); 00672 CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL); 00673 CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info); 00674 00675 00676 enum OclVectorStrategy 00677 { 00678 // all matrices have its own vector width 00679 OCL_VECTOR_OWN = 0, 00680 // all matrices have maximal vector width among all matrices 00681 // (useful for cases when matrices have different data types) 00682 OCL_VECTOR_MAX = 1, 00683 00684 // default strategy 00685 OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN 00686 }; 00687 00688 CV_EXPORTS int predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), 00689 InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), 00690 InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), 00691 OclVectorStrategy strat = OCL_VECTOR_DEFAULT); 00692 00693 CV_EXPORTS int checkOptimalVectorWidth(const int *vectorWidths, 00694 InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), 00695 InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), 00696 InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), 00697 OclVectorStrategy strat = OCL_VECTOR_DEFAULT); 00698 00699 // with OCL_VECTOR_MAX strategy 00700 CV_EXPORTS int predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), 00701 InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), 00702 InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray()); 00703 00704 CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const String& name, InputArray _m); 00705 00706 class CV_EXPORTS Image2D 00707 { 00708 public: 00709 Image2D(); 00710 00711 // src: The UMat from which to get image properties and data 00712 // norm: Flag to enable the use of normalized channel data types 00713 // alias: Flag indicating that the image should alias the src UMat. 00714 // If true, changes to the image or src will be reflected in 00715 // both objects. 00716 explicit Image2D(const UMat &src, bool norm = false, bool alias = false); 00717 Image2D(const Image2D & i); 00718 ~Image2D(); 00719 00720 Image2D & operator = (const Image2D & i); 00721 00722 // Indicates if creating an aliased image should succeed. Depends on the 00723 // underlying platform and the dimensions of the UMat. 00724 static bool canCreateAlias(const UMat &u); 00725 00726 // Indicates if the image format is supported. 00727 static bool isFormatSupported(int depth, int cn, bool norm); 00728 00729 void* ptr() const; 00730 protected: 00731 struct Impl; 00732 Impl* p; 00733 }; 00734 00735 00736 CV_EXPORTS MatAllocator* getOpenCLAllocator(); 00737 00738 00739 #ifdef __OPENCV_BUILD 00740 namespace internal { 00741 00742 CV_EXPORTS bool isOpenCLForced(); 00743 #define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition)) 00744 00745 CV_EXPORTS bool isPerformanceCheckBypassed(); 00746 #define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition)) 00747 00748 CV_EXPORTS bool isCLBuffer(UMat& u); 00749 00750 } // namespace internal 00751 #endif 00752 00753 //! @} 00754 00755 }} 00756 00757 #endif
Generated on Tue Jul 12 2022 18:20:19 by
