Stephen Smith's Blog

Musings on Machine Learning…

Posts Tagged ‘apple m1

State of Software on Apple Silicon

leave a comment »

Introduction

Apple Silicon ARM based Macintoshes first shipped back on Nov. 20, 2020. We are now three months later, so I thought I’d review the state of software on these new Macs. Whenever a vendor changes the CPUs in their computers there is typically a lag between the hardware shipping and then software becoming available for the new platform. Apple took a number of extraordinary measures to try to eliminate this lag, to have a lot of software available when the first real hardware shipped. In this article we’ll look at what is available now, what is missing and how the journey seems to be going.

Rosetta and the Early Adopter Program

Knowing that software would be a problem when Apple switched from Intel to ARM for their Macintoshes, they worked hard to produce an excellent Intel emulation program called Rosetta. This allows most Intel based MacOS programs to run as is on the new hardware. I found this to work really well, with a couple of exceptions. One problem is battery life, when I first received my new MacBook Air, there wasn’t a native general media player yet, and running the Intel version of VLC would drain the battery in a couple of hours. Since then a native ARM version of VLC has been released and I’m able to play videos all day without recharging. Another problem is that Rosetta doesn’t emulate Intel AVX vector processing instructions and this prevents some machine learning libraries from running. However, I found most things did work and hence I could get everything I needed done, done.

The other thing Apple did was seed developers with an early prototype Mac Mini using an iPad Pro’s ARM CPU and a beta version of MacOS Big Sur. This allowed developers to get a jump on porting their applications to the new platform. The downside was that this hardware cost US $600 and you had  to sign a heavy nondisclosure along with agreeing to return this hardware when the real thing shipped. This limited the program to mostly larger companies who could easily afford this. At the end Apple provided a $500 Apple store credit if you returned the unit and if this was known at the beginning, more people might have participated.

Native Applications

There are now a large collection of native Apple Silicon applications available including Microsoft Office, Google Chrome, VLC Player and Zoom. Others such as Adobe Lightroom or Parallels virtualization software are available in beta. There is a list of native applications here.

Of course all Apple’s applications are available for the M1 chip including Xcode which gives a pretty robust starting point.

Porting applications from Intel to ARM appears to be fairly straightforward and expect any missing applications (as long as they are still actively developed) to show up soon.

MacOS is based on Unix as is Linux and Mac users are used to all the various Linux applications having MacOS versions as well. A great place to get these is from one of the MacOS package managers like Homebrew. Homebrew has ARM native versions of most open source programs, including GCC and lots of Python libraries.

Xcode installed the LLVM compiler collection and then with GCC you can download and build most open source projects if you really need to, but chances are the folk at Homebrew have beaten you to it.

Another source of native Apps are iOS iPad and iPhone apps, many of these will install on the new Macs and for a lot of things are the best way to go.

Virtualization

If you want to run Linux or Windows on your new Apple Silicon Mac, one way to go is via virtualization. Parallels has a beta version of their software for Apple Silicon and I gave it a try and got a virtualized copy Ubuntu Linux up and running without any problems. The target operating system has to be 64-bit ARM based, which means you can choose from quite a few flavours of Linux.

Although bootcamp isn’t supported on the new Macs, you can run virtualized ARM based Windows using Parallels, but this version of Windows is only available through the Windows Insider program.

Other Operating Systems

There is a large contingent of Linux developers working hard to get Linux running natively on this new Apple hardware. Correlium has Ubuntu Linux running natively, booting either from the SSD or from a USB drive. This version supports much of the new Apple hardware, except it doesn’t use the GPU at all. Asahi Linux is working hard on GPU support, but that is a big job.

Apple is making this job hard but not providing documentation on the low level hardware interfaces, but people are making good progress reverse engineering MacOS.

The good news is that it is possible to run other OS’s like Linux and over time we’ll hopefully see other operating systems in addition to Linux ported as well.

What’s Missing

The big thing missing is support for the GPU and TPU. All the libraries that utilize GPUs for acceleration, won’t use the Apple GPU. This is a huge advantage that nVidia has, that nearly every machine learning library supports acceleration on nVidia GPUs, then next, but still lagging is support for AMD GPUs. 

Apple wants everyone to use their Metal API to access the GPU, but the problem is getting people to do this. Apple has taken a branch of Google’s Tensorflow and is adding Metal support themselves, but they have a bit of a tough road ahead to get good support across the board. They could try to help organizations like OpenCL write their drivers, but I think this will take time.

Another thing is to sort out the installation of systems like Python where there are hundreds of add-on libraries. There are lots of conda virtual installs for the new M1s but most mix and match installs are still a pain, and nowhere near as painless as they are on Intel based MacOS or on Linux.

Summary

There has been huge progress in porting software to the new ARM based Macs. There is still work to do, but it appears the new Macs are selling well and there seem to be lots of developers acquiring these new Macs. Anyone serious about iOS development wants these as it is so much easier having your development system running the same processor as your target. The missing pieces are becoming more and more obscure and most of the holes can be filled with programs running under Rosetta. I use my new MacBook for pretty much all my work and find everything I need already there and working really well.

Written by smist08

February 19, 2021 at 11:13 am

Posted in Business

Tagged with , , , ,

More Linux for Apple Silicon

leave a comment »

Introduction

Last week, I covered Asahi Linux and their drive to port Linux to Apple’s new ARM based Macintoshes. This week, there was a new contender where Corellium, a virtualization and security company, have successfully gotten Ubuntu Linux running on Apple M1 ARM based systems. Corellium created a system to allow security researchers to run iOS in virtual machines to allow more rapid testing of Apps for security problems. No one had heard of Corellium until Apple sued them for copyright infringement for doing this. The lawsuit has mostly been thrown out and Corellium was able to use the knowledge they learned virtualizing iOS to produce Linux device drivers for the new Apple M1 chips.

Corellium Linux

