Transcription of Monte-Carlo Simulation on AM57x Using OpenCL …
1 1 TIDUAR9 September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationTI DesignsMonte-CarloSimulationon AM57xUsingOpenCLtoLeverageDSPA ccelerationARM,Cortexare registeredtrademarksof a trademarkof a registeredtrademarkof othertrademarksare the propertyof DesignsTI Designsprovidethe foundationthat you needincludingmethodology,testingand designfiles toquicklyevaluateand customizethe Designshelpyouaccelerateyourtime to E2E ExpertsWEBENCH CalculatorToolsDesignFeatures EnablesUse of the DSPA cceleratorsWithoutRequiringthe Userto HaveExpertKnowledgeofDSP Providesan Exampleof the monte -CarloAlgorithmto GenerateGaussianRandomSequencesThatRun Fasteron the C66xDSPT hanon The ARM Cortex -A15 Core Offersa CompleteSystemReferenceDesignWithExample SoftwareImplementedand TestedUsingthe TI ProcessorSDKand the TI AM57xEVM IncludesSoftwareSource,Schematics,Bill ofMaterials,and DesignFiles Applicableto Any ApplicationThatUsesthe BusinessStrategy RadioChannelSimulation PersonalFinance TrafficLoad(RoadCongestion,NetworkCapaci ty,and More)An IMPORTANTNOTICEat the end of this TI referencedesignaddressesauthorizeduse, intellectualpropertymattersand otherimportantdisclaimersand September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA cceleration1 DesignSummaryThis TI Designis an exampleof how to DSPeasyfor developersand is usedfor applicationssuchas medicalimaging,currencycountersand sorters,visioninspectionsystems,and designshowsDSPacceleratorsfor theMonte-Carlosimulationusingthe Linux OpenCLprogramthat run on the a commonlyusedtool in manyfieldssuchas physics,communications,publicutilities,a nd Normal(Gaussian)
2 Distributedrandomnumbersequenceis an essentialpart of computationalload to generatelong normaldistributedrandomsequenceis manymodels,this load consumesmostof the designedto efficientlyexecutedigitalsignalalgorithm s,suchas the generationof designusesthe DSPto generatethe randomsequenceusinga standardOpenCLcoderunningonthe Cortex-A15processorunderthe showsthe GeneratingNormalDistributedRandomSequenc eTrueRandomNumberGenerationis generatedby s SecurityAcceleratorIP has atrue (PRNG)can be generatedbysoftwareand has generateuniformlydistributedrandomsequen ceare commonlyusemethodis the LinearCongruentialGenerator(LCG) LCGstartswith an initialseedandgeneratesrandomsequencebas edon Equation1:Xn+1 = (a Xn=c) Mod(M)(1)The followingare valuesand theirdescriptions:X0 a seedM the moduloa the multiplierc the incrementUndercertainconditions,the lengthof the sequence(the numberof randomnumbersbeforethesequencestartsrepe ating)is generatesnumbersthat are pseudo-uniformlydistributedbetween1 and M.
3 ScalingLCGsequenceto a uniformlydistributedsequencein the rangeof[ 1, 1] is (X)P [X] log P [X]c= -= c= c September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationTo convertuniformlydistributedrandomsequenc einto a NormalGaussianrandomsequence,the designusesthe polarformof the Box-Mullertransformation(seeReference1 in Section4).The NormalGaussiandistributionhas two parameters,the average,and the a sequenceof N randomvariables:X (n), n = 1,..NThe average(or E (X)) = ( X (n)) NStandardDeviation = sqrt [E(X m)2]For a standardnormaldistributioncase, = 0 and = get Gaussianrandomvariablesfromuniformlydist ributedrandomvariableis asfollows:1. Get two uniformlydistributed( , ),x and y2. Calculatew = (x x + y y)3. If w < sqrt(( log (w) ) w)4. y1 = x y5. y2 = y wY1 and Y2 are two ,SequenceLength,and ParallelComputationMultipletestsare suggestedin the literaturefor the randomness of a NormalRandomsequence: Havethe correctdistribution(lim (1 n S(X (n)) ~ N (0,1) No predictability(Afterreachingthe lengthof the sequence,the sequencebeginsto preferableto shortersequences.)))
4 Auto-correlationgoesto infinite,crossingcorrelationgoesto zero (lim (S (X (n) X (n)) ) (lim (s (X (n) X (n k)) 0)Measurethe entropy lack of orderor predictability;For a finitesequenceX, the entropyis definedinthe formulain Equation1. (seethe discussionin Reference2 in Section4).Figure2. Equation2 Manypublicationsdiscusshow to choosethe constantsa, M, and c, and the initialseedx0 to achievepositiverandomnessfeatures(seeRef erence3 in Section4).TI chosea and M as constantsforEquation1 to ensurea long this TI designto use the full powerof the multipleDSPaccelerators,it mustmergemultipleindependentrandomsequen cesinto a singlerandomsequencewhilepreservingthe in Section4 suggestsa methodof choosingthe additiveconstantc for designusesa set of primenumbersfor parallelgeneratingof a portableheterogeneousstandardcomputingla nguagethat supportsthe easyuse of genericacceleratorsfor OpenCLapplications,knowledgeaboutthe architectureof the acceleratoris codecan run on differentdeviceswith (kernel)))
5 Is writtenin C or otherstandardlanguage,and the systemknowswhatcompilerto use to convertthe codeinto an a genericOpenCLcodethat requiresno knowledgeof the the developerisfamiliarwith the acceleratorarchitecture,and is willingto give up portability,architectureoptimizedexecuta blemay be usedby the deviceCompute deviceCompute unitMultiple processing elementsCompute unitMultiple processing elementsCompute unitMultiple processing elementsCompute unitMultiple processing elementsCompute unitMultiple processing elementsCompute unitMultiple processing September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationOpenCLstandardbodyis implementationof OpenCLon the AM57xis , see .In this TI design,the DSPacceleratorcodeis developedusingANSIC ,the projectmaybe easilyportedto otherdeviceswith showsthe OpenCLPlatformModelA host is connectedto one or OpenCLdeviceis a collectionof one or morecomputeunitsthat sharethe caseof the AM57x ,the host is the the set of C66xDSPs,and the computeunit is a September2015 SubmitDocumentationFeedbackCopyright 2015, acceleratorsusedin this TI designare kernelcodeis writtenin standardANSIC, sono intrinsicor assemblylanguageis codetakesadvantageof the C66xmemoryarchitecture,and the eightfunctionalunitsinsidethe core.
6 The codeusesTI real-timestandardoptimizedMathlibraryfor standardMathfunctionssuchassquareroot,lo g, one overx, and so on. The runtimelibrarythat containsthesefunctionsis part of thestandardreleaseand is linkedby the devicethat supportsC musthavea similarlibrary(withthe sameor very similarsyntax)so portingthesefunctionsto anotherarchitectureis simple. The codetakesadvantageof the L1 DataSRAM part of the is a 32-KBareaof zerowait-stateaccesstime that is usedto storeand all acceleratorshaveL1 SRAM. The accessto the memoryis hard-codedin the DSPcode. To use the DSPinternalresources,eachcoregeneratestw o sequencesthat are latercombinedintoone algorithmfollowsReference4 in Section4 to ensurerandomnessof the combinedsequence. The samemethodusedin Reference4 in Section4 is usedto combinemultipleDSPcoresequencesinto a showsthe September2015 SubmitDocumentationFeedbackCopyright 2015, availableon a multitudeof programminglanguagesincludingC and C++.This TI designusesC++ for the OpenCLcode,and ANSIC codefor the acceleratorkernelcodemaybe presentedas an ASCII string,or in separateC compilationof the kernelstringis doneduringrun time by the compilationof C files is doneduringthe buildprocess;however,linkingthecodeand gettingthe executablefromthe compiledfiles are doneduringrun processincreasesthe OpenCLruntimeoverhead.
7 However,the OpenCLbeingportableto any OpenCLdeviceisadvantageousfor the usersare the benchmarkingof applicationsovermultipledevices,and the updatingor scalingof the September2015 SubmitDocumentationFeedbackCopyright 2015, AM57xEVMB ootableSDThe TI processorSDKis a unifiedset of softwarebuildingblocksthat TI processoris in the publicdomainand can be loadedandusedfree of and Figure6 showpart of the downloadpagefor the PROCESSOR-SDK-LINUX-AM57X02_00_01_07, see Reference5 in the Section4 Processor-SDK-LinuxAM57 XInstallPageTo burnan SD-bootablecardusinga Windowscomputer,followthe instructionsfoundon theWindowsSDCardCreationWikiand the imageto burnis in the zip file that burna bootableSD cardusinga Linuxmachine,the usershouldinstallthe releaseon a Linuxmachine,and thenfollowtheinstructionson be developedon the target,or on an externalLinuxmachineusingthe crosscompiler, enablecrosscompiler,the usermustinstallti-processor-SDK-am57xxon a LinuxmachineusingProcessor-SDK-LINUX-AM5 7X02_00_01_07, and the instructionson how toinstallthe ti-processor-SDK-am57xxon a Linuxmachineare in the documentationon the September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationIn this TI designthe codeis built on the targetusingthe internalcodegenerationtoolsfor the ARMC ortex-A15processorand the TerminalConsoleProgramThis sectionwill explainhow to installthe FTDI driversand Installa terminalconsoleprogramsuchas Tera-Term,Putti,picocom,or minicomon a Connectthe FTDI-to-USBcableto the AM57 EVMboardwherethe greenwire is the furthestawayfromthe powerjack,and the blackwire is closeto the power,as shownin ConnectingThe FTDIC ableTo connectto the EVM,the terminalconsoleparametersare as follows.
8 Baudrate 115200 8-bitdata No parity 1-bitstop No flow September2015 SubmitDocumentationFeedbackCopyright 2015, EVM1. Connectthe boardto the Ethernetusingthe connectionthat is awayfromthe Figure8 Insertthe microSD cardthat you preparedinto the slot on the otherside of the EVMnext to the the boarddiagramthat showsthe microSD cardlocation,see theAM572xEvaluationModuleQuickStartGuide (SPRW275).3. Connectthe powersupplyand pushthe blue switchnext to the terminalconsoledisplaysthe showswhatthe consoledisplayswhenthe Log in as root and no passwordis Connectingthe EthernetCableFigure9. ScreenShot1, LoginPageLinux initializationQueue random tasksCore0 Core12x16 KRandom numbersLOOPQ ueue Random tasksRead data L2 Process modelQueue random tasksRead data L2 Process modelTimeCore0 Core12x16 KRandom numbersCore0 Core12x16 KRandom September2015 SubmitDocumentationFeedbackCopyright 2015, ApplicationsThe in the/usr/shared/ti/ on to buildand run the releaseexamplesare giveninthe ProcessorSDKLINUXS oftwareDeveloper's TI designhas two first generatesa sequenceof 32-KGaussianrandomvariablesusingonly the ARMcoresand benchmarksthe averagetime it takesto generateone :In futurereleases,the MonteCarlosimulationwill be part of the examplesin the ,the examplewill be built with all secondprogramis an programusesthe DSPcoresto generatesequencesofGaussianrandomvariabl es;eachsequencehas DSPcoresgeneratesequenceN,the ARMcoresprocessthe previoussequence,sequenceN-1.
9 Figure10 showsthe flow of the ProgramFlow1. Createa new directoryfor the two Log in as root Changedirectoryto the new directorycd Copythe Makefilecp /usr/shared/ti/examples/ Copythe cp /usr/shared/ti/examples/ (Figure11 showswhatappearsonthe screen).Figure11. ScreenShot26. Buildthe September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationNOTE:The sourcecodefor the ARM-onlyMonte-Carlosimulationis storedas a TARfile in thedesignsourcesof this TI followinginstructionsuse scp froma Ubuntumachineto the Pushthe monte_carlo_armsimulationinto the AM57 EVMusingthe scp Loadthe into a Findthe IP addressof the AM57 EVMdo ifconfig,as shownin Figure12 NOTE:In Figure12, the IP addressis Writedownthe systemIP ScreenShot311. Go to the directoryin the Ubuntumachinewherethe Use the scp to copythe file into the :The file appearsasscp you are askedto updatethe secureaddresses,followthe systempromptor agreeto ScreenShot413.
10 Verifythat the opencldirectoryon the AM57 EVMhas the tar To un-tarthe ,type in tar xvf shownin September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA cceleration15. U-tarthe monte_carlo_arm,tarfile by typingtar xvf shownin ScreenShot616. Go to the To viewthe contentsof the monte_carlo_armmakefile,use the vi, more,or cat Observethat the ARMcodeis compiledwith optimization( ) and the A15 specialproperties(Neon ) are enabledas shownin ScreenShot719. Lookat the sourcecodeand includethe See the algorithiumto generatethe Buildthe monte_carlo_armexecutablecdto the Run the monte_carlo_armprogramby returningto the Verifythe executableby shownin September2015 SubmitDocumentationFeedbackCopyright 2015,TexasInstrumentsIncorporatedMonte-C arloSimulationonAM57xUsingOpenCLtoLevera geDSPA ccelerationThe acceleratorversionof the monte -Carlosimulationusesthe DSPto generateGaussianRandomnumbersand usesthe ARMprocessorto executea functionthat appliesthe ARMfunctioncreatesa simplehistogram;the functioncountsthenumberof valuesgreaterthanzeroand the numberof valuesthat are less or equalto two countson the Buildthe acceleratorversionof the Go to the sourcecodefor the Selectthe file Pushthe file into the To un-tarthe , selecttar xvf monte_carlo_openclas shownin ScreenShot930.
