版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
ParallelProgrammingInstructor:ZhangWeizhe(張偉哲)ComputerNetworkandInformationSecurityTechniqueResearchCenter,SchoolofComputerScienceandTechnology,HarbinInstituteofTechnologyCELL處理器及其編程模型3提綱
ArchitectureoftheCell單元架構(gòu)
Cellprogrammingmodel單元編程模型
TheIBMFullSystemSimulatorIBM全系統(tǒng)模擬器Challenges:ThreeMajorLimiterstoProcessorPerformanceFrequencyWall頻率墻Diminishingreturnsfromdeeperpipelines從更深的管道減少返回MemoryWall記憶墻Processorfrequencyvs.DRAMmemorylatency處理器頻率與DRAM內(nèi)存延遲Latencyintroducedbymultiplelevelsofmemory延遲由多層次的內(nèi)存引入PowerWall電源墻LimitsinCMOStechnologyCMOS技術(shù)的局限性Hardlimittoacceptablesystempower硬限制到可接受的系統(tǒng)功率CellBE(CellBroadbandEngine)SolutionsIncreaseconcurrency增加并發(fā)性Multiplecores多核心SIMD/Vectoroperationsinacore在核心SIMD/向量運算Startmemorymovementearlysothatmemoryisavailablewhenneeded提前啟動記憶運動,以便在需要時記憶可用Increaseefficiency提高效率Simplercoresdevotemoreresourcestoactualcomputation更簡單的核心將更多的資源用于實際的計算Programmermanagedmemoryismoreefficientthandraggingdatathroughcaches程序員管理的內(nèi)存比通過緩存拖動數(shù)據(jù)更有效率Largeregisterfilesgivethecompilermoreflexibilityandeliminatetransistorsneededforregisterrenaming大寄存器文件給編譯器更多的靈活性和消除需要的寄存器重命名晶體管Specializeprocessorcoresforspecifictasks為特定任務(wù)專門處理核心TheCellBEConceptCompatibilitywith64bPowerArchitecture?與64bPowerArchitecture?的兼容性BuildsonandleveragesIBMinvestmentandcommunity建立并利用IBM投資和社區(qū)Increasedefficiencyandperformance提高效率和性能Attacksonthe“PowerWall”攻擊“電墻”NonHomogenousCoherentMultiprocessor非同質(zhì)相干多處理器Highdesignfrequency@alowoperatingvoltagewithadvancedpowermanagement高設(shè)計頻率@低工作電壓,并具有先進的電源管理功能Attacksonthe“MemoryWall”攻擊“記憶墻”StreamingDMAarchitecture流式DMA架構(gòu)3-levelMemoryModel:MainStorage,LocalStorage,RegisterFiles3級內(nèi)存模式:主存儲,本地存儲,注冊文件Attacksonthe“FrequencyWall”攻擊“頻率墻”Highlyoptimizedimplementation高度優(yōu)化的實現(xiàn)Largesharedregisterfilesandsoftwarecontrolledbranchingtoallowdeeperpipelines大型共享寄存器文件和軟件控制分支,以允許更深的管道CellBEBlockDiagramSPU:Synergisticprocessorunit協(xié)同處理器單元PPU:PowerPCprocessorunitMIC:memoryinterfacecontrollerBIC:businterfacecontrollerVMX:vector/SIMDmultimedia多媒體extensionPPEBlockDiagram支持兩個線程:基于Cache訪問MemorySPEBlockDiagram支持一個SIMD線程:直接可訪問Localstore(256KB),localstore通過DMA與memory交換數(shù)據(jù)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中央仲裁器支持每個數(shù)據(jù)環(huán)最多三個并發(fā)傳輸Twostage,dualroundrobinarbiter兩階段雙循環(huán)仲裁者Eachelementportsimultaneouslysupports16Binand16BoutdatapathRingtopologyistransparenttoelementdatainterface16提綱
ArchitectureoftheCell
Cellprogrammingmodel
TheIBMFullSystemSimulatorCellBERuntimeEnvironmentLinuxKernelSupportCellBEThreadsandTasksModelBasicPPEandSPEProgramControlandDataFlowCell/BEBasicProgrammingConceptsCellBERuntimeEnvironmentLinux內(nèi)核支持單元BE線程和任務(wù)模型基本PPE和SPE程序控制和數(shù)據(jù)流Cell/BE基本編程概念LinuxKernelSupportPPErunsPowerPCapplicationsandoperatingsystemsPPEhandlesthreadallocationandresourcemanagementamongSPEsPPE’sLinuxkernelcontrolstheSPUs’executionofprogramsScheduleSPEexecutionindependentfromregularLinuxthreadsResponsibleforruntimeloading,passingparameterstoSPEprograms,notificationofSPEeventsanderrors,anddebuggersupportPPE’sLinuxkernelmanagesvirtualmemory,includingmappingeachSPE’slocalstore(LS)andproblemstate(PS)intotheeffective-addressspaceThekernelalsocontrolsvirtual-memorymappingofMFCresources,aswellasMFCsegment-faultandfaulthandlingLargepages(16-MBpages,usingthehugetlbfsLinuxextension)aresupportedLinuxKernelSupportPPE運行PowerPC應(yīng)用程序和操作系統(tǒng)PPE處理SPE之間的線程分配和資源管理PPE的Linux內(nèi)核控制SPU執(zhí)行程序安排SPE執(zhí)行獨立于常規(guī)Linux線程負(fù)責(zé)運行時加載,將參數(shù)傳遞給SPE程序,SPE事件和錯誤的通知以及調(diào)試器支持PPE的Linux內(nèi)核管理虛擬內(nèi)存,包括將每個SPE的本地存儲(LS)和問題狀態(tài)(PS)映射到有效地址空間內(nèi)核還控制MFC資源的虛擬內(nèi)存映射以及MFC段故障和頁錯誤處理支持大頁面(16MB頁面,使用hugetlbfsLinux擴展)CellBEThreadsandTasksModelPPEprogram–LinuxtasksaLinuxtaskcaninitiateoneormore“SPEthreads”SPEprogram–“l(fā)ocal”SPEexecutables(“SPEthreads”)SPEexecutablesarepackagedinsidePPEexecutablefilesAnSPEthread:isinitiatedbyataskrunningonthePPEisassociatedwiththeinitiatingtaskonthePPErunsasynchronouslyfrominitiatingtaskhasauniqueidentifierknowntoboththeSPEthreadandtheinitiatingtaskcompletesatreturnfrommainintheSPEcodeCellBEThreadsandTasksModelPPE程序-Linux任務(wù)Linux任務(wù)可以啟動一個或多個“SPE線程”SPE程序-“本地”SPE可執(zhí)行文件(“SPE線程”)SPE可執(zhí)行文件打包在PPE可執(zhí)行文件中SPE線程:由在PPE上運行的任務(wù)啟動與PPE上的啟動任務(wù)相關(guān)聯(lián)從啟動任務(wù)異步運行具有SPE線程和啟動任務(wù)都已知的唯一標(biāo)識符在SPE代碼返回主站完成AnSPEgroupacollectionofSPEthreadsthatshareschedulingattributesthereisadefaultgroupwithdefaultattributeseachSPEthreadbelongstoexactlyoneSPEgroupBasicPPEandSPEProgramControlandDataFlow(PPEProgram)LoadstheSPEprogramtotheLS.(PPEProgram)InstructstheSPEstoexecutetheSPEprogram.(SPEProgram)TransfersrequireddatafromthemainmemorytotheLS.(SPEProgram)Processesthereceiveddatainaccordancewiththerequirements.(SPEProgram)TransferstheprocessedresultfromtheLStothemainmemory.(SPEProgram)NotifiesthePPEprogramoftheterminationofprocessing.一個SPE組共享調(diào)度屬性的SPE線程的集合有一個具有默認(rèn)屬性的默認(rèn)組每個SPE線程僅屬于一個SPE組基本PPE和SPE程序控制和數(shù)據(jù)流(PPE程序)將SPE程序加載到LS。(PPE程序)指示SPE執(zhí)行SPE程序。(SPE程序)將所需的數(shù)據(jù)從主存儲器傳輸?shù)絃S。(SPE程序)根據(jù)要求處理接收到的數(shù)據(jù)。(SPE程序)將處理后的結(jié)果從LS傳送到主存儲器。(SPE程序)通知PPE程序終止處理。Cell/BEBasicProgrammingConceptsSPEsandPPEareheterogeneousmulticoresystemdifferentarchitecturesdisjointaddressspacesdifferentmodelsofmemoryandresourceprotectionrequiretwodistincttoolchainsforsoftwaredevelopment.ThePPEisjustaPowerPCrunningLinux.Nospecialprogrammingtechniquesorcompilersareneeded.ThePPEmanagesSPEprocessesasPOSIXpthreads.IBM-providedlibrary(libspe2)handlesSPEprocessmanagementwithinthethreads.LIBSPE:SPEruntimemanagementlibraryCompilertoolsembedSPEexecutablesintoPPEexecutables:onefileprovidesinstructionsforallexecutionunits.Cell/BEBasicProgrammingConceptsSPE和PPE是異構(gòu)多核系統(tǒng)不同的架構(gòu)不相交的地址空間不同型號的內(nèi)存和資源保護需要兩個不同的工具鏈來進行軟件開發(fā)。PPE只是運行Linux的PowerPC。不需要特殊的編程技術(shù)或編譯器。PPE將SPE進程管理為POSIXpthread。IBM提供的庫(libspe2)處理線程內(nèi)的SPE進程管理。LIBSPE:SPE運行時管理庫編譯器工具將SPE可執(zhí)行文件嵌入到PPE可執(zhí)行文件中:一個文件為所有執(zhí)行單元提供指令。SPEruntimemanagementlibrary:LIBSPETheSPEruntimemanagementlibrary(libspe)containsanSPEthreadprogrammingmodelforCellBEapplicationsisusedtocontrolSPEprogramexecutionfromthePPEprogramHandlesSPEsasvirtualobjectscalledSPEcontextsSPEprogramscanbeloadedandexecutedbyoperatingSPEcontextsSPEruntimemanagementlibrary:LIBSPESPE運行時管理庫(libspe)包含用于CellBE應(yīng)用程序的SPE線程編程模型用于從PPE程序中控制SPE程序執(zhí)行處理SPE作為稱為SPE上下文的虛擬對象SPE程序可以通過操作SPE上下文來加載和執(zhí)行CellProgrammingWorkshop12/31/2024ClassObjectivesYouwilllearnhowtowrite,buildandrun“HelloWorld!”ontheCellSystemSimulatorNavigatethroughthebasicbuildprocessandmakefilesFamiliarizewithgccandxlccompilersFamiliarizewiththesystemsimulatorTherearethreedifferentversionsof“HelloWorld!”usedinthissessionPPEonly,SPEonly,andCellBE,i.e.usingbothPPEandSPESynchronousAsynchronousCellProgrammingWorkshop12/31/2024ClassObjectives您將學(xué)習(xí)如何在CellSystemSimulator上編寫,構(gòu)建和運行“HelloWorld!”瀏覽基本構(gòu)建過程并制作文件熟悉gcc和xlc編譯器熟悉系統(tǒng)模擬器在這個會話中使用了三個不同版本的“HelloWorld!”僅限PPE,只有SPE,和CellBE,即使用PPE和SPE兩者同步異步CellProgrammingWorkshop12/31/2024Howtobuild,compileandexecutethe“HelloWorld!”programPre-requisitesToolchainCompilerBuildProcessSourceCodeMakefilesSourcePPESourceSPESimulatorGettingthebinaryintothesimulatorRunningthebinaryCellProgrammingWorkshop12/31/2024Howtobuild,compileandexecutethe“HelloWorld!”program先決條件工具鏈編譯器構(gòu)建過程源代碼Makefile文件來源PPE來源SPE模擬器將二進制進入模擬器運行二進制文件CellProgrammingWorkshop12/31/2024CellBE
ExecutableBuildProcessSPECodeSPE
ToolchainSPE
ObjectsEmbed
UtilityPPEObjPPECodePPE
ToolchainPPE
ObjectsPPE
Toolchain
(Linker)SPECodeSPE
CodePPECodeCellProgrammingWorkshop12/31/2024CompilingwithintheSDKTopofbuildenvironmentis/opt/cell/sdk/Includesthebuildenvironmentfiles包括構(gòu)建環(huán)境文件README_build_env.txtProvidesdetailsonthebuildenvironmentfeatures,includingfiles,structureandvariables.提供有關(guān)構(gòu)建環(huán)境功能的詳細(xì)信息,包括文件,結(jié)構(gòu)和變量。make.footerSpecifiesallofthebuildrulesneededtoproperlybuildCBEAbinaries指定正確構(gòu)建CBEA二進制文件所需的所有構(gòu)建規(guī)則MustbeincludedinallSDKMakefiles(referencedrelativelyif$CELL_TOPisnotdefined)必須包含在所有SDKMakefile中(如果沒有定義$CELL_TOP,則引用)Includesmake.headermake.headerSpecifiesdefinitionsneededtoprocesstheMakefiles指定處理Makefile所需的定義Includesmake.envmake.envSpecifiesthedefaultcompilersandtoolstobeusedbymake指定make使用的默認(rèn)編譯器和工具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協(xié)同PPE和SPE:同步使用一個SPE。主線程阻塞并等待SPE代碼運行完成協(xié)同PPE和SPE:異步使用八個SPE主線程使用pthreads來執(zhí)行并發(fā)/異步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)應(yīng)用程序使用稱為SPE上下文的軟件構(gòu)造來管理和控制SPE。Linux根據(jù)與可運行的SPE上下文相關(guān)聯(lián)的調(diào)度優(yōu)先級和策略,將來自所有運行的應(yīng)用程序的SPE上下文調(diào)度到系統(tǒng)中的物理SPE資源以執(zhí)行。libspe為PPE線程和SPE之間的通信和數(shù)據(jù)傳輸提供了手段。CellProgrammingWorkshop12/31/2024HowdoesaPPEprogramstartanSPEthread?4basicstepsmustbedonebythePPEprogramCreateanSPEcontext.LoadanSPEexecutableobjectintotheSPEcontextlocalstore.RuntheSPEcontext.Thistransferscontroltotheoperatingsystem,whichrequeststheactualschedulingofthecontextontoaphysicalSPEinthesystem.DestroytheSPEcontext.CellProgrammingWorkshop12/31/2024HowdoesaPPEprogramstartanSPEthread?PPE程序必須執(zhí)行4個基本步驟創(chuàng)建一個SPE上下文。將SPE可執(zhí)行對象加載到SPE上下文本地存儲中。運行SPE上下文。這將控制轉(zhuǎn)移到操作系統(tǒng),操作系統(tǒng)請求上下文的實際調(diào)度到系統(tǒng)中的物理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數(shù)據(jù)結(jié)構(gòu)的指針,它用作應(yīng)該運行的特定SPE上下文的標(biāo)識符。unsignedintflags=0;//flags是一個位掩碼,可用于請求某些特定行為來執(zhí)行SPE上下文。如果值為0,則表示默認(rèn)行為。unsignedintentry=SPE_DEFAULT_ENTRY;//entry是指向包含SPU指令指針的初始值的變量的指針,SPE指令指針是SPE程序應(yīng)該開始執(zhí)行的地址。如果條目值為SPE_DEFAULT_ENTRY,則從加載的SPE圖像獲取SPU主程序的入口點。這通常是初始化函數(shù)的本地存儲地址。void*argp=NULL;//argp是指向應(yīng)用程序特定數(shù)據(jù)的指針,并作為第二個參數(shù)傳遞給SPE程序的main()函數(shù)void*envp=NULL;//envp是指向環(huán)境特定數(shù)據(jù)的指針,并作為第三個參數(shù)傳遞給SPE程序的main()函數(shù)spe_stop_info_tstop_info;//stop_info是指向spe_stop_info_t數(shù)據(jù)結(jié)構(gòu)的指針,它提供了SPE停止其程序執(zhí)行的詳細(xì)信息。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一個簡單的應(yīng)用程序使用單個PPE線程,即應(yīng)用程序的PPE線程使用SPE的簡單應(yīng)用程序的基本方案如下:創(chuàng)建一個SPE上下文將SPE可執(zhí)行對象加載到SPE上下文的本地存儲中運行SPE上下文-這將控制轉(zhuǎn)移到操作系統(tǒng),請求實際調(diào)度上下文到系統(tǒng)中的物理SPE破壞SPE上下文請注意,上面的步驟3.代表對操作系統(tǒng)的同步調(diào)用。調(diào)用應(yīng)用程序的PPE線程阻塞,直到SPE停止執(zhí)行,并且操作系統(tǒng)從調(diào)用SPE執(zhí)行的系統(tǒng)調(diào)用返回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許多應(yīng)用程序需要同時使用多個SPE在這種情況下,應(yīng)用程序必須至少創(chuàng)建與并行SPE上下文相同數(shù)量的PPE線程這些PPE線程中的每一個可以一次運行單個SPE上下文如果需要N個并發(fā)SPE上下文,通常有一個主應(yīng)用程序線程加上專用于SPE上下文執(zhí)行的NPPE線程運行NSPE上下文的簡單應(yīng)用程序的基本方案是創(chuàng)建N個SPE上下文將相應(yīng)的SPE可執(zhí)行對象加載到每個SPE上下文的本地存儲中創(chuàng)建N個PPE線程在每個這些PPE線程中運行一個SPE上下文終止PPE線程等待所有N個PPE線程終止銷毀所有NSPE上下文Multi-thread:SingleThreadAsynchronousExecutionExampleTheapplicationcreatesonePPEthreadThePPEthreadwillrunanSPEcontextatatimeThebasicschemeforasimpleapplicationrunning1SPEcontextsasynchronouslyisCreateanSPEcontextLoadtheappropriateSPEexecutableobjectintotheSPEcontext’slocalstoreCreateaPPEthreadRuntheSPEcontextinthePPEthreadTerminatethePPEthreadWaitforthePPEthreadtoterminateDestroytheSPEcontextMulti-thread:SingleThreadAsynchronousExecutionExample應(yīng)用程序創(chuàng)建一個PPE線程PPE線程將一次運行SPE上下文運行1個SPE上下文的簡單應(yīng)用程序的基本方案是異步運行創(chuàng)建一個SPE上下文將相應(yīng)的SPE可執(zhí)行對象加載到SPE上下文的本地存儲中創(chuàng)建一個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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度安全生產(chǎn)標(biāo)準(zhǔn)化培訓(xùn)協(xié)議書3篇
- 2025年度多子女贍養(yǎng)老人生活照料與醫(yī)療護理合同3篇
- 2025年度變壓器知識產(chǎn)權(quán)轉(zhuǎn)讓合同2篇
- 2025年度電子產(chǎn)品研發(fā)供應(yīng)商合作協(xié)議范本
- 2025年度道路工程結(jié)算付款協(xié)議2篇
- 2025年度兒童家具安全認(rèn)證合作協(xié)議范本
- 2024年度石灰石原材料采購及運輸一體化服務(wù)合同3篇
- 應(yīng)天職業(yè)技術(shù)學(xué)院《平法鋼筋識圖與算量》2023-2024學(xué)年第一學(xué)期期末試卷
- 營口理工學(xué)院《面向?qū)ο蠹夹g(shù)課程設(shè)計》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024年度貨物運輸搬家服務(wù)合同
- Q∕GDW 11311-2021 氣體絕緣金屬封閉開關(guān)設(shè)備特高頻法局部放電在線監(jiān)測裝置技術(shù)規(guī)范
- [玻璃幕墻施工方案]隱框玻璃幕墻施工方案
- 中聯(lián)QY100T汽車吊主臂起重性能表
- 支付寶手持承諾函
- 國航因私免折票系統(tǒng)
- 三相自耦變壓器設(shè)計模版
- 國家開放大學(xué)電大本科《管理案例分析》2023-2024期末試題及答案(試卷代號:1304)
- 生產(chǎn)安全事故的應(yīng)急救援預(yù)案
- 二面角的求法---三垂線法
- 煤礦井下供電設(shè)計課件
- 未婚承諾書模板
評論
0/150
提交評論