Corellium starts with the Raspberry Pi version of Ubuntu Linux. This is a full complete 64-bit version of Linux that runs on the Raspberry Pi’s ARM processor and has all the development tools and applications bundled. They then add their Apple M1 Linux drivers to the kernel, rebuild it and replace the Raspberry Pi kernel. Viola, Ubuntu Linux on the new Apple Silicon Macs. All the source code is available in Github and the install instructions are available here.

To virtualize iOS, Corellium had to figure out all the hardware register accesses made by iOS, intercept them and translate them into matching calls in the operating system hosting the virtualized iOS. Accomplishing this was an impressive feat. We are lucky that the M1 SoC used in the new Macs is really just the next generation of the processor chips Apple has been using for all their iPhones and iPads (even AppleTV and iWatches). As a consequence, all the directly integrated devices like USB support are all the same. Corellium could then use all this hard fought knowledge to modify various Linux device drivers to work properly with Apple devices. It is still impressive that they were able to accomplish this in such a short time.

This version of Ubuntu Linux is fully GUI, but the graphics aren’t accelerated and no use of the M1’s fancy GPU cores are used. Basically they figured out how to get an area of memory that represents the screen and then use Linux’s builtin ability to deal with this simple sort of graphics (almost like going back to the days of VGA).

Corellium recommends creating your Linux image on an USB storage device and then gives instructions on how to get your Mac to boot from this. Then you are running Linux. We’re probably still a distance away from dual booting Linux or MacOS and you probably don’t want to replace MacOS entirely from your new Mac. 

This is a great starting point to getting Linux fully supported on the new Macs, it seems progress is moving really fast. Asahi Linux is making good progress in understanding and using the M1’s GPU. With such a full featured working system, progress is accelerating.

What Next?

When new hardware appears, Linux support starts in local specialty source code repositories, that is the case now with Corellium and Asahi. The source code is all new, rough and needs cleaning up. Once this is done it is submitted to upstream source code repositories where it is reviewed and eventually accepted. Eventually, this will all make it into the main Linux kernel source code repository. When this happens, all the myriad Linux distributions will get it for free as they incorporate a newer kernel into their downstream repos. This may sound like a long process, but typically it happens quite quickly. Then we can look forward to Apple Silicon versions of all our favorite Linux distributions.

Summary

Apple Silicon Macs have only been in people’s hands for a very short time. It’s amazing that we already have a working version of Ubuntu Linux for these devices. We have the Raspberry Pi to thank for taking ARM based Linux mainstream so quickly and groups like Corelium and Asahi to thank for figuring out the hardware nitty-gritty details of these new Macs. All this just makes the new products from Apple more exciting and a nice alternative to the Intel/AMD world.

All of this requires a good knowledge of ARM 64-bit Assembly Language, so consider my book as a great way to learn all the details on how it works. I even have a chapter on reverse engineering which is hopefully helpful.

Written by smist08

January 22, 2021 at 12:56 pm

Porting Linux to Apple Silicon

with 2 comments

Introduction

When Apple announced they were switching from Intel to ARM CPUs, there was a worry that Apple would lock out installing non-Apple operating systems such as Linux. There is a new security processor that people worried would only allow MacOS to boot on these new chips. Fortunately, this proved to be false and the new ARM based Macintoshes fully support booting homebrew operating systems either from the SSD or from USB storage. However, the new Apple M1 chips present a number of problems that we’ll discuss in this article as well as why so many people are so interested in doing this.

Linus Torvalds, the father of Linux, recently said that he wished the new MacBooks ran Linux and that he would consider this the ultimate laptop and really want one. Linus said he saw porting Linux as possible, but personally he didn’t have the time to commit.

Last week’s article on an Assembly Language “Hello World” program hit number 1 on Hacker News and based on the comments, the interest was largely generated by the challenge of porting Linux to these new Apple systems. As we’ll see, doing this is going to require both reverse engineering and then writing ARM 64-bit Assembly Language code.

Asahi Linux

Last week we saw the announcement of the Asahi Linux project. Asahi means “rising sun” in Japanese and “asahi ringo” is Japanese for Macintosh Apple. The goal of this project is to develop a version of Linux that fully supports all the new hardware features of the Apple M1 chip including the GPU and USB-C ports. This won’t be easy because even though Apple doesn’t block you from doing this, they don’t help and they don’t provide any documentation on how the hardware works. People already have character based Linux booting and running on the Apple M1 Macs, and you can run the regular ARM version of Linux under virtualization on these new Macs, but the real goal is to understand the new hardware and have a version of Linux talking directly to the hardware that uses all the capabilities, like the GPU, to run as well as or better than MacOS.

GPUs and Linux

GPUs have always been a sore point with the Linux community. None of the GPU vendors properly document their hardware APIs to their products and believe the best way to support various operating systems is to provide precompiled binaries with no source code. Obviously this roils the open source community. GPUs are complicated and change a lot with each hardware generation. Newer Intel and AMD CPUs all have integrated graphics that have good open source drivers that at least will work, but at the disadvantage of not using all the fancy hardware you paid for in your expensive gaming PC. Even the Raspberry Pi versions of Linux use a binary Broadcom drive for the integrated GPU, rather than something open source.

Over the years, intrepid Linux developers have reverse engineered how all these GPUs work, so there are open source drivers for most nVidia and AMD GPUs. In fact, since neither nVidia or AMD support their hardware for all that long, if you have a more than 10 year old graphics card and run Linux, then you are pretty much forced to use the open source driver or switch to Intel integrated graphics (if available) or just stop upgrading the operating system and drivers.

The good news is that the open source community has a lot of experience figuring out how GPUs work, including those from nVidia, AMD, ARM and Broadcom. The bad news is that it takes time to first work out a disassembler of the GPU instructions to go from the binary form and work out what each bit means to produce a mnemonic Assembly Language source form. Then once this is known, write an Assembler for this and then use the tool to create the graphics driver. The Apple GPU isn’t entirely new, originally it was based on Imagination Technologies GPU design and then went through several iterations in iPads and iPhones before the current newest version ending up in the M1. Hopefully this history will be some help in developing the new Linux drivers.

