Added SharedMatrix
This commit is contained in:
parent
fa2d79a15b
commit
037ac27ec8
@ -2,20 +2,20 @@
|
||||
# IPP_A_LIBRARIES and IPP_A_INCLUDE to use IPP Async
|
||||
# HAVE_IPP_A for conditional compilation OpenCV with/without IPP Async
|
||||
|
||||
# IPPAROOT - root of IPP Async installation
|
||||
# IPP_ASYNC_ROOT - root of IPP Async installation
|
||||
|
||||
if(X86_64)
|
||||
find_path(
|
||||
IPP_A_INCLUDE_DIR
|
||||
NAMES ipp_async_defs.h
|
||||
PATHS $ENV{IPPAROOT}
|
||||
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||
PATH_SUFFIXES include
|
||||
DOC "Path to Intel IPP Async interface headers")
|
||||
|
||||
find_file(
|
||||
IPP_A_LIBRARIES
|
||||
NAMES ipp_async_preview.lib
|
||||
PATHS $ENV{IPPAROOT}
|
||||
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||
PATH_SUFFIXES lib/intel64
|
||||
DOC "Path to Intel IPP Async interface libraries")
|
||||
|
||||
@ -23,14 +23,14 @@ else()
|
||||
find_path(
|
||||
IPP_A_INCLUDE_DIR
|
||||
NAMES ipp_async_defs.h
|
||||
PATHS $ENV{IPPAROOT}
|
||||
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||
PATH_SUFFIXES include
|
||||
DOC "Path to Intel IPP Async interface headers")
|
||||
|
||||
find_file(
|
||||
IPP_A_LIBRARIES
|
||||
NAMES ipp_async_preview.lib
|
||||
PATHS $ENV{IPPAROOT}
|
||||
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||
PATH_SUFFIXES lib/ia32
|
||||
DOC "Path to Intel IPP Async interface libraries")
|
||||
endif()
|
||||
|
@ -39,7 +39,7 @@ Explanation
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
Ptr<hppiMatrix> src, dst;
|
||||
hppiMatrix* src,* dst;
|
||||
hppAccel accel = 0;
|
||||
hppAccelType accelType;
|
||||
hppStatus sts;
|
||||
@ -101,8 +101,8 @@ Explanation
|
||||
.. code-block:: cpp
|
||||
|
||||
//convert Mat to hppiMatrix
|
||||
src = getHpp(gray);
|
||||
dst = getHpp(result);
|
||||
src = getHpp(gray, accel);
|
||||
dst = getHpp(result, accel);
|
||||
|
||||
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
||||
CHECK_STATUS(sts,"hppiSobel");
|
||||
@ -127,6 +127,16 @@ Explanation
|
||||
|
||||
waitKey(15);
|
||||
|
||||
#. Delete hpp matrices.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
sts = hppiFreeMatrix(src);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
|
||||
sts = hppiFreeMatrix(dst);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
|
||||
#. Delete virtual matrices and accelerator instance.
|
||||
|
||||
.. code-block:: cpp
|
||||
@ -143,8 +153,6 @@ Explanation
|
||||
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
|
||||
}
|
||||
|
||||
We shouldn't delete hppiMatrix_ because we use :ptr:`Ptr <>` and so `hppiFreeMatrix <http://software.intel.com/en-us/node/501699>`_ will be called implicitly.
|
||||
|
||||
Result
|
||||
=======
|
||||
|
||||
|
@ -222,6 +222,7 @@ Here you will learn the about the basic building blocks of the library. A must r
|
||||
.. |Author_ElenaG| unicode:: Elena U+0020 Gvozdeva
|
||||
|
||||
=============== ======================================================
|
||||
|
||||
.. raw:: latex
|
||||
|
||||
\pagebreak
|
||||
|
@ -62,6 +62,8 @@ Building the OpenCV library from scratch requires a couple of tools installed be
|
||||
.. _IntelTBB: http://threadingbuildingblocks.org/file.php?fid=77
|
||||
.. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*IPP*)
|
||||
.. _IntelIIP: http://software.intel.com/en-us/articles/intel-ipp/
|
||||
.. |IntelIIPA| replace:: Intel |copy| IPP Asynchronous C/C++
|
||||
.. _IntelIIPA: http://software.intel.com/en-us/intel-ipp-preview
|
||||
.. |qtframework| replace:: Qt framework
|
||||
.. _qtframework: http://qt.nokia.com/downloads
|
||||
.. |Eigen| replace:: Eigen
|
||||
@ -97,6 +99,8 @@ OpenCV may come in multiple flavors. There is a "core" section that will work on
|
||||
|
||||
+ |IntelIIP|_ may be used to improve the performance of color conversion, Haar training and DFT functions of the OpenCV library. Watch out, since this isn't a free service.
|
||||
|
||||
+ |IntelIIPA|_ is currently focused delivering Intel |copy| Graphics support for advanced image processing and computer vision functions.
|
||||
|
||||
+ OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one by using the |qtframework|_. For a quick overview of what this has to offer look into the documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of the framework is required.
|
||||
|
||||
+ |Eigen|_ is a C++ template library for linear algebra.
|
||||
@ -168,6 +172,8 @@ Building the library
|
||||
:alt: The Miktex Install Screen
|
||||
:align: center
|
||||
|
||||
#) For the |IntelIIPA|_ download the source files and set environment variable **IPP_ASYNC_ROOT**. It should point to :file:`<your Program Files(x86) directory>/Intel/IPP Preview */ipp directory`. Here ``*`` denotes the particular preview name.
|
||||
|
||||
#) In case of the |Eigen|_ library it is again a case of download and extract to the :file:`D:/OpenCV/dep` directory.
|
||||
|
||||
#) Same as above with |OpenEXR|_.
|
||||
|
@ -13,11 +13,21 @@ hpp::getHpp
|
||||
-----------
|
||||
Create ``hppiMatrix`` from ``Mat``.
|
||||
|
||||
.. ocv:function:: Ptr<hppiMatrix> hpp::getHpp(const Mat& src)
|
||||
.. ocv:function:: hppiMatrix* hpp::getHpp(const Mat& src, hppAccel accel)
|
||||
|
||||
:param src: input matrix.
|
||||
:param accel: accelerator instance. Supports type:
|
||||
|
||||
* **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions.
|
||||
|
||||
* **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function accelerators.
|
||||
|
||||
* **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available.
|
||||
|
||||
This function allocates and initializes the ``hppiMatrix`` that has the same size and type as input matrix, returns the ``hppiMatrix*``.
|
||||
|
||||
If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details `hppiCreateSharedMatrix <http://software.intel.com/ru-ru/node/501697>`_.
|
||||
|
||||
This function allocates and initializes the ``hppiMatrix`` that has the same size and type as input matrix, returns the ``Ptr<hppiMatrix>``.
|
||||
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
||||
|
||||
.. note:: The ``hppiMatrix`` pointer to the image buffer in system memory refers to the ``src.data``. Control the lifetime of the matrix and don't change its data, if there is no special need.
|
||||
@ -32,7 +42,7 @@ Create ``Mat`` from ``hppiMatrix``.
|
||||
|
||||
:param src: input hppiMatrix.
|
||||
|
||||
:param accel: accelerator instance.
|
||||
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
|
||||
|
||||
:param cn: number of channels.
|
||||
|
||||
@ -52,7 +62,7 @@ Convert ``hppiMatrix`` to ``Mat``.
|
||||
|
||||
:param dst: output matrix.
|
||||
|
||||
:param accel: accelerator instance.
|
||||
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
|
||||
|
||||
:param cn: number of channels.
|
||||
|
||||
|
@ -1,16 +1,14 @@
|
||||
#ifndef __OPENCV_CORE_IPPASYNC_HPP__
|
||||
#define __OPENCV_CORE_IPPASYNC_HPP__
|
||||
|
||||
#ifdef HAVE_IPP_A
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include <ipp_async_op.h>
|
||||
#include <ipp_async_accel.h>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
void DefaultDeleter<hppiMatrix>::operator () (hppiMatrix* p) const
|
||||
{
|
||||
hppiFreeMatrix(p);
|
||||
}
|
||||
|
||||
namespace hpp
|
||||
{
|
||||
@ -47,7 +45,8 @@ namespace hpp
|
||||
hpp32u width, height;
|
||||
hppStatus sts;
|
||||
|
||||
CV_Assert(src!=NULL);
|
||||
if (src == NULL)
|
||||
return dst.release();
|
||||
|
||||
sts = hppiInquireMatrix(src, &type, &width, &height);
|
||||
|
||||
@ -76,17 +75,31 @@ namespace hpp
|
||||
return dst;
|
||||
}
|
||||
|
||||
//create hppiMatrix from cv::Mat
|
||||
inline Ptr<hppiMatrix> getHpp(const Mat& src)
|
||||
//create hppiMatrix from cv::Mat
|
||||
inline hppiMatrix* getHpp(const Mat& src, hppAccel accel)
|
||||
{
|
||||
int htype = toHppType(src.type());
|
||||
int cn = src.channels();
|
||||
|
||||
CV_Assert(src.data);
|
||||
hppiMatrix *dst = hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));
|
||||
hppAccelType accelType = hppQueryAccelType(accel);
|
||||
|
||||
return Ptr<hppiMatrix>(dst);
|
||||
if (accelType!=HPP_ACCEL_TYPE_CPU)
|
||||
{
|
||||
hpp32u pitch, size;
|
||||
hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size);
|
||||
if (pitch!=0 && size!=0)
|
||||
if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step))
|
||||
{
|
||||
return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size);
|
||||
}
|
||||
}
|
||||
|
||||
return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,6 +1,7 @@
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_IPP_A
|
||||
#include "opencv2/core/ippasync.hpp"
|
||||
|
||||
using namespace cv;
|
||||
@ -18,7 +19,7 @@ PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
|
||||
hppAccelType accelType;
|
||||
|
||||
Mat matrix, result;
|
||||
Ptr<hppiMatrix> hppMat;
|
||||
hppiMatrix * hppMat;
|
||||
hppAccel accel;
|
||||
hppiVirtualMatrix * virtMatrix;
|
||||
hppStatus sts;
|
||||
@ -47,17 +48,16 @@ PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
|
||||
|
||||
TEST_P(IPPAsync, accuracy)
|
||||
{
|
||||
if (depth==CV_32S || depth==CV_64F)
|
||||
return;
|
||||
|
||||
sts = hppCreateInstance(accelType, 0, &accel);
|
||||
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus= %d\n",sts);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
|
||||
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData();
|
||||
hppMat = hpp::getHpp(matrix);
|
||||
hppMat = hpp::getHpp(matrix,accel);
|
||||
|
||||
hppScalar a = 3;
|
||||
|
||||
@ -72,6 +72,9 @@ TEST_P(IPPAsync, accuracy)
|
||||
result = hpp::getMat(virtMatrix[1], accel, cn);
|
||||
|
||||
Near(5.0e-6);
|
||||
|
||||
sts = hppiFreeMatrix(hppMat);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
||||
@ -80,26 +83,82 @@ TEST_P(IPPAsync, accuracy)
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
TEST_P(IPPAsync, conversion)
|
||||
PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType)
|
||||
{
|
||||
int cn;
|
||||
int type;
|
||||
hppAccelType accelType;
|
||||
|
||||
Mat matrix, result;
|
||||
hppiMatrix* hppMat;
|
||||
hppAccel accel;
|
||||
hppiVirtualMatrix * virtMatrix;
|
||||
hppStatus sts;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cn = GET_PARAM(0);
|
||||
accelType = GET_PARAM(1);
|
||||
type=CV_MAKE_TYPE(CV_8U, GET_PARAM(0));
|
||||
}
|
||||
|
||||
virtual void generateTestData()
|
||||
{
|
||||
Size matrix_Size = randomSize(2, 100);
|
||||
hpp32u pitch, size;
|
||||
const int upValue = 100;
|
||||
|
||||
sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size);
|
||||
|
||||
if (pitch!=0 && size!=0)
|
||||
{
|
||||
uchar *pData = (uchar*)_aligned_malloc(size, 4096);
|
||||
|
||||
for (int j=0; j<matrix_Size.height; j++)
|
||||
for(int i=0; i<matrix_Size.width*cn; i++)
|
||||
pData[i+j*pitch] = rand()%upValue;
|
||||
|
||||
matrix = Mat(matrix_Size.height, matrix_Size.width, type, pData, pitch);
|
||||
}
|
||||
|
||||
matrix = randomMat(matrix_Size, type, 0, upValue);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
EXPECT_MAT_NEAR(matrix, result, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(IPPAsyncShared, accuracy)
|
||||
{
|
||||
sts = hppCreateInstance(accelType, 0, &accel);
|
||||
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus= %d\n",sts);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
|
||||
|
||||
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData();
|
||||
hppMat = hpp::getHpp(matrix);
|
||||
hppMat = hpp::getHpp(matrix,accel);
|
||||
|
||||
sts = hppiCopy (accel, hppMat, virtMatrix[0]);
|
||||
hppScalar a = 3;
|
||||
|
||||
sts = hppiAddC(accel, hppMat, a, 0, virtMatrix[0]);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
sts = hppiSubC(accel, virtMatrix[0], a, 0, virtMatrix[1]);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
|
||||
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
|
||||
result = hpp::getMat(virtMatrix[0], accel, cn);
|
||||
result = hpp::getMat(virtMatrix[1], accel, cn);
|
||||
|
||||
Near();
|
||||
Near(0);
|
||||
|
||||
sts = hppiFreeMatrix(hppMat);
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
||||
@ -108,9 +167,13 @@ TEST_P(IPPAsync, conversion)
|
||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
|
||||
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsyncShared, Combine(Values(1, 2, 3, 4),
|
||||
Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32F),
|
||||
Values(1, 2, 3, 4),
|
||||
Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,9 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/core/ippasync.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "cvconfig.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
#ifdef HAVE_IPP_A
|
||||
#include "opencv2/core/ippasync.hpp"
|
||||
|
||||
#define CHECK_STATUS(STATUS, NAME)\
|
||||
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\
|
||||
@ -14,9 +20,7 @@
|
||||
#define CHECK_DEL_STATUS(STATUS, NAME)\
|
||||
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;}
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace hpp;
|
||||
#endif
|
||||
|
||||
static void help()
|
||||
{
|
||||
@ -42,15 +46,17 @@ int main(int argc, const char** argv)
|
||||
help();
|
||||
|
||||
VideoCapture cap;
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
Mat image, gray, result;
|
||||
|
||||
Ptr<hppiMatrix> src, dst;
|
||||
#ifdef HAVE_IPP_A
|
||||
|
||||
hppiMatrix* src,* dst;
|
||||
hppAccel accel = 0;
|
||||
hppAccelType accelType;
|
||||
hppStatus sts;
|
||||
hppiVirtualMatrix * virtMatrix;
|
||||
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
bool useCamera = parser.has("camera");
|
||||
string file = parser.get<string>("file_name");
|
||||
string sAccel = parser.get<string>("accel");
|
||||
@ -106,8 +112,8 @@ int main(int argc, const char** argv)
|
||||
double execTime = (double)getTickCount();
|
||||
|
||||
//convert Mat to hppiMatrix
|
||||
src = getHpp(gray);
|
||||
dst = getHpp(result);
|
||||
src = hpp::getHpp(gray,accel);
|
||||
dst = hpp::getHpp(result,accel);
|
||||
|
||||
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
||||
CHECK_STATUS(sts,"hppiSobel");
|
||||
@ -127,6 +133,13 @@ int main(int argc, const char** argv)
|
||||
imshow("rez", result);
|
||||
|
||||
waitKey(15);
|
||||
|
||||
sts = hppiFreeMatrix(src);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
|
||||
sts = hppiFreeMatrix(dst);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
|
||||
}
|
||||
|
||||
if (!useCamera)
|
||||
@ -145,5 +158,12 @@ int main(int argc, const char** argv)
|
||||
}
|
||||
|
||||
printf("SUCCESS\n");
|
||||
return -1;
|
||||
|
||||
#else
|
||||
|
||||
printf("IPP Async not supported\n");
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user