开发者

How to create IPP (Intel Performace primitives) C++ wrapper functions?

IPP is a C library, with hundreds of functions like this:

IppStatus ippiTranspose_8u_C1R(const Ipp8u* pSrc, int srcStep,
                               Ipp8u* pDst, int dstStep,
                               IppiSize roiSize));

To be able to call these functions in a more convenient, safe and consistent way, we need a C++ wrapper function for each C function. For example:

void ippiTranspose(const Image<Ipp8u> &src, Rect srcRect, Image<Ipp8u> &dst, Point dstPos)
{
  if (!src.valid()) throw "Invalid src";
  if (!ds开发者_开发技巧t.valid()) throw "Invalid dst";
  Rect srcRoi = srcRect.isEmpty() ? src.rect() : srcRect;
  if (!src.rect().contains(srcRoi)) throw "Invalid src rect";
  Rect dstRoi = Rect(dstPos, srcRoi.size());
  if (!dst.rect().contains(dstRoi)) throw "Invalid dst rect";
  IppStatus st = ippiTranspose_8u_C1R(&src.at(srcRoi.topLeft()), src.step(), &dst.at(dstRoi.topLeft()), dst.step(), toIppiSize(srcRoi.size());
  if (st < 0) throw "ippiTranspose_8u_C1R failed";
}

There are logical patterns, which can be applied to all the functions in IPP.

How to automatically generate all these wrappers?


There are some kind of wrappers, provided by Intel, which are well hidden in ipp-samples for windows only. I'm using the latest 7.0 beta version. They provide C++ headers, generated by a perl script, which are supposed to be used as a C++ wrappers. The "wrapper" for the ippiTranspose_8u_C1R function in the question is this:

 static inline IppStatus ippiTranspose_C1R( const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize) {
   return ippiTranspose_8u_C1R( pSrc, srcStep, pDst, dstStep, roiSize );
 }

This is just a shorter version of the function call.

What I expect from a good C++ wrapper for a C function:

  • map C-like params to C++ (objects, templates)
  • check if the input params are valid
  • check if the result is a success, error or warning
  • error handling using exceptions

We need a real solution for the C++ world, Intel!

I am currently working on a program, which automatically generates wrappers like the example in the question, and the things look nice.

Thanks to Ross for pointing the solution from Intel.


Better late than never. IPP 2017 has an extension package with full-blown C++ API. The preview had small functionality coverage, but it may have been extend for the gold release. https://software.intel.com/en-us/articles/intel-ipp-integration-wrappers


Look at the examples there is ippi.hpp file in "language" examples section. It is C++ wrapper.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