{"id":650,"date":"2022-12-08T09:39:49","date_gmt":"2022-12-08T14:39:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/matlab\/?p=650"},"modified":"2023-06-22T15:05:36","modified_gmt":"2023-06-22T19:05:36","slug":"playing-with-the-r2022b-matlab-apple-silicon-beta-for-m1-m2-mac","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/matlab\/2022\/12\/08\/playing-with-the-r2022b-matlab-apple-silicon-beta-for-m1-m2-mac\/","title":{"rendered":"Playing with the R2022b MATLAB Apple Silicon beta for M1\/M2 Mac"},"content":{"rendered":"<div class=\"rtcContent\">\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><strong>Update 22nd June 2023:<\/strong> An updated blog post about MATLAB on Apple Silicon can be found at <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2023\/06\/22\/native-apple-silicon-support-in-the-matlab-simulink-r2023b-pre-release\">https:\/\/blogs.mathworks.com\/matlab\/2023\/06\/22\/native-apple-silicon-support-in-the-matlab-simulink-r2023b-pre-release<\/a><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Since the release of the first <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2022\/05\/05\/exploring-the-matlab-beta-for-native-apple-silicon\/\">MATLAB beta for Apple Silicon<\/a>, MathWorkers have been toiling away to bring more of the MATLAB experience to this platform and I'm very happy to be able to announce that we have something new for you - <a href=\"https:\/\/uk.mathworks.com\/support\/apple-silicon-r2022b-beta.html\">MATLAB R2022b Native Apple Silicon Platform Open Beta<\/a>. <span style=\"font-weight: bold;\">This beta will be available until June 30, 2023.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">It's faster, more stable and with a bunch of toolboxes alongside MATLAB itself. Your feedback was crucial to getting us here so we encourage you to try out the new release and let us know what you find.<\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: bold; text-align: left;\">Support for Simulink and (some) toolboxes<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">One of the most requested features of the previous beta was support for toolboxes and we've made a lot of progress here. Alongside MATLAB itself you'll find the following<\/div>\r\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px;\">\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">MATLAB<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Simulink<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Signal Processing Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Statistics and Machine Learning Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Image Processing Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">DSP System Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Parallel Computing Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Curve Fitting Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Symbolic Math Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Communications Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Control System Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Deep Learning Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">5G Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">LTE Toolbox<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">MATLAB Compiler<\/li>\r\n \t<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">MATLAB Compiler SDK<\/li>\r\n<\/ul>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">There are some limitations within these. For example Parallel Computing Toolbox's <span style=\"font-family: monospace;\">distributed <\/span>arrays (mentioned in my <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2022\/11\/07\/matlabs-high-performance-computing-hpc-and-big-data-datatypes\/\">article on HPC datatypes in MATLAB<\/a>) don't work, the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_external\/install-the-matlab-engine-for-python.html\">MATLAB Engine API for Python<\/a> is not available and so on but a lot of things <span style=\"font-weight: bold;\">are<\/span> supported. Work on all of the other toolboxes not listed above is ongoing of course.<\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: bold; text-align: left;\">Bench<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Let's start by looking at the output of the <span style=\"font-family: monospace;\">bench <\/span>command using a <span style=\"font-weight: bold;\">MacStudio with M1 Ultra (20 core),<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 577px; height: 365px;\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/12\/AppleMacR2022b_1.png\" alt=\"\" width=\"577\" height=\"365\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 563px; height: 331px;\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/12\/AppleMacR2022b_2.png\" alt=\"\" width=\"563\" height=\"331\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This puts the machine at close to the top of the list of systems reported by Bench. <span style=\"font-weight: bold;\">One thing that we've noticed is that the graphics results depend on the resolution of your screen.<\/span> We are working on this!<\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: bold; text-align: left;\">More linear algebra results<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Bench is great but it only runs one problem size for each computation. This varies with release and for R2022b, the size of the matrix computed by LU is 5200 x 5200 <span style=\"font-family: monospace;\">double<\/span> matrix. You can see this yourself if you look at the source for Bench.<\/div>\r\n<div style=\"background-color: #f5f5f5; margin: 10px 0 10px 0;\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px; border: 1px solid #bfbfbf;\"><span style=\"white-space: pre;\">edit <span style=\"color: #a709f5;\">bench.m<\/span><\/span><\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">For our internal benchmarking we look at range of matrix sizes in both <span style=\"font-family: monospace;\">single<\/span> and <span style=\"font-family: monospace;\">double<\/span>, <span style=\"font-family: monospace;\">real<\/span> and <span style=\"font-family: monospace;\">complex.<\/span> In <span style=\"font-family: monospace;\">double <\/span>precision, here are the timings on an <span style=\"font-weight: bold;\">M1 Ultra (20 cores)<\/span> in both betas for <span style=\"font-family: monospace;\">lu(A)<\/span> for various sizes of matrix <span style=\"font-family: monospace;\">A<\/span>.<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-656\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/12\/m1ultraBenchMATLAB.jpeg\" alt=\"\" width=\"421\" height=\"171\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">It can be seen that while the new beta is faster for most problem sizes when computing <span style=\"font-family: monospace;\">lu(A)<\/span> <span style=\"font-family: monospace;\">(<\/span>over 4x faster in one case), it is actually a little slower for <span style=\"font-family: monospace;\">500 x 500<\/span> matrices. More on this later.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The result closest to the matrices used in R2022b's <span style=\"font-family: monospace;\">bench<\/span>, <span style=\"font-family: monospace;\">5000 x 5000<\/span>, is<span style=\"font-family: monospace;\"> 1.3x<\/span> faster than the previous beta but push the matrix size to <span style=\"font-family: monospace;\">10,000 x 10,000<\/span>, and all those cores have plenty of work to do. The speed-up in this case is <span style=\"font-family: monospace;\">2.1x<\/span> compared to the previous beta. Working with large matrices should be a pleasant experience on these machines.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Running the same benchmark on an <span style=\"font-weight: bold;\">8 core M1 Mac Mini<\/span> gives the following,<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-659\" src=\"http:\/\/blogs.mathworks.com\/matlab\/files\/2022\/12\/m1MiniBenchMATLAB.jpg\" alt=\"\" width=\"431\" height=\"172\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">In the old beta, the more powerful M1 Ultra was actually slower than an 8 core Mac mini for small matrices (N=10,N=100). This has been fixed for this release but, as mentioned above, there is a problem at N=500 which got slower on the M1 Ultra but stayed at roughly the same speed on the Mac Mini. This is due to us tweaking the thresholds at which multithreading kicks in, a process that is ongoing.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Looking across our internal benchmark results from the two betas I see speed-ups as great as <span style=\"font-family: monospace;\">10x<\/span> in some cases (e.g. <span style=\"font-family: monospace;\">[u,s,v]=svd(R)<\/span> for <span style=\"font-family: monospace;\">single<\/span> and <span style=\"font-family: monospace;\">complex<\/span> <span style=\"font-family: monospace;\">R<\/span> for <span style=\"font-family: monospace;\">R<\/span> of size <span style=\"font-family: monospace;\">100x50<\/span> on an M1 Ultra) but then there is a <span style=\"font-family: monospace;\">&gt;5x<\/span> slow down for <span style=\"font-family: monospace;\">inv(symA)<\/span> (where <span style=\"font-family: monospace;\">symA<\/span> is a double symmetric matrix of size <span style=\"font-family: monospace;\">5000x5000<\/span>) on the Mac mini and everything in-between. There are many more speed-ups than slowdowns and what you are seeing here is a Work in Progress snapshot of MathWorks' tuning efforts for this hardware.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-weight: bold;\">Why not use Apple Accelerate?<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">One of the most common questions from my article about the previous beta was <span style=\"font-style: italic;\">\"Why not use Apple Accelerate?\"<\/span>. LAPACK and BLAS from the Accelerate package were considered (benchmarked even!), but were not chosen for this, or the previous beta, due to its 32-bit integer only support and the fact that it doesn't support the latest version of LAPACK. We continue to monitor the situation and frequently benchmark several BLAS\/LAPACK alternatives. We are using what we currently believe (following extensive testing!) to be the best combination for us on this platform.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-weight: bold;\">Over to you<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">So much for the linear algebra. User musicscientist <a href=\"https:\/\/www.reddit.com\/r\/matlab\/comments\/z1cxxc\/2022b_apple_silicon_beta_benchmark_results_blown\/\">posted on Reddit that they were 'blown away'<\/a> by the performance they saw but this is a beta so your mileage may vary. With Simulink and 14 toolboxes also supported, there is a lot to try out so we encourage you to try this beta on your own code and <a href=\"https:\/\/www.mathworks.com\/support\/apple-silicon-r2022b-beta-feedback.html\">let us know what you find<\/a>.<\/div>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/matlab\/files\/2022\/12\/AppleMacR2022b_1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\nUpdate 22nd June 2023: An updated blog post about MATLAB on Apple Silicon can be found at... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/matlab\/2022\/12\/08\/playing-with-the-r2022b-matlab-apple-silicon-beta-for-m1-m2-mac\/\">read more >><\/a><\/p>","protected":false},"author":176,"featured_media":641,"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\/650"}],"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=650"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/650\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/650\/revisions\/1307"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media\/641"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media?parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/categories?post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/tags?post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}