mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
OpenVX calls updated to use single common OpenVX context per thread
This commit is contained in:
parent
ec7f74f7b4
commit
9a4b5a4545
13
3rdparty/openvx/hal/openvx_hal.cpp
vendored
13
3rdparty/openvx/hal/openvx_hal.cpp
vendored
@ -52,8 +52,17 @@ struct Tick
|
||||
|
||||
inline ivx::Context& getOpenVXHALContext()
|
||||
{
|
||||
// not thread safe
|
||||
static ivx::Context instance = ivx::Context::create();
|
||||
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
//CXX11
|
||||
static thread_local ivx::Context instance = ivx::Context::create();
|
||||
#else //__cplusplus >= 201103L || _MSC_VER >= 1800
|
||||
//CXX98
|
||||
#ifdef WIN32
|
||||
static __declspec(thread) ivx::Context instance = ivx::Context::create();
|
||||
#else
|
||||
static __thread ivx::Context instance = ivx::Context::create();
|
||||
#endif
|
||||
#endif
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,12 @@
|
||||
#define IVX_USE_OPENCV
|
||||
#include "ivx.hpp"
|
||||
|
||||
namespace cv{
|
||||
namespace ovx{
|
||||
// Get common thread local OpenVX context
|
||||
CV_EXPORTS_W ivx::Context& getOpenVXContext();
|
||||
}}
|
||||
|
||||
#define CV_OVX_RUN(condition, func, ...) \
|
||||
if (cv::useOpenVX() && (condition) && func) \
|
||||
{ \
|
||||
|
@ -4673,7 +4673,7 @@ static bool _openvx_cvt(const T* src, size_t sstep,
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
|
||||
// Other conversions are marked as "experimental"
|
||||
if(context.vendorID() == VX_ID_KHRONOS &&
|
||||
@ -5406,7 +5406,7 @@ static bool openvx_LUT(Mat src, Mat dst, Mat _lut)
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
|
@ -14,6 +14,38 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace ovx
|
||||
{
|
||||
#ifdef HAVE_OPENVX
|
||||
|
||||
// Simple TLSData<ivx::Context> doesn't work, because default constructor doesn't create any OpenVX context.
|
||||
struct OpenVXTLSData
|
||||
{
|
||||
OpenVXTLSData() : ctx(ivx::Context::create()) {}
|
||||
ivx::Context ctx;
|
||||
};
|
||||
|
||||
static TLSData<OpenVXTLSData>& getOpenVXTLSData()
|
||||
{
|
||||
CV_SINGLETON_LAZY_INIT_REF(TLSData<OpenVXTLSData>, new TLSData<OpenVXTLSData>())
|
||||
}
|
||||
|
||||
struct OpenVXCleanupFunctor
|
||||
{
|
||||
~OpenVXCleanupFunctor() { getOpenVXTLSData().cleanup(); }
|
||||
};
|
||||
static OpenVXCleanupFunctor g_openvx_cleanup_functor;
|
||||
|
||||
ivx::Context& getOpenVXContext()
|
||||
{
|
||||
return getOpenVXTLSData().get()->ctx;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
bool haveOpenVX()
|
||||
{
|
||||
#ifdef HAVE_OPENVX
|
||||
@ -22,7 +54,7 @@ bool haveOpenVX()
|
||||
{
|
||||
try
|
||||
{
|
||||
ivx::Context context = ivx::Context::create();
|
||||
ivx::Context context = ovx::getOpenVXContext();
|
||||
vx_uint16 vComp = ivx::compiledWithVersion();
|
||||
vx_uint16 vCurr = context.version();
|
||||
g_haveOpenVX =
|
||||
|
@ -1665,7 +1665,7 @@ namespace cv
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
#ifndef VX_VERSION_1_1
|
||||
if (ctx.vendorID() == VX_ID_KHRONOS)
|
||||
return false; // Do not use OpenVX meanStdDev estimation for sample 1.0.1 implementation due to lack of accuracy
|
||||
@ -2312,7 +2312,7 @@ static bool openvx_minMaxIdx(Mat &src, double* minVal, double* maxVal, int* minI
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, stype == CV_8UC1 ? VX_DF_IMAGE_U8 : VX_DF_IMAGE_S16,
|
||||
ivx::Image::createAddressing(cols, rows, stype == CV_8UC1 ? 1 : 2, (vx_int32)(src.step[0])), src.ptr());
|
||||
|
@ -354,7 +354,7 @@ static bool openvx_FAST(InputArray _img, std::vector<KeyPoint>& keypoints,
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
Image img = Image::createFromHandle(context, Image::matTypeToFormat(imgMat.type()),
|
||||
Image::createAddressing(imgMat), (void*)imgMat.data);
|
||||
ivx::Scalar threshold = ivx::Scalar::create<VX_TYPE_FLOAT32>(context, _threshold);
|
||||
|
@ -1958,7 +1958,7 @@ static bool openvx_accumulate(InputArray _src, InputOutputArray _dst, InputArray
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context context = ivx::Context::create();
|
||||
ivx::Context context = ovx::getOpenVXContext();
|
||||
ivx::Image srcImage = ivx::Image::createFromHandle(context, ivx::Image::matTypeToFormat(srcMat.type()),
|
||||
ivx::Image::createAddressing(srcMat), srcMat.data);
|
||||
ivx::Image dstImage = ivx::Image::createFromHandle(context, ivx::Image::matTypeToFormat(dstMat.type()),
|
||||
|
@ -782,7 +782,7 @@ static bool openvx_canny(const Mat& src, Mat& dst, int loVal, int hiVal, int kSi
|
||||
{
|
||||
using namespace ivx;
|
||||
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
try
|
||||
{
|
||||
Image _src = Image::createFromHandle(
|
||||
|
@ -236,7 +236,7 @@ namespace cv
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
if ((vx_size)ksize > ctx.convolutionMaxDimension())
|
||||
return false;
|
||||
|
||||
|
@ -286,7 +286,7 @@ static bool openvx_harris(Mat image, OutputArray _corners,
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
|
||||
Image ovxImage = Image::createFromHandle(context, Image::matTypeToFormat(image.type()),
|
||||
Image::createAddressing(image), image.data);
|
||||
|
@ -1282,7 +1282,7 @@ namespace cv
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
#if VX_VERSION <= VX_VERSION_1_0
|
||||
if (ctx.vendorID() == VX_ID_KHRONOS && (range % histSize))
|
||||
return false;
|
||||
@ -3773,7 +3773,7 @@ static bool openvx_equalize_hist(Mat srcMat, Mat dstMat)
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
Image srcImage = Image::createFromHandle(context, Image::matTypeToFormat(srcMat.type()),
|
||||
Image::createAddressing(srcMat), srcMat.data);
|
||||
Image dstImage = Image::createFromHandle(context, Image::matTypeToFormat(dstMat.type()),
|
||||
|
@ -4795,7 +4795,7 @@ static bool openvx_remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
|
||||
Mat a;
|
||||
if (dst.data != src.data)
|
||||
|
@ -1290,7 +1290,7 @@ static bool openvx_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz,
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
if(context.vendorID() == VX_ID_KHRONOS)
|
||||
{
|
||||
// This implementation performs floor-like rounding
|
||||
|
@ -1677,7 +1677,7 @@ namespace cv
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
|
||||
return false;
|
||||
|
||||
@ -2239,7 +2239,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
|
||||
return false;
|
||||
|
||||
@ -3361,7 +3361,7 @@ namespace cv
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
#ifdef VX_VERSION_1_1
|
||||
if ((vx_size)ksize > ctx.nonlinearMaxDimension())
|
||||
return false;
|
||||
|
@ -1301,7 +1301,7 @@ static bool openvx_threshold(Mat src, Mat dst, int thresh, int maxval, int type)
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ivx::Context::create();
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
|
||||
ivx::Threshold thh = ivx::Threshold::createBinary(ctx, VX_TYPE_UINT8, thresh);
|
||||
thh.setValueTrue(trueVal);
|
||||
|
@ -1099,7 +1099,7 @@ namespace
|
||||
|
||||
try
|
||||
{
|
||||
Context context = Context::create();
|
||||
Context context = ovx::getOpenVXContext();
|
||||
|
||||
if(context.vendorID() == VX_ID_KHRONOS)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user