Leveraging Existing Drivers

All the CPU vendors including ARM Holdings are motivated to contribute to the Linux kernel to ensure it runs well on their hardware. Linux is big enough that it greatly benefits vendors adoption to have a solid Linux offering. There is already really good ARM support in the Linux kernel and its tool chain such as GNU GCC. This is a solid first step in producing a working version of Linux for Apple Silicon.

Further, Apple doesn’t do everything themselves. There is hope that even if components are integrated into the M1 SoC that they still used standard designs. After all, Apple didn’t want to write all new drivers for MacOS. Hopefully a lot of the hardware drivers for the Intel Macs will just need to be recompiled for ARM and just work (or require very little work).

I haven’t mentioned the Apple integrated AI processor, but the hope here is that once the GPU is understood, that the AI processor is fairly similar, just missing the graphics specific parts and containing the same core vector processor.

There are quite a few other components in the SoC including sound processing and video decoding, hopefully these are known entities and not entirely new.

Why Do All This Work?

It’s hard enough writing device drivers when you have complete hardware documentation and can call a vendor’s support line. Having to reverse engineer how everything works first is a monumental task, so why are all these open source developers flocking to this task? Quite a few people like the challenge, if Apple provided lots of good documentation, then it would just be too easy. There is an attraction to having to connect hardware diagnostic equipment to your computer and iteratively write Assembly Language to figure out how to control things. None of this work is paid, besides the odd bit of gofundme money, these are mostly volunteers doing this in their spare time separate from their day jobs.

Humans are very curious creatures. Apple, by not providing any details, has piqued everyone’s curiosity. We don’t like being told no, you’re not allowed to know something. This just irritates us and perhaps we think there is something good being withheld from us.

There is also some fame to be had in hacker circles, as the people who solve the big problems are going to become legends in the Linux world.

Whatever the reason, we will all benefit from their hard work and determination. A well running Linux on Apple Silicon will be a great way to get full control of your hardware and escape App store restrictions and Apple’s policies on what you can and cannot do with your computer. It might even be a first step to producing Linux for iPhones and iPads which would be cool.

Summary

Apple has set a mythic challenge to hackers everywhere. By not providing any hardware documentation, Apple has created an epic contest for hackers to crack this nut and figure out how all the nitty gritty details of Apple Silicon work. This is a fun and difficult problem to work on. The kind of thing hackers love. I bet we are going to see prototype drivers and hardware details much faster than we think.

All of this requires a good knowledge of ARM 64-bit Assembly Language, so consider my book as a great way to learn all the details on how it works. I even have a chapter on reverse engineering which is hopefully helpful.

Written by smist08

January 15, 2021 at 10:59 am

Apple M1 Assembly Language Hello World

with 15 comments

Introduction

Last week, we talked about using a new Apple M1 based Macintosh as a development workstation and how installing Apple’s development system XCode also installed a large number of open source development tools including LLVM and make. This week, we’ll cover how to compile and run a simple command line ARM Assembly Language Hello World program.

Thanks to Alex vonBelow

My book “Programming with 64-Bit ARM Assembly Language” contains lots of sample self contained Assembly Language programs and a number of iOS and Android samples. The command line utilities are compiled for Linux using the GNU tool set. Alex vonBelow took all of these and modified them to work with the LLVM tool chain and to work within Apple’s development environment. He dealt with all the differences between Linux and MacOS/iOS as well. His version of the source code for my book, but modified for Apple M1 is available here:

https://github.com/below/HelloSilicon.

Differences Between MacOS and Linux

Both MacOS and Linux are based on Unix and are more similar than different. However there are a few differences of note:

  • MacOS uses LLVM by default whereas Linux uses GNU GCC. This really just affects the command line arguments in the makefile for the purposes of this article. You can use LLVM on Linux and GCC should be available for Apple M1 shortly.
  • The MacOS linker/loader doesn’t like doing relocations, so you need to use the ADR rather than LDR instruction to load addresses. You could use ADR in Linux and if you do this it will work in both.
  • The Unix API calls are nearly the same, the difference is that Linux redid the function numbers when they went to 64-bit, but MacOS kept the function numbers the same. In the 32-bit world they were the same, but now they are all different.
  • When calling a Linux service the function number goes in X16 rather than X8.
  • Linux installs the various libraries and includes files under /usr/lib and /usr/include, so they are easy to find and use. When you install XCode, it installs SDKs for MacOS, iOS, iPadOS, iWatchOS, etc. with the option of installing lots for versions. The paths to the libs and includes are rather complicated and you need a tool to find them.
  • In MacOS the program must start on a 64-bit boundary, hence the listing has an “.align 2” directive near top.
  • In MacOS you need to link in the System library even if you don’t make a system call from it or you get a linker error. This sample Hello World program uses software interrupts to make the system calls rather than the API in the System library and so shouldn’t need to link to it.
  • In MacOS the default entry point is _main whereas in Linux it is _start. This is changed via a command line argument to the linker.

Hello World Assembly File

Below is the simple Assembly Language program to print out “Hello World” in a terminal window. For all the gory details on these instructions and the architecture of the ARM processor, check out my book.

//
// Assembler program to print "Hello World!"
// to stdout.
//
// X0-X2 - parameters to linux function services
// X16 - linux function number
//
.global _start             // Provide program starting address to linker
.align 2

// Setup the parameters to print hello world
// and then call Linux to do it.

_start: mov X0, #1     // 1 = StdOut
adr X1, helloworld // string to print
mov X2, #13     // length of our string
mov X16, #4     // MacOS write system call
svc 0     // Call linux to output the string

// Setup the parameters to exit the program
// and then call Linux to do it.

