CUDA 矩阵乘法优化.pdf

CUDA 矩阵乘法优化.pdf

ID:49822526

大小:1.12 MB

页数:10页

时间:2020-03-04

CUDA 矩阵乘法优化.pdf_第1页
CUDA 矩阵乘法优化.pdf_第2页
CUDA 矩阵乘法优化.pdf_第3页
CUDA 矩阵乘法优化.pdf_第4页
CUDA 矩阵乘法优化.pdf_第5页
资源描述:

《CUDA 矩阵乘法优化.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、GPUAssignment5KSearcKhthissite70IntroductionMatrixMulExamplePreparationLearningMaterialsExamplesMatrixmultiplicationisafundamentalbuildingblockforscientificcomputation.WhilesolvinglinearequationsandMatrixMulExamplefindingeigenvalues,theworkloadisdominatedbymatrixmultiplication.Assci

2、entificcomputingisanimportantMemoryaccessgroupingexampleapplicationdomaininGPUcomputing,optimizingmatrixmultiplicationonGPUisthekeytoachievehighperformanceAssignmentinthisdomain.ContrastEnhancementKnownIssuesSitemapContents1ThematrixMulproblem2SerialImplementationonCPU3NaiveImplemen

3、tationonGPU4IncreaseComputationtoMemoryRatiobyTiling5MemoryCoalescing6Avoidingmemorybankconflict7Multiply/AddBalancing8Loopunrolling9PrefetchingThematrixMulproblemGivenanMxKmatrixAandaKxNmatrixB,multiplyAwithBandstoretheresultintoaMxNmatrixC.ThematrixMulexampleonthispagewillshowseve

4、raltechniquestooptimizematrixmultiplicationonGPU.Mostofthemaregeneric,whichcanbeappliedtootherapplications.Thesetechniquesare:1.Tiling2.Memorycoalescing3.Avoidingmemorybankconflicts4.Increasefloatingportionbyouterproduct.5.Loopunrolling6.PrefetchingTheperformanceoftheseoptimizationt

5、echniquesareshowinthefiguresbelow.WewillstartwithasimpleserialcoderunningonCPU,andthengothroughtheseoptimizationsstepbystep.convertedbyWeb2PDFConvert.comThesourcecodeoftheseexamplesisavailableintheattachmentofthispage(clicktodownload).UnzipthepackagetoC/srcpathtocompile.SerialImplem

6、entationonCPUvoidmain(){defineA,B,Cfori=0toMdoforj=0toNdo/*computeelementC(i,j)*/fork=0toKdoC(i,j)<=C(i,j)+A(i,k)*B(k,j)endendend}Tosimplifytheexplanation,squarematricesareusedinthisfigure.ThefigureshowsthememoryfootprinttocomputeanelementC(3,11).Thiscanbeviewedastheinnerproductofon

7、erowofAandonecolumnofB.NaiveImplementationonGPU/*CodesrunningonCPU*/voidmain(){defineA_cpu,B_cpu,C_cpuintheCPUmemorydefineA_gpu,B_gpu,C_gpuintheGPUmemorymemcopyA_cputoA_gpumemcopyB_cputoB_gpudim3dimBlock(16,16)dim3dimGrid(N/dimBlock.x,M/dimBlock.y)matrixMul<<>>(A_g

8、pu,B_gpu,C_gpu,K)me

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。