{"id":50,"date":"2022-05-05T08:17:59","date_gmt":"2022-05-05T12:17:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/matlab\/?p=50"},"modified":"2022-12-08T10:09:14","modified_gmt":"2022-12-08T15:09:14","slug":"exploring-the-matlab-beta-for-native-apple-silicon","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/matlab\/2022\/05\/05\/exploring-the-matlab-beta-for-native-apple-silicon\/","title":{"rendered":"Exploring the MATLAB beta for Native Apple Silicon"},"content":{"rendered":"<p><strong>Update 8th December 2022: You may be interested in the newer Apple Silicon beta that&#8217;s discussed at <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2022\/12\/08\/playing-with-the-r2022b-matlab-apple-silicon-beta-for-m1-m2-mac\/\">Playing with the R2022b MATLAB Apple Silicon beta for M1\/M2 Mac \u00bb The MATLAB Blog &#8211; MATLAB &amp; Simulink (mathworks.com)<\/a><\/strong><\/p>\n<p>When Apple released the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Apple_M1\">M1 chip<\/a>, the first version of their new ARM-based processors, in November 2020, it caused a great deal of excitement in the computing world. Naturally, everybody wanted to use all of their favorite applications on the new hardware from day one. There was a small problem though:<\/p>\n<h3><strong>One does not simply release an Apple Silicon port of MATLAB!<\/strong><\/h3>\n<p>It takes a lot of time to port applications as complex as MATLAB, Simulink, Simscape etc to a new CPU architecture.\u00a0 Decades of person-years in fact!\u00a0 Fortunately, Apple understands this and, just as they did for the <a href=\"https:\/\/en.wikipedia.org\/wiki\/PowerPC\">PowerPC<\/a> to Intel transition in 2005, they created a compatibility layer called <a href=\"https:\/\/support.apple.com\/en-us\/HT211861\">Rosetta 2<\/a> that allows software targeted at Intel Processors to run on the new architecture.\u00a0 This gives vendors time to manage the transition.\u00a0 MathWorks made use of this and MATLAB has been supported on Apple Silicon Macs via Rosetta 2 since\u00a0R2020b Update 3.<\/p>\n<h3><strong>MATLAB beta on Native Apple Silicon available now<\/strong><\/h3>\n<p>Ever since the M1 release, MATLAB users have been asking the question &#8220;When is a <strong>native<\/strong> Apple Silicon version going to be available?&#8221;.\u00a0 The good news is that the answer is &#8216;Right now!&#8217;\u00a0 The bad news is that its MATLAB only (no toolboxes or Simulink yet) and its still in beta.\u00a0 That is, its a work in progress that shouldn&#8217;t be used in production environments and MathWorks are really interested in\u00a0 getting your feedback.<\/p>\n<p>The beta is available at\u00a0<a href=\"https:\/\/mathworks.com\/support\/apple-silicon-r2022a-beta.html\">https:\/\/mathworks.com\/support\/apple-silicon-r2022a-beta.html<\/a>\u00a0to everyone who has a MATLAB license.\u00a0\u00a0Try it out and let us know what you find <a href=\"https:\/\/mathworks.com\/support\/apple-silicon-r2022a-beta-feedback.html\" target=\"_blank\" rel=\"noopener\">using this feedback form<\/a><\/p>\n<h3><strong>What did I find in the beta?<\/strong><\/h3>\n<p>The first thing I did on launching the Native Apple Silicon Beta of MATLAB on an M1 Pro (with 10 CPU cores and 16 GPU cores) was to run bench twice using the command <a href=\"https:\/\/mathworks.com\/help\/matlab\/ref\/bench.html\">bench(2)<\/a><\/p>\n<p><a href=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Rosetta-M1Pro-Bench-Graph.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-68 size-large\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Rosetta-M1Pro-Bench-Graph-1024x497.png\" alt=\"Rosetta-M1Pro-Bench-Graph\" width=\"1024\" height=\"497\" \/><\/a><\/p>\n<p><a href=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Native-M1Pro-Bench-Results.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-71 size-large\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Native-M1Pro-Bench-Results-1024x478.png\" alt=\"\" width=\"1024\" height=\"478\" \/><\/a><\/p>\n<p>Let&#8217;s see how this compares to R2022a running under Rosetta 2 on the same machine:<\/p>\n<p><a href=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Rosetta-M1Pro-Bench-Results.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-74 size-large\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Rosetta-M1Pro-Bench-Results-1024x478.png\" alt=\"Rosetta M1Pro Bench Results\" width=\"1024\" height=\"478\" \/><\/a><\/p>\n<p>Everything measured in bench shows better performance in the native beta than in the production version running on Rosetta.\u00a0 This is a great start but its definitely not true for all application benchmarks we&#8217;ve tried and we encourage you to give us feedback when you find something in the beta that doesn&#8217;t perform at least as well as R2022a under Rosetta.<\/p>\n<p>Let&#8217;s zoom in on a couple of these results.<\/p>\n<h3><strong>ODE Performance is great in the Apple Silicon Beta of R2022a<\/strong><\/h3>\n<p>As you can see, Ordinary Differential Equation (ODE) solving performance is superb for the new beta. Indeed, <strong>the ODE result for native Apple Silicon is faster than all of the other systems included in the R2022a bench results<\/strong>.\u00a0 I reached out to the development team and asked what was going on.\u00a0 They told me &#8220;ODE is a sequential program, so its performance depends heavily on the performance of a single CPU core. A more aggressive out-of-order pipeline can significantly improve instruction level parallelism (ILP) for sequential programs.\u00a0As an example, M1 includes a wider decoder, issue queues, register renaming, more ALUs, and a larger L1 cache.\u00a0 As a result, ODE performs better on M1 compared to x86 architecture.&#8221;<\/p>\n<h3><strong>LU factorization performance<\/strong><\/h3>\n<p>LU factorization performance in the beta isn&#8217;t too bad but it didn&#8217;t blow me away.\u00a0 I asked development what&#8217;s going on and if we could expect better performance in the production release.\u00a0 LU performance depends on two things: The speed of the underlying <a href=\"https:\/\/en.wikipedia.org\/wiki\/Basic_Linear_Algebra_Subprograms\">BLAS library<\/a> and the speed of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/LAPACK\">LAPACK library<\/a> that wraps around this. There are several implementations of BLAS and LAPACK that one could choose from.\u00a0 For x86 hardware, MATLAB currently uses the Intel MKL or AMD AOCL implementations of BLAS and LAPACK for example.<\/p>\n<p>In this beta, MATLAB is using the well optimized <a href=\"https:\/\/github.com\/xianyi\/OpenBLAS\">OpenBLAS library<\/a> for BLAS routines but only the\u00a0<a href=\"http:\/\/www.netlib.org\/lapack\/\">reference version of LAPACK<\/a>.\u00a0 That is, the LAPACK code behind LU factorization in the beta is not optimized at all!\u00a0 MathWorks are exploring options to see what the best way forward is here.\u00a0 It&#8217;s not as obvious as you might think!<\/p>\n<h3><strong>Sometimes the M1 outperforms the M1 pro<\/strong><\/h3>\n<p>It doesn&#8217;t show up in the computations used in the bench function but we have seen a small number of examples where the M1 pro is beaten by the smaller M1.\u00a0 This is almost always related to multithreading overheads. Essentially, MathWorks have some tuning to do to ensure that all of the additional cores in the M1 pro are used well.<\/p>\n<h3><strong>Over to you<\/strong><\/h3>\n<p>Did you try the beta <a href=\"https:\/\/se.mathworks.com\/support\/apple-silicon-r2022a-beta.html\">(get it from here)<\/a>? What did you find?\u00a0Tell us at <a href=\"https:\/\/mathworks.com\/support\/apple-silicon-r2022a-beta-feedback.html\">https:\/\/mathworks.com\/support\/apple-silicon-r2022a-beta-feedback.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/04\/Rosetta-M1Pro-Bench-Results-1024x478.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Update 8th December 2022: You may be interested in the newer Apple Silicon beta that&#8217;s discussed at Playing with the R2022b MATLAB Apple Silicon beta for M1\/M2 Mac \u00bb The MATLAB Blog &#8211;&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/matlab\/2022\/05\/05\/exploring-the-matlab-beta-for-native-apple-silicon\/\">read more >><\/a><\/p>\n","protected":false},"author":176,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,14],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/50"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":14,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":668,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/50\/revisions\/668"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}