版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ParallelProgrammingInstructor:ZhangWeizhe(张伟哲)ComputerNetworkandInformationSecurityTechniqueResearchCenter,SchoolofComputerScienceandTechnology,HarbinInstituteofTechnologyCELL处理器及其编程模型3提纲
ArchitectureoftheCell单元架构
Cellprogrammingmodel单元编程模型
TheIBMFullSystemSimulatorIBM全系统模拟器Challenges:ThreeMajorLimiterstoProcessorPerformanceFrequencyWall频率墙Diminishingreturnsfromdeeperpipelines从更深的管道减少返回MemoryWall记忆墙Processorfrequencyvs.DRAMmemorylatency处理器频率与DRAM内存延迟Latencyintroducedbymultiplelevelsofmemory延迟由多层次的内存引入PowerWall电源墙LimitsinCMOStechnologyCMOS技术的局限性Hardlimittoacceptablesystempower硬限制到可接受的系统功率CellBE(CellBroadbandEngine)SolutionsIncreaseconcurrency增加并发性Multiplecores多核心SIMD/Vectoroperationsinacore在核心SIMD/向量运算Startmemorymovementearlysothatmemoryisavailablewhenneeded提前启动记忆运动,以便在需要时记忆可用Increaseefficiency提高效率Simplercoresdevotemoreresourcestoactualcomputation更简单的核心将更多的资源用于实际的计算Programmermanagedmemoryismoreefficientthandraggingdatathroughcaches程序员管理的内存比通过缓存拖动数据更有效率Largeregisterfilesgivethecompilermoreflexibilityandeliminatetransistorsneededforregisterrenaming大寄存器文件给编译器更多的灵活性和消除需要的寄存器重命名晶体管Specializeprocessorcoresforspecifictasks为特定任务专门处理核心TheCellBEConceptCompatibilitywith64bPowerArchitecture™与64bPowerArchitecture™的兼容性BuildsonandleveragesIBMinvestmentandcommunity建立并利用IBM投资和社区Increasedefficiencyandperformance提高效率和性能Attacksonthe“PowerWall”攻击“电墙”NonHomogenousCoherentMultiprocessor非同质相干多处理器Highdesignfrequency@alowoperatingvoltagewithadvancedpowermanagement高设计频率@低工作电压,并具有先进的电源管理功能Attacksonthe“MemoryWall”攻击“记忆墙”StreamingDMAarchitecture流式DMA架构3-levelMemoryModel:MainStorage,LocalStorage,RegisterFiles3级内存模式:主存储,本地存储,注册文件Attacksonthe“FrequencyWall”攻击“频率墙”Highlyoptimizedimplementation高度优化的实现Largesharedregisterfilesandsoftwarecontrolledbranchingtoallowdeeperpipelines大型共享寄存器文件和软件控制分支,以允许更深的管道CellBEBlockDiagramSPU:Synergisticprocessorunit协同处理器单元PPU:PowerPCprocessorunitMIC:memoryinterfacecontrollerBIC:businterfacecontrollerVMX:vector/SIMDmultimedia多媒体extensionPPEBlockDiagram支持两个线程:基于Cache访问MemorySPEBlockDiagram支持一个SIMD线程:直接可访问Localstore(256KB),localstore通过DMA与memory交换数据MFCDetailMemoryFlowControlSystemDMAUnitLS<->LS,LS<->SysMemory,LS<->I/OTransfers8PPE-sideCommandQueueentries16SPU-sideCommandQueueentriesMMUsimilartoPowerPCMMU8SLBs,256TLBs4K,64K,1M,16MpagesizesSoftware/HWpagetablewalkPT/SLBmissesinterruptPPEAtomicCacheFacility4cachelinesforatomicupdates2cachelinesforcastout/MMUreloadUpto16outstandingDMArequestsinBIUResource/BandwidthManagementTablesTokenBasedBusAccessManagementTLBLockingIsolationModeSupport(SecurityFeature)Hardwareenforced“isolation”SPUandLocalStorenotvisible(busorjtag)SmallLS“untrustedarea”forcommunicationareaSecureBootChipSpecificKeyDecrypt/AuthenticateBootcode“SecureVault”–RuntimeIsolationSupportIsolateLoadFeatureIsolateExitFeatureElementInterconnectBus-DataTopologyFour16Bdataringsconnecting12buselementsTwoclockwise/Twocounter-clockwise两个顺时针/两个逆时针Physicallyoverlapsallprocessorelements与所有处理器元件物理重叠Centralarbitersupportsuptothreeconcurrenttransfersperdataring中央仲裁器支持每个数据环最多三个并发传输Twostage,dualroundrobinarbiter两阶段双循环仲裁者Eachelementportsimultaneouslysupports16Binand16BoutdatapathRingtopologyistransparenttoelementdatainterface16提纲
ArchitectureoftheCell
Cellprogrammingmodel
TheIBMFullSystemSimulatorCellBERuntimeEnvironmentLinuxKernelSupportCellBEThreadsandTasksModelBasicPPEandSPEProgramControlandDataFlowCell/BEBasicProgrammingConceptsCellBERuntimeEnvironmentLinux内核支持单元BE线程和任务模型基本PPE和SPE程序控制和数据流Cell/BE基本编程概念LinuxKernelSupportPPErunsPowerPCapplicationsandoperatingsystemsPPEhandlesthreadallocationandresourcemanagementamongSPEsPPE’sLinuxkernelcontrolstheSPUs’executionofprogramsScheduleSPEexecutionindependentfromregularLinuxthreadsResponsibleforruntimeloading,passingparameterstoSPEprograms,notificationofSPEeventsanderrors,anddebuggersupportPPE’sLinuxkernelmanagesvirtualmemory,includingmappingeachSPE’slocalstore(LS)andproblemstate(PS)intotheeffective-addressspaceThekernelalsocontrolsvirtual-memorymappingofMFCresources,aswellasMFCsegment-faultandfaulthandlingLargepages(16-MBpages,usingthehugetlbfsLinuxextension)aresupportedLinuxKernelSupportPPE运行PowerPC应用程序和操作系统PPE处理SPE之间的线程分配和资源管理PPE的Linux内核控制SPU执行程序安排SPE执行独立于常规Linux线程负责运行时加载,将参数传递给SPE程序,SPE事件和错误的通知以及调试器支持PPE的Linux内核管理虚拟内存,包括将每个SPE的本地存储(LS)和问题状态(PS)映射到有效地址空间内核还控制MFC资源的虚拟内存映射以及MFC段故障和页错误处理支持大页面(16MB页面,使用hugetlbfsLinux扩展)CellBEThreadsandTasksModelPPEprogram–LinuxtasksaLinuxtaskcaninitiateoneormore“SPEthreads”SPEprogram–“local”SPEexecutables(“SPEthreads”)SPEexecutablesarepackagedinsidePPEexecutablefilesAnSPEthread:isinitiatedbyataskrunningonthePPEisassociatedwiththeinitiatingtaskonthePPErunsasynchronouslyfrominitiatingtaskhasauniqueidentifierknowntoboththeSPEthreadandtheinitiatingtaskcompletesatreturnfrommainintheSPEcodeCellBEThreadsandTasksModelPPE程序-Linux任务Linux任务可以启动一个或多个“SPE线程”SPE程序-“本地”SPE可执行文件(“SPE线程”)SPE可执行文件打包在PPE可执行文件中SPE线程:由在PPE上运行的任务启动与PPE上的启动任务相关联从启动任务异步运行具有SPE线程和启动任务都已知的唯一标识符在SPE代码返回主站完成AnSPEgroupacollectionofSPEthreadsthatshareschedulingattributesthereisadefaultgroupwithdefaultattributeseachSPEthreadbelongstoexactlyoneSPEgroupBasicPPEandSPEProgramControlandDataFlow(PPEProgram)LoadstheSPEprogramtotheLS.(PPEProgram)InstructstheSPEstoexecutetheSPEprogram.(SPEProgram)TransfersrequireddatafromthemainmemorytotheLS.(SPEProgram)Processesthereceiveddatainaccordancewiththerequirements.(SPEProgram)TransferstheprocessedresultfromtheLStothemainmemory.(SPEProgram)NotifiesthePPEprogramoftheterminationofprocessing.一个SPE组共享调度属性的SPE线程的集合有一个具有默认属性的默认组每个SPE线程仅属于一个SPE组基本PPE和SPE程序控制和数据流(PPE程序)将SPE程序加载到LS。(PPE程序)指示SPE执行SPE程序。(SPE程序)将所需的数据从主存储器传输到LS。(SPE程序)根据要求处理接收到的数据。(SPE程序)将处理后的结果从LS传送到主存储器。(SPE程序)通知PPE程序终止处理。Cell/BEBasicProgrammingConceptsSPEsandPPEareheterogeneousmulticoresystemdifferentarchitecturesdisjointaddressspacesdifferentmodelsofmemoryandresourceprotectionrequiretwodistincttoolchainsforsoftwaredevelopment.ThePPEisjustaPowerPCrunningLinux.Nospecialprogrammingtechniquesorcompilersareneeded.ThePPEmanagesSPEprocessesasPOSIXpthreads.IBM-providedlibrary(libspe2)handlesSPEprocessmanagementwithinthethreads.LIBSPE:SPEruntimemanagementlibraryCompilertoolsembedSPEexecutablesintoPPEexecutables:onefileprovidesinstructionsforallexecutionunits.Cell/BEBasicProgrammingConceptsSPE和PPE是异构多核系统不同的架构不相交的地址空间不同型号的内存和资源保护需要两个不同的工具链来进行软件开发。PPE只是运行Linux的PowerPC。不需要特殊的编程技术或编译器。PPE将SPE进程管理为POSIXpthread。IBM提供的库(libspe2)处理线程内的SPE进程管理。LIBSPE:SPE运行时管理库编译器工具将SPE可执行文件嵌入到PPE可执行文件中:一个文件为所有执行单元提供指令。SPEruntimemanagementlibrary:LIBSPETheSPEruntimemanagementlibrary(libspe)containsanSPEthreadprogrammingmodelforCellBEapplicationsisusedtocontrolSPEprogramexecutionfromthePPEprogramHandlesSPEsasvirtualobjectscalledSPEcontextsSPEprogramscanbeloadedandexecutedbyoperatingSPEcontextsSPEruntimemanagementlibrary:LIBSPESPE运行时管理库(libspe)包含用于CellBE应用程序的SPE线程编程模型用于从PPE程序中控制SPE程序执行处理SPE作为称为SPE上下文的虚拟对象SPE程序可以通过操作SPE上下文来加载和执行CellProgrammingWorkshop12/31/2024ClassObjectivesYouwilllearnhowtowrite,buildandrun“HelloWorld!”ontheCellSystemSimulatorNavigatethroughthebasicbuildprocessandmakefilesFamiliarizewithgccandxlccompilersFamiliarizewiththesystemsimulatorTherearethreedifferentversionsof“HelloWorld!”usedinthissessionPPEonly,SPEonly,andCellBE,i.e.usingbothPPEandSPESynchronousAsynchronousCellProgrammingWorkshop12/31/2024ClassObjectives您将学习如何在CellSystemSimulator上编写,构建和运行“HelloWorld!”浏览基本构建过程并制作文件熟悉gcc和xlc编译器熟悉系统模拟器在这个会话中使用了三个不同版本的“HelloWorld!”仅限PPE,只有SPE,和CellBE,即使用PPE和SPE两者同步异步CellProgrammingWorkshop12/31/2024Howtobuild,compileandexecutethe“HelloWorld!”programPre-requisitesToolchainCompilerBuildProcessSourceCodeMakefilesSourcePPESourceSPESimulatorGettingthebinaryintothesimulatorRunningthebinaryCellProgrammingWorkshop12/31/2024Howtobuild,compileandexecutethe“HelloWorld!”program先决条件工具链编译器构建过程源代码Makefile文件来源PPE来源SPE模拟器将二进制进入模拟器运行二进制文件CellProgrammingWorkshop12/31/2024CellBE
ExecutableBuildProcessSPECodeSPE
ToolchainSPE
ObjectsEmbed
UtilityPPEObjPPECodePPE
ToolchainPPE
ObjectsPPE
Toolchain
(Linker)SPECodeSPE
CodePPECodeCellProgrammingWorkshop12/31/2024CompilingwithintheSDKTopofbuildenvironmentis/opt/cell/sdk/Includesthebuildenvironmentfiles包括构建环境文件README_build_env.txtProvidesdetailsonthebuildenvironmentfeatures,includingfiles,structureandvariables.提供有关构建环境功能的详细信息,包括文件,结构和变量。make.footerSpecifiesallofthebuildrulesneededtoproperlybuildCBEAbinaries指定正确构建CBEA二进制文件所需的所有构建规则MustbeincludedinallSDKMakefiles(referencedrelativelyif$CELL_TOPisnotdefined)必须包含在所有SDKMakefile中(如果没有定义$CELL_TOP,则引用)Includesmake.headermake.headerSpecifiesdefinitionsneededtoprocesstheMakefiles指定处理Makefile所需的定义Includesmake.envmake.envSpecifiesthedefaultcompilersandtoolstobeusedbymake指定make使用的默认编译器和工具make.footerandmake.headershouldnotbemodifiedCellProgrammingWorkshop12/31/2024CommonMakefilevariablesDIRS listofsubdirectoriestobuildfirstPROGRAM_ppu PROGRAMS_ppu32-bitPPUprogram(orlistofprograms)tobuild.PROGRAM_ppu64 PROGRAMS_ppu6464-bitPPUprogram(orlistofprograms)tobuild.PROGRAM_spu PROGRAMS_spuSPUprogram(orlistofprograms)tobuild.Ifwrittenasastandalonebinary,canrunwithoutbeingembeddedinaPPUprogram.LIBRARY_embed LIBRARY_embed64CreatesalinkedlibraryfromanSPUprogramtobeembeddedintoa32-bitor64-bitPPUprogram.OBJS OBJS_<program> Listofobjectsfortheprograms(oronespecificprogram).Bydefault,allobjectsinthecurrentdirectoryarelinkedintothebinary.IMPORTS IMPORTS_<program>Listoflibrariestolinkintheprograms(oronespecificprogram).AlsousedbythePPUprogramstoembedtheSPUlinkedlibrary.CellProgrammingWorkshop12/31/2024DirectoryLayoutandExamplesofMakefilesamplesample.hMakefilesample/spuMakefilesample_spu.csample/ppuMakefilesample.cDIRS=spuppuinclude$(CELL_TOP)/buildutils/make.footerPROGRAM_spu=sample_spuLIBRARY_embed=lib_sample_spu.ainclude$(CELL_TOP)/buildutils/make.footerPROGRAM_ppu=sampleIMPORTS=../spu/lib_sample_spu.ainclude$(CELL_TOP)/buildutils/make.footerCellProgrammingWorkshop12/31/2024BuildingTheCodeEnvironmentsetupSettheCELL_TOPenvironmentvariablesothatthemakefilesystemcanbefound:exportCELL_TOP=/opt/cell/sdk/make.footercontainsthebuildrulesforthemakefilesystemEnsurecompilersorcross-compilersareintheexecutablesearchpathSeparateSPEcodeandPPEcodeintodifferentdirectoriesEachsetofcodehasit’sownmakefileandtoolchaintouseSuggestion:createasubdirectorycalled‘spu’inthedirectorywherethePPUcodeisfoundMakefiletemplateforPPEcode:DIRS=spuPROGRAM_ppu=<PPU_executable_name>IMPORTS=<spu_executable-embed.a>-lspe2include$(CELL_TOP)/buildutils/make.footerMakefiletemplateforSPEcode:PROGRAM_spu=<SPU_executable_name>LIBRARY_embed=<spu_executable-embed.a>include$(CELL_TOP)/buildutils/make.footerCellProgrammingWorkshop12/31/2024FourDifferentVersionsof“HelloWorld!”PPEonlySPEonlySynergisticPPEandSPE:synchronousOneSPEisused.MainthreadblocksandwaitsfortheSPEcodetoruntocompletionSynergisticPPEandSPE:asynchronousEightSPEsareusedMainthreadusespthreadstogetconcurrent/asynchronousexecutionCellProgrammingWorkshop12/31/2024FourDifferentVersionsof“HelloWorld!”仅PPE仅SPE协同PPE和SPE:同步使用一个SPE。主线程阻塞并等待SPE代码运行完成协同PPE和SPE:异步使用八个SPE主线程使用pthreads来执行并发/异步CellProgrammingWorkshop12/31/2024“HelloWorld!”–PPEOnlyPPUprogramjustlikeany“HelloWorld!”programonewouldwriteMakefilemake.footerincludedtosetupcompilerandcompilerflagsPROGRAM_pputellsmaketousePPCcross-compiler#include<stdio.h>intmain(void){printf("Helloworld!\n");return0;}PROGRAM_ppu=hello_ppuinclude$(CELL_TOP)/buildutils/make.footerPROGRAM_pputellsmaketousePPCcompilerCellProgrammingWorkshop12/31/2024“HelloWorld!”–SPEOnlySPUProgramSPUMakefile#include<stdio.h>intmain(){printf("Helloworld!\n");return0;}PROGRAM_spu:=hello_spuinclude$(CELL_TOP)/buildutils/make.footerPROGRAM_sputellsmaketouseSPEcompilerCellProgrammingWorkshop12/31/2024SynergisticPPEandSPE(SPEEmbedded)ApplicationsusesoftwareconstructscalledSPEcontextstomanageandcontrolSPEs.LinuxschedulesSPEcontextsfromallrunningapplicationsontothephysicalSPEresourcesinthesystemforexecutionaccordingtotheschedulingprioritiesandpoliciesassociatedwiththerunableSPEcontexts.libspeprovidesthemeansforcommunicationanddatatransferbetweenPPEthreadsandSPEs.CellProgrammingWorkshop12/31/2024SynergisticPPEandSPE(SPEEmbedded)应用程序使用称为SPE上下文的软件构造来管理和控制SPE。Linux根据与可运行的SPE上下文相关联的调度优先级和策略,将来自所有运行的应用程序的SPE上下文调度到系统中的物理SPE资源以执行。libspe为PPE线程和SPE之间的通信和数据传输提供了手段。CellProgrammingWorkshop12/31/2024HowdoesaPPEprogramstartanSPEthread?4basicstepsmustbedonebythePPEprogramCreateanSPEcontext.LoadanSPEexecutableobjectintotheSPEcontextlocalstore.RuntheSPEcontext.Thistransferscontroltotheoperatingsystem,whichrequeststheactualschedulingofthecontextontoaphysicalSPEinthesystem.DestroytheSPEcontext.CellProgrammingWorkshop12/31/2024HowdoesaPPEprogramstartanSPEthread?PPE程序必须执行4个基本步骤创建一个SPE上下文。将SPE可执行对象加载到SPE上下文本地存储中。运行SPE上下文。这将控制转移到操作系统,操作系统请求上下文的实际调度到系统中的物理SPE。销毁SPE上下文。StructureofanSPEContextspe_context_ptr_tspeid;//speidisapointerpointstothespe_context_ptr_tdatastructurewhichservesastheidentifierforaspecificSPEcontextthatshouldberun.unsignedintflags=0;//flagsisabitmaskthatcanbeusedtorequestcertainspecificbehaviorfortheexecutionoftheSPEcontext.Ifthevalueis0,thisindicatesdefaultbehavior.unsignedintentry=SPE_DEFAULT_ENTRY;//entryisapointertothevariablecontainingtheinitialvalueoftheSPUinstructionpointer,theaddressatwhichtheSPEprogramshouldstartexecuting.IfthevalueofentryisSPE_DEFAULT_ENTRY,theentrypointfortheSPUmainprogramisobtainedfromtheloadedSPEimage.Thisisusuallythelocalstoreaddressoftheinitializationfunction.void*argp=NULL;//argpisapointertoapplicationspecificdata,andispassedasthesecondparametertotheSPEprogram’smain()functionvoid*envp=NULL;//envpisapointertoenvironmentspecificdata,andispassedasthethirdparametertotheSPEprogram’smain()functionspe_stop_info_tstop_info;//stop_infoisapointerpointstothespe_stop_info_tdatastructurewhichprovidesdetailedinformationwhytheSPEstoppeditsprogramexecution.StructureofanSPEContextspe_context_ptr_tspeid//speid是指向spe_context_ptr_t数据结构的指针,它用作应该运行的特定SPE上下文的标识符。unsignedintflags=0;//flags是一个位掩码,可用于请求某些特定行为来执行SPE上下文。如果值为0,则表示默认行为。unsignedintentry=SPE_DEFAULT_ENTRY;//entry是指向包含SPU指令指针的初始值的变量的指针,SPE指令指针是SPE程序应该开始执行的地址。如果条目值为SPE_DEFAULT_ENTRY,则从加载的SPE图像获取SPU主程序的入口点。这通常是初始化函数的本地存储地址。void*argp=NULL;//argp是指向应用程序特定数据的指针,并作为第二个参数传递给SPE程序的main()函数void*envp=NULL;//envp是指向环境特定数据的指针,并作为第三个参数传递给SPE程序的main()函数spe_stop_info_tstop_info;//stop_info是指向spe_stop_info_t数据结构的指针,它提供了SPE停止其程序执行的详细信息。CellProgrammingWorkshop12/31/2024SPEcontextcreationspe_context_create-CreateandinitializeanewSPEcontextdatastructure.
#include<libspe2.h> spe_context_ptr_tspe_context_create(unsignedintflags,spe_gang_context_ptr_tgang)flags-Abit-wiseORofmodifiersthatareappliedwhentheSPEcontextiscreated.gang-AssociatethenewSPEcontextwiththisgangcontext.IfNULLisspecified,thenewSPEcontextisnotassociatedwithanygang.Onsuccess,apointertothenewlycreatedSPEcontextisreturned.CellProgrammingWorkshop12/31/2024spe_program_loadspe_program_load-LoadanSPEmainprogram.
#include<libspe2.h> intspe_program_load(spe_context_ptr_tspe,spe_program_handle_t*program)spe-AvalidpointertotheSPEcontextforwhichanSPEprogramshouldbeloaded.program-AvalidaddressofamappedSPEprogram.CellProgrammingWorkshop12/31/2024spe_context_runspe_context_run-RequestexecutionofanSPEcontext.
#include<libspe2.h> intspe_context_run(spe_context_ptr_tspe,unsignedint*entry,unsignedintrunflags,void*argp,void*envp,spe_stop_info_t*stopinfo)spe-ApointertotheSPEcontextthatshouldberun.entry-Input:Theentrypoint,thatis,theinitialvalueoftheSPUinstructionpointer,atwhichtheSPEprogramshouldstartexecuting.IfthevalueofentryisSPE_DEFAULT_ENTRY,theentrypointfortheSPUmainprogramisobtainedfromtheloadedSPEimage.Thisisusuallythelocalstoreaddressoftheinitializationfunctioncrt0.runflags-AbitmaskthatcanbeusedtorequestcertainspecificbehaviorfortheexecutionoftheSPEcontext.0indicatesdefaultbehavior.argp-An(optional)pointertoapplicationspecificdata,andispassedasthesecondparametertotheSPEprogram,envp-An(optional)pointertoenvironmentspecificdata,andispassedasthethirdparametertotheSPEprogram,stopinfoAn(optional)pointertoastructureoftypespe_stop_info_tCellProgrammingWorkshop12/31/2024spe_context_destroyspe_context_destroy-DestroythespecifiedSPEcontext.
#include<libspe2.h>
intspe_context_destroy(spe_context_ptr_tspe)spe-SpecifiestheSPEcontexttobedestroyedOnsuccess,0(zero)isreturned,else-1isreturnedLIBSPEVersion2.0–SinglethreadAsimpleapplicationusesasinglePPEthread,thatis,theapplication’sPPEthreadThebasicschemeforasimpleapplicationusinganSPEisasfollows:CreateanSPEcontextLoadanSPEexecutableobjectintotheSPEcontext’slocalstoreRunSPEcontext–thistransferscontroltotheoperatingsystemrequestingtheactualschedulingofthecontexttoaphysicalSPEinthesystemDestroySPEcontextNotethatstep3.aboverepresentsasynchronouscalltotheoperatingsystem.Thecallingapplication’sPPEthreadblocksuntiltheSPEstopsexecutionandtheoperatingsystemreturnsfromthesystemcallinvokingtheSPEexecutionLIBSPEVersion2.0–Singlethread一个简单的应用程序使用单个PPE线程,即应用程序的PPE线程使用SPE的简单应用程序的基本方案如下:创建一个SPE上下文将SPE可执行对象加载到SPE上下文的本地存储中运行SPE上下文-这将控制转移到操作系统,请求实际调度上下文到系统中的物理SPE破坏SPE上下文请注意,上面的步骤3.代表对操作系统的同步调用。调用应用程序的PPE线程阻塞,直到SPE停止执行,并且操作系统从调用SPE执行的系统调用返回HelloWorldsinglethreadsample:SPEprogram
hello_spu#include<stdio.h>intmain(unsignedlonglongspeid,unsignedlonglongargp,unsignedlonglongenvp){printf("HelloWorld!\n");return0;}HelloWorldsinglethreadsample:SPEprogram
hello_ppu#include<errno.h>#include<stdio.h>#include<stdlib.h>#include<libspe2.h>externspe_program_handle_thello_spu;intmain(void){//StructureforanSPEcontextspe_context_ptr_tspeid;unsignedintflags=0;unsignedintentry=SPE_DEFAULT_ENTRY;void*argp=NULL;void*envp=NULL;spe_stop_info_tstop_info;intrc;//CreateanSPEcontextspeid=spe_context_create(flags,NULL);if(speid==NULL){perror("spe_context_create");return-2;}//LoadanSPEexecutableobjectintotheSPEcontextlocalstoreif(spe_program_load(speid,&hello_spu)){perror("spe_program_load");return-3;}//RuntheSPEcontextrc=spe_context_run(speid,&entry,0,argp,envp,&stop_info);if(rc<0)perror("spe_context_run");//DestroytheSPEcontextspe_context_destroy(speid);return0;}NameofanSPEprogramlibspe2headerfileLIBSPEVersion2.0–Multi-threadManyapplicationsneedtousemultipleSPEsconcurrentlyInthiscase,itisnecessaryfortheapplicationtocreateatleastasmanyPPEthreadsasconcurrentSPEcontextsarerequiredEachofthesePPEthreadsmayrunasingleSPEcontextatatimeIfNconcurrentSPEcontextsareneeded,itiscommontohaveamainapplicationthreadplusNPPEthreadsdedicatedtoSPEcontextexecutionThebasicschemeforasimpleapplicationrunningNSPEcontextsisCreateNSPEcontextsLoadtheappropriateSPEexecutableobjectintoeachSPEcontext’slocalstoreCreateNPPEthreadsIneachofthesePPEthreadsrunoneoftheSPEcontextsTerminatethePPEthreadWaitforallNPPEthreadstoterminateDestroyallNSPEcontextsLIBSPEVersion2.0–Multi-thread许多应用程序需要同时使用多个SPE在这种情况下,应用程序必须至少创建与并行SPE上下文相同数量的PPE线程这些PPE线程中的每一个可以一次运行单个SPE上下文如果需要N个并发SPE上下文,通常有一个主应用程序线程加上专用于SPE上下文执行的NPPE线程运行NSPE上下文的简单应用程序的基本方案是创建N个SPE上下文将相应的SPE可执行对象加载到每个SPE上下文的本地存储中创建N个PPE线程在每个这些PPE线程中运行一个SPE上下文终止PPE线程等待所有N个PPE线程终止销毁所有NSPE上下文Multi-thread:SingleThreadAsynchronousExecutionExampleTheapplicationcreatesonePPEthreadThePPEthreadwillrunanSPEcontextatatimeThebasicschemeforasimpleapplicationrunning1SPEcontextsasynchronouslyisCreateanSPEcontextLoadtheappropriateSPEexecutableobjectintotheSPEcontext’slocalstoreCreateaPPEthreadRuntheSPEcontextinthePPEthreadTerminatethePPEthreadWaitforthePPEthreadtoterminateDestroytheSPEcontextMulti-thread:SingleThreadAsynchronousExecutionExample应用程序创建一个PPE线程PPE线程将一次运行SPE上下文运行1个SPE上下文的简单应用程序的基本方案是异步运行创建一个SPE上下文将相应的SPE可执行对象加载到SPE上下文的本地存储中创建一个PPE线程在PPE线程中运行SPE上下文终止PPE线程等待PPE线程终止销毁SPE上下文#include<errno.h>#include<stdio.h>#include<stdlib.h>#include<libspe2.h>#include<pthread.h>//StructureforanSPEthreadtypedefstructppu_pthread_data{spe_context_ptr_tcontext;pthread_tpthread;unsignedintentry;unsignedintflags;void*argp;void*envp;spe_stop_info_tstopinfo;}ppu_pthread_data_t;//pthreadfunctiontoruntheSPEcontextvoid*ppu_pthread_function(void*arg){ppu_pthread_data_t*datap=(ppu_pthread_data_t*)arg;intrc;rc=spe_context_run(datap->context,&datap->entry,datap->flags,datap->argp,datap->envp,&datap->stopinfo);pthread_exit(NULL);}externspe_program_handle_thello_spu;intmain(void){ppu_pthread_data_tdata;data.context=spe_context_create(0,NULL);spe_program_load(data.context,&hello_spu);data.entry=SPE_DEFAULT_ENTRY;data.flags=0;data.argp=NULL;data.envp=NULL;pthread_create(&data.pthread,NULL,&ppu_pthread_function,&data);pthread_join(data.pthread,NULL);spe_context_destroy(data.context);return0;}MultiThreadAsynchronousExecutionExample#include<stdlib.h>#include<stdio.h>#include<errno.h>#include<libspe2.h>#include<pthread.h>externspe_program_handle_tsimple_spu;#defineSPU_THREADS6void*ppu_pthread_function(void*arg){spe_context_ptr_tctx;unsignedintentry=SPE_DEFAULT_ENTRY;ctx=*((spe_context_ptr_t*)arg);if(spe_context_run(ctx,&entry,0,NULL,NULL,NULL)<0){perror("Failedrunningcontext");exit(1);}pthread_exit(NULL);}intmain(){inti;spe_context_ptr_tctxs[SPU_THREADS];pthread_tthreads[SPU_THREADS];for(i=0;i<SPU_THREADS;i++){//CreateseveralSPE-threadstoexecute'simple_spu'.if((ctxs[i]=
spe_context_create(0,NULL))==NULL){perror("Failedcreatingcontext");exit(1);}//Createcontextif(spe_program_load(ctxs[i],&simple_spu)){perror("Failedloadingprogram");exit(1); }//Loadprogramintocontextif(pthread_create(&threads[i],NULL,&ppu_pthread_function,&ctxs[i])){perror("Failedcreatingthread");exit(1);}//CreatethreadforeachSPEcontext}for(i=0;i<SPU_THREADS;i++){//WaitforSPU-threadtocompleteexecution.if(pthread_join(threads[i],NULL)){perror("Failedpthread_join");exit(1);}}printf("\nTheprogramhassuccessfullyexecuted.\n");return(0);}63提纲
ArchitectureoftheCell
Cellprogrammingmodel
TheIBMFullSystemSimulatorCellProgrammingWorkshop12/31/2024Intelx86SimulatorOverviewSystemSimPowerPCCaches(L1/L2)MemoryROMExecutablesUARTL3IntCtrlrPowerPCx86-64RuntimeandlibrariesPowerPCPowerPCBEBusLinux(FedoraCore5)SystemSoftware:Hypervisor,Linux/PPCorK42RealSystems:SystemSim:SimulationofhardwareSoftwareStack:RunningonSystemSimDMADisksConsoleWindowGUIWindowsApplicationSourceCodeProgrammingToolsCompilersProgrammingModelOpenMPMPIDevelopmentEnvironment:TracesCellProgrammingWorkshop12/31/2024SystemSimSystemSimRuntimeEnvironmenttcl/tk/blt/mambocmdsTCL/Tk/BLTGUIScripts41StartupTCLFile(.systemsim.tcl)#Createsimulatorinstancedefinedupcellmysim#Loadkernelbootimagemysimloadvmlinux./vmlinux0x1000000#StarttheGUIMamboInit::guiunix$PATH=/opt/IBM/systemsim-cell/bin:$PATHsystemsim-gGUIEnabledLicensedMaterials–PropertyofIBM.©CopyrightIBMCorporation2001,2006AllRightsReserved%5KernelBootImage(vmlinux)3DiskImage(sysroot_disk)NetworkServiceDaemonmysim(cellmodel)consoleROMnetmodelcpumodelmemory2diskmodelROMImage(rom.bin)CellProgrammingWorkshop12/31/2024Operating-SystemModesLinuxModeSimulatorbootsafullLinuxoperatingsystemonthesimulatedsystemApplicationsarelaunchedfromtheLinuxconsolewindowandrunThesimulatedoperatingsystemhandlesallthesystemcallsStandaloneModeTheapplicationisloadeddirectlyintothesimulatedmachinewithoutanoperatingsystemThesimulatortrapsallsystemcallsmadebytheapplicationandperformsthesefunctionsinplace
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年吐鲁番职业技术学院单招职业适应性考试题库附答案解析
- 2025年广州工商学院马克思主义基本原理概论期末考试模拟题带答案解析(夺冠)
- 2025年莒县招教考试备考题库带答案解析
- 2024年郑州城建职业学院马克思主义基本原理概论期末考试题带答案解析
- 2025年河南对外经济贸易职业学院马克思主义基本原理概论期末考试模拟题带答案解析(夺冠)
- 2025年浙江工业大学马克思主义基本原理概论期末考试模拟题带答案解析(必刷)
- 2024年湖南软件职业技术大学马克思主义基本原理概论期末考试题带答案解析
- 2026广东佛山高明区沧江中学附属小学临聘教师招聘备考题库附答案详解(模拟题)
- 2026四川成都经开建工集团有限公司招聘项目制工作人员6人备考题库附参考答案详解(b卷)
- 2026年市场营销策略分析师考试试题与答案解析
- T/CNFAGS 3-2021三聚氰胺单位产品消耗限额
- T/CHTS 10149-2024公路缆索承重桥梁健康监测阈值技术指南
- 2025跨境电商购销合同范本(中英文对照)
- 《骆驼祥子》知识点24章分章内容详述(按原著)
- 2025年人教版九年级物理知识点全面梳理与总结
- DB33T 2256-2020 大棚草莓生产技术规程
- 《建设工程造价咨询服务工时标准(房屋建筑工程)》
- 工程(项目)投资合作协议书样本
- 半导体技术合作开发合同样式
- 制程PQE述职报告
- 小广告清理服务投标方案
评论
0/150
提交评论