C ++在本征库中的性能 [英] C++ performance in eigen library

查看:162
本文介绍了C ++在本征库中的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查看效果基准:

http://eigen.tuxfamily.org/index.php?title=Benchmark

我不禁注意到eigen似乎始终优于所有专业供应商库。问题是:怎么可能?我们假设mkl / goto使用处理器专用的调试代码,而eigen则是通用的。

And I could not help but notice that eigen appears to consistently outperform all the specialized vendor libraries. The questions is: how is it possible? One would assume that mkl/goto would use processor specific tuned code, while eigen is rather generic.

注意这个 http://download.tuxfamily.org/eigen/btl-results-110323/aat.pdf ,基本上是dgemm。对于N = 1000特征获得大约17Gf,MKL只有12Gf

Notice this http://download.tuxfamily.org/eigen/btl-results-110323/aat.pdf, essentially a dgemm. For N=1000 Eigen gets roughly 17Gf, MKL only 12Gf

推荐答案

Eigen有惰性评估。从 Eigen如何与BLAS / LAPACK比较

Eigen has lazy evaluation. From How does Eigen compare to BLAS/LAPACK?:


对于涉及复杂表达式的操作,Eigen固有地比任何BLAS实现都快
,因为它可以处理和优化
a全局操作 - 而BLAS迫使程序员
将复杂操作拆分成与BLAS
固定函数API匹配的小步骤,由于引入
临时值,导致效率低下。例如,参见Y = a * X + b * Y
操作的基准结果,其涉及对BLAS level1例程的两次调用,而Eigen
自动生成单个向量化循环。

For operations involving complex expressions, Eigen is inherently faster than any BLAS implementation because it can handle and optimize a whole operation globally -- while BLAS forces the programmer to split complex operations into small steps that match the BLAS fixed-function API, which incurs inefficiency due to introduction of temporaries. See for instance the benchmark result of a Y = a*X + b*Y operation which involves two calls to BLAS level1 routines while Eigen automatically generates a single vectorized loop.

基准中的第二个图表是 Y = a * X + b * Y ,这是Eigen专门设计来处理的。它应该是难怪一个图书馆在一个基准创建为赢。你会注意到,更通用的基准,如矩阵矩阵乘法,没有显示任何优势Eigen。

The second chart in the benchmarks is Y = a*X + b*Y, which Eigen was specially designed to handle. It should be no wonder that a library wins at a benchmark it was created for. You'll notice that the more generic benchmarks, like matrix-matrix multiplication, don't show any advantage for Eigen.

这篇关于C ++在本征库中的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