mov     X0, #0      // Use 0 return code
       mov     X16, #1     // Service command code 1 terminates this program
       svc     0           // Call MacOS to terminate the program

helloworld:      .ascii  "Hello World!\n"

Makefile

Here is the makefile, the command to assemble the source code is simple, then the command to link is a bit more complicated.

HelloWorld: HelloWorld.o
ld -macosx_version_min 11.0.0 -o HelloWorld HelloWorld.o -lSystem -syslibroot
`xcrun -sdk macosx --show-sdk-path` -e _start -arch arm64

HelloWorld.o: HelloWorld.s
as -o HelloWorld.o HelloWorld.s

The xcrun command is Apple’s command to run or find the various SDKs. Here is a sample of running it:

stephensmith@Stephens-MacBook-Air-2 ~ % xcrun -sdk macosx –show-sdk-path
objc[42012]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1edb5b8f0) and ?? (0x122dd02b8). One of the two will be used. Which one is undefined.
objc[42012]: Class AMSupportURLSession is implemented in both ?? (0x1edb5b940) and ?? (0x122dd0308). One of the two will be used. Which one is undefined.
objc[42013]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1edb5b8f0) and ?? (0x1141942b8). One of the two will be used. Which one is undefined.
objc[42013]: Class AMSupportURLSession is implemented in both ?? (0x1edb5b940) and ?? (0x114194308). One of the two will be used. Which one is undefined.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk
stephensmith@Stephens-MacBook-Air-2 ~ %

After the ugly warnings from Objective-C, the path to the MacOS SDK is displayed.

Now we can compile and run our program.

stephensmith@Stephens-MacBook-Air-2 Chapter 1 % make -B
as -o HelloWorld.o HelloWorld.s
objc[42104]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1edb5b8f0) and ?? (0x1145342b8). One of the two will be used. Which one is undefined.
objc[42104]: Class AMSupportURLSession is implemented in both ?? (0x1edb5b940) and ?? (0x114534308). One of the two will be used. Which one is undefined.
ld -macosx_version_min 11.0.0 -o HelloWorld HelloWorld.o -lSystem -syslibroot `xcrun -sdk macosx –show-sdk-path` -e _start -arch arm64 
stephensmith@Stephens-MacBook-Air-2 Chapter 1 % ./HelloWorld 
Hello World!
stephensmith@Stephens-MacBook-Air-2 Chapter 1 %

Summary

The new Apple M1 Macintoshes are running ARM processors as part of all that Apple Silicon and you can run standard ARM 64-bit Assembly Language. LLVM is a standard open source development tool which contains an Assembler that is similar to the GNU Assembler. Programming MacOS is similar to Linux since both are based on Unix and if you are familiar with Linux, most of your knowledge is directly applicable.

Written by smist08

January 8, 2021 at 10:31 am

Apple M1 as a Development Workstation

with 12 comments

Introduction

I’ve been playing with my new M1 based Apple MacBook Air for a few weeks now, so I thought I’d blog about how it is as a development machine. These are now the best way to develop iOS Apps for iPhones and iPads. These systems are really new so there are a few missing pieces, but these are filling in fast. You can run most MacOS Intel based programs using Rosetta 2, but I’m interested in what runs in natively compiled ARM code that ideally uses the builtin M1 functionality where appropriate.

XCode

XCode is Apple’s IDE for development. The whole XCode system is a combination of Apple created software along with a number of open source development tools. As long as you don’t compile or debug for Intel, you don’t need Rosetta installed to run all these. That means besides XCode and Swift, you also get natively compiled versions of LLVM, Python and a number of other tools. After installing XCode (which is huge), you can run command line tools to compile C code and Assembly language code. There is a version of make installed and you can do this all from a command shell without using the XCode IDE at all. All these tools are very fast and seem to work perfectly in the native ARM environment. This shouldn’t be too much of a surprise as these have all been working fine on the ARM based Raspberry Pi for quite a few years now.

If you develop iOS or MacOS applications using Cocoa then this is the platform for you. On older Intel based Macs, to test the application the computer had to emulate the ARM processor and the iOS simulators were quite slow and clunky. Now that everything is using the same processor, suddenly the iPhone and iOS simulators are fast and much more productive. In fact currently the M1 processor is faster than any existing iPhone or iPads, so iOS apps actually run fastest on the new Macs.

What’s Missing?

Apple has fully embraced the LLVM open source toolchain and helped have that project fully support the new Macs. Sadly they didn’t provide the same level of help to the GNU GCC open source toolchain. There are now test builds of the GNU toolchain, or you can build it yourself, but not a released one yet. This then slowed down the development of any applications that depend on the GNU toolchain. The most notable case is anything written in Fortran was stalled because GNU has the good Fortran compiler.

Now you might ask, so what? Who uses Fortran these days anyway? The thing is nearly all scientific libraries were written in the 60s and 70s in Fortran and have all been made open source. These libraries are highly reliable and work great. Now you might ask, so what? Not many people do scientific computing? The thing is that all modern machine learning and AI applications make extensive use of these libraries especially for things like linear algebra. This means that even though Python itself is available natively for the Apple M1, all the scientific libraries, most notably numpy are not as they contain Fortran components. Again there are test builds available, but it could be a few months before these are all generally available.

Another problem is the Apple M1 GPU and machine learning accelerator components. Even once these all compile and are available for the M1, which should be soon, it may be considerably longer before versions are available that can make use of the GPU or TPU for vector acceleration. Most of these libraries have support for nVidia and AMD GPUs, however now that Apple has gone their own way, it may be a bit of a wait for Apple versions. Apple has allocated engineers to help with these projects so hopefully it is sooner than later, and any project that previously supported acceleration on an iPhone or iPad will be good to go.

Meanwhile if you use some other programming language or system, like say ERLang, you will have to check their website for native availability, compile them yourself or use Rosetta 2.

