Merge pull request #2250 from ilya-lavrenov:tapi_renaming

This commit is contained in:
Andrey Pavlenko 2014-02-05 09:27:06 +04:00 committed by OpenCV Buildbot
commit 055f41c92a
15 changed files with 169 additions and 293 deletions

View File

@ -65,8 +65,8 @@ foreach(cl ${cl_list})
set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n") set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n") set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
if(new_mode) if(new_mode)
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource2 ${cl_filename}_oclsrc(${cl_filename}.programStr);\n") set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource2 ${cl_filename}_oclsrc;\n") set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
endif() endif()
set(STR_CPP "${STR_CPP}${STR_CPP_DECL}") set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")

View File

@ -67,10 +67,10 @@ namespace ocl {
using namespace cv::ocl; using namespace cv::ocl;
// TODO static functions in the Context class // TODO static functions in the Context class
CV_EXPORTS Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device); CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);
CV_EXPORTS Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device); CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);
CV_EXPORTS Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex); CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);
CV_EXPORTS Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9); CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);
} // namespace cv::directx::ocl } // namespace cv::directx::ocl

View File

@ -85,10 +85,9 @@ public:
OPENGL_BUFFER = 7 << KIND_SHIFT, OPENGL_BUFFER = 7 << KIND_SHIFT,
CUDA_MEM = 8 << KIND_SHIFT, CUDA_MEM = 8 << KIND_SHIFT,
GPU_MAT = 9 << KIND_SHIFT, GPU_MAT = 9 << KIND_SHIFT,
OCL_MAT =10 << KIND_SHIFT, UMAT =10 << KIND_SHIFT,
UMAT =11 << KIND_SHIFT, STD_VECTOR_UMAT =11 << KIND_SHIFT,
STD_VECTOR_UMAT =12 << KIND_SHIFT, UEXPR =12 << KIND_SHIFT
UEXPR =13 << KIND_SHIFT
}; };
_InputArray(); _InputArray();

View File

