Home | History | Annotate | Download | only in core
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                           License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
     14 // Third party copyrights are property of their respective owners.
     15 //
     16 // Redistribution and use in source and binary forms, with or without modification,
     17 // are permitted provided that the following conditions are met:
     18 //
     19 //   * Redistribution's of source code must retain the above copyright notice,
     20 //     this list of conditions and the following disclaimer.
     21 //
     22 //   * Redistribution's in binary form must reproduce the above copyright notice,
     23 //     this list of conditions and the following disclaimer in the documentation
     24 //     and/or other materials provided with the distribution.
     25 //
     26 //   * The name of the copyright holders may not be used to endorse or promote products
     27 //     derived from this software without specific prior written permission.
     28 //
     29 // This software is provided by the copyright holders and contributors "as is" and
     30 // any express or implied warranties, including, but not limited to, the implied
     31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     32 // In no event shall the OpenCV Foundation or contributors be liable for any direct,
     33 // indirect, incidental, special, exemplary, or consequential damages
     34 // (including, but not limited to, procurement of substitute goods or services;
     35 // loss of use, data, or profits; or business interruption) however caused
     36 // and on any theory of liability, whether in contract, strict liability,
     37 // or tort (including negligence or otherwise) arising in any way out of
     38 // the use of this software, even if advised of the possibility of such damage.
     39 //
     40 //M*/
     41 
     42 #ifndef __OPENCV_OPENCL_HPP__
     43 #define __OPENCV_OPENCL_HPP__
     44 
     45 #include "opencv2/core.hpp"
     46 
     47 namespace cv { namespace ocl {
     48 
     49 //! @addtogroup core_opencl
     50 //! @{
     51 
     52 CV_EXPORTS_W bool haveOpenCL();
     53 CV_EXPORTS_W bool useOpenCL();
     54 CV_EXPORTS_W bool haveAmdBlas();
     55 CV_EXPORTS_W bool haveAmdFft();
     56 CV_EXPORTS_W void setUseOpenCL(bool flag);
     57 CV_EXPORTS_W void finish();
     58 
     59 CV_EXPORTS bool haveSVM();
     60 
     61 class CV_EXPORTS Context;
     62 class CV_EXPORTS Device;
     63 class CV_EXPORTS Kernel;
     64 class CV_EXPORTS Program;
     65 class CV_EXPORTS ProgramSource;
     66 class CV_EXPORTS Queue;
     67 class CV_EXPORTS PlatformInfo;
     68 class CV_EXPORTS Image2D;
     69 
     70 class CV_EXPORTS Device
     71 {
     72 public:
     73     Device();
     74     explicit Device(void* d);
     75     Device(const Device& d);
     76     Device& operator = (const Device& d);
     77     ~Device();
     78 
     79     void set(void* d);
     80 
     81     enum
     82     {
     83         TYPE_DEFAULT     = (1 << 0),
     84         TYPE_CPU         = (1 << 1),
     85         TYPE_GPU         = (1 << 2),
     86         TYPE_ACCELERATOR = (1 << 3),
     87         TYPE_DGPU        = TYPE_GPU + (1 << 16),
     88         TYPE_IGPU        = TYPE_GPU + (1 << 17),
     89         TYPE_ALL         = 0xFFFFFFFF
     90     };
     91 
     92     String name() const;
     93     String extensions() const;
     94     String version() const;
     95     String vendorName() const;
     96     String OpenCL_C_Version() const;
     97     String OpenCLVersion() const;
     98     int deviceVersionMajor() const;
     99     int deviceVersionMinor() const;
    100     String driverVersion() const;
    101     void* ptr() const;
    102 
    103     int type() const;
    104 
    105     int addressBits() const;
    106     bool available() const;
    107     bool compilerAvailable() const;
    108     bool linkerAvailable() const;
    109 
    110     enum
    111     {
    112         FP_DENORM=(1 << 0),
    113         FP_INF_NAN=(1 << 1),
    114         FP_ROUND_TO_NEAREST=(1 << 2),
    115         FP_ROUND_TO_ZERO=(1 << 3),
    116         FP_ROUND_TO_INF=(1 << 4),
    117         FP_FMA=(1 << 5),
    118         FP_SOFT_FLOAT=(1 << 6),
    119         FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7)
    120     };
    121     int doubleFPConfig() const;
    122     int singleFPConfig() const;
    123     int halfFPConfig() const;
    124 
    125     bool endianLittle() const;
    126     bool errorCorrectionSupport() const;
    127 
    128     enum
    129     {
    130         EXEC_KERNEL=(1 << 0),
    131         EXEC_NATIVE_KERNEL=(1 << 1)
    132     };
    133     int executionCapabilities() const;
    134 
    135     size_t globalMemCacheSize() const;
    136 
    137     enum
    138     {
    139         NO_CACHE=0,
    140         READ_ONLY_CACHE=1,
    141         READ_WRITE_CACHE=2
    142     };
    143     int globalMemCacheType() const;
    144     int globalMemCacheLineSize() const;
    145     size_t globalMemSize() const;
    146 
    147     size_t localMemSize() const;
    148     enum
    149     {
    150         NO_LOCAL_MEM=0,
    151         LOCAL_IS_LOCAL=1,
    152         LOCAL_IS_GLOBAL=2
    153     };
    154     int localMemType() const;
    155     bool hostUnifiedMemory() const;
    156 
    157     bool imageSupport() const;
    158 
    159     bool imageFromBufferSupport() const;
    160     uint imagePitchAlignment() const;
    161     uint imageBaseAddressAlignment() const;
    162 
    163     size_t image2DMaxWidth() const;
    164     size_t image2DMaxHeight() const;
    165 
    166     size_t image3DMaxWidth() const;
    167     size_t image3DMaxHeight() const;
    168     size_t image3DMaxDepth() const;
    169 
    170     size_t imageMaxBufferSize() const;
    171     size_t imageMaxArraySize() const;
    172 
    173     enum
    174     {
    175         UNKNOWN_VENDOR=0,
    176         VENDOR_AMD=1,
    177         VENDOR_INTEL=2,
    178         VENDOR_NVIDIA=3
    179     };
    180     int vendorID() const;
    181     // FIXIT
    182     // dev.isAMD() doesn't work for OpenCL CPU devices from AMD OpenCL platform.
    183     // This method should use platform name instead of vendor name.
    184     // After fix restore code in arithm.cpp: ocl_compare()
    185     inline bool isAMD() const { return vendorID() == VENDOR_AMD; }
    186     inline bool isIntel() const { return vendorID() == VENDOR_INTEL; }
    187     inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; }
    188 
    189     int maxClockFrequency() const;
    190     int maxComputeUnits() const;
    191     int maxConstantArgs() const;
    192     size_t maxConstantBufferSize() const;
    193 
    194     size_t maxMemAllocSize() const;
    195     size_t maxParameterSize() const;
    196 
    197     int maxReadImageArgs() const;
    198     int maxWriteImageArgs() const;
    199     int maxSamplers() const;
    200 
    201     size_t maxWorkGroupSize() const;
    202     int maxWorkItemDims() const;
    203     void maxWorkItemSizes(size_t*) const;
    204 
    205     int memBaseAddrAlign() const;
    206 
    207     int nativeVectorWidthChar() const;
    208     int nativeVectorWidthShort() const;
    209     int nativeVectorWidthInt() const;
    210     int nativeVectorWidthLong() const;
    211     int nativeVectorWidthFloat() const;
    212     int nativeVectorWidthDouble() const;
    213     int nativeVectorWidthHalf() const;
    214 
    215     int preferredVectorWidthChar() const;
    216     int preferredVectorWidthShort() const;
    217     int preferredVectorWidthInt() const;
    218     int preferredVectorWidthLong() const;
    219     int preferredVectorWidthFloat() const;
    220     int preferredVectorWidthDouble() const;
    221     int preferredVectorWidthHalf() const;
    222 
    223     size_t printfBufferSize() const;
    224     size_t profilingTimerResolution() const;
    225 
    226     static const Device& getDefault();
    227 
    228 protected:
    229     struct Impl;
    230     Impl* p;
    231 };
    232 
    233 
    234 class CV_EXPORTS Context
    235 {
    236 public:
    237     Context();
    238     explicit Context(int dtype);
    239     ~Context();
    240     Context(const Context& c);
    241     Context& operator = (const Context& c);
    242 
    243     bool create();
    244     bool create(int dtype);
    245     size_t ndevices() const;
    246     const Device& device(size_t idx) const;
    247     Program getProg(const ProgramSource& prog,
    248                     const String& buildopt, String& errmsg);
    249 
    250     static Context& getDefault(bool initialize = true);
    251     void* ptr() const;
    252 
    253     friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
    254 
    255     bool useSVM() const;
    256     void setUseSVM(bool enabled);
    257 
    258     struct Impl;
    259     Impl* p;
    260 };
    261 
    262 class CV_EXPORTS Platform
    263 {
    264 public:
    265     Platform();
    266     ~Platform();
    267     Platform(const Platform& p);
    268     Platform& operator = (const Platform& p);
    269 
    270     void* ptr() const;
    271     static Platform& getDefault();
    272 
    273     friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
    274 protected:
    275     struct Impl;
    276     Impl* p;
    277 };
    278 
    279 // TODO Move to internal header
    280 void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
    281 
    282 class CV_EXPORTS Queue
    283 {
    284 public:
    285     Queue();
    286     explicit Queue(const Context& c, const Device& d=Device());
    287     ~Queue();
    288     Queue(const Queue& q);
    289     Queue& operator = (const Queue& q);
    290 
    291     bool create(const Context& c=Context(), const Device& d=Device());
    292     void finish();
    293     void* ptr() const;
    294     static Queue& getDefault();
    295 
    296 protected:
    297     struct Impl;
    298     Impl* p;
    299 };
    300 
    301 
    302 class CV_EXPORTS KernelArg
    303 {
    304 public:
    305     enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 };
    306     KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0);
    307     KernelArg();
    308 
    309     static KernelArg Local() { return KernelArg(LOCAL, 0); }
    310     static KernelArg PtrWriteOnly(const UMat& m)
    311     { return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); }
    312     static KernelArg PtrReadOnly(const UMat& m)
    313     { return KernelArg(PTR_ONLY+READ_ONLY, (UMat*)&m); }
    314     static KernelArg PtrReadWrite(const UMat& m)
    315     { return KernelArg(PTR_ONLY+READ_WRITE, (UMat*)&m); }
    316     static KernelArg ReadWrite(const UMat& m, int wscale=1, int iwscale=1)
    317     { return KernelArg(READ_WRITE, (UMat*)&m, wscale, iwscale); }
    318     static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1, int iwscale=1)
    319     { return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale, iwscale); }
    320     static KernelArg ReadOnly(const UMat& m, int wscale=1, int iwscale=1)
    321     { return KernelArg(READ_ONLY, (UMat*)&m, wscale, iwscale); }
    322     static KernelArg WriteOnly(const UMat& m, int wscale=1, int iwscale=1)
    323     { return KernelArg(WRITE_ONLY, (UMat*)&m, wscale, iwscale); }
    324     static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1)
    325     { return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); }
    326     static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1)
    327     { return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); }
    328     static KernelArg Constant(const Mat& m);
    329     template<typename _Tp> static KernelArg Constant(const _Tp* arr, size_t n)
    330     { return KernelArg(CONSTANT, 0, 1, 1, (void*)arr, n); }
    331 
    332     int flags;
    333     UMat* m;
    334     const void* obj;
    335     size_t sz;
    336     int wscale, iwscale;
    337 };
    338 
    339 
    340 class CV_EXPORTS Kernel
    341 {
    342 public:
    343     Kernel();
    344     Kernel(const char* kname, const Program& prog);
    345     Kernel(const char* kname, const ProgramSource& prog,
    346            const String& buildopts = String(), String* errmsg=0);
    347     ~Kernel();
    348     Kernel(const Kernel& k);
    349     Kernel& operator = (const Kernel& k);
    350 
    351     bool empty() const;
    352     bool create(const char* kname, const Program& prog);
    353     bool create(const char* kname, const ProgramSource& prog,
    354                 const String& buildopts, String* errmsg=0);
    355 
    356     int set(int i, const void* value, size_t sz);
    357     int set(int i, const Image2D& image2D);
    358     int set(int i, const UMat& m);
    359     int set(int i, const KernelArg& arg);
    360     template<typename _Tp> int set(int i, const _Tp& value)
    361     { return set(i, &value, sizeof(value)); }
    362 
    363     template<typename _Tp0>
    364     Kernel& args(const _Tp0& a0)
    365     {
    366         set(0, a0); return *this;
    367     }
    368 
    369     template<typename _Tp0, typename _Tp1>
    370     Kernel& args(const _Tp0& a0, const _Tp1& a1)
    371     {
    372         int i = set(0, a0); set(i, a1); return *this;
    373     }
    374 
    375     template<typename _Tp0, typename _Tp1, typename _Tp2>
    376     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2)
    377     {
    378         int i = set(0, a0); i = set(i, a1); set(i, a2); return *this;
    379     }
    380 
    381     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3>
    382     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3)
    383     {
    384         int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this;
    385     }
    386 
    387     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4>
    388     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
    389                  const _Tp3& a3, const _Tp4& a4)
    390     {
    391         int i = set(0, a0); i = set(i, a1); i = set(i, a2);
    392         i = set(i, a3); set(i, a4); return *this;
    393     }
    394 
    395     template<typename _Tp0, typename _Tp1, typename _Tp2,
    396              typename _Tp3, typename _Tp4, typename _Tp5>
    397     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
    398                  const _Tp3& a3, const _Tp4& a4, const _Tp5& a5)
    399     {
    400         int i = set(0, a0); i = set(i, a1); i = set(i, a2);
    401         i = set(i, a3); i = set(i, a4); set(i, a5); return *this;
    402     }
    403 
    404     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    405              typename _Tp4, typename _Tp5, typename _Tp6>
    406     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    407                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6)
    408     {
    409         int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3);
    410         i = set(i, a4); i = set(i, a5); set(i, a6); return *this;
    411     }
    412 
    413     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    414              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7>
    415     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    416                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7)
    417     {
    418         int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3);
    419         i = set(i, a4); i = set(i, a5); i = set(i, a6); set(i, a7); return *this;
    420     }
    421 
    422     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
    423              typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8>
    424     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    425                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    426                  const _Tp8& a8)
    427     {
    428         int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4);
    429         i = set(i, a5); i = set(i, a6); i = set(i, a7); set(i, a8); return *this;
    430     }
    431 
    432     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
    433              typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8, typename _Tp9>
    434     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    435                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    436                  const _Tp8& a8, const _Tp9& a9)
    437     {
    438         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);
    439         i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this;
    440     }
    441 
    442     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    443              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    444              typename _Tp8, typename _Tp9, typename _Tp10>
    445     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    446                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    447                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10)
    448     {
    449         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);
    450         i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this;
    451     }
    452 
    453     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    454              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    455              typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11>
    456     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    457                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    458                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11)
    459     {
    460         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);
    461         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;
    462     }
    463 
    464     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    465              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    466              typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12>
    467     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    468                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    469                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
    470                  const _Tp12& a12)
    471     {
    472         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);
    473         i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
    474         set(i, a12); return *this;
    475     }
    476 
    477     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    478              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    479              typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
    480              typename _Tp13>
    481     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    482                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    483                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
    484                  const _Tp12& a12, const _Tp13& a13)
    485     {
    486         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);
    487         i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
    488         i = set(i, a12); set(i, a13); return *this;
    489     }
    490 
    491     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    492              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    493              typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
    494              typename _Tp13, typename _Tp14>
    495     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    496                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    497                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
    498                  const _Tp12& a12, const _Tp13& a13, const _Tp14& a14)
    499     {
    500         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);
    501         i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
    502         i = set(i, a12); i = set(i, a13); set(i, a14); return *this;
    503     }
    504 
    505     template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
    506              typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
    507              typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
    508              typename _Tp13, typename _Tp14, typename _Tp15>
    509     Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
    510                  const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
    511                  const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
    512                  const _Tp12& a12, const _Tp13& a13, const _Tp14& a14, const _Tp15& a15)
    513     {
    514         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);
    515         i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
    516         i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this;
    517     }
    518 
    519     bool run(int dims, size_t globalsize[],
    520              size_t localsize[], bool sync, const Queue& q=Queue());
    521     bool runTask(bool sync, const Queue& q=Queue());
    522 
    523     size_t workGroupSize() const;
    524     size_t preferedWorkGroupSizeMultiple() const;
    525     bool compileWorkGroupSize(size_t wsz[]) const;
    526     size_t localMemSize() const;
    527 
    528     void* ptr() const;
    529     struct Impl;
    530 
    531 protected:
    532     Impl* p;
    533 };
    534 
    535 class CV_EXPORTS Program
    536 {
    537 public:
    538     Program();
    539     Program(const ProgramSource& src,
    540             const String& buildflags, String& errmsg);
    541     explicit Program(const String& buf);
    542     Program(const Program& prog);
    543 
    544     Program& operator = (const Program& prog);
    545     ~Program();
    546 
    547     bool create(const ProgramSource& src,
    548                 const String& buildflags, String& errmsg);
    549     bool read(const String& buf, const String& buildflags);
    550     bool write(String& buf) const;
    551 
    552     const ProgramSource& source() const;
    553     void* ptr() const;
    554 
    555     String getPrefix() const;
    556     static String getPrefix(const String& buildflags);
    557 
    558 protected:
    559     struct Impl;
    560     Impl* p;
    561 };
    562 
    563 
    564 class CV_EXPORTS ProgramSource
    565 {
    566 public:
    567     typedef uint64 hash_t;
    568 
    569     ProgramSource();
    570     explicit ProgramSource(const String& prog);
    571     explicit ProgramSource(const char* prog);
    572     ~ProgramSource();
    573     ProgramSource(const ProgramSource& prog);
    574     ProgramSource& operator = (const ProgramSource& prog);
    575 
    576     const String& source() const;
    577     hash_t hash() const;
    578 
    579 protected:
    580     struct Impl;
    581     Impl* p;
    582 };
    583 
    584 class CV_EXPORTS PlatformInfo
    585 {
    586 public:
    587     PlatformInfo();
    588     explicit PlatformInfo(void* id);
    589     ~PlatformInfo();
    590 
    591     PlatformInfo(const PlatformInfo& i);
    592     PlatformInfo& operator =(const PlatformInfo& i);
    593 
    594     String name() const;
    595     String vendor() const;
    596     String version() const;
    597     int deviceNumber() const;
    598     void getDevice(Device& device, int d) const;
    599 
    600 protected:
    601     struct Impl;
    602     Impl* p;
    603 };
    604 
    605 CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf);
    606 CV_EXPORTS const char* typeToStr(int t);
    607 CV_EXPORTS const char* memopTypeToStr(int t);
    608 CV_EXPORTS const char* vecopTypeToStr(int t);
    609 CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL);
    610 CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
    611 
    612 
    613 enum OclVectorStrategy
    614 {
    615     // all matrices have its own vector width
    616     OCL_VECTOR_OWN = 0,
    617     // all matrices have maximal vector width among all matrices
    618     // (useful for cases when matrices have different data types)
    619     OCL_VECTOR_MAX = 1,
    620 
    621     // default strategy
    622     OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN
    623 };
    624 
    625 CV_EXPORTS int predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
    626                                          InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
    627                                          InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
    628                                          OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
    629 
    630 CV_EXPORTS int checkOptimalVectorWidth(const int *vectorWidths,
    631                                        InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
    632                                        InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
    633                                        InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
    634                                        OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
    635 
    636 // with OCL_VECTOR_MAX strategy
    637 CV_EXPORTS int predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
    638                                             InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
    639                                             InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray());
    640 
    641 CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const String& name, InputArray _m);
    642 
    643 class CV_EXPORTS Image2D
    644 {
    645 public:
    646     Image2D();
    647 
    648     // src:     The UMat from which to get image properties and data
    649     // norm:    Flag to enable the use of normalized channel data types
    650     // alias:   Flag indicating that the image should alias the src UMat.
    651     //          If true, changes to the image or src will be reflected in
    652     //          both objects.
    653     explicit Image2D(const UMat &src, bool norm = false, bool alias = false);
    654     Image2D(const Image2D & i);
    655     ~Image2D();
    656 
    657     Image2D & operator = (const Image2D & i);
    658 
    659     // Indicates if creating an aliased image should succeed.  Depends on the
    660     // underlying platform and the dimensions of the UMat.
    661     static bool canCreateAlias(const UMat &u);
    662 
    663     // Indicates if the image format is supported.
    664     static bool isFormatSupported(int depth, int cn, bool norm);
    665 
    666     void* ptr() const;
    667 protected:
    668     struct Impl;
    669     Impl* p;
    670 };
    671 
    672 
    673 CV_EXPORTS MatAllocator* getOpenCLAllocator();
    674 
    675 
    676 #ifdef __OPENCV_BUILD
    677 namespace internal {
    678 
    679 CV_EXPORTS bool isPerformanceCheckBypassed();
    680 #define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition))
    681 
    682 CV_EXPORTS bool isCLBuffer(UMat& u);
    683 
    684 } // namespace internal
    685 #endif
    686 
    687 //! @}
    688 
    689 }}
    690 
    691 #endif
    692