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_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
if(new_mode)
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource2 ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource2 ${cl_filename}_oclsrc;\n")
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
endif()
set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")

View File

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

View File

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

View File

@ -51,15 +51,15 @@ CV_EXPORTS bool useOpenCL();
CV_EXPORTS bool haveAmdBlas();
CV_EXPORTS bool haveAmdFft();
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 Kernel;
class CV_EXPORTS Program;
class CV_EXPORTS ProgramSource2;
class CV_EXPORTS ProgramSource;
class CV_EXPORTS Queue;
class CV_EXPORTS PlatformInfo2;
class CV_EXPORTS PlatformInfo;
class CV_EXPORTS Image2D;
class CV_EXPORTS Device
@ -206,26 +206,26 @@ protected:
};
class CV_EXPORTS Context2
class CV_EXPORTS Context
{
public:
Context2();
explicit Context2(int dtype);
~Context2();
Context2(const Context2& c);
Context2& operator = (const Context2& c);
Context();
explicit Context(int dtype);
~Context();
Context(const Context& c);
Context& operator = (const Context& c);
bool create();
bool create(int dtype);
size_t ndevices() const;
const Device& device(size_t idx) const;
Program getProg(const ProgramSource2& prog,
Program getProg(const ProgramSource& prog,
const String& buildopt, String& errmsg);
static Context2& getDefault(bool initialize = true);
static Context& getDefault(bool initialize = true);
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:
struct Impl;
Impl* p;
@ -242,25 +242,25 @@ public:
void* ptr() const;
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:
struct Impl;
Impl* p;
};
// 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
{
public:
Queue();
explicit Queue(const Context2& c, const Device& d=Device());
explicit Queue(const Context& c, const Device& d=Device());
~Queue();
Queue(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* ptr() const;
static Queue& getDefault();
@ -314,7 +314,7 @@ class CV_EXPORTS Kernel
public:
Kernel();
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);
~Kernel();
Kernel(const Kernel& k);
@ -322,7 +322,7 @@ public:
bool empty() const;
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);
int set(int i, const void* value, size_t sz);
@ -508,7 +508,7 @@ class CV_EXPORTS Program
{
public:
Program();
Program(const ProgramSource2& src,
Program(const ProgramSource& src,
const String& buildflags, String& errmsg);
explicit Program(const String& buf);
Program(const Program& prog);
@ -516,12 +516,12 @@ public:
Program& operator = (const Program& prog);
~Program();
bool create(const ProgramSource2& src,
bool create(const ProgramSource& src,
const String& buildflags, String& errmsg);
bool read(const String& buf, const String& buildflags);
bool write(String& buf) const;
const ProgramSource2& source() const;
const ProgramSource& source() const;
void* ptr() const;
String getPrefix() const;
@ -533,17 +533,17 @@ protected:
};
class CV_EXPORTS ProgramSource2
class CV_EXPORTS ProgramSource
{
public:
typedef uint64 hash_t;
ProgramSource2();
explicit ProgramSource2(const String& prog);
explicit ProgramSource2(const char* prog);
~ProgramSource2();
ProgramSource2(const ProgramSource2& prog);
ProgramSource2& operator = (const ProgramSource2& prog);
ProgramSource();
explicit ProgramSource(const String& prog);
explicit ProgramSource(const char* prog);
~ProgramSource();
ProgramSource(const ProgramSource& prog);
ProgramSource& operator = (const ProgramSource& prog);
const String& source() const;
hash_t hash() const;
@ -553,15 +553,15 @@ protected:
Impl* p;
};
class CV_EXPORTS PlatformInfo2
class CV_EXPORTS PlatformInfo
{
public:
PlatformInfo2();
explicit PlatformInfo2(void* id);
~PlatformInfo2();
PlatformInfo();
explicit PlatformInfo(void* id);
~PlatformInfo();
PlatformInfo2(const PlatformInfo2& i);
PlatformInfo2& operator =(const PlatformInfo2& i);
PlatformInfo(const PlatformInfo& i);
PlatformInfo& operator =(const PlatformInfo& i);
String name() 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* memopTypeToStr(int t);
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
{

View File

@ -236,7 +236,7 @@ namespace ocl {
static bool g_isDirect3DDevice9Ex = false; // Direct3DDevice9Ex or Direct3DDevice9 was used
#endif
Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
{
(void)pD3D11Device;
#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);
return ctx;
#endif
}
Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
{
(void)pD3D10Device;
#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);
return ctx;
#endif
}
Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex)
Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex)
{
(void)pDirect3DDevice9Ex;
#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");
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = true;
return ctx;
#endif
}
Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9)
Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9)
{
(void)pDirect3DDevice9;
#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");
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = false;
return ctx;
@ -720,7 +720,7 @@ void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D)
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
@ -777,7 +777,7 @@ void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst
CV_Assert(textureType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// 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);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
@ -925,7 +925,7 @@ void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst
CV_Assert(textureType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// 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);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
@ -1083,7 +1083,7 @@ void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArr
CV_Assert(surfaceType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// 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];
// 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
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))
// ready to bake
cl_command_queue commandQueue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &commandQueue, NULL, NULL))
cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &queue, NULL, NULL))
}
~FftPlan()
@ -1593,7 +1593,7 @@ public:
clAmdFftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP,
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 ++)
{
@ -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 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;
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)))
tmpBuffer.addref();

