Merge pull request #1824 from vpisarev:ocl_experiments5
This commit is contained in:
@@ -347,6 +347,10 @@ CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
|
||||
CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
||||
CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
//! computes per-element minimum of two arrays (dst = min(src1, src2))
|
||||
CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst);
|
||||
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
||||
CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst);
|
||||
|
||||
//! computes square root of each matrix element (dst = src**0.5)
|
||||
CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
|
||||
|
@@ -58,6 +58,8 @@ namespace cv
|
||||
enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25,
|
||||
ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 };
|
||||
|
||||
class CV_EXPORTS _OutputArray;
|
||||
|
||||
//////////////////////// Input/Output Array Arguments /////////////////////////////////
|
||||
|
||||
/*!
|
||||
@@ -116,12 +118,22 @@ public:
|
||||
void* getObj() const;
|
||||
|
||||
virtual int kind() const;
|
||||
virtual int dims(int i=-1) const;
|
||||
virtual Size size(int i=-1) const;
|
||||
virtual int sizend(int* sz, int i=-1) const;
|
||||
virtual bool sameSize(const _InputArray& arr) const;
|
||||
virtual size_t total(int i=-1) const;
|
||||
virtual int type(int i=-1) const;
|
||||
virtual int depth(int i=-1) const;
|
||||
virtual int channels(int i=-1) const;
|
||||
virtual bool isContinuous(int i=-1) const;
|
||||
virtual bool empty() const;
|
||||
virtual void copyTo(const _OutputArray& arr) const;
|
||||
bool isMat() const;
|
||||
bool isUMat() const;
|
||||
bool isMatVectot() const;
|
||||
bool isUMatVector() const;
|
||||
bool isMatx();
|
||||
|
||||
virtual ~_InputArray();
|
||||
|
||||
@@ -197,8 +209,10 @@ public:
|
||||
virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void createSameSize(const _InputArray& arr, int mtype) const;
|
||||
virtual void release() const;
|
||||
virtual void clear() const;
|
||||
virtual void setTo(const _InputArray& value) const;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -108,6 +108,12 @@ inline _InputArray::_InputArray(const cuda::CudaMem& cuda_mem)
|
||||
|
||||
inline _InputArray::~_InputArray() {}
|
||||
|
||||
inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
|
||||
inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; }
|
||||
inline bool _InputArray::isMatVectot() const { return kind() == _InputArray::STD_VECTOR_MAT; }
|
||||
inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; }
|
||||
inline bool _InputArray::isMatx() { return kind() == _InputArray::MATX; }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); }
|
||||
|
@@ -49,13 +49,13 @@ namespace cv { namespace ocl {
|
||||
CV_EXPORTS bool haveOpenCL();
|
||||
CV_EXPORTS bool useOpenCL();
|
||||
CV_EXPORTS void setUseOpenCL(bool flag);
|
||||
CV_EXPORTS void finish();
|
||||
CV_EXPORTS void finish2();
|
||||
|
||||
class CV_EXPORTS Context;
|
||||
class CV_EXPORTS Context2;
|
||||
class CV_EXPORTS Device;
|
||||
class CV_EXPORTS Kernel;
|
||||
class CV_EXPORTS Program;
|
||||
class CV_EXPORTS ProgramSource;
|
||||
class CV_EXPORTS ProgramSource2;
|
||||
class CV_EXPORTS Queue;
|
||||
|
||||
class CV_EXPORTS Device
|
||||
@@ -199,22 +199,22 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Context
|
||||
class CV_EXPORTS Context2
|
||||
{
|
||||
public:
|
||||
Context();
|
||||
explicit Context(int dtype);
|
||||
~Context();
|
||||
Context(const Context& c);
|
||||
Context& operator = (const Context& c);
|
||||
Context2();
|
||||
explicit Context2(int dtype);
|
||||
~Context2();
|
||||
Context2(const Context2& c);
|
||||
Context2& operator = (const Context2& c);
|
||||
|
||||
bool create(int dtype);
|
||||
size_t ndevices() const;
|
||||
const Device& device(size_t idx) const;
|
||||
Program getProg(const ProgramSource& prog,
|
||||
Program getProg(const ProgramSource2& prog,
|
||||
const String& buildopt, String& errmsg);
|
||||
|
||||
static Context& getDefault();
|
||||
static Context2& getDefault();
|
||||
void* ptr() const;
|
||||
protected:
|
||||
struct Impl;
|
||||
@@ -226,12 +226,12 @@ class CV_EXPORTS Queue
|
||||
{
|
||||
public:
|
||||
Queue();
|
||||
explicit Queue(const Context& c, const Device& d=Device());
|
||||
explicit Queue(const Context2& c, const Device& d=Device());
|
||||
~Queue();
|
||||
Queue(const Queue& q);
|
||||
Queue& operator = (const Queue& q);
|
||||
|
||||
bool create(const Context& c=Context(), const Device& d=Device());
|
||||
bool create(const Context2& c=Context2(), const Device& d=Device());
|
||||
void finish();
|
||||
void* ptr() const;
|
||||
static Queue& getDefault();
|
||||
@@ -245,41 +245,55 @@ protected:
|
||||
class CV_EXPORTS KernelArg
|
||||
{
|
||||
public:
|
||||
enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8 };
|
||||
KernelArg(int _flags, UMat* _m, void* _obj=0, size_t _sz=0);
|
||||
enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, NO_SIZE=256 };
|
||||
KernelArg(int _flags, UMat* _m, int wscale=1, const void* _obj=0, size_t _sz=0);
|
||||
KernelArg();
|
||||
|
||||
static KernelArg Local() { return KernelArg(LOCAL, 0); }
|
||||
static KernelArg ReadOnly(const UMat& m) { return KernelArg(READ_ONLY, (UMat*)&m); }
|
||||
static KernelArg WriteOnly(const UMat& m) { return KernelArg(WRITE_ONLY, (UMat*)&m); }
|
||||
static KernelArg ReadWrite(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(READ_WRITE, (UMat*)&m, wscale); }
|
||||
static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale); }
|
||||
static KernelArg ReadOnly(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(READ_ONLY, (UMat*)&m, wscale); }
|
||||
static KernelArg WriteOnly(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(WRITE_ONLY, (UMat*)&m, wscale); }
|
||||
static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale); }
|
||||
static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1)
|
||||
{ return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale); }
|
||||
static KernelArg Constant(const Mat& m);
|
||||
template<typename _Tp> static KernelArg Constant(const _Tp* arr, size_t n)
|
||||
{ return KernelArg(CONSTANT, 0, (void*)arr, n); }
|
||||
{ return KernelArg(CONSTANT, 0, 1, (void*)arr, n); }
|
||||
|
||||
int flags;
|
||||
UMat* m;
|
||||
void* obj;
|
||||
const void* obj;
|
||||
size_t sz;
|
||||
int wscale;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Kernel
|
||||
{
|
||||
public:
|
||||
Kernel();
|
||||
Kernel(const char* kname, const Program& prog);
|
||||
Kernel(const char* kname, const ProgramSource& prog,
|
||||
const String& buildopts, String& errmsg);
|
||||
Kernel(const char* kname, const ProgramSource2& prog,
|
||||
const String& buildopts, String* errmsg=0);
|
||||
~Kernel();
|
||||
Kernel(const Kernel& k);
|
||||
Kernel& operator = (const Kernel& k);
|
||||
|
||||
bool empty() const;
|
||||
bool create(const char* kname, const Program& prog);
|
||||
bool create(const char* kname, const ProgramSource& prog,
|
||||
const String& buildopts, String& errmsg);
|
||||
bool create(const char* kname, const ProgramSource2& prog,
|
||||
const String& buildopts, String* errmsg=0);
|
||||
|
||||
void set(int i, const void* value, size_t sz);
|
||||
void set(int i, const UMat& m);
|
||||
void set(int i, const KernelArg& arg);
|
||||
template<typename _Tp> void set(int i, const _Tp& value)
|
||||
int set(int i, const void* value, size_t sz);
|
||||
int set(int i, const UMat& m);
|
||||
int set(int i, const KernelArg& arg);
|
||||
template<typename _Tp> int set(int i, const _Tp& value)
|
||||
{ return set(i, &value, sizeof(value)); }
|
||||
|
||||
template<typename _Tp0>
|
||||
@@ -291,26 +305,27 @@ public:
|
||||
template<typename _Tp0, typename _Tp1>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1)
|
||||
{
|
||||
set(0, a0); set(1, a1); return *this;
|
||||
int i = set(0, a0); set(i, a1); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); return *this;
|
||||
int i = set(0, a0); i = set(i, a1); set(i, a2); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); return *this;
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
|
||||
const _Tp3& a3, const _Tp4& a4)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); set(4, a4); return *this;
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2);
|
||||
i = set(i, a3); set(i, a4); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2,
|
||||
@@ -318,8 +333,8 @@ public:
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
|
||||
const _Tp3& a3, const _Tp4& a4, const _Tp5& a5)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2);
|
||||
set(3, a3); set(4, a4); set(5, a5); return *this;
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2);
|
||||
i = set(i, a3); i = set(i, a4); set(i, a5); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
@@ -327,8 +342,8 @@ public:
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3);
|
||||
set(4, a4); set(5, a5); set(6, a6); return *this;
|
||||
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); set(i, a6); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
@@ -336,8 +351,8 @@ public:
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3);
|
||||
set(4, a4); set(5, a5); set(6, a6); set(7, a7); return *this;
|
||||
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); i = set(i, a6); set(i, a7); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
|
||||
@@ -346,8 +361,8 @@ public:
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); set(4, a4);
|
||||
set(5, a5); set(6, a6); set(7, a7); set(8, a8); return *this;
|
||||
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); i = set(i, a6); i = set(i, a7); set(i, a8); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
|
||||
@@ -356,8 +371,8 @@ public:
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); set(4, a4); set(5, a5);
|
||||
set(6, a6); set(7, a7); set(8, a8); set(9, a9); return *this;
|
||||
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);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
@@ -367,8 +382,8 @@ public:
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); set(4, a4); set(5, a5);
|
||||
set(6, a6); set(7, a7); set(8, a8); set(9, a9); set(10, a10); return *this;
|
||||
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);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
@@ -378,13 +393,13 @@ public:
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11)
|
||||
{
|
||||
set(0, a0); set(1, a1); set(2, a2); set(3, a3); set(4, a4); set(5, a5);
|
||||
set(6, a6); set(7, a7); set(8, a8); set(9, a9); set(10, a10); set(11, a11); return *this;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
void run(int dims, size_t offset[], size_t globalsize[],
|
||||
bool run(int dims, size_t globalsize[],
|
||||
size_t localsize[], bool sync, const Queue& q=Queue());
|
||||
void runTask(bool sync, const Queue& q=Queue());
|
||||
bool runTask(bool sync, const Queue& q=Queue());
|
||||
|
||||
size_t workGroupSize() const;
|
||||
bool compileWorkGroupSize(size_t wsz[]) const;
|
||||
@@ -401,7 +416,7 @@ class CV_EXPORTS Program
|
||||
{
|
||||
public:
|
||||
Program();
|
||||
Program(const ProgramSource& src,
|
||||
Program(const ProgramSource2& src,
|
||||
const String& buildflags, String& errmsg);
|
||||
explicit Program(const String& buf);
|
||||
Program(const Program& prog);
|
||||
@@ -409,12 +424,12 @@ public:
|
||||
Program& operator = (const Program& prog);
|
||||
~Program();
|
||||
|
||||
bool create(const ProgramSource& src,
|
||||
bool create(const ProgramSource2& src,
|
||||
const String& buildflags, String& errmsg);
|
||||
bool read(const String& buf, const String& buildflags);
|
||||
bool write(String& buf) const;
|
||||
|
||||
const ProgramSource& source() const;
|
||||
const ProgramSource2& source() const;
|
||||
void* ptr() const;
|
||||
|
||||
String getPrefix() const;
|
||||
@@ -426,17 +441,17 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS ProgramSource
|
||||
class CV_EXPORTS ProgramSource2
|
||||
{
|
||||
public:
|
||||
typedef uint64 hash_t;
|
||||
|
||||
ProgramSource();
|
||||
explicit ProgramSource(const String& prog);
|
||||
explicit ProgramSource(const char* prog);
|
||||
~ProgramSource();
|
||||
ProgramSource(const ProgramSource& prog);
|
||||
ProgramSource& operator = (const ProgramSource& prog);
|
||||
ProgramSource2();
|
||||
explicit ProgramSource2(const String& prog);
|
||||
explicit ProgramSource2(const char* prog);
|
||||
~ProgramSource2();
|
||||
ProgramSource2(const ProgramSource2& prog);
|
||||
ProgramSource2& operator = (const ProgramSource2& prog);
|
||||
|
||||
const String& source() const;
|
||||
hash_t hash() const;
|
||||
@@ -446,6 +461,10 @@ protected:
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf);
|
||||
CV_EXPORTS const char* typeToStr(int t);
|
||||
CV_EXPORTS const char* memopTypeToStr(int t);
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
60
modules/core/include/opencv2/core/ocl_genbase.hpp
Normal file
60
modules/core/include/opencv2/core/ocl_genbase.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OPENCL_GENBASE_HPP__
|
||||
#define __OPENCV_OPENCL_GENBASE_HPP__
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
{
|
||||
|
||||
struct ProgramEntry
|
||||
{
|
||||
const char* name;
|
||||
const char* programStr;
|
||||
const char* programHash;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user