如何创建 IPP(英特尔性能原语)C++包装函数?
IPP 是一个 C 库,有数百个这样的函数:
IppStatus ippiTranspose_8u_C1R(const Ipp8u* pSrc, int srcStep,
Ipp8u* pDst, int dstStep,
IppiSize roiSize));
为了能够以更方便、安全和一致的方式调用这些函数,我们需要为每个 C 函数提供一个 C++ 包装函数。例如:
void ippiTranspose(const Image<Ipp8u> &src, Rect srcRect, Image<Ipp8u> &dst, Point dstPos)
{
if (!src.valid()) throw "Invalid src";
if (!dst.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";
}
有逻辑模式,可以应用于IPP中的所有功能。
如何自动生成所有这些包装器?
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 (!dst.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Intel 提供了某种包装器,它们很好地隐藏在仅适用于 Windows 的 ipp-samples 中。我使用的是最新的 7.0 beta 版本。
它们提供由 perl 脚本生成的 C++ 标头,这些标头应该用作 C++ 包装器。问题中 ippiTranspose_8u_C1R 函数的“包装器”是这样的:
这只是函数调用的较短版本。
我对 C 函数的良好 C++ 包装器的期望是:
模板)
我们需要一个真正的 C++ 世界解决方案,英特尔!
我目前正在开发一个程序,它会自动生成像问题中的示例那样的包装器,而且看起来不错。
感谢罗斯指出英特尔的解决方案。
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:
This is just a shorter version of the function call.
What I expect from a good C++ wrapper for a C function:
templates)
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.
迟到总比不到好。 IPP 2017 有一个带有成熟 C++ API 的扩展包。预览版的功能覆盖范围很小,但可能已扩展到黄金版本。 https://software.intel.com/en-us/文章/intel-ipp-integration-wrappers
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
查看示例,“语言”示例部分中有 ippi.hpp 文件。它是 C++ 包装器。
Look at the examples there is ippi.hpp file in "language" examples section. It is C++ wrapper.