View File

@ -1495,11 +1495,6 @@ Size _InputArray::size(int i) const
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 );
//if( k == CUDA_MEM )
{
@ -1679,11 +1674,6 @@ int _InputArray::dims(int i) const
return 2;
}
if( k == OCL_MAT )
{
return 2;
}
CV_Assert( k == CUDA_MEM );
//if( k == CUDA_MEM )
{
@ -1841,11 +1831,6 @@ bool _InputArray::empty() const
if( k == OPENGL_BUFFER )
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 )
return ((const cuda::GpuMat*)obj)->empty();
@ -1881,7 +1866,7 @@ bool _InputArray::isContinuous(int i) const
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;
}

View File

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

View File

@ -25,7 +25,7 @@
//
// * 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 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
// 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;
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;
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);
if (((channels != 1) && (channels != 2) && (channels != 4))
|| (borderType != BORDER_DEFAULT))
if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
return false;
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() );
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;
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",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
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);
if (((channels != 1) && (channels != 2) && (channels != 4))
|| (borderType != BORDER_DEFAULT))
if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
return false;
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
if ((depth == CV_64F) && !(doubleSupport))
if (depth == CV_64F && !doubleSupport)
return false;
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() );
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;
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",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst));
size_t globalThreads[2] = {dst.cols, dst.rows};

View File

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

View File

@ -98,14 +98,14 @@ void dumpOpenCLDevice()
using namespace cv::ocl;
try
{
std::vector<PlatformInfo2> platforms;
std::vector<PlatformInfo> platforms;
cv::ocl::getPlatfomsInfo(platforms);
if (platforms.size() > 0)
{
DUMP_MESSAGE_STDOUT("OpenCL Platforms: ");
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());
Device current_device;
for (int j = 0; j < platform->deviceNumber(); j++)

View File

@ -134,7 +134,7 @@ static void renderToD3DObject(void)
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)
{
@ -360,7 +360,7 @@ static cv::Mat getInputTexture()
{
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::putText(inputMat,
cv::format("OpenCL Device name: %s", deviceName.c_str()),
@ -396,13 +396,13 @@ static int mainLoop()
if (cv::ocl::haveOpenCL())
{
#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)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev);
#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)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev);
#else
#error "Invalid USE_D3D value"
#endif

View File

@ -10,14 +10,10 @@
#include "opencv2/superres/optical_flow.hpp"
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_OCL)
#include "opencv2/ocl/ocl.hpp"
#endif
using namespace std;
using namespace cv;
using namespace cv::superres;
bool useOclChanged;
#define MEASURE_TIME(op) \
{ \
TickMeter tm; \
@ -50,40 +46,11 @@ static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
else if (name == "pyrlk")
return createOptFlow_PyrLK_CUDA();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
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[])
{
useOclChanged = false;
@ -94,7 +61,7 @@ int main(int argc, const char* argv[])
"{ i iterations | 180 | Iteration count }"
"{ t temporal | 4 | Radius of the temporal search area }"
"{ 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 }"
);
@ -102,7 +69,7 @@ int main(int argc, const char* argv[])
{
cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl;
cmd.printMessage();
return 0;
return EXIT_SUCCESS;
}
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);
bool useCuda = false;
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
bool useCuda = gpuOption.compare("cuda") == 0;
Ptr<SuperResolution> superRes;
#if defined(HAVE_OPENCV_OCL)
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);
}
if (useCuda)
superRes = createSuperResolution_BTVL1_CUDA();
else
#endif
{
if (useCuda)
superRes = createSuperResolution_BTVL1_CUDA();
else
superRes = createSuperResolution_BTVL1();
superRes = createSuperResolution_BTVL1();
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
if (of.empty())
exit(-1);
superRes->set("opticalFlow", of);
}
if (of.empty())
return EXIT_FAILURE;
superRes->set("opticalFlow", of);
superRes->set("scale", scale);
superRes->set("iterations", iterations);
@ -201,11 +127,7 @@ int main(int argc, const char* argv[])
cout << "Iterations : " << iterations << endl;
cout << "Temporal radius : " << temporalAreaRadius << 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;
#endif
}
superRes->setInput(frameSource);
@ -217,32 +139,8 @@ int main(int argc, const char* argv[])
cout << '[' << setw(3) << i << "] : ";
Mat result;
#if defined(HAVE_OPENCV_OCL)
cv::ocl::oclMat result_;
MEASURE_TIME(superRes->nextFrame(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())
break;