使用Intel编译器(0)基础(3)循环相关的优化技术Loop optimization
2012-02-01 16:38
351 查看
参考手册:
http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011Update/compiler_c/index.htm
说明:本系列文章为个人笔记,如有不正确之处,请参考官方相关文档,如果错误发现,我会尽量更新修改。另外,以下内容不保证对于所有版本的编译器都正确,编译器的实现也可能有一些变化之处,具体参考官方文档。
更多说明请参考/article/8516772.html中补充说明部分。
说明:这里主要讨论和循环相关的基本优化技术的“术语”以及对其的理解。(不断更新)
循环是程序中一个很重要的部分,因为在优化理论中,有很多对循环进行优化的研究。
参考:
Loop optimization (wiki):
http://en.wikipedia.org/wiki/Loop_optimization
1. Loop unwinding/loop unrolling/loop unroll循环展开
http://en.wikipedia.org/wiki/Loop_unrolling
Loop unwinding, also known as loop unrolling, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size (space-time tradeoff). The transformation can be undertaken manually by the programmer or
by an optimizing compiler.
简单来说,循环展开,是一种增加了二进制文件大小来优化程序执行速度的循环转换技术,可以人工或者通过编译器完成。循环展开的目的是通过减少或者消除控制循环的指令来增加程序速度。
当然,循环展开有很多情况分类,参考wiki理解其中的细节。对于最简单的循环展开的情况,就是静态的循环的展开,如下:
2. sectioning/loop-sectioning/strip-mining/strip mining
循环切分?
wiki没有找到专门介绍sectioning的页面,在上面的循环优化的wiki(http://en.wikipedia.org/wiki/Loop_optimization)中提到了此项优化技术如下:
loop-sectioning (also known as strip-mining) is a loop-transformation technique for enabling SIMD-encodings of loops and improving memory performance. This technique involves each vector operation being done for a size less than or equal to the maximum vector
length on a given vector machine.
其后面给出了和此项技术有关的链接:
Strip Mining to Optimize Memory Use on 32-Bit Intel® Architecture
Strip-Mining(http://docs.oracle.com/cd/E19205-01/819-5262/aeugr/index.html)
简单来说,sectioning(不确定中文翻译如何表述),是一项加强SIMD对循环的编码和提高内存性能的循环转换技术,使得每一个向量操作以小于或者等于给定的向量机最大的向量长度的大小来完成。
参考上面的链接能很容易的理解此项技术对内存优化的过程,当然,上面的链接没有包括SIMD相关的优化的例子。
3. Loop interchange循环交换
http://en.wikipedia.org/wiki/Loop_interchange
In compiler theory, loop interchange is the process of exchanging the order of two iteration variables.
简单来说,循环交换就是交换内外层循环的迭代变量的过程。需要注意的是,不是所有情况都能直接进行循环交换,需要判断数据依赖关系。
下面的例子可以很容易理解循环交换的过程:
和循环交换相关的博文:
/article/5461390.html
http://www.cdblp.cn/paper/%E5%BE%AA%E7%8E%AF%E4%BA%A4%E6%8D%A2%E4%B8%8E%E9%80%92%E5%BD%92%E6%B6%88%E9%99%A4/6951.html
4. Loop blocking
loop blocking是intel编译器提供的一种优化技术,是strip mining和loop interchange的结合。
参考http://software.intel.com/en-us/articles/performance-tools-for-software-developers-loop-blocking/理解其细节。
http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011Update/compiler_c/index.htm
说明:本系列文章为个人笔记,如有不正确之处,请参考官方相关文档,如果错误发现,我会尽量更新修改。另外,以下内容不保证对于所有版本的编译器都正确,编译器的实现也可能有一些变化之处,具体参考官方文档。
更多说明请参考/article/8516772.html中补充说明部分。
说明:这里主要讨论和循环相关的基本优化技术的“术语”以及对其的理解。(不断更新)
循环是程序中一个很重要的部分,因为在优化理论中,有很多对循环进行优化的研究。
参考:
Loop optimization (wiki):
http://en.wikipedia.org/wiki/Loop_optimization
1. Loop unwinding/loop unrolling/loop unroll循环展开
http://en.wikipedia.org/wiki/Loop_unrolling
Loop unwinding, also known as loop unrolling, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size (space-time tradeoff). The transformation can be undertaken manually by the programmer or
by an optimizing compiler.
简单来说,循环展开,是一种增加了二进制文件大小来优化程序执行速度的循环转换技术,可以人工或者通过编译器完成。循环展开的目的是通过减少或者消除控制循环的指令来增加程序速度。
当然,循环展开有很多情况分类,参考wiki理解其中的细节。对于最简单的循环展开的情况,就是静态的循环的展开,如下:
int x; for (x = 0; x < 100; x++) { delete(x); }一种可能的展开是:
int x; for (x = 0; x < 100; x+=5) { delete(x); delete(x+1); delete(x+2); delete(x+3); delete(x+4); }上面的代码很容易理解,循环的迭代次数从100次减少为20次,显然,这样会较少循环控制的判断(对x的判断)的指令执行次数,从而提高性能。当然,实际上,仅仅依靠上述循环展开往往不能很大程度的提高性能,而且上面的静态的循环迭代次数只是最简单的情况,还有很多情况需要动态进行循环展开等,另外,循环展开是对循环进行优化的一项基础技术,往往需要和其他优化进行合作。向量化的过程,往往就是从循环展开开始的。
2. sectioning/loop-sectioning/strip-mining/strip mining
循环切分?
wiki没有找到专门介绍sectioning的页面,在上面的循环优化的wiki(http://en.wikipedia.org/wiki/Loop_optimization)中提到了此项优化技术如下:
loop-sectioning (also known as strip-mining) is a loop-transformation technique for enabling SIMD-encodings of loops and improving memory performance. This technique involves each vector operation being done for a size less than or equal to the maximum vector
length on a given vector machine.
其后面给出了和此项技术有关的链接:
Strip Mining to Optimize Memory Use on 32-Bit Intel® Architecture
Strip-Mining(http://docs.oracle.com/cd/E19205-01/819-5262/aeugr/index.html)
简单来说,sectioning(不确定中文翻译如何表述),是一项加强SIMD对循环的编码和提高内存性能的循环转换技术,使得每一个向量操作以小于或者等于给定的向量机最大的向量长度的大小来完成。
参考上面的链接能很容易的理解此项技术对内存优化的过程,当然,上面的链接没有包括SIMD相关的优化的例子。
3. Loop interchange循环交换
http://en.wikipedia.org/wiki/Loop_interchange
In compiler theory, loop interchange is the process of exchanging the order of two iteration variables.
简单来说,循环交换就是交换内外层循环的迭代变量的过程。需要注意的是,不是所有情况都能直接进行循环交换,需要判断数据依赖关系。
下面的例子可以很容易理解循环交换的过程:
for(int i=0;i<M;i++) for(int j=0;j<N;j++) a[i][j]=i+j; for(int j=0;j<N;j++) for(int i=0;j<M;i++) a[i][j]=i+j;显然,上面两个循环是等价的,但是性能不一样。哪一个更好?大多数情况,相信是第一个循环更好,因为二维数组是连续排列的,第二个循环很有可能导致了更多刷新cache的次数。
和循环交换相关的博文:
/article/5461390.html
http://www.cdblp.cn/paper/%E5%BE%AA%E7%8E%AF%E4%BA%A4%E6%8D%A2%E4%B8%8E%E9%80%92%E5%BD%92%E6%B6%88%E9%99%A4/6951.html
4. Loop blocking
loop blocking是intel编译器提供的一种优化技术,是strip mining和loop interchange的结合。
参考http://software.intel.com/en-us/articles/performance-tools-for-software-developers-loop-blocking/理解其细节。
相关文章推荐
- 使用Intel 向量化编译器优化性能(2)
- 使用Intel编译器(0)基础(1)内联
- 使用Intel 向量化编译器优化性能(2)
- 使用Intel编译器(2)向量化(1)自动向量化基础
- 使用Intel 向量化编译器优化性能(3)
- 使用Intel 向量化编译器优化性能(3)
- dubbo源码学习(一)基础知识及使用的相关技术
- 使用Intel编译器(5)PGO(3)评测函数或循环执行时间(Profile Function or Loop Execution Time)
- 使用Intel编译器(0)基础(2)基本块Basic Block
- Dubbo 源码学习(一)基础知识及使用的相关技术
- 使用Intel编译器(1)并行化(3)自动并行化相关的选项和总结
- 使用Intel编译器(1)并行化(2)自动并行化代码相关
- 使用Intel 向量化编译器优化性能(1)
- 使用Intel编译器(1)并行化(1)自动并行化基础
- 使用Intel编译器(3)HLO(1)高级别优化的选项和使用
- 使用Intel 向量化编译器优化性能(1)
- Android中,JNI技术的相关基础知识
- 【C++沉思录】编译器使用的优化技巧
- android 技术总结 图片优化 sqlite使用 Fragment使用
- SQL优化基础 使用索引(一个小例子)