Matlab-Coder自动生成C-C++代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

AutomaticCCodeGenerationfromMATLABMarcBarberis–ApplicationEngineeringGroup,MathWorksInc.AGENDAAGENDA•QuickDemo•BenefitsofAutomaticCCodeGeneration•In-DepthExample•ComparisonbetweenMATLABCoderandMATLABCompiler•ComparisonbetweenMATLABCoderandMATLABCompiler•Fixed-PointDesign•ConclusionDemo:UsingGeneratedCCodeinaStand-AloneCProjectWhytranslateMATLABtoC?IntegrateMATLABalgorithmsw/existingCenvironmentusingsourcecodeorstaticlibrariesPrototypeMATLABalgorithmsondesktopsasstandaloneexecutablesPrototypeMATLABalgorithmsondesktopsasstandaloneexecutablesAccelerateuser-writtenMATLABalgorithmsImplementC/C++codeonprocessorsorhand-offtosoftwareengineersChallengeswithManualTranslationfromMATLABtoC/C++•Separatefunctionalandimplementationspecification–Leadstomultipleimplementationsthatareinconsistent–Hardtomodifyrequirementsduringdevelopment–Hardtomodifyrequirementsduringdevelopment–DifficulttokeepreferenceMATLABcodeandCcodein-sync•Manualcodingerrors•TimeconsumingandexpensiveAutomaticTranslationofMATLABtoCWithMATLABCoder,designengineerscan•MaintainonedesigninMATLABWithMATLABCoder,designengineerscan•MaintainonedesigninMATLAB•MaintainonedesigninMATLAB•DesignfasterandgettoC/C++quickly•Testmoresystematicallyandfrequently•SpendmoretimeimprovingalgorithmsinMATLAB•MaintainonedesigninMATLAB•DesignfasterandgettoC/C++quickly•Testmoresystematicallyandfrequently•SpendmoretimeimprovingalgorithmsinMATLABImplementationConstraintsElementbyelementmultiplyElementbyelementmultiplyElementbyelementmultiplylogicalintegerfunctiona=foo(b,c)a=b*c;voidfoo(constdoubleb[15],ElementbyelementmultiplyDotproductMatrixmultiplyElementbyelementmultiplyDotproductMatrixmultiplyElementbyelementmultiplyDotproductMatrixmultiplyintegerrealcomplex…Cdoublefoo(doubleb,doublec){returnb*c;}voidfoo(constdoubleb[15],constdoublec[30],doublea[18]){inti0,i1,i2;for(i0=0;i03;i0++){for(i1=0;i16;i1++){a[i0+3*i1]=0.0;for(i2=0;i25;i2++){a[i0+3*i1]+=b[i0+3*i2]*c[i2+5*i1];C}a[i0+3*i1]+=b[i0+3*i2]*c[i2+5*i1];}}}}ImplementationConstraints•Polymorphism•Polymorphism•Memoryallocation•Processingmatrices&arrays•Fixed-pointdatatypes7LinesofMATLAB107LinesofC7LinesofMATLAB107LinesofC107LinesofC107LinesofCIn-DepthDemoofMATLABCoder•CoderUI•CoderUI•CodeGenerationoptions•Generatecode•BrowsethroughreportSupportedMATLABLanguageFeaturesandFunctions•Broadsetoflanguagefeaturesandfunctions/systemobjectssupportedfor•Broadsetoflanguagefeaturesandfunctions/systemobjectssupportedforcodegenerationMatricesandArraysDataTypesProgrammingConstructsFunctions•Matrixoperations•N-dimensionalarrays•Subscripting•Frames•Persistentvariables•Globalvariables•Complexnumbers•Integermath•Double/single-precision•Fixed-pointarithmetic•Characters•Structures•Numericclasses•Variable-sizeddata•Arithmetic,relational,andlogicaloperators•Programcontrol(if,for,while,switch)•MATLABfunctionsandsub-functions•Variablelengthargumentlists•FunctionhandlesSupportedalgorithms•400MATLABoperatorsandfunctions•200Systemobjectsfor•Signalprocessing•Variable-sizeddata•Systemobjects•Classes•Signalprocessing•Communications•ComputervisionCodeGenerationReadinessToolInstantfeedbackoncodegenerationcomplianceofyourMATLABcodecomplianceofyourMATLABcodeProvidesestimateofeffortneededtogenerateCcodefromyourMATLABcodeonascaleof1to5ProvidesalistofissuesthatneedtoberesolvedinonereportGivesdetailedinformationonunsupportedfunctionsOtherDeploymentOptionsDeployingApplicationswithMATLABCompiler•Shareapplications•Shareapplications–DesktoporWebsoftwarecomponentsMATLABCompilerMATLABBuilderNEMATLABBuilderEXMATLABBuilderJA–SupportsfullMATLABlanguageandmosttoolboxes–RequiresMCR•Freerun-timelibraryJavaExcel.NETWebCOM.exe.dllBuilderNEBuilderEXBuilderJA•Freerun-timelibrary•Royalty-freedeploymentChoosingtheRightDeploymentSolutionMATLABCoderandMATLABCompilerOutputPortableandreadableCsourcecodeExecutableorsoftwarecomponent/libraryMATLABCompilerMATLABCoderCsourcecodecomponent/libraryMATLABsupportSubsetoflanguageSometoolboxesFulllanguageMosttoolboxesGraphicsRuntimerequirementNoneMATLABCompilerRuntime(MCR)LicensemodelRoyalty-freeRoyalty-freeFixedPointDesign:MotivationConsiderationFixedPointFloatingPointRAMandROMconsumptionSmallLargeExecutiontimeFasterSlowerHardwarepowerconsumptionLowHighDevelopmenttimeLongShortDevelopmenttimeLongShortImplementationcomplexityMorecomplex.Controlofwordlength,roundingmode,saturation...LessErrorProneHardertodevelop.MorepronetoprogrammingerrorsEasiertodevelopFixedPointDesign:PitfallsArithmeticPitfallsArithmeticPitfalls–Introducesquantizationerrors–WordlengthandFractionLengthmustbespecifiedForeveryvariable–DegradationmustbeanalyzedInteger+signfractionalL-NNQuantizationoverflowInteger+signfractionalLQuantizationoverflowFixedPointDesign:Pitfalls•FixedPointCPitfalls•FixedPointCPitfalls–Nonativefixed-pointmathlibraries–Nobuilt-inoverflow/underflowchecks–Notoolstodetermineoptimalintegerandfractionalbits–Novisualizationoffloatingandfixed-pointrepresentationsInteger+signfractionalL-NNQuantizationoverflowInteger+signfractionalLQuantizationoverflowFixed-PointT

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功