Stephen Smith's Blog

Musings on Machine Learning…

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

12 Responses

Subscribe to comments with RSS.

  1. I will stick with the Raspberry Pi, it costs less than one adapter for any of the MacBooks.

    jlgreer1

    January 1, 2021 at 12:05 pm

  2. […] 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 …View full source […]

  3. […] 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. […]

  4. Having just received a minimally configured M1 MacBook Air, I must say that it is the best Apple computer I have ever owned and I have had Macs since 1984. It is also the cheapest!

    As a retired physicist I wanted to learn it use assembly language to speed up some of my already written physics demos. (I have some experience with assembly language programming on DEC machines: a PDP-8 and PDP-11). I therefore bought your book, which I am enjoying very much.

    I did notice on page 95 a statement which is at odds with my understanding of 2’s complement addition. You say, “When addition overflows, it sets the carry flag”. This is true for unsigned addition but not, I believe, for signed addition. For example, for 8-but signed addition, adding (Hex) 41+42=84. This overflows (84 Hex is larger than the largest positive number represented by a signed byte) but there is no carry. The rule is, I believe, that overflow occurs when the exclusive OR of the carry into the most significant bit and the carry out yields a one (I.e., they are both different). Is this not the case?

    Thanks very much for a wonderful and much needed book.

    Warren Nagourney

    February 17, 2021 at 9:31 am

    • Sorry for the typos. I wanted 42+42=84.

      Warren Nagourney

      February 17, 2021 at 9:33 am

    • Yes, you are correct. I should correct/tighten this up in a future edition. Thanks.

      smist08

      February 17, 2021 at 11:52 am

  5. […] 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 […]

  6. […] you debug by running the application in the iOS/WatchOS simulator. The nice thing about my new ARM based Mac is that the simulator is quite fast, since it doesn’t have to simulate running an ARM CPU on an […]

  7. You mentioned Fortran. A native version of gfortran is available and in my limited testing seems to work very well. You need the latest version of the Xcode command-line tools or you well get linking errors. I am not sure whether it needs gcc, but that is also available in the recently released native version of Homebrew. The gfortran is available at: https://github.com/fxcoudert/gfortran-for-macOS/releases

    Fortran is my favorite language for number crunching. I learned it from a class taught by one of its developers in 1961. It is a rather unfortunate indication of Apple’s lack of interest in the scientific and engineering community that their preferred language, Swift, doesn’t have a native complex data type, making it useless for many scientific numerical calculations.

    Warren Nagourney

    March 31, 2021 at 11:13 am

    • Yes and from Home Brew, they have a full native port of all of GCC now including Fortran. They then have used it to build most of the Python libraries that still have Fortran components.

      smist08

      March 31, 2021 at 1:01 pm

  8. Sorry, that date (when I learned fortran) was 1966

    Warren Nagourney

    March 31, 2021 at 11:15 am

    • FORTRAN works, but interactive debugging does not allow inspection of variables. This is a big issue when developing code. Because of this, most FORTRAN developers will have to use LINUX or WINDOWS for adequate interactive debugging capability.

      Rex

      January 23, 2022 at 12:49 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: