程序循环优化方法10_第1页
程序循环优化方法10_第2页
程序循环优化方法10_第3页
程序循环优化方法10_第4页
程序循环优化方法10_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、提升循环级并行IntelCopyright 2002 Intel Corporation1AgendaIntroductionWho Cares?DefinitionLoop Dependence and RemovalDependency Identification LabSummary2IntroductionLoops must meet certain criteriaIteration IndependenceMemory DisambiguationHigh Loop CountEtc3Who Cares实现真正的并行:OpenMPAuto Parallelization显式的指

2、令级并行 ILP (Instruction Level Parallelism)Streaming SIMD (MMX, SSE, SSE2, )Software Pipelining on Intel Itanium ProcessorRemove Dependencies for the Out-of-Order CoreMore Instructions run in parallel on Intel Itanium-Processor自动编译器并行High Level Optimizations4Definitionint aMAX;for (J=0;JMAX;J+) aJ = bJ

3、;Loop Independence: Iteration Y of a loop is independent of when or whether iteration X happens5图例OpenMP: True ParallelismSIMD: VectorizationSWP: Software PipeliningOOO: Out-of-Order Core ILP: Instruction Level Parallelism Green: Benefits from concept Yellow: Some Benefits from Concept Red: No Benef

4、it from Concept 6AgendaDefinitionWho Cares?Loop Dependence and RemovalData DependenciesRemoving DependenciesData Ambiguity and the CompilerDependency Removal LabSummary7Flow DependencyRead After WriteCross-Iteration Flow Dependence: Variables written then read in different iterationsfor (J=1; JMAX;

5、J+) AJ=AJ-1;A1=A0;A2=A1;8Anti-DependencyWrite After ReadCross-Iteration Anti-Dependence: Variables written then read in different iterationsfor (J=1; JMAX; J+) AJ=AJ+1; A1=A2;A2=A3;9Output DependencyWrite After WriteCross-Iteration Output Dependence: Variables written then written again in a differe

6、nt iterationfor (J=1; JMAX; J+) AJ=BJ;AJ+1=CJ;A1=B1;A2=C1;A2=B1;A3=C1;10IntraIteration DependencyDependency within an iterationHurts ILPMay be automatically removed by compilerK = 1;for (J=1; JMAX; J+) AJ=AJ + 1;BK=AK + 1;K = K + 2; A1 = A1 + 1;B1= A1 + 1;11for (J=1; JMAX; J+) AJ= A0 + J;Remove Depe

7、ndenciesBest ChoiceRequirement for true ParallelismNot all dependencies can be removedfor (J=1; JMAX; J+) AJ=AJ-1 + 1;12for (J=1;JMAX;J+=2) AJ=AJ-1 + BJ;AJ+1=AJ-1 + (BJ + BJ+1);Increasing ILP, without removing dependencies Good: Unroll LoopMake sure the compiler cant or didnt do this for youCompiler

8、 should not apply common sub-expression elimination Also notice that if this is floating point data - precision could be alteredfor (J=1;JMAX;J+) AJ =AJ-1 + BJ;13Induction VariablesInduction variables are incremented on each trip through the loopFix by replacing increment expressions with pure funct

9、ion of loop indexi1 = 0;i2 = 0;for(J=0,JMAX,J+) i1 = i1 + 1; B(i1) = i2 = i2 + J; A(i2) = for(J=0,JMAX,J+) B(J) = . A(J*2 + J)/2)= .14ReductionsReductions collapse array data to scalar data via associative operations:Take advantage of associativity and compute partial sums or local maximum in privat

10、e storageNext, combine partial results into shared result, taking care to synchronize accessfor (J=0; JMAX; J+) sum = sum + cJ;15Data Ambiguity and the Compilervoid func(int *a, int *b) for (J=0;JMAX;J+) aJ = bJ;Are the loop iterations independent?The C+ compiler has no ideaNo chance for optimizatio

11、n - In order to run error free the compiler assumes that a and b overlap16Function Callsfor (J=0;J=0;J-) compute(J,.) A Simple TestReverse the loop order and rerun in serialIf results are unchanged, the loop is Independent*for(J=0;JMAX;J+) compute(J,.) *Exception: Loops with induction variablesReverse19SummaryLoop Independence: Loop Iterations are independent of each other.Explained its importanceILP and Para

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论