The new XCode is great for Apple mobile development, but what about Android? Android Studio is currently being ported to the M1 and there are test builds available, but with lots of missing pieces. Once complete, this will be the best way to develop Android applications since again, you can run the apps natively and don’t require an ARM emulator for testing and debugging.

Summary

Whenever a new generation of hardware is released, there is always a delay as software catches up. If you do a lot of development for iOS then you need one of these new Macs as these are now the best environment for mobile development. Once Android Studio finishes their M1 version, the new Apple M1’s will be by far the best platform for mobile development. Apple has done a really good job of having so much work at release for their new generation of Macintosh computers; but, as is always the case at the bleeding edge, there are a few holes to be filled in. Of course most of these projects are open source so if you need them, you can always contribute to help them move a little faster. As more and more M1 based Macs ship and get into people’s hands these problems will start to be knocked off and more things will move into the “it just works” category.

Written by smist08

January 1, 2021 at 11:54 am

Apple M1 MacBook Air Review

with 4 comments

Introduction

I received my new shiny golden ARM based MacBook Air a few days ago, so I thought I’d write this blog posting on my initial impressions. This replaces our aging 2012 MacBook Air which continues to be a good computer, but sadly it isn’t supported by the new Big Sur MacOS release. It is also a bit limited with only 4Gig RAM and a 128Gig SSD. The new MacBook Air has 16Gig RAM, a 512Gig SSD and has an 8 core GPU.

Same Old Mac

The first impression when you turn it on and perform the initial setup, is that it is the same MacOS as you are used to. Everything works the same and you wouldn’t know there is a new ARM based CPU running behind the scenes. The screen is really nice at a resolution of 2560×1600, the keyboard is the updated magic keyboard and is quite nice to type on. The laptop is relatively lite and the battery lasts a long time.

Installing Software

Using software natively compiled for the new Apple M1 ARM processor is the best and there is already a lot of software available this way. All the Apple software, of course, is compiled for ARM. I installed XCode, which took a little while since it is so large. As long as you don’t compile for Intel, you don’t need the Rosetta emulator to run this. I installed Microsoft Office and Google Chrome, both of which are natively compiled for ARM and run great.

Bigger companies all bought or were provided with the developer prototype hardware to get ready for the real release, however smaller developers and open source developers weren’t going to pay the $600 for the prototypes that you were contractually required to trade in when the real release happened. Now that the ARM based Macs are released and people are receiving them, we are seeing lots of projects with test native ARM builds posted. Further, Apple engineers are contributing to a number of open source projects to help them move a little quicker.

After all this, I needed some utilities that weren’t compiled natively yet, so I let Rosetta install. Then the utilities installed and worked seamlessly. I haven’t installed a great many non-native applications, but for the ones I have installed, I’m impressed that they just work and you can’t see any sign of all the magic working in the background to seamlessly emulate an Intel processor.

You Can Run iOS Apps

Besides running MacOS applications, you can run iOS Apps. From the App Store you can select most iOS Apps to install as well. When I heard about this, I didn’t think I’d really need this. However, it lets you do some things that I couldn’t do before. For instance, a complaint about EchoLink, a ham radio program, is that you need to run it on a phone. Now I can run it on my laptop, which I find handy.

There are actually a number of useful phone or tablet apps that are handy to finally be able to run on a laptop.

UPS Sucks

When I ordered the MacBook, I ordered from apple.ca, so I sort of expected it would ship from Canada. There were no options for shipping, it just said free shipping, so that is what I got. The website said to expect two to three weeks before it ships. OK fine. Then exactly two weeks later, I received the notification that it had shipped. I clicked on the track shipping button and found out it was shipping from Shanghai, China via UPS. Oh no, I’ve never had a good experience with UPS. It took three days to leave Shanghai and then showed up in Incheon, South Korea. Then the next day, tracking showed it in Anchorage, Alaska. What the heck, was it on a boat sailing around the Pacific? The next day, Louisville Kentucky, so it was flying. Sucks that UPS routes everything through this hub. Next day, Seattle Washington. Next day Richmond, BC. It then sat in Richmond for three days. Then it moved to Gibsons, BC and sat there for three days before being delivered. It seems to me that sending anything UPS is about the worst way you can ship things.

Apple sucks that they use UPS. For instance, my experience with FedEx is that it would have flown from Shanghai to Vancouver directly and then gotten here the next day, since FedEx does two deliveries each weekday and then also delivers on Saturdays. FedEx is the best, but Purolator and DHL aren’t far behind. Again UPS sucks, please Apple stop using them.

Summary

The MacBook Air is a very nice laptop. It is well made, light and fast. It’s easy to work on and the long battery life makes it ideal for a mobile workforce. There is tons of software available, naively compiled MacOS, Intel based MacOS and then all the iOS Apps. If you are looking for a new laptop or an upgrade to an old Mac Mini, then these new M1 based Apple Macs are a great choice.

Written by smist08

December 23, 2020 at 11:10 am

Posted in Life, Mobility

Tagged with , , , ,

What’s Next for the Apple M2 ARM CPU

with 3 comments

Introduction

Last week, Apple started shipping their new ARM M1 based Macintosh computers. I ordered a new MacBook Air and maybe I’ll get it before XMas. The demand for these new ARM based computers is high and they are selling like mad. The big attraction is that they have the computing power of top end Intel chips, but use a tenth of the power, leading to a new class of powerful laptops with battery life now measured in days rather than hours. With all the hype around the M1, people are starting to ask where Apple will go next? When will there be an M2 chip and what will it contain? Apple is a secretive company so all this speculation is mostly rumours. This article will look at my wish list and where I think things will go.

First, there will be more M1 base Macs early next year. Expect higher end MacBook Pros, these won’t have a completely new M2, more like an M1X which will have either more CPU or CPU cores and higher memory options. I expect the real M2 will come out towards next XMas as Apple prepares all their new products for the next holiday shopping season.

The Chip Manufacturing Process

