程序循環(huán)優(yōu)化方法10_第1頁
程序循環(huán)優(yōu)化方法10_第2頁
程序循環(huán)優(yōu)化方法10_第3頁
程序循環(huán)優(yōu)化方法10_第4頁
程序循環(huán)優(yōu)化方法10_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、提升循環(huán)級并行IntelCopyright 2002 Intel Corporation1AgendaIntroductionWho Cares?DefinitionLoop Dependence and RemovalDependency Identification LabSummary2IntroductionLoops must meet certain criteriaIteration IndependenceMemory DisambiguationHigh Loop CountEtc3Who Cares實現(xiàn)真正的并行: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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論