@ -51,15 +51,15 @@ CV_EXPORTS bool useOpenCL();
CV_EXPORTS bool haveAmdBlas(); CV_EXPORTS bool haveAmdBlas();
CV_EXPORTS bool haveAmdFft(); CV_EXPORTS bool haveAmdFft();
CV_EXPORTS void setUseOpenCL(bool flag); CV_EXPORTS void setUseOpenCL(bool flag);
CV_EXPORTS void finish2(); CV_EXPORTS void finish();
class CV_EXPORTS Context2; class CV_EXPORTS Context;
class CV_EXPORTS Device; class CV_EXPORTS Device;
class CV_EXPORTS Kernel; class CV_EXPORTS Kernel;
class CV_EXPORTS Program; class CV_EXPORTS Program;
class CV_EXPORTS ProgramSource2; class CV_EXPORTS ProgramSource;
class CV_EXPORTS Queue; class CV_EXPORTS Queue;
class CV_EXPORTS PlatformInfo2; class CV_EXPORTS PlatformInfo;
class CV_EXPORTS Image2D; class CV_EXPORTS Image2D;
class CV_EXPORTS Device class CV_EXPORTS Device
@ -206,26 +206,26 @@ protected:
}; };
class CV_EXPORTS Context2 class CV_EXPORTS Context
{ {
public: public:
Context2(); Context();
explicit Context2(int dtype); explicit Context(int dtype);
~Context2(); ~Context();
Context2(const Context2& c); Context(const Context& c);
Context2& operator = (const Context2& c); Context& operator = (const Context& c);
bool create(); bool create();
bool create(int dtype); bool create(int dtype);
size_t ndevices() const; size_t ndevices() const;
const Device& device(size_t idx) const; const Device& device(size_t idx) const;
Program getProg(const ProgramSource2& prog, Program getProg(const ProgramSource& prog,
const String& buildopt, String& errmsg); const String& buildopt, String& errmsg);
static Context2& getDefault(bool initialize = true); static Context& getDefault(bool initialize = true);
void* ptr() const; void* ptr() const;
friend void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device); friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
protected: protected:
struct Impl; struct Impl;
Impl* p; Impl* p;
@ -242,25 +242,25 @@ public:
void* ptr() const; void* ptr() const;
static Platform& getDefault(); static Platform& getDefault();
friend void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device); friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
protected: protected:
struct Impl; struct Impl;
Impl* p; Impl* p;
}; };
// TODO Move to internal header // TODO Move to internal header
void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device); void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
class CV_EXPORTS Queue class CV_EXPORTS Queue
{ {
public: public:
Queue(); Queue();
explicit Queue(const Context2& c, const Device& d=Device()); explicit Queue(const Context& c, const Device& d=Device());
~Queue(); ~Queue();
Queue(const Queue& q); Queue(const Queue& q);
Queue& operator = (const Queue& q); Queue& operator = (const Queue& q);
bool create(const Context2& c=Context2(), const Device& d=Device()); bool create(const Context& c=Context(), const Device& d=Device());
void finish(); void finish();
void* ptr() const; void* ptr() const;
static Queue& getDefault(); static Queue& getDefault();
@ -314,7 +314,7 @@ class CV_EXPORTS Kernel
public: public:
Kernel(); Kernel();
Kernel(const char* kname, const Program& prog); Kernel(const char* kname, const Program& prog);
Kernel(const char* kname, const ProgramSource2& prog, Kernel(const char* kname, const ProgramSource& prog,
const String& buildopts = String(), String* errmsg=0); const String& buildopts = String(), String* errmsg=0);
~Kernel(); ~Kernel();
Kernel(const Kernel& k); Kernel(const Kernel& k);
@ -322,7 +322,7 @@ public:
bool empty() const; bool empty() const;
bool create(const char* kname, const Program& prog); bool create(const char* kname, const Program& prog);
bool create(const char* kname, const ProgramSource2& prog, bool create(const char* kname, const ProgramSource& prog,
const String& buildopts, String* errmsg=0); const String& buildopts, String* errmsg=0);
int set(int i, const void* value, size_t sz); int set(int i, const void* value, size_t sz);
@ -508,7 +508,7 @@ class CV_EXPORTS Program
{ {
public: public:
Program(); Program();
Program(const ProgramSource2& src, Program(const ProgramSource& src,
const String& buildflags, String& errmsg); const String& buildflags, String& errmsg);
explicit Program(const String& buf); explicit Program(const String& buf);
Program(const Program& prog); Program(const Program& prog);
@ -516,12 +516,12 @@ public:
Program& operator = (const Program& prog); Program& operator = (const Program& prog);
~Program(); ~Program();
bool create(const ProgramSource2& src, bool create(const ProgramSource& src,
const String& buildflags, String& errmsg); const String& buildflags, String& errmsg);
bool read(const String& buf, const String& buildflags); bool read(const String& buf, const String& buildflags);
bool write(String& buf) const; bool write(String& buf) const;
const ProgramSource2& source() const; const ProgramSource& source() const;
void* ptr() const; void* ptr() const;
String getPrefix() const; String getPrefix() const;
@ -533,17 +533,17 @@ protected:
}; };
class CV_EXPORTS ProgramSource2 class CV_EXPORTS ProgramSource
{ {
public: public:
typedef uint64 hash_t; typedef uint64 hash_t;
ProgramSource2(); ProgramSource();
explicit ProgramSource2(const String& prog); explicit ProgramSource(const String& prog);
explicit ProgramSource2(const char* prog); explicit ProgramSource(const char* prog);
~ProgramSource2(); ~ProgramSource();
ProgramSource2(const ProgramSource2& prog); ProgramSource(const ProgramSource& prog);
ProgramSource2& operator = (const ProgramSource2& prog); ProgramSource& operator = (const ProgramSource& prog);
const String& source() const; const String& source() const;
hash_t hash() const; hash_t hash() const;
@ -553,15 +553,15 @@ protected:
Impl* p; Impl* p;
}; };
class CV_EXPORTS PlatformInfo2 class CV_EXPORTS PlatformInfo
{ {
public: public:
PlatformInfo2(); PlatformInfo();
explicit PlatformInfo2(void* id); explicit PlatformInfo(void* id);
~PlatformInfo2(); ~PlatformInfo();
PlatformInfo2(const PlatformInfo2& i); PlatformInfo(const PlatformInfo& i);
PlatformInfo2& operator =(const PlatformInfo2& i); PlatformInfo& operator =(const PlatformInfo& i);
String name() const; String name() const;
String vendor() const; String vendor() const;
@ -578,7 +578,7 @@ CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf)
CV_EXPORTS const char* typeToStr(int t); CV_EXPORTS const char* typeToStr(int t);
CV_EXPORTS const char* memopTypeToStr(int t); CV_EXPORTS const char* memopTypeToStr(int t);
CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1); CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1);
CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo2>& platform_info); CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
class CV_EXPORTS Image2D class CV_EXPORTS Image2D
{ {

View File

@ -236,7 +236,7 @@ namespace ocl {
static bool g_isDirect3DDevice9Ex = false; // Direct3DDevice9Ex or Direct3DDevice9 was used static bool g_isDirect3DDevice9Ex = false; // Direct3DDevice9Ex or Direct3DDevice9 was used
#endif #endif
Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device) Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
{ {
(void)pD3D11Device; (void)pD3D11Device;
#if !defined(HAVE_DIRECTX) #if !defined(HAVE_DIRECTX)
@ -338,13 +338,13 @@ Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
} }
Context2& ctx = Context2::getDefault(false); Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device); initializeContextFromHandle(ctx, platforms[found], context, device);
return ctx; return ctx;
#endif #endif
} }
Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device) Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
{ {
(void)pD3D10Device; (void)pD3D10Device;
#if !defined(HAVE_DIRECTX) #if !defined(HAVE_DIRECTX)
@ -446,13 +446,13 @@ Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
} }
Context2& ctx = Context2::getDefault(false); Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device); initializeContextFromHandle(ctx, platforms[found], context, device);
return ctx; return ctx;
#endif #endif
} }
Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex) Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex)
{ {
(void)pDirect3DDevice9Ex; (void)pDirect3DDevice9Ex;
#if !defined(HAVE_DIRECTX) #if !defined(HAVE_DIRECTX)
@ -555,14 +555,14 @@ Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDe
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop"); CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop");
} }
Context2& ctx = Context2::getDefault(false); Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device); initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = true; g_isDirect3DDevice9Ex = true;
return ctx; return ctx;
#endif #endif
} }
Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9) Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9)
{ {
(void)pDirect3DDevice9; (void)pDirect3DDevice9;
#if !defined(HAVE_DIRECTX) #if !defined(HAVE_DIRECTX)
@ -665,7 +665,7 @@ Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop"); CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop");
} }
Context2& ctx = Context2::getDefault(false); Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device); initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = false; g_isDirect3DDevice9Ex = false;
return ctx; return ctx;
@ -720,7 +720,7 @@ void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D)
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height); CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat(); UMat u = src.getUMat();
@ -777,7 +777,7 @@ void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst
CV_Assert(textureType >= 0); CV_Assert(textureType >= 0);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying! // TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
@ -868,7 +868,7 @@ void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D)
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height); CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat(); UMat u = src.getUMat();
@ -925,7 +925,7 @@ void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst
CV_Assert(textureType >= 0); CV_Assert(textureType >= 0);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying! // TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
@ -1019,7 +1019,7 @@ void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurfa
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height); CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat(); UMat u = src.getUMat();
@ -1083,7 +1083,7 @@ void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArr
CV_Assert(surfaceType >= 0); CV_Assert(surfaceType >= 0);
using namespace cv::ocl; using namespace cv::ocl;
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr(); cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying! // TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!

View File

@ -1545,7 +1545,7 @@ class PlanCache
clStridesOut[2] = dft_rows ? clStridesOut[1] : dft_size.width * clStridesOut[1]; clStridesOut[2] = dft_rows ? clStridesOut[1] : dft_size.width * clStridesOut[1];
// TODO remove all plans if context changed // TODO remove all plans if context changed
CLAMDDFT_Assert(clAmdFftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context2::getDefault().ptr(), dim, clLengthsIn)) CLAMDDFT_Assert(clAmdFftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context::getDefault().ptr(), dim, clLengthsIn))
// setting plan properties // setting plan properties
CLAMDDFT_Assert(clAmdFftSetPlanPrecision(plHandle, doubleFP ? CLFFT_DOUBLE : CLFFT_SINGLE)); CLAMDDFT_Assert(clAmdFftSetPlanPrecision(plHandle, doubleFP ? CLFFT_DOUBLE : CLFFT_SINGLE));
@ -1560,8 +1560,8 @@ class PlanCache
CLAMDDFT_Assert(clAmdFftSetPlanScale(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, scale)) CLAMDDFT_Assert(clAmdFftSetPlanScale(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, scale))
// ready to bake // ready to bake
cl_command_queue commandQueue = (cl_command_queue)ocl::Queue::getDefault().ptr(); cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &commandQueue, NULL, NULL)) CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &queue, NULL, NULL))
} }
~FftPlan() ~FftPlan()
@ -1593,7 +1593,7 @@ public:
clAmdFftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP, clAmdFftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP,
bool inplace, int flags, FftType fftType) bool inplace, int flags, FftType fftType)
{ {
cl_context currentContext = (cl_context)ocl::Context2::getDefault().ptr(); cl_context currentContext = (cl_context)ocl::Context::getDefault().ptr();
for (size_t i = 0, size = planStorage.size(); i < size; i ++) for (size_t i = 0, size = planStorage.size(); i < size; i ++)
{ {
@ -1704,11 +1704,11 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags)
cl_mem srcarg = (cl_mem)src.handle(ACCESS_READ); cl_mem srcarg = (cl_mem)src.handle(ACCESS_READ);
cl_mem dstarg = (cl_mem)dst.handle(ACCESS_RW); cl_mem dstarg = (cl_mem)dst.handle(ACCESS_RW);
cl_command_queue commandQueue = (cl_command_queue)ocl::Queue::getDefault().ptr(); cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
cl_event e = 0; cl_event e = 0;
CLAMDDFT_Assert(clAmdFftEnqueueTransform(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, CLAMDDFT_Assert(clAmdFftEnqueueTransform(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD,
1, &commandQueue, 0, NULL, &e, 1, &queue, 0, NULL, &e,
&srcarg, &dstarg, (cl_mem)tmpBuffer.handle(ACCESS_RW))) &srcarg, &dstarg, (cl_mem)tmpBuffer.handle(ACCESS_RW)))
tmpBuffer.addref(); tmpBuffer.addref();

View File

@ -1495,11 +1495,6 @@ Size _InputArray::size(int i) const
return d_mat->size(); return d_mat->size();
} }
if( k == OCL_MAT )
{
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet");
}
CV_Assert( k == CUDA_MEM ); CV_Assert( k == CUDA_MEM );
//if( k == CUDA_MEM ) //if( k == CUDA_MEM )
{ {
@ -1679,11 +1674,6 @@ int _InputArray::dims(int i) const
return 2; return 2;
} }
if( k == OCL_MAT )
{
return 2;
}
CV_Assert( k == CUDA_MEM ); CV_Assert( k == CUDA_MEM );
//if( k == CUDA_MEM ) //if( k == CUDA_MEM )
{ {
@ -1841,11 +1831,6 @@ bool _InputArray::empty() const
if( k == OPENGL_BUFFER ) if( k == OPENGL_BUFFER )
return ((const ogl::Buffer*)obj)->empty(); return ((const ogl::Buffer*)obj)->empty();
if( k == OCL_MAT )
{
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet");
}
if( k == GPU_MAT ) if( k == GPU_MAT )
return ((const cuda::GpuMat*)obj)->empty(); return ((const cuda::GpuMat*)obj)->empty();
@ -1881,7 +1866,7 @@ bool _InputArray::isContinuous(int i) const
return vv[i].isContinuous(); return vv[i].isContinuous();
} }
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet"); CV_Error(CV_StsNotImplemented, "Unknown/unsupported array type");
return false; return false;
} }

View File