The current M1 CPU is manufactured using TSMC’s 5nm process. TSMC recently completed their 3nm fabrication facility (at least the building). The expectation is that the next generation of Apple’s iPhone, iPad and Mac chips will be created using this process. With this size reduction, Apple will be able to fit 1.67 times as many transistors on the chip using the same form factor and power. Compare this to Intel which has been having trouble making the transition from 14nm to 10nm over the last few years. Of course AMD also uses TSMC to manufacture their chips, so there could be competitive AMD chips, but reaching the same power utilization as an ARM CPU is extremely difficult.

Samsung manufactures most of its chips using 8nm technology and is investing heavily trying to catch up to TSMC, hoping to get some of Apple and AMD’s business back. I don’t think Samsung will catch up in 2021 but beyond 2021, the competition could heat up and we’ll see even faster progress.

More Cores

The most obvious place to make use of all these extra transistors is in placing more CPU, GPU or AIPU cores on the chip. The M1 has 8 CPU cores, 8 GPU cores and 16 AI Processor cores. Apple could add to any of these. If they want a more powerful gaming computer, then adding GPU cores is the obvious place. I suspect 8 CPU cores is sufficient for most laptop workloads, but with more GPU cores, they could start being competitive with top of the line nVidia and AMD GPUs. The AI processing cores are interesting and are being used more and more, 

Apple is continually profiling how their processor components are used by applications and will be monitoring which parts of the system are maxed out and which remain mostly idle. Using this information they can allocate more processing cores to the areas that need it most.

More Memory

The current M1 chips come with either 8 or 16 GB of RAM. I suspect this is only a limitation of trying to get some systems shipping in 2020 and that there will be higher memory M1 chips sooner than later. For the M2 chip, I don’t think we really need an 8GB model anymore and if there are two sizes it should be 16 or 32 GB. Further, with high end graphics using a lot of memory, a good case for 64 GB can be made even for a laptop.

More and Faster Ports

The first few Mac computers have 2 USB 4 ports and one video port. There has been a lot of complaining about this, but it is a bit misleading because you can add hubs to these ports. It has been demonstrated that you can actually connect 6 monitors to the video out using a hub. Similarly you can connect a hub and have any number of ports. I’m not sure if Apple will add more ports back and either way I’m not too worried about it.

The good thing is that USB 4 is fast and it makes connecting an external drive (whether SSD or mechanical) more practical for general use. Of course making the ports even faster next time around would be great.

General Optimizations

Each year, ARM improves their CPU cores and Apple incorporates these improvements. The optimizations could be to the pipeline processing, improved algorithms for longer running operations, better out of order execution, security improvements, etc. There are also newer instructions and functionality incorporated. Apple takes all these and adds their own improvements as well. We’ve seen this year over year as the performance of the ARM processors have improved so much in the iPhones and iPads. This will continue and this alone will yield a 30% or so performance improvement.

More Co-processors

The M1 chip is more than a multi-core ARM CPU. It includes all sorts of co-processors like the GPU cores and AI processing. It includes the main RAM, memory controller, a security processor and support for specialty things like video decoding. We don’t know what Apple is working on, but they could easily use some fraction of their transistor budget to add new specialty co-processors. Hopefully whatever they do add is open for programmers to take advantage of and not proprietary and only used by the operating system.

Summary

The Apple M1 Silicon is a significant first milestone. Everyone is excited to see where Apple will go with this. Apple has huge resources to develop these chips going forwards. The R&D Apple puts into Apple Silicon benefits all their businesses from the Apple Watch to the iPad, so they are fully committed to this. I’m excited to see what the next generation chips will be able to do, though I’m hoping to use my M1 based MacBook for 8 years, like I did with my last MacBook.

If you are interested in the M1 ARM processor and want to learn more about how it works internally, then consider my book: Programming with 64-Bit ARM Assembly Language.

Written by smist08

November 27, 2020 at 10:56 am

Apple M1 Unified Memory

leave a comment »

Introduction

I recently upgraded three 2008 MacBook Pros from 1Gig to 4Gig of RAM. It was super-easy, you remove the battery (accessible via a coin), remove a small cover over the RAM and hard-drive, then pop the RAM and push in the new ones. Upgrading the hard drive or RAM on these old laptops is straightforward and anyone can do it. Newer MacBooks require partial disassembly which makes the process harder. For the newest ARM based MacBooks, upgrading is impossible. So, do we gain anything for this lack of upgradeability?

This article looks at Apple’s new unified memory architecture that they claim gives large performance gains. Apple hasn’t released a lot of in depth technical details on the M1 chip, but from what they have released, and now that people have received these units and performed real benchmarks we can see that Apple really does have something here.

Why Would We Want To Upgrade?

In the case of the 2008 MacBook Pro, when it was new, 4Gig was expensive. Now 4Gig of DDR2 memory is $10. It makes total sense to upgrade to maximum memory. Similarly, the MacBook came with a mechanical hard drive which is quite small and slow by modern standards. It was easy to upgrade these to larger faster SSD drives for around $40 each.Often this is the case that the maximum configuration is too expensive at the time of the original purchase, but becomes much cheaper a few years later. Performing these upgrades then lets you get quite a few years more service out of your computer. The 2008 MacBook Pros upgraded to maximum configuration are still quite usable computers (of course you have to run Linux on them, since Apple software no longer supports them).

Enter the New Apple ARM Based Macintoshes

The newly released MacBooks based on ARM System on a Chips (SoCs) have their RAM integrated into their CPU chips. This means that unless you can replace the entire CPU, you can’t upgrade the RAM. Apple claims integrating the memory into the CPU gives them a number of performance gains, since the memory is high speed, very close to all the devices and shared by all the devices. A major bottleneck in modern computer systems is moving data between memory and the CPU or copying data from the CPU’s memory to the GPU’s memory.