@ -1572,7 +1572,7 @@ bool haveAmdFft()
#endif #endif
void finish2() void finish()
{ {
Queue::getDefault().finish(); Queue::getDefault().finish();
} }
@ -2025,7 +2025,7 @@ size_t Device::profilingTimerResolution() const
const Device& Device::getDefault() const Device& Device::getDefault()
{ {
const Context2& ctx = Context2::getDefault(); const Context& ctx = Context::getDefault();
int idx = coreTlsData.get()->device; int idx = coreTlsData.get()->device;
return ctx.device(idx); return ctx.device(idx);
} }
@ -2230,7 +2230,7 @@ not_found:
return NULL; return NULL;
} }
struct Context2::Impl struct Context::Impl
{ {
Impl() Impl()
{ {
@ -2337,7 +2337,7 @@ struct Context2::Impl
devices.clear(); devices.clear();
} }
Program getProg(const ProgramSource2& src, Program getProg(const ProgramSource& src,
const String& buildflags, String& errmsg) const String& buildflags, String& errmsg)
{ {
String prefix = Program::getPrefix(buildflags); String prefix = Program::getPrefix(buildflags);
@ -2357,7 +2357,7 @@ struct Context2::Impl
cl_context handle; cl_context handle;
std::vector<Device> devices; std::vector<Device> devices;
typedef ProgramSource2::hash_t hash_t; typedef ProgramSource::hash_t hash_t;
struct HashKey struct HashKey
{ {
@ -2372,18 +2372,18 @@ struct Context2::Impl
}; };
Context2::Context2() Context::Context()
{ {
p = 0; p = 0;
} }
Context2::Context2(int dtype) Context::Context(int dtype)
{ {
p = 0; p = 0;
create(dtype); create(dtype);
} }
bool Context2::create() bool Context::create()
{ {
if( !haveOpenCL() ) if( !haveOpenCL() )
return false; return false;
@ -2398,7 +2398,7 @@ bool Context2::create()
return p != 0; return p != 0;
} }
bool Context2::create(int dtype0) bool Context::create(int dtype0)
{ {
if( !haveOpenCL() ) if( !haveOpenCL() )
return false; return false;
@ -2413,7 +2413,7 @@ bool Context2::create(int dtype0)
return p != 0; return p != 0;
} }
Context2::~Context2() Context::~Context()
{ {
if (p) if (p)
{ {
@ -2422,14 +2422,14 @@ Context2::~Context2()
} }
} }
Context2::Context2(const Context2& c) Context::Context(const Context& c)
{ {
p = (Impl*)c.p; p = (Impl*)c.p;
if(p) if(p)
p->addref(); p->addref();
} }
Context2& Context2::operator = (const Context2& c) Context& Context::operator = (const Context& c)
{ {
Impl* newp = (Impl*)c.p; Impl* newp = (Impl*)c.p;
if(newp) if(newp)
@ -2440,34 +2440,34 @@ Context2& Context2::operator = (const Context2& c)
return *this; return *this;
} }
void* Context2::ptr() const void* Context::ptr() const
{ {
return p == NULL ? NULL : p->handle; return p == NULL ? NULL : p->handle;
} }
size_t Context2::ndevices() const size_t Context::ndevices() const
{ {
return p ? p->devices.size() : 0; return p ? p->devices.size() : 0;
} }
const Device& Context2::device(size_t idx) const const Device& Context::device(size_t idx) const
{ {
static Device dummy; static Device dummy;
return !p || idx >= p->devices.size() ? dummy : p->devices[idx]; return !p || idx >= p->devices.size() ? dummy : p->devices[idx];
} }
Context2& Context2::getDefault(bool initialize) Context& Context::getDefault(bool initialize)
{ {
static Context2 ctx; static Context ctx;
if(!ctx.p && haveOpenCL()) if(!ctx.p && haveOpenCL())
{ {
if (!ctx.p) if (!ctx.p)
ctx.p = new Impl(); ctx.p = new Impl();
if (initialize) if (initialize)
{ {
// do not create new Context2 right away. // do not create new Context right away.
// First, try to retrieve existing context of the same type. // First, try to retrieve existing context of the same type.
// In its turn, Platform::getContext() may call Context2::create() // In its turn, Platform::getContext() may call Context::create()
// if there is no such context. // if there is no such context.
if (ctx.p->handle == NULL) if (ctx.p->handle == NULL)
ctx.p->setDefault(); ctx.p->setDefault();
@ -2477,19 +2477,19 @@ Context2& Context2::getDefault(bool initialize)
return ctx; return ctx;
} }
Program Context2::getProg(const ProgramSource2& prog, Program Context::getProg(const ProgramSource& prog,
const String& buildopts, String& errmsg) const String& buildopts, String& errmsg)
{ {
return p ? p->getProg(prog, buildopts, errmsg) : Program(); return p ? p->getProg(prog, buildopts, errmsg) : Program();
} }
void initializeContextFromHandle(Context2& ctx, void* platform, void* _context, void* _device) void initializeContextFromHandle(Context& ctx, void* platform, void* _context, void* _device)
{ {
cl_context context = (cl_context)_context; cl_context context = (cl_context)_context;
cl_device_id device = (cl_device_id)_device; cl_device_id device = (cl_device_id)_device;
// cleanup old context // cleanup old context
Context2::Impl * impl = ctx.p; Context::Impl * impl = ctx.p;
if (impl->handle) if (impl->handle)
{ {
CV_OclDbgAssert(clReleaseContext(impl->handle) == CL_SUCCESS); CV_OclDbgAssert(clReleaseContext(impl->handle) == CL_SUCCESS);
@ -2509,14 +2509,14 @@ void initializeContextFromHandle(Context2& ctx, void* platform, void* _context,
struct Queue::Impl struct Queue::Impl
{ {
Impl(const Context2& c, const Device& d) Impl(const Context& c, const Device& d)
{ {
refcount = 1; refcount = 1;
const Context2* pc = &c; const Context* pc = &c;
cl_context ch = (cl_context)pc->ptr(); cl_context ch = (cl_context)pc->ptr();
if( !ch ) if( !ch )
{ {
pc = &Context2::getDefault(); pc = &Context::getDefault();
ch = (cl_context)pc->ptr(); ch = (cl_context)pc->ptr();
} }
cl_device_id dh = (cl_device_id)d.ptr(); cl_device_id dh = (cl_device_id)d.ptr();
@ -2553,7 +2553,7 @@ Queue::Queue()
p = 0; p = 0;
} }
Queue::Queue(const Context2& c, const Device& d) Queue::Queue(const Context& c, const Device& d)
{ {
p = 0; p = 0;
create(c, d); create(c, d);
@ -2583,7 +2583,7 @@ Queue::~Queue()
p->release(); p->release();
} }
bool Queue::create(const Context2& c, const Device& d) bool Queue::create(const Context& c, const Device& d)
{ {
if(p) if(p)
p->release(); p->release();
@ -2608,7 +2608,7 @@ Queue& Queue::getDefault()
{ {
Queue& q = coreTlsData.get()->oclQueue; Queue& q = coreTlsData.get()->oclQueue;
if( !q.p && haveOpenCL() ) if( !q.p && haveOpenCL() )
q.create(Context2::getDefault()); q.create(Context::getDefault());
return q; return q;
} }
@ -2725,7 +2725,7 @@ Kernel::Kernel(const char* kname, const Program& prog)
create(kname, prog); create(kname, prog);
} }
Kernel::Kernel(const char* kname, const ProgramSource2& src, Kernel::Kernel(const char* kname, const ProgramSource& src,
const String& buildopts, String* errmsg) const String& buildopts, String* errmsg)
{ {
p = 0; p = 0;
@ -2769,7 +2769,7 @@ bool Kernel::create(const char* kname, const Program& prog)
return p != 0; return p != 0;
} }
bool Kernel::create(const char* kname, const ProgramSource2& src, bool Kernel::create(const char* kname, const ProgramSource& src,
const String& buildopts, String* errmsg) const String& buildopts, String* errmsg)
{ {
if(p) if(p)
@ -2779,7 +2779,7 @@ bool Kernel::create(const char* kname, const ProgramSource2& src,
} }
String tempmsg; String tempmsg;
if( !errmsg ) errmsg = &tempmsg; if( !errmsg ) errmsg = &tempmsg;
const Program& prog = Context2::getDefault().getProg(src, buildopts, *errmsg); const Program& prog = Context::getDefault().getProg(src, buildopts, *errmsg);
return create(kname, prog); return create(kname, prog);
} }
@ -2984,11 +2984,11 @@ size_t Kernel::localMemSize() const
struct Program::Impl struct Program::Impl
{ {
Impl(const ProgramSource2& _src, Impl(const ProgramSource& _src,
const String& _buildflags, String& errmsg) const String& _buildflags, String& errmsg)
{ {
refcount = 1; refcount = 1;
const Context2& ctx = Context2::getDefault(); const Context& ctx = Context::getDefault();
src = _src; src = _src;
buildflags = _buildflags; buildflags = _buildflags;
const String& srcstr = src.source(); const String& srcstr = src.source();
@ -3044,7 +3044,7 @@ struct Program::Impl
if(_buf.empty()) if(_buf.empty())
return; return;
String prefix0 = Program::getPrefix(buildflags); String prefix0 = Program::getPrefix(buildflags);
const Context2& ctx = Context2::getDefault(); const Context& ctx = Context::getDefault();
const Device& dev = Device::getDefault(); const Device& dev = Device::getDefault();
const char* pos0 = _buf.c_str(); const char* pos0 = _buf.c_str();
const char* pos1 = strchr(pos0, '\n'); const char* pos1 = strchr(pos0, '\n');
@ -3099,7 +3099,7 @@ struct Program::Impl
IMPLEMENT_REFCOUNTABLE(); IMPLEMENT_REFCOUNTABLE();
ProgramSource2 src; ProgramSource src;
String buildflags; String buildflags;
cl_program handle; cl_program handle;
}; };
@ -3107,7 +3107,7 @@ struct Program::Impl
Program::Program() { p = 0; } Program::Program() { p = 0; }
Program::Program(const ProgramSource2& src, Program::Program(const ProgramSource& src,
const String& buildflags, String& errmsg) const String& buildflags, String& errmsg)
{ {
p = 0; p = 0;
@ -3138,7 +3138,7 @@ Program::~Program()
p->release(); p->release();
} }
bool Program::create(const ProgramSource2& src, bool Program::create(const ProgramSource& src,
const String& buildflags, String& errmsg) const String& buildflags, String& errmsg)
{ {
if(p) if(p)
@ -3152,9 +3152,9 @@ bool Program::create(const ProgramSource2& src,
return p != 0; return p != 0;
} }
const ProgramSource2& Program::source() const const ProgramSource& Program::source() const
{ {
static ProgramSource2 dummy; static ProgramSource dummy;
return p ? p->src : dummy; return p ? p->src : dummy;
} }
@ -3188,15 +3188,15 @@ String Program::getPrefix() const
String Program::getPrefix(const String& buildflags) String Program::getPrefix(const String& buildflags)
{ {
const Context2& ctx = Context2::getDefault(); const Context& ctx = Context::getDefault();
const Device& dev = ctx.device(0); const Device& dev = ctx.device(0);
return format("name=%s\ndriver=%s\nbuildflags=%s\n", return format("name=%s\ndriver=%s\nbuildflags=%s\n",
dev.name().c_str(), dev.driverVersion().c_str(), buildflags.c_str()); dev.name().c_str(), dev.driverVersion().c_str(), buildflags.c_str());
} }
///////////////////////////////////////// ProgramSource2 /////////////////////////////////////////////// ///////////////////////////////////////// ProgramSource ///////////////////////////////////////////////
struct ProgramSource2::Impl struct ProgramSource::Impl
{ {
Impl(const char* _src) Impl(const char* _src)
{ {
@ -3215,39 +3215,39 @@ struct ProgramSource2::Impl
IMPLEMENT_REFCOUNTABLE(); IMPLEMENT_REFCOUNTABLE();
String src; String src;
ProgramSource2::hash_t h; ProgramSource::hash_t h;
}; };
ProgramSource2::ProgramSource2() ProgramSource::ProgramSource()
{ {
p = 0; p = 0;
} }
ProgramSource2::ProgramSource2(const char* prog) ProgramSource::ProgramSource(const char* prog)
{ {
p = new Impl(prog); p = new Impl(prog);
} }
ProgramSource2::ProgramSource2(const String& prog) ProgramSource::ProgramSource(const String& prog)
{ {
p = new Impl(prog); p = new Impl(prog);
} }
ProgramSource2::~ProgramSource2() ProgramSource::~ProgramSource()
{ {
if(p) if(p)
p->release(); p->release();
} }
ProgramSource2::ProgramSource2(const ProgramSource2& prog) ProgramSource::ProgramSource(const ProgramSource& prog)
{ {
p = prog.p; p = prog.p;
if(p) if(p)
p->addref(); p->addref();
} }
ProgramSource2& ProgramSource2::operator = (const ProgramSource2& prog) ProgramSource& ProgramSource::operator = (const ProgramSource& prog)
{ {
Impl* newp = (Impl*)prog.p; Impl* newp = (Impl*)prog.p;
if(newp) if(newp)
@ -3258,13 +3258,13 @@ ProgramSource2& ProgramSource2::operator = (const ProgramSource2& prog)
return *this; return *this;
} }
const String& ProgramSource2::source() const const String& ProgramSource::source() const
{ {
static String dummy; static String dummy;
return p ? p->src : dummy; return p ? p->src : dummy;
} }
ProgramSource2::hash_t ProgramSource2::hash() const ProgramSource::hash_t ProgramSource::hash() const
{ {
return p ? p->h : 0; return p ? p->h : 0;
} }
@ -3365,7 +3365,7 @@ protected:
{ {
CV_DbgAssert(entry.clBuffer_ == NULL); CV_DbgAssert(entry.clBuffer_ == NULL);
entry.capacity_ = alignSize(size, (int)_allocationGranularity(size)); entry.capacity_ = alignSize(size, (int)_allocationGranularity(size));
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
cl_int retval = CL_SUCCESS; cl_int retval = CL_SUCCESS;
entry.clBuffer_ = clCreateBuffer((cl_context)ctx.ptr(), CL_MEM_READ_WRITE, entry.capacity_, 0, &retval); entry.clBuffer_ = clCreateBuffer((cl_context)ctx.ptr(), CL_MEM_READ_WRITE, entry.capacity_, 0, &retval);
CV_Assert(retval == CL_SUCCESS); CV_Assert(retval == CL_SUCCESS);
@ -3482,7 +3482,7 @@ public:
return u; return u;
} }
void getBestFlags(const Context2& ctx, int /*flags*/, int& createFlags, int& flags0) const void getBestFlags(const Context& ctx, int /*flags*/, int& createFlags, int& flags0) const
{ {
const Device& dev = ctx.device(0); const Device& dev = ctx.device(0);
createFlags = CL_MEM_READ_WRITE; createFlags = CL_MEM_READ_WRITE;
@ -3507,7 +3507,7 @@ public:
total *= sizes[i]; total *= sizes[i];
} }
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
int createFlags = 0, flags0 = 0; int createFlags = 0, flags0 = 0;
getBestFlags(ctx, flags, createFlags, flags0); getBestFlags(ctx, flags, createFlags, flags0);
@ -3536,7 +3536,7 @@ public:
if(u->handle == 0) if(u->handle == 0)
{ {
CV_Assert(u->origdata != 0); CV_Assert(u->origdata != 0);
Context2& ctx = Context2::getDefault(); Context& ctx = Context::getDefault();
int createFlags = 0, flags0 = 0; int createFlags = 0, flags0 = 0;
getBestFlags(ctx, accessFlags, createFlags, flags0); getBestFlags(ctx, accessFlags, createFlags, flags0);
@ -3982,7 +3982,7 @@ static void getDevices(std::vector<cl_device_id>& devices, cl_platform_id platfo
numDevices, &devices[0], &numDevices) == CL_SUCCESS); numDevices, &devices[0], &numDevices) == CL_SUCCESS);
} }
struct PlatformInfo2::Impl struct PlatformInfo::Impl
{ {
Impl(void* id) Impl(void* id)
{ {
@ -4004,30 +4004,30 @@ struct PlatformInfo2::Impl
cl_platform_id handle; cl_platform_id handle;
}; };
PlatformInfo2::PlatformInfo2() PlatformInfo::PlatformInfo()
{ {
p = 0; p = 0;
} }
PlatformInfo2::PlatformInfo2(void* platform_id) PlatformInfo::PlatformInfo(void* platform_id)
{ {
p = new Impl(platform_id); p = new Impl(platform_id);
} }
PlatformInfo2::~PlatformInfo2() PlatformInfo::~PlatformInfo()
{ {
if(p) if(p)
p->release(); p->release();
} }
PlatformInfo2::PlatformInfo2(const PlatformInfo2& i) PlatformInfo::PlatformInfo(const PlatformInfo& i)
{ {
if (i.p) if (i.p)
i.p->addref(); i.p->addref();
p = i.p; p = i.p;
} }
PlatformInfo2& PlatformInfo2::operator =(const PlatformInfo2& i) PlatformInfo& PlatformInfo::operator =(const PlatformInfo& i)
{ {
if (i.p != p) if (i.p != p)
{ {
@ -4040,29 +4040,29 @@ PlatformInfo2& PlatformInfo2::operator =(const PlatformInfo2& i)
return *this; return *this;
} }
int PlatformInfo2::deviceNumber() const int PlatformInfo::deviceNumber() const
{ {
return p ? (int)p->devices.size() : 0; return p ? (int)p->devices.size() : 0;
} }
void PlatformInfo2::getDevice(Device& device, int d) const void PlatformInfo::getDevice(Device& device, int d) const
{ {
CV_Assert(p && d < (int)p->devices.size() ); CV_Assert(p && d < (int)p->devices.size() );
if(p) if(p)
device.set(p->devices[d]); device.set(p->devices[d]);
} }
String PlatformInfo2::name() const String PlatformInfo::name() const
{ {
return p ? p->getStrProp(CL_PLATFORM_NAME) : String(); return p ? p->getStrProp(CL_PLATFORM_NAME) : String();
} }
String PlatformInfo2::vendor() const String PlatformInfo::vendor() const
{ {
return p ? p->getStrProp(CL_PLATFORM_VENDOR) : String(); return p ? p->getStrProp(CL_PLATFORM_VENDOR) : String();
} }
String PlatformInfo2::version() const String PlatformInfo::version() const
{ {
return p ? p->getStrProp(CL_PLATFORM_VERSION) : String(); return p ? p->getStrProp(CL_PLATFORM_VERSION) : String();
} }
@ -4082,13 +4082,13 @@ static void getPlatforms(std::vector<cl_platform_id>& platforms)
CV_OclDbgAssert(clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms) == CL_SUCCESS); CV_OclDbgAssert(clGetPlatformIDs(numPlatforms, &platforms[0], &numPlatforms) == CL_SUCCESS);
} }
void getPlatfomsInfo(std::vector<PlatformInfo2>& platformsInfo) void getPlatfomsInfo(std::vector<PlatformInfo>& platformsInfo)
{ {
std::vector<cl_platform_id> platforms; std::vector<cl_platform_id> platforms;
getPlatforms(platforms); getPlatforms(platforms);
for (size_t i = 0; i < platforms.size(); i++) for (size_t i = 0; i < platforms.size(); i++)
platformsInfo.push_back( PlatformInfo2((void*)&platforms[i]) ); platformsInfo.push_back( PlatformInfo((void*)&platforms[i]) );
} }
const char* typeToStr(int type) const char* typeToStr(int type)
@ -4233,7 +4233,7 @@ struct Image2D::Impl
format.image_channel_data_type = (cl_channel_type)channelType; format.image_channel_data_type = (cl_channel_type)channelType;
format.image_channel_order = (cl_channel_order)channelOrder; format.image_channel_order = (cl_channel_order)channelOrder;
cl_context context = (cl_context)Context2::getDefault().ptr(); cl_context context = (cl_context)Context::getDefault().ptr();
cl_command_queue queue = (cl_command_queue)Queue::getDefault().ptr(); cl_command_queue queue = (cl_command_queue)Queue::getDefault().ptr();
#ifdef CL_VERSION_1_2 #ifdef CL_VERSION_1_2

View File

@ -25,7 +25,7 @@
// //
// * Redistribution's in binary form must reproduce the above copyright notice, // * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation // this list of conditions and the following disclaimer in the documentation
// and/or other oclMaterials provided with the distribution. // and/or other materials provided with the distribution.
// //
// * The name of the copyright holders may not be used to endorse or promote products // * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission. // derived from this software without specific prior written permission.

View File

@ -3900,7 +3900,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
return false; return false;
const char * const interpolationMap[3] = { "NEAREST", "LINEAR", "CUBIC" }; const char * const interpolationMap[3] = { "NEAREST", "LINEAR", "CUBIC" };
ocl::ProgramSource2 program = op_type == OCL_OP_AFFINE ? ocl::ProgramSource program = op_type == OCL_OP_AFFINE ?
ocl::imgproc::warp_affine_oclsrc : ocl::imgproc::warp_perspective_oclsrc; ocl::imgproc::warp_affine_oclsrc : ocl::imgproc::warp_perspective_oclsrc;
const char * const kernelName = op_type == OCL_OP_AFFINE ? "warpAffine" : "warpPerspective"; const char * const kernelName = op_type == OCL_OP_AFFINE ? "warpAffine" : "warpPerspective";

View File

@ -407,8 +407,7 @@ static bool ocl_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, in
{ {
int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type); int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
if (((channels != 1) && (channels != 2) && (channels != 4)) if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
|| (borderType != BORDER_DEFAULT))
return false; return false;
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
@ -425,18 +424,16 @@ static bool ocl_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, in
_dst.create( dsize, src.type() ); _dst.create( dsize, src.type() );
UMat dst = _dst.getUMat(); UMat dst = _dst.getUMat();
const char * const kernelName = "pyrDown";
ocl::ProgramSource2 program = ocl::imgproc::pyr_down_oclsrc;
ocl::Kernel k;
int float_depth = depth == CV_64F ? CV_64F : CV_32F; int float_depth = depth == CV_64F ? CV_64F : CV_32F;
char cvt[2][50]; char cvt[2][50];
k.create(kernelName, program, ocl::Kernel k("pyrDown", ocl::imgproc::pyr_down_oclsrc,
format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s", format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)), ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]), ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]), ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : "")); doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst)); k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst));
@ -449,12 +446,11 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
{ {
int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type); int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
if (((channels != 1) && (channels != 2) && (channels != 4)) if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
|| (borderType != BORDER_DEFAULT))
return false; return false;
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
if ((depth == CV_64F) && !(doubleSupport)) if (depth == CV_64F && !doubleSupport)
return false; return false;
Size ssize = _src.size(); Size ssize = _src.size();
@ -466,18 +462,16 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
_dst.create( dsize, src.type() ); _dst.create( dsize, src.type() );
UMat dst = _dst.getUMat(); UMat dst = _dst.getUMat();
const char * const kernelName = "pyrUp";
ocl::ProgramSource2 program = ocl::imgproc::pyr_up_oclsrc;
ocl::Kernel k;
int float_depth = depth == CV_64F ? CV_64F : CV_32F; int float_depth = depth == CV_64F ? CV_64F : CV_32F;
char cvt[2][50]; char cvt[2][50];
k.create(kernelName, program, ocl::Kernel k("pyrUp", ocl::imgproc::pyr_up_oclsrc,
format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s", format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)), ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]), ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]), ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : "")); doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst)); k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst));
size_t globalThreads[2] = {dst.cols, dst.rows}; size_t globalThreads[2] = {dst.cols, dst.rows};

View File

@ -119,7 +119,7 @@ CV_EXPORTS void randu(InputOutputArray dst);
inline void safeFinish() inline void safeFinish()
{ {
if (cv::ocl::useOpenCL()) if (cv::ocl::useOpenCL())
cv::ocl::finish2(); cv::ocl::finish();
} }
} // namespace perf } // namespace perf

View File

@ -98,14 +98,14 @@ void dumpOpenCLDevice()
using namespace cv::ocl; using namespace cv::ocl;
try try
{ {
std::vector<PlatformInfo2> platforms; std::vector<PlatformInfo> platforms;
cv::ocl::getPlatfomsInfo(platforms); cv::ocl::getPlatfomsInfo(platforms);
if (platforms.size() > 0) if (platforms.size() > 0)
{ {
DUMP_MESSAGE_STDOUT("OpenCL Platforms: "); DUMP_MESSAGE_STDOUT("OpenCL Platforms: ");
for (size_t i = 0; i < platforms.size(); i++) for (size_t i = 0; i < platforms.size(); i++)
{ {
const PlatformInfo2* platform = &platforms[i]; const PlatformInfo* platform = &platforms[i];
DUMP_MESSAGE_STDOUT(" " << platform->name().c_str()); DUMP_MESSAGE_STDOUT(" " << platform->name().c_str());
Device current_device; Device current_device;
for (int j = 0; j < platform->deviceNumber(); j++) for (int j = 0; j < platform->deviceNumber(); j++)

View File

@ -134,7 +134,7 @@ static void renderToD3DObject(void)
const float fps = getFps(); const float fps = getFps();
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context2::getDefault().device(0).name() : "No OpenCL device"; String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context::getDefault().device(0).name() : "No OpenCL device";
if ((frame % std::max(1, (int)(fps / 25))) == 0) if ((frame % std::max(1, (int)(fps / 25))) == 0)
{ {
@ -360,7 +360,7 @@ static cv::Mat getInputTexture()
{ {
cv::resize(inputMat, inputMat, cv::Size(WIDTH, HEIGHT)); cv::resize(inputMat, inputMat, cv::Size(WIDTH, HEIGHT));
} }
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context2::getDefault().device(0).name() : "No OpenCL device"; String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context::getDefault().device(0).name() : "No OpenCL device";
cv::Scalar color(64, 255, 64, 255); cv::Scalar color(64, 255, 64, 255);
cv::putText(inputMat, cv::putText(inputMat,
cv::format("OpenCL Device name: %s", deviceName.c_str()), cv::format("OpenCL Device name: %s", deviceName.c_str()),
@ -396,13 +396,13 @@ static int mainLoop()
if (cv::ocl::haveOpenCL()) if (cv::ocl::haveOpenCL())
{ {
#if defined(USE_D3D9) #if defined(USE_D3D9)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9(dev); cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9(dev);
#elif defined (USE_D3DEX) #elif defined (USE_D3DEX)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev); cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev);
#elif defined(USE_D3D10) #elif defined(USE_D3D10)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromD3D10Device(dev); cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D10Device(dev);
#elif defined(USE_D3D11) #elif defined(USE_D3D11)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev); cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev);
#else #else
#error "Invalid USE_D3D value" #error "Invalid USE_D3D value"
#endif #endif

View File

@ -10,14 +10,10 @@
#include "opencv2/superres/optical_flow.hpp" #include "opencv2/superres/optical_flow.hpp"
#include "opencv2/opencv_modules.hpp" #include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_OCL)
#include "opencv2/ocl/ocl.hpp"
#endif
using namespace std; using namespace std;
using namespace cv; using namespace cv;
using namespace cv::superres; using namespace cv::superres;
bool useOclChanged;
#define MEASURE_TIME(op) \ #define MEASURE_TIME(op) \
{ \ { \
TickMeter tm; \ TickMeter tm; \
@ -50,40 +46,11 @@ static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
else if (name == "pyrlk") else if (name == "pyrlk")
return createOptFlow_PyrLK_CUDA(); return createOptFlow_PyrLK_CUDA();
else else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl; cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
return Ptr<DenseOpticalFlowExt>(); return Ptr<DenseOpticalFlowExt>();
} }
#if defined(HAVE_OPENCV_OCL)
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name)
{
if (name == "farneback")
{
return createOptFlow_Farneback_OCL();
}
else if (name == "simple")
{
useOclChanged = true;
std::cout<<"simple on OpenCL has not been implemented. Use CPU instead!\n";
return createOptFlow_Simple();
}
else if (name == "tvl1")
return createOptFlow_DualTVL1_OCL();
else if (name == "brox")
{
std::cout<<"brox has not been implemented!\n";
return Ptr<DenseOpticalFlowExt>();
}
else if (name == "pyrlk")
return createOptFlow_PyrLK_OCL();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
return Ptr<DenseOpticalFlowExt>();
}
#endif
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
useOclChanged = false; useOclChanged = false;
@ -94,7 +61,7 @@ int main(int argc, const char* argv[])
"{ i iterations | 180 | Iteration count }" "{ i iterations | 180 | Iteration count }"
"{ t temporal | 4 | Radius of the temporal search area }" "{ t temporal | 4 | Radius of the temporal search area }"
"{ f flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }" "{ f flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }"
"{ g | false | CPU as default device, cuda for CUDA and ocl for OpenCL }" "{ g | false | CPU as default device, cuda for CUDA }"
"{ h help | false | Print help message }" "{ h help | false | Print help message }"
); );
@ -102,7 +69,7 @@ int main(int argc, const char* argv[])
{ {
cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl; cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl;
cmd.printMessage(); cmd.printMessage();
return 0; return EXIT_SUCCESS;
} }
const string inputVideoName = cmd.get<string>("video"); const string inputVideoName = cmd.get<string>("video");
@ -115,60 +82,19 @@ int main(int argc, const char* argv[])
std::transform(gpuOption.begin(), gpuOption.end(), gpuOption.begin(), ::tolower); std::transform(gpuOption.begin(), gpuOption.end(), gpuOption.begin(), ::tolower);
bool useCuda = false; bool useCuda = gpuOption.compare("cuda") == 0;
bool useOcl = false;
if(gpuOption.compare("ocl") == 0)
useOcl = true;
else if(gpuOption.compare("cuda") == 0)
useCuda = true;
#ifndef HAVE_OPENCV_OCL
if(useOcl)
{
{
cout<<"OPENCL is not compiled\n";
return 0;
}
}
#endif
#if defined(HAVE_OPENCV_OCL)
if(useCuda)
{
CV_Assert(!useOcl);
}
#endif
Ptr<SuperResolution> superRes; Ptr<SuperResolution> superRes;
if (useCuda)
#if defined(HAVE_OPENCV_OCL) superRes = createSuperResolution_BTVL1_CUDA();
if(useOcl)
{
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow);
if (of.empty())
exit(-1);
if(useOclChanged)
{
superRes = createSuperResolution_BTVL1();
useOcl = !useOcl;
}else
superRes = createSuperResolution_BTVL1_OCL();
superRes->set("opticalFlow", of);
}
else else
#endif superRes = createSuperResolution_BTVL1();
{
if (useCuda)
superRes = createSuperResolution_BTVL1_CUDA();
else
superRes = createSuperResolution_BTVL1();
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda); Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
if (of.empty()) if (of.empty())
exit(-1); return EXIT_FAILURE;
superRes->set("opticalFlow", of); superRes->set("opticalFlow", of);
}
superRes->set("scale", scale); superRes->set("scale", scale);
superRes->set("iterations", iterations); superRes->set("iterations", iterations);
@ -201,11 +127,7 @@ int main(int argc, const char* argv[])
cout << "Iterations : " << iterations << endl; cout << "Iterations : " << iterations << endl;
cout << "Temporal radius : " << temporalAreaRadius << endl; cout << "Temporal radius : " << temporalAreaRadius << endl;
cout << "Optical Flow : " << optFlow << endl; cout << "Optical Flow : " << optFlow << endl;
#if defined(HAVE_OPENCV_OCL)
cout << "Mode : " << (useCuda ? "CUDA" : useOcl? "OpenCL" : "CPU") << endl;
#else
cout << "Mode : " << (useCuda ? "CUDA" : "CPU") << endl; cout << "Mode : " << (useCuda ? "CUDA" : "CPU") << endl;
#endif
} }
superRes->setInput(frameSource); superRes->setInput(frameSource);
@ -217,32 +139,8 @@ int main(int argc, const char* argv[])
cout << '[' << setw(3) << i << "] : "; cout << '[' << setw(3) << i << "] : ";
Mat result; Mat result;
#if defined(HAVE_OPENCV_OCL) MEASURE_TIME(superRes->nextFrame(result));
cv::ocl::oclMat result_;
if(useOcl)
{
MEASURE_TIME(
{
superRes->nextFrame(result_);
ocl::finish();
});
}
else
#endif
{
MEASURE_TIME(superRes->nextFrame(result));
}
#ifdef HAVE_OPENCV_OCL
if(useOcl)
{
if(!result_.empty())
{
result_.download(result);
}
}
#endif
if (result.empty()) if (result.empty())
break; break;