AMD and nVidia graphics cards contain their own memory separate from the memory used by the CPU. So a modern gaming computer might have 16Gig RAM for the CPU and then 8Gig or RAM for the GPU. If you want the GPU to perform a matrix multiplication you need to transfer the matrices to the GPU, tell it to multiply them and then transfer the resulting matrix back to the CPU’s memory. nVidia and AMD claim this is necessary since they incorporate newer faster memory in their GPUs than is typically installed on the CPU motherboard. Most CPUs currently use DDR4 memory whereas GPUs typically incorporate faster DDR6 memory. There are GPUs (like the Raspberry Pi’s) that share CPU memory, however these tend to be lower end (cheaper since they don’t have their own memory) and slower since there is more contention for the CPU memory.

The Apple M1 tries to address these problems by incorporating the fastest memory and then providing a much wider bandwidth between the memory and the various processors on the M1 chip. For the M1 there isn’t just the GPU, but also a Neural Engine for AI processing (which is similar to a GPU) as well as other units for specialized functions like data encryption and video decoding. Most newer computers have a 64-bit memory controller that can move 64-bits of data between the CPU and RAM at the speed of the RAM, sometimes the RAM is as fast as the CPU, sometimes it’s a bit slower. Newer CPUs have large caches to try to save on some of this transfer, but the caches are in MegaBytes whereas main memory is in GigaBytes. Separate GPU memory helps by having a completely separate memory controller, expensive servers help by having multiple memory controllers. Apple’s block diagrams seem to indicate they have two 64-bit memory controllers or parallel pathways to main memory, but this is a bit hypothetical. As people are benchmarking these new computers, it does appear that Apple has made some significant performance improvements.

Summary

If Apple has greatly reduced the memory bottleneck and having the GPU, Neural Engine and CPU all accessing the same memory doesn’t cause too much contention, then saving the copying of data between the processing units will be a big advantage. On the downside, you should overbuy on the memory now, since you can’t upgrade it later.

If you are interested in the M1 ARM processor and want to learn more about how it works internally, then consider my book: Programming with 64-Bit ARM Assembly Language.

Written by smist08

November 20, 2020 at 1:09 pm

Apple Mac ARM M1 Competitive Trade-offs

with 3 comments

Introduction

Earlier this week, Apple started their transition from using Intel CPUs to ARM CPUs in their Macintosh laptop and desktop computers. Although the actual computers don’t ship for a week or two, there has been a lot of press coverage comparing these to various Intel/AMD offerings. In this article, we’ll look at what Apple is trying to accomplish with this transition. Note that Apple pushed out three computers to fulfill their promise of shipping ARM based Macs before the end of the year, so there is lots of room for gaps in the current offerings to be filled early in 2021.

It’s All About Power and Heat

iPhones and iPads are powerful computers in their own right, and they need to run for days without recharging. Compare that to top of the line gaming laptops that have trouble running for more than an hour or two without recharging. Apple realizes that we live in a mobile world and don’t like being a slave to power cords. With the ARM processor, Apple realized that they now have the power of Intel/AMD chips, but at a fraction of the power. Hence, the new M1/ARM based Apple Laptops can run for possibly 24 hours of use between charges. This means, if you are ever allowed to fly to Australia again, you can work for the entire 16 hour flight without a worry.

The M1 ARM CPU used in these new computers utilize the ARM big.LITTLE architecture that allows the mixing of high power/low efficiency cores with low power/high efficiency cores on the same chip. The MacOS Big Sur has been tuned to correctly schedule threads to the appropriate type of core for the job that needs to be done. The M1 has four high power cores and four low power cores. Intel is considering introducing big.LITTLE chips, but if they do, they will need to get both Windows and Linux to add support for this, until then, it will do more harm than good.

The M1 ARM CPU is manufactured using TSMC’s 5nm process technology which allows record numbers of transistors on a chip. As a consequence Apple has combined the CPUs, GPUs, memory and other co-processors all onto a single chip. This is a potential problem as the more functions of the chip in use at once, the more heat will be produced. The MacBook Air doesn’t even have a fan, so it will be interesting to see how it manages under heavy load. If you run a workload that utilizes all eight cores, is graphics intensive and performs AI computations, then that will be a lot of transistors in use at once.

All modern chips monitor their temperature and if it gets too high then they throttle down the speed. The higher the clock rate of a CPU, the higher the power consumed and the more heat produced. Thus throttling down the CPU is a good method to let a CPU cool off.

Apple has chosen their design to maximize battery life, which means reducing the power used. Reducing the power used, then reduces the cooling required that then saves on the energy and space used by fans. Apple is making big claims about how good the performance of these new computers will be, while maintaining low power usage and not overheating. If they are successful at this, it will be a huge competitive advantage.

Look at the top performing Intel/AMD gaming systems. They require liquid cooling on the CPU chip and there are typically six fans installed in the case. Then an nVidia RTX3090 has a further three fans installed on the GPU board. With all this, people still complain about overheating and the throttling of the games they are playing. Are the new Apple systems going to turn these into dinosaurs?

Software Compatibility

The downside of switching CPU types, is that you require all your software to be re-compiled. Admittedly for Java, you just need the JavaVM recompiled, and interpreted programs like written in Python, Julia or JavaScript shouldn’t require reworking. The truth is that people have been running Intel programs for a long time and they probably have a number of programs that are written in Objective-C (being the Macs previous favorite programming language) and that these will need to be recompiled to work best on the new Macs.

MacOS Big Sur includes an Intel emulation layer called Rosetta that can efficiently translate Intel Assembly language into ARM Assembly language and the claim is that it works quite well. If you received a new M1 MacBook Air today, it would run Microsoft Office this way. Microsoft has a beta of a native ARM version of Office, but the released version could be a few weeks or months away.

Note that the Rosetta emulation layer can’t run everything. If the program uses newer Intel AVX instructions, then it will fail. The emulation only covers the core instruction set and not any extensions like the AVX vector processing instructions.

Another problem is virtual machines (VMs). Many Mac users occasionally have a need for a Windows program. With Intel based Macs you can run Windows in a VM. With the new M1 Macs, new VM software is going to be required to run Intel VMs on the ARM processors and I don’t know how well this will work.

On the other hand, now that the Macs are ARM based, they can natively run all iPhone and iPad apps, so although you lose a few compiled programs and VMs, you gain all this mobile software.

The Raspberry Pi is also ARM based and has a huge amount of software available for this. The Raspberry Pi has already driven a lot of software to ARM, perhaps helping ease the road for Apple.

Summary

Apple made the choice to switch to the ARM processor for their Mac computers to greatly lower power usage, extending their laptop’s battery life. The cost of switching CPUs is software compatibility, which Apple is mitigating with Rosetta and the availability of iOS apps. I think long term this strategy is a winning one. If you mostly run Apple software like Pages or Final Cut then you can get a new Mac now, if you need it. If you are a developer, developing for iOS using XCode then these M1 Macs become the development platform of choice since you can run your software directly without emulation.

Otherwise, you might want to wait till the software you use is re-released with ARM native versions, also down the road there will be more powerful models, for instance with memory beyond 16GB.

If you are interested in the M1 ARM processor and want to learn more about how it works internally, then consider my book: Programming with 64-Bit ARM Assembly Language.

Written by smist08

November 13, 2020 at 10:51 am

Posted in Business, Mobility

Tagged with , , , ,

Apple Macs Move to ARM Processors

with 7 comments

Introduction

I watched Apple’s introduction of their new Mac computers based on Apple Silicon which contain ARM CPUs. Of course I was excited about this since I wrote two books on ARM Assembly Language Programming. ARM processors are used in nearly all cell phones and tablets. They are used in single board computers like the Raspberry Pi as well as many IoT devices. Finally it looks like we are getting a good line of computers based on ARM processors. In this article we’ll look at why this is a good thing, as well as some of the hurdles that Apple will need to jump for this to be a success.

A Bit of History

The first Macs contained Motorola 68000 series CPUs, then Apple moved to IBM’s PowerPC chips and then on to using Intel CPUs like all other PCs. The Motorola 68000 was a CISC CPU that competed with Intel in the early days to be the heart of the PC. Intel won the race and Motorola lost interest in spending the billions that were required to keep this line of processors competitive. Apple made the decision to jump to IBM’s new RISC based PowerPC platform. Initially this was quite successful, but again IBM didn’t think it was worth investing the money required to keep up with Intel. Intel was competing fiercely against AMD to maintain a lead in processor technology and this battle between Intel and AMD left IBM in their dust. Apple saw the writing on the wall and moved the Mac line of computers to Intel processors.

Advance a few years, and the battle has moved to cell phones. Cell phones all use ARM processors mainly due to their lower power requirements. Now there is a furious battle between the various ARM chip makers to have the faster cell phone. Now the tables have turned and Intel is being left in the dust as its chips are getting older and it is having trouble competing. This gives Apple the chance to move to faster ARM processors that use less power (hence longer battery life) with the added advantage that all their devices from watches to phones to tablets to laptops to desktops all use variations of the same ARM processor.

The Apple M1 Processor

With these new ARM based Apple Macs, Apple introduced their new Apple M1 System on a Chip (SoC). This SoC contains eight ARM CPU cores, 4 are high power units, and 4 are lower power. The new MacOS dispatches threads based on whether they need to save power or maximize performance. This chip incorporates the CPU, GPU and memory all into one chip. The main downside of this is that this will be the least upgradeable Mac yet. I would recommend getting a higher configuration since you won’t be able to add to it down the road.

This is an impressive chip that Apple claims will be competitive with Intel i9 processors. It will be interesting to see the real benchmarks when these computers actually ship next week.

Unified Software

Now that iOS and MacOS programs use the same processor, it makes writing applications that run on everything from watches and phones to laptops and desktop easier. If you need some Assembly language optimizations, now you only need to include the same ARM code for all of them. It’s really cool that you can now run iPhone and iPad apps on your Mac.

Downsides

There are a couple of downsides to this approach, one is the lack up upgradeability due to the memory being included on the CPU chip. Another is that all software needs to be recompiled for the ARM processor. Apple has made this as easy as possible, so hopefully all the main software packages will be updated with ARM versions.

Even if a software vendor doesn’t do this (perhaps they went out of business), these new Macs claim they can run the software anyway by using an Intel emulator called Rosetta. We’ll have to get some real feedback on how well this works, but Apple claims it runs Intel programs better than only slightly older Intel processors.

The other headwind with Apple products is the price. These are higher end products that compete with Microsoft Surface and higher end Dell models. However there are a lot of much cheaper laptops from vendors like Acer or HP. I purchased a MacBook Air in 2012 and it is still going strong, a very solid laptop. The Sunshine Coast Tech Hub maintains half a dozen 2008 MacBook Pros that we use for an Arduino kids coding camp and all these laptops are going strong (admittedly upgraded to SSD drives and running Linux Mint). The price of these new ARM laptops are the same as the previous equivalent Intel models and my experience with Apple products is that they do last.

Will Microsoft and Others Follow?

ARM has released their Cortex A78C CPU that is an 8 core CPU for laptops and desktops where all 8 cores are high performance. How many other hardware vendors will try releasing laptops and desktops based on this chip? Linux runs fine on ARM CPUs, just look at the Raspberry Pi or nVidia Jetson Nano. Microsoft has a simplified version of Windows, similar to ChromeOS for ARM laptops. Will Microsoft support the full Windows Home and Pro on ARM? It will be interesting to see what new devices get released in 2021.

Summary

I’m excited about the new ARM based Apple Macs. If you want to learn more about the ARM CPU, check out one of my books on ARM Assembly Language programming such as the one pictured below. It will be interesting to see how these sell compared to Intel/AMD computers and how many other vendors choose to support ARM CPUs in laptops and desktops in 2021.

Written by smist08

November 10, 2020 at 3